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

Commit 40981269 authored by Leon Scroggins's avatar Leon Scroggins
Browse files

Fixes for moving a focused textfield on screen when entering a character.

When the focused node is a textfield, but the WebView has focus
(for example if the page had an initial focus) and the cursor
is not over a plugin or textfield, rebuild the WebTextView
to handle the keys.  Also, remove mScrollToAccommodateCursor,
since now the WebTextView is only showing when we want to
scroll.
parent 3ccd3655
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.webkit;

import android.content.Context;
import android.graphics.Rect;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Selection;
@@ -58,9 +57,6 @@ import java.util.ArrayList;
    // on the enter key.  The method for blocking unmatched key ups prevents
    // the shift key from working properly.
    private boolean         mGotEnterDown;
    // mScrollToAccommodateCursor being set to false prevents us from scrolling
    // the cursor on screen when using the trackball to select a textfield.
    private boolean         mScrollToAccommodateCursor;
    private int             mMaxLength;
    // Keep track of the text before the change so we know whether we actually
    // need to send down the DOM events.
@@ -189,7 +185,6 @@ import java.util.ArrayList;
            if (maxedOut && !isArrowKey && keyCode != KeyEvent.KEYCODE_DEL) {
                if (oldEnd == oldStart) {
                    // Return true so the key gets dropped.
                    mScrollToAccommodateCursor = true;
                    return true;
                } else if (!oldText.equals(getText().toString())) {
                    // FIXME: This makes the text work properly, but it
@@ -203,7 +198,6 @@ import java.util.ArrayList;
                    int newEnd = Selection.getSelectionEnd(span);
                    mWebView.replaceTextfieldText(0, oldLength, span.toString(),
                            newStart, newEnd);
                    mScrollToAccommodateCursor = true;
                    return true;
                }
            }
@@ -219,7 +213,6 @@ import java.util.ArrayList;
                sendDomEvent(event);
            }
             */
            mScrollToAccommodateCursor = true;
            return true;
        }
        // Ignore the key up event for newlines. This prevents
@@ -373,12 +366,6 @@ import java.util.ArrayList;
            // Selection is changed in onSelectionChanged
            return true;
        }
        // If the user is in a textfield, and the movement method is not
        // handling the trackball events, it means they are at the end of the
        // field and continuing to move the trackball.  In this case, we should
        // not scroll the cursor on screen bc the user may be attempting to
        // scroll the page, possibly in the opposite direction of the cursor.
        mScrollToAccommodateCursor = false;
        return false;
    }

@@ -392,11 +379,6 @@ import java.util.ArrayList;
                getWindowToken(), 0);
        mWebView.removeView(this);
        mWebView.requestFocus();
        mScrollToAccommodateCursor = false;
    }

    /* package */ void enableScrollOnScreen(boolean enable) {
        mScrollToAccommodateCursor = enable;
    }

    /* package */ void bringIntoView() {
@@ -405,14 +387,6 @@ import java.util.ArrayList;
        }
    }

    @Override
    public boolean requestRectangleOnScreen(Rect rectangle) {
        if (mScrollToAccommodateCursor) {
            return super.requestRectangleOnScreen(rectangle);
        }
        return false;
    }

    /**
     *  Send the DOM events for the specified event.
     *  @param event    KeyEvent to be translated into a DOM event.
+8 −3
Original line number Diff line number Diff line
@@ -3029,7 +3029,6 @@ public class WebView extends AbsoluteLayout

        if (isTextView) {
            imm.showSoftInput(mWebTextView, 0);
            mWebTextView.enableScrollOnScreen(true);
            // Now we need to fake a touch event to place the cursor where the
            // user touched.
            AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams)
@@ -3090,8 +3089,7 @@ public class WebView extends AbsoluteLayout
        // should be in content coordinates.
        Rect bounds = nativeFocusCandidateNodeBounds();
        if (!Rect.intersects(bounds, visibleRect)) {
            // Node is not on screen, so do not bother.
            return;
            mWebTextView.bringIntoView();
        }
        String text = nativeFocusCandidateText();
        int nodePointer = nativeFocusCandidatePointer();
@@ -3329,6 +3327,13 @@ public class WebView extends AbsoluteLayout
            rebuildWebTextView();
            // Now we need to pass the event to it
            return mWebTextView.onKeyDown(keyCode, event);
        } else if (nativeHasFocusNode()) {
            // In this case, the cursor is not on a text input, but the focus
            // might be.  Check it, and if so, hand over to the WebTextView.
            rebuildWebTextView();
            if (inEditingMode()) {
                return mWebTextView.onKeyDown(keyCode, event);
            }
        }

        // TODO: should we pass all the keys to DOM or check the meta tag