@@ -847,7 +847,7 @@ protected void measureContent() {
847847 private int mFieldPointer ;
848848 private PastePopupWindow mPasteWindow ;
849849 private AutoCompletePopup mAutoCompletePopup ;
850- Rect mEditTextBounds = new Rect ();
850+ Rect mEditTextContentBounds = new Rect ();
851851 Rect mEditTextContent = new Rect ();
852852 int mEditTextLayerId ;
853853 boolean mIsEditingText = false ;
@@ -1231,6 +1231,7 @@ public void onTrimMemory(int level) {
12311231 static final int ANIMATE_TEXT_SCROLL = 149 ;
12321232 static final int EDIT_TEXT_SIZE_CHANGED = 150 ;
12331233 static final int SHOW_CARET_HANDLE = 151 ;
1234+ static final int UPDATE_CONTENT_BOUNDS = 152 ;
12341235
12351236 private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID ;
12361237 private static final int LAST_PACKAGE_MSG_ID = HIT_TEST_RESULT ;
@@ -3866,7 +3867,7 @@ private void scrollLayerTo(int x, int y) {
38663867 }
38673868 if (mAutoCompletePopup != null &&
38683869 mCurrentScrollingLayerId == mEditTextLayerId ) {
3869- mEditTextBounds .offset (dx , dy );
3870+ mEditTextContentBounds .offset (dx , dy );
38703871 mAutoCompletePopup .resetRect ();
38713872 }
38723873 nativeScrollLayer (mCurrentScrollingLayerId , x , y );
@@ -6095,7 +6096,8 @@ public void run() {
60956096 }
60966097 startTouch (x , y , eventTime );
60976098 if (mIsEditingText ) {
6098- mTouchInEditText = mEditTextBounds .contains (contentX , contentY );
6099+ mTouchInEditText = mEditTextContentBounds
6100+ .contains (contentX , contentY );
60996101 }
61006102 break ;
61016103 }
@@ -6121,8 +6123,23 @@ public void run() {
61216123 parent .requestDisallowInterceptTouchEvent (true );
61226124 }
61236125 if (deltaX != 0 || deltaY != 0 ) {
6124- snapDraggingCursor (contentX , contentY );
6126+ int handleX = contentX +
6127+ viewToContentDimension (mSelectDraggingOffset .x );
6128+ int handleY = contentY +
6129+ viewToContentDimension (mSelectDraggingOffset .y );
6130+ mSelectDraggingCursor .set (handleX , handleY );
6131+ boolean inCursorText =
6132+ mSelectDraggingTextQuad .containsPoint (handleX , handleY );
6133+ boolean inEditBounds = mEditTextContentBounds
6134+ .contains (handleX , handleY );
6135+ if (inCursorText || (mIsEditingText && !inEditBounds )) {
6136+ snapDraggingCursor ();
6137+ }
61256138 updateWebkitSelection ();
6139+ if (!inCursorText && mIsEditingText && inEditBounds ) {
6140+ // Visually snap even if we have moved the handle.
6141+ snapDraggingCursor ();
6142+ }
61266143 mLastTouchX = x ;
61276144 mLastTouchY = y ;
61286145 invalidate ();
@@ -6736,23 +6753,22 @@ private void cancelTouch() {
67366753 mTouchMode = TOUCH_DONE_MODE ;
67376754 }
67386755
6739- private void snapDraggingCursor (int x , int y ) {
6740- x += viewToContentDimension (mSelectDraggingOffset .x );
6741- y += viewToContentDimension (mSelectDraggingOffset .y );
6742- if (mSelectDraggingTextQuad .containsPoint (x , y )) {
6743- float scale = scaleAlongSegment (x , y ,
6744- mSelectDraggingTextQuad .p4 , mSelectDraggingTextQuad .p3 );
6745- // clamp scale to ensure point is on the bottom segment
6746- scale = Math .max (0.0f , scale );
6747- scale = Math .min (scale , 1.0f );
6748- float newX = scaleCoordinate (scale ,
6749- mSelectDraggingTextQuad .p4 .x , mSelectDraggingTextQuad .p3 .x );
6750- float newY = scaleCoordinate (scale ,
6751- mSelectDraggingTextQuad .p4 .y , mSelectDraggingTextQuad .p3 .y );
6752- mSelectDraggingCursor .set (Math .round (newX ), Math .round (newY ));
6753- } else {
6754- mSelectDraggingCursor .set (x , y );
6755- }
6756+ private void snapDraggingCursor () {
6757+ float scale = scaleAlongSegment (
6758+ mSelectDraggingCursor .x , mSelectDraggingCursor .y ,
6759+ mSelectDraggingTextQuad .p4 , mSelectDraggingTextQuad .p3 );
6760+ // clamp scale to ensure point is on the bottom segment
6761+ scale = Math .max (0.0f , scale );
6762+ scale = Math .min (scale , 1.0f );
6763+ float newX = scaleCoordinate (scale ,
6764+ mSelectDraggingTextQuad .p4 .x , mSelectDraggingTextQuad .p3 .x );
6765+ float newY = scaleCoordinate (scale ,
6766+ mSelectDraggingTextQuad .p4 .y , mSelectDraggingTextQuad .p3 .y );
6767+ int x = Math .max (mEditTextContentBounds .left ,
6768+ Math .min (mEditTextContentBounds .right , Math .round (newX )));
6769+ int y = Math .max (mEditTextContentBounds .top ,
6770+ Math .min (mEditTextContentBounds .bottom , Math .round (newY )));
6771+ mSelectDraggingCursor .set (x , y );
67566772 }
67576773
67586774 private static float scaleCoordinate (float scale , float coord1 , float coord2 ) {
@@ -7544,11 +7560,11 @@ private int getTextScrollY() {
75447560 }
75457561
75467562 private int getMaxTextScrollX () {
7547- return Math .max (0 , mEditTextContent .width () - mEditTextBounds .width ());
7563+ return Math .max (0 , mEditTextContent .width () - mEditTextContentBounds .width ());
75487564 }
75497565
75507566 private int getMaxTextScrollY () {
7551- return Math .max (0 , mEditTextContent .height () - mEditTextBounds .height ());
7567+ return Math .max (0 , mEditTextContent .height () - mEditTextContentBounds .height ());
75527568 }
75537569
75547570 /**
@@ -8456,10 +8472,10 @@ public void handleMessage(Message msg) {
84568472 mFieldPointer = initData .mFieldPointer ;
84578473 mInputConnection .initEditorInfo (initData );
84588474 mInputConnection .setTextAndKeepSelection (initData .mText );
8459- mEditTextBounds .set (initData .mNodeBounds );
8475+ mEditTextContentBounds .set (initData .mContentBounds );
84608476 mEditTextLayerId = initData .mNodeLayerId ;
84618477 nativeMapLayerRect (mNativeClass , mEditTextLayerId ,
8462- mEditTextBounds );
8478+ mEditTextContentBounds );
84638479 mEditTextContent .set (initData .mContentRect );
84648480 relocateAutoCompletePopup ();
84658481 }
@@ -8532,6 +8548,10 @@ public void handleMessage(Message msg) {
85328548 }
85338549 break ;
85348550
8551+ case UPDATE_CONTENT_BOUNDS :
8552+ mEditTextContentBounds .set ((Rect ) msg .obj );
8553+ break ;
8554+
85358555 default :
85368556 super .handleMessage (msg );
85378557 break ;
0 commit comments