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

Commit 2a30744c authored by Leon Scroggins's avatar Leon Scroggins
Browse files

Line up textfield with WebTextView more often.

Bug:3097705

Line up when the selection changes (such as when the
selection is altered by the context menu) or when the
WebTextView scrolls.

Change-Id: Ia491064548131be1ac6f4d701a43cd8419a25367
parent c1e7b218
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -288,6 +288,21 @@ import java.util.ArrayList;
        return ptr == mNodePointer;
    }

    /**
     * Ensure that the underlying textfield is lined up with the WebTextView.
     */
    private void lineUpScroll() {
        if (mWebView != null) {
            float maxScrollX = Touch.getMaxScrollX(this, getLayout(), mScrollY);
            if (DebugFlags.WEB_TEXT_VIEW) {
                Log.v(LOGTAG, "onTouchEvent x=" + mScrollX + " y="
                        + mScrollY + " maxX=" + maxScrollX);
            }
            mWebView.scrollFocusedTextInput(maxScrollX > 0 ?
                    mScrollX / maxScrollX : 0, mScrollY);
        }
    }

    @Override public InputConnection onCreateInputConnection(
            EditorInfo outAttrs) {
        InputConnection connection = super.onCreateInputConnection(outAttrs);
@@ -358,6 +373,12 @@ import java.util.ArrayList;
        mFromFocusChange = false;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        lineUpScroll();
    }

    @Override
    protected void onSelectionChanged(int selStart, int selEnd) {
        if (mInSetTextAndKeepSelection) return;
@@ -378,6 +399,7 @@ import java.util.ArrayList;
                        + " selEnd=" + selEnd);
            }
            mWebView.setSelection(selStart, selEnd);
            lineUpScroll();
        }
    }

@@ -481,16 +503,7 @@ import java.util.ArrayList;
            // to big for the case of a small textfield.
            int smallerSlop = slop/2;
            if (dx > smallerSlop || dy > smallerSlop) {
                if (mWebView != null) {
                    float maxScrollX = (float) Touch.getMaxScrollX(this,
                                getLayout(), mScrollY);
                    if (DebugFlags.WEB_TEXT_VIEW) {
                        Log.v(LOGTAG, "onTouchEvent x=" + mScrollX + " y="
                                + mScrollY + " maxX=" + maxScrollX);
                    }
                    mWebView.scrollFocusedTextInput(maxScrollX > 0 ?
                            mScrollX / maxScrollX : 0, mScrollY);
                }
                // Scrolling is handled in onScrollChanged.
                mScrolled = true;
                cancelLongPress();
                return true;