@@ -846,7 +846,7 @@ protected void measureContent() {
846846 private int mFieldPointer ;
847847 private PastePopupWindow mPasteWindow ;
848848 private AutoCompletePopup mAutoCompletePopup ;
849- Rect mEditTextBounds = new Rect ();
849+ Rect mEditTextContentBounds = new Rect ();
850850 Rect mEditTextContent = new Rect ();
851851 int mEditTextLayerId ;
852852 boolean mIsEditingText = false ;
@@ -1230,6 +1230,7 @@ public void onTrimMemory(int level) {
12301230 static final int ANIMATE_TEXT_SCROLL = 149 ;
12311231 static final int EDIT_TEXT_SIZE_CHANGED = 150 ;
12321232 static final int SHOW_CARET_HANDLE = 151 ;
1233+ static final int UPDATE_CONTENT_BOUNDS = 152 ;
12331234
12341235 private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID ;
12351236 private static final int LAST_PACKAGE_MSG_ID = HIT_TEST_RESULT ;
@@ -3865,7 +3866,7 @@ private void scrollLayerTo(int x, int y) {
38653866 }
38663867 if (mAutoCompletePopup != null &&
38673868 mCurrentScrollingLayerId == mEditTextLayerId ) {
3868- mEditTextBounds .offset (dx , dy );
3869+ mEditTextContentBounds .offset (dx , dy );
38693870 mAutoCompletePopup .resetRect ();
38703871 }
38713872 nativeScrollLayer (mCurrentScrollingLayerId , x , y );
@@ -6094,7 +6095,8 @@ public void run() {
60946095 }
60956096 startTouch (x , y , eventTime );
60966097 if (mIsEditingText ) {
6097- mTouchInEditText = mEditTextBounds .contains (contentX , contentY );
6098+ mTouchInEditText = mEditTextContentBounds
6099+ .contains (contentX , contentY );
60986100 }
60996101 break ;
61006102 }
@@ -6120,8 +6122,23 @@ public void run() {
61206122 parent .requestDisallowInterceptTouchEvent (true );
61216123 }
61226124 if (deltaX != 0 || deltaY != 0 ) {
6123- snapDraggingCursor (contentX , contentY );
6125+ int handleX = contentX +
6126+ viewToContentDimension (mSelectDraggingOffset .x );
6127+ int handleY = contentY +
6128+ viewToContentDimension (mSelectDraggingOffset .y );
6129+ mSelectDraggingCursor .set (handleX , handleY );
6130+ boolean inCursorText =
6131+ mSelectDraggingTextQuad .containsPoint (handleX , handleY );
6132+ boolean inEditBounds = mEditTextContentBounds
6133+ .contains (handleX , handleY );
6134+ if (inCursorText || (mIsEditingText && !inEditBounds )) {
6135+ snapDraggingCursor ();
6136+ }
61246137 updateWebkitSelection ();
6138+ if (!inCursorText && mIsEditingText && inEditBounds ) {
6139+ // Visually snap even if we have moved the handle.
6140+ snapDraggingCursor ();
6141+ }
61256142 mLastTouchX = x ;
61266143 mLastTouchY = y ;
61276144 invalidate ();
@@ -6735,23 +6752,22 @@ private void cancelTouch() {
67356752 mTouchMode = TOUCH_DONE_MODE ;
67366753 }
67376754
6738- private void snapDraggingCursor (int x , int y ) {
6739- x += viewToContentDimension (mSelectDraggingOffset .x );
6740- y += viewToContentDimension (mSelectDraggingOffset .y );
6741- if (mSelectDraggingTextQuad .containsPoint (x , y )) {
6742- float scale = scaleAlongSegment (x , y ,
6743- mSelectDraggingTextQuad .p4 , mSelectDraggingTextQuad .p3 );
6744- // clamp scale to ensure point is on the bottom segment
6745- scale = Math .max (0.0f , scale );
6746- scale = Math .min (scale , 1.0f );
6747- float newX = scaleCoordinate (scale ,
6748- mSelectDraggingTextQuad .p4 .x , mSelectDraggingTextQuad .p3 .x );
6749- float newY = scaleCoordinate (scale ,
6750- mSelectDraggingTextQuad .p4 .y , mSelectDraggingTextQuad .p3 .y );
6751- mSelectDraggingCursor .set (Math .round (newX ), Math .round (newY ));
6752- } else {
6753- mSelectDraggingCursor .set (x , y );
6754- }
6755+ private void snapDraggingCursor () {
6756+ float scale = scaleAlongSegment (
6757+ mSelectDraggingCursor .x , mSelectDraggingCursor .y ,
6758+ mSelectDraggingTextQuad .p4 , mSelectDraggingTextQuad .p3 );
6759+ // clamp scale to ensure point is on the bottom segment
6760+ scale = Math .max (0.0f , scale );
6761+ scale = Math .min (scale , 1.0f );
6762+ float newX = scaleCoordinate (scale ,
6763+ mSelectDraggingTextQuad .p4 .x , mSelectDraggingTextQuad .p3 .x );
6764+ float newY = scaleCoordinate (scale ,
6765+ mSelectDraggingTextQuad .p4 .y , mSelectDraggingTextQuad .p3 .y );
6766+ int x = Math .max (mEditTextContentBounds .left ,
6767+ Math .min (mEditTextContentBounds .right , Math .round (newX )));
6768+ int y = Math .max (mEditTextContentBounds .top ,
6769+ Math .min (mEditTextContentBounds .bottom , Math .round (newY )));
6770+ mSelectDraggingCursor .set (x , y );
67556771 }
67566772
67576773 private static float scaleCoordinate (float scale , float coord1 , float coord2 ) {
@@ -7543,11 +7559,11 @@ private int getTextScrollY() {
75437559 }
75447560
75457561 private int getMaxTextScrollX () {
7546- return Math .max (0 , mEditTextContent .width () - mEditTextBounds .width ());
7562+ return Math .max (0 , mEditTextContent .width () - mEditTextContentBounds .width ());
75477563 }
75487564
75497565 private int getMaxTextScrollY () {
7550- return Math .max (0 , mEditTextContent .height () - mEditTextBounds .height ());
7566+ return Math .max (0 , mEditTextContent .height () - mEditTextContentBounds .height ());
75517567 }
75527568
75537569 /**
@@ -8455,10 +8471,10 @@ public void handleMessage(Message msg) {
84558471 mFieldPointer = initData .mFieldPointer ;
84568472 mInputConnection .initEditorInfo (initData );
84578473 mInputConnection .setTextAndKeepSelection (initData .mText );
8458- mEditTextBounds .set (initData .mNodeBounds );
8474+ mEditTextContentBounds .set (initData .mContentBounds );
84598475 mEditTextLayerId = initData .mNodeLayerId ;
84608476 nativeMapLayerRect (mNativeClass , mEditTextLayerId ,
8461- mEditTextBounds );
8477+ mEditTextContentBounds );
84628478 mEditTextContent .set (initData .mContentRect );
84638479 relocateAutoCompletePopup ();
84648480 }
@@ -8531,6 +8547,10 @@ public void handleMessage(Message msg) {
85318547 }
85328548 break ;
85338549
8550+ case UPDATE_CONTENT_BOUNDS :
8551+ mEditTextContentBounds .set ((Rect ) msg .obj );
8552+ break ;
8553+
85348554 default :
85358555 super .handleMessage (msg );
85368556 break ;
0 commit comments