Skip to content

Commit 7102eb2

Browse files
George MountAndroid (Google) Code Review
authored andcommitted
Revert "Revert "Keep selection handles in edit fields.""
This reverts commit 90c08ea
1 parent 90c08ea commit 7102eb2

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
@@ -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;

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)