Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d84368a authored by George Mount's avatar George Mount
Browse files

Keep selection handles in edit fields.

 Bug 6264769
 Webkit Change: Ie937a8c55da0f8aef66cfcee11beb961669b7168

Change-Id: I9ee89f8b1d4e6954092b8c4d677fb75b79354b36
parent cbcb24cd
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -129,13 +129,13 @@ class AutoCompletePopup implements OnItemClickListener, Filter.FilterListener {
    }

    public void resetRect() {
        int left = mWebView.contentToViewX(mWebView.mEditTextBounds.left);
        int right = mWebView.contentToViewX(mWebView.mEditTextBounds.right);
        int left = mWebView.contentToViewX(mWebView.mEditTextContentBounds.left);
        int right = mWebView.contentToViewX(mWebView.mEditTextContentBounds.right);
        int width = right - left;
        mPopup.setWidth(width);

        int bottom = mWebView.contentToViewY(mWebView.mEditTextBounds.bottom);
        int top = mWebView.contentToViewY(mWebView.mEditTextBounds.top);
        int bottom = mWebView.contentToViewY(mWebView.mEditTextContentBounds.bottom);
        int top = mWebView.contentToViewY(mWebView.mEditTextContentBounds.top);
        int height = bottom - top;

        AbsoluteLayout.LayoutParams lp =
+45 −25
Original line number Diff line number Diff line
@@ -846,7 +846,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
    private int mFieldPointer;
    private PastePopupWindow mPasteWindow;
    private AutoCompletePopup mAutoCompletePopup;
    Rect mEditTextBounds = new Rect();
    Rect mEditTextContentBounds = new Rect();
    Rect mEditTextContent = new Rect();
    int mEditTextLayerId;
    boolean mIsEditingText = false;
@@ -1230,6 +1230,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
    static final int ANIMATE_TEXT_SCROLL                = 149;
    static final int EDIT_TEXT_SIZE_CHANGED             = 150;
    static final int SHOW_CARET_HANDLE                  = 151;
    static final int UPDATE_CONTENT_BOUNDS              = 152;

    private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID;
    private static final int LAST_PACKAGE_MSG_ID = HIT_TEST_RESULT;
@@ -3865,7 +3866,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
        }
        if (mAutoCompletePopup != null &&
                mCurrentScrollingLayerId == mEditTextLayerId) {
            mEditTextBounds.offset(dx, dy);
            mEditTextContentBounds.offset(dx, dy);
            mAutoCompletePopup.resetRect();
        }
        nativeScrollLayer(mCurrentScrollingLayerId, x, y);
@@ -6094,7 +6095,8 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
                }
                startTouch(x, y, eventTime);
                if (mIsEditingText) {
                    mTouchInEditText = mEditTextBounds.contains(contentX, contentY);
                    mTouchInEditText = mEditTextContentBounds
                            .contains(contentX, contentY);
                }
                break;
            }
@@ -6120,8 +6122,23 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                    if (deltaX != 0 || deltaY != 0) {
                        snapDraggingCursor(contentX, contentY);
                        int handleX = contentX +
                                viewToContentDimension(mSelectDraggingOffset.x);
                        int handleY = contentY +
                                viewToContentDimension(mSelectDraggingOffset.y);
                        mSelectDraggingCursor.set(handleX, handleY);
                        boolean inCursorText =
                                mSelectDraggingTextQuad.containsPoint(handleX, handleY);
                        boolean inEditBounds = mEditTextContentBounds
                                .contains(handleX, handleY);
                        if (inCursorText || (mIsEditingText && !inEditBounds)) {
                            snapDraggingCursor();
                        }
                        updateWebkitSelection();
                        if (!inCursorText && mIsEditingText && inEditBounds) {
                            // Visually snap even if we have moved the handle.
                            snapDraggingCursor();
                        }
                        mLastTouchX = x;
                        mLastTouchY = y;
                        invalidate();
@@ -6735,11 +6752,9 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
        mTouchMode = TOUCH_DONE_MODE;
    }

    private void snapDraggingCursor(int x, int y) {
        x += viewToContentDimension(mSelectDraggingOffset.x);
        y += viewToContentDimension(mSelectDraggingOffset.y);
        if (mSelectDraggingTextQuad.containsPoint(x, y)) {
            float scale = scaleAlongSegment(x, y,
    private void snapDraggingCursor() {
        float scale = scaleAlongSegment(
                mSelectDraggingCursor.x, mSelectDraggingCursor.y,
                mSelectDraggingTextQuad.p4, mSelectDraggingTextQuad.p3);
        // clamp scale to ensure point is on the bottom segment
        scale = Math.max(0.0f, scale);
@@ -6748,11 +6763,12 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
                mSelectDraggingTextQuad.p4.x, mSelectDraggingTextQuad.p3.x);
        float newY = scaleCoordinate(scale,
                mSelectDraggingTextQuad.p4.y, mSelectDraggingTextQuad.p3.y);
            mSelectDraggingCursor.set(Math.round(newX), Math.round(newY));
        } else {
        int x = Math.max(mEditTextContentBounds.left,
                    Math.min(mEditTextContentBounds.right, Math.round(newX)));
        int y = Math.max(mEditTextContentBounds.top,
                    Math.min(mEditTextContentBounds.bottom, Math.round(newY)));
        mSelectDraggingCursor.set(x, y);
    }
    }

    private static float scaleCoordinate(float scale, float coord1, float coord2) {
        float diff = coord2 - coord1;
@@ -7543,11 +7559,11 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
    }

    private int getMaxTextScrollX() {
        return Math.max(0, mEditTextContent.width() - mEditTextBounds.width());
        return Math.max(0, mEditTextContent.width() - mEditTextContentBounds.width());
    }

    private int getMaxTextScrollY() {
        return Math.max(0, mEditTextContent.height() - mEditTextBounds.height());
        return Math.max(0, mEditTextContent.height() - mEditTextContentBounds.height());
    }

    /**
@@ -8455,10 +8471,10 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
                        mFieldPointer = initData.mFieldPointer;
                        mInputConnection.initEditorInfo(initData);
                        mInputConnection.setTextAndKeepSelection(initData.mText);
                        mEditTextBounds.set(initData.mNodeBounds);
                        mEditTextContentBounds.set(initData.mContentBounds);
                        mEditTextLayerId = initData.mNodeLayerId;
                        nativeMapLayerRect(mNativeClass, mEditTextLayerId,
                                mEditTextBounds);
                                mEditTextContentBounds);
                        mEditTextContent.set(initData.mContentRect);
                        relocateAutoCompletePopup();
                    }
@@ -8531,6 +8547,10 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
                    }
                    break;

                case UPDATE_CONTENT_BOUNDS:
                    mEditTextContentBounds.set((Rect) msg.obj);
                    break;

                default:
                    super.handleMessage(msg);
                    break;
+9 −3
Original line number Diff line number Diff line
@@ -949,7 +949,7 @@ public final class WebViewCore {
        public String mName;
        public String mLabel;
        public int mMaxLength;
        public Rect mNodeBounds;
        public Rect mContentBounds;
        public int mNodeLayerId;
        public Rect mContentRect;
    }
@@ -1299,7 +1299,13 @@ public final class WebViewCore {
                            } else {
                                xPercent = ((Float) msg.obj).floatValue();
                            }
                            nativeScrollFocusedTextInput(mNativeClass, xPercent, msg.arg2);
                            Rect contentBounds = new Rect();
                            nativeScrollFocusedTextInput(mNativeClass, xPercent,
                                    msg.arg2, contentBounds);
                            Message.obtain(
                                    mWebViewClassic.mPrivateHandler,
                                    WebViewClassic.UPDATE_CONTENT_BOUNDS,
                                    contentBounds).sendToTarget();
                            break;

                        case LOAD_URL: {
@@ -2845,7 +2851,7 @@ public final class WebViewCore {
     * Scroll the focused textfield to (xPercent, y) in document space
     */
    private native void nativeScrollFocusedTextInput(int nativeClass,
            float xPercent, int y);
            float xPercent, int y, Rect contentBounds);

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