Skip to content

Commit 1bee28f

Browse files
George MountAndroid (Google) Code Review
authored andcommitted
Merge "Revert "Revert "Keep selection handles in edit fields."""
2 parents cd1c059 + 7102eb2 commit 1bee28f

File tree

3 files changed

+58
-32
lines changed

3 files changed

+58
-32
lines changed

core/java/android/webkit/AutoCompletePopup.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
129129
}
130130

131131
public void resetRect() {
132-
int left = mWebView.contentToViewX(mWebView.mEditTextBounds.left);
133-
int right = mWebView.contentToViewX(mWebView.mEditTextBounds.right);
132+
int left = mWebView.contentToViewX(mWebView.mEditTextContentBounds.left);
133+
int right = mWebView.contentToViewX(mWebView.mEditTextContentBounds.right);
134134
int width = right - left;
135135
mPopup.setWidth(width);
136136

137-
int bottom = mWebView.contentToViewY(mWebView.mEditTextBounds.bottom);
138-
int top = mWebView.contentToViewY(mWebView.mEditTextBounds.top);
137+
int bottom = mWebView.contentToViewY(mWebView.mEditTextContentBounds.bottom);
138+
int top = mWebView.contentToViewY(mWebView.mEditTextContentBounds.top);
139139
int height = bottom - top;
140140

141141
AbsoluteLayout.LayoutParams lp =

core/java/android/webkit/WebViewClassic.java

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

core/java/android/webkit/WebViewCore.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ static class TextFieldInitData {
949949
public String mName;
950950
public String mLabel;
951951
public int mMaxLength;
952-
public Rect mNodeBounds;
952+
public Rect mContentBounds;
953953
public int mNodeLayerId;
954954
public Rect mContentRect;
955955
}
@@ -1299,7 +1299,13 @@ public void handleMessage(Message msg) {
12991299
} else {
13001300
xPercent = ((Float) msg.obj).floatValue();
13011301
}
1302-
nativeScrollFocusedTextInput(mNativeClass, xPercent, msg.arg2);
1302+
Rect contentBounds = new Rect();
1303+
nativeScrollFocusedTextInput(mNativeClass, xPercent,
1304+
msg.arg2, contentBounds);
1305+
Message.obtain(
1306+
mWebViewClassic.mPrivateHandler,
1307+
WebViewClassic.UPDATE_CONTENT_BOUNDS,
1308+
contentBounds).sendToTarget();
13031309
break;
13041310

13051311
case LOAD_URL: {
@@ -2845,7 +2851,7 @@ private native String nativeRequestLabel(int nativeClass, int framePtr,
28452851
* Scroll the focused textfield to (xPercent, y) in document space
28462852
*/
28472853
private native void nativeScrollFocusedTextInput(int nativeClass,
2848-
float xPercent, int y);
2854+
float xPercent, int y, Rect contentBounds);
28492855

28502856
// these must be in document space (i.e. not scaled/zoomed).
28512857
private native void nativeSetScrollOffset(int nativeClass,

0 commit comments

Comments
 (0)