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

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

Changes to make the cursor blink at the correct times.

Make the blinking caret active when the user actually starts editing
text.  To be consistent with that idea, do not rebuild the WebTextView
when the WebView regains focus.  Now sendMouseMoveIfLatest takes a
boolean parameter to determine whether to make the focusController
inactive.  Requires a matching change in webkit to pass a parameter
to the method.  Now that we only call setFocusControllerActive with
false, change the method to no longer take a boolean parameter.
Change names to reflect that.

This change also reflects a behavioral change.  If the WebView or
its window lose focus, we do not restore the blinking caret when
focus returns.
parent d1ac159d
Loading
Loading
Loading
Loading
+13 −33
Original line number Original line Diff line number Diff line
@@ -366,10 +366,6 @@ public class WebView extends AbsoluteLayout
    // take control of touch events unless it says no for touch down event.
    // take control of touch events unless it says no for touch down event.
    private boolean mPreventDrag;
    private boolean mPreventDrag;


    // If rebuildWebTextView gets called while we are out of focus, use this
    // variable to remember to do it next time we gain focus.
    private boolean mNeedsRebuildWebTextView = false;

    // Whether or not to draw the cursor ring.
    // Whether or not to draw the cursor ring.
    private boolean mDrawCursorRing = true;
    private boolean mDrawCursorRing = true;


@@ -2951,7 +2947,6 @@ public class WebView extends AbsoluteLayout
        if (!hasFocus() && (null == mWebTextView || !mWebTextView.hasFocus())
        if (!hasFocus() && (null == mWebTextView || !mWebTextView.hasFocus())
                || (mTouchMode >= FIRST_SCROLL_ZOOM
                || (mTouchMode >= FIRST_SCROLL_ZOOM
                && mTouchMode <= LAST_SCROLL_ZOOM)) {
                && mTouchMode <= LAST_SCROLL_ZOOM)) {
            mNeedsRebuildWebTextView = true;
            return;
            return;
        }
        }
        boolean alreadyThere = inEditingMode();
        boolean alreadyThere = inEditingMode();
@@ -3200,7 +3195,6 @@ public class WebView extends AbsoluteLayout


        // TODO: should we pass all the keys to DOM or check the meta tag
        // TODO: should we pass all the keys to DOM or check the meta tag
        if (nativeCursorWantsKeyEvents() || true) {
        if (nativeCursorWantsKeyEvents() || true) {
            mWebViewCore.sendMessage(EventHub.SET_ACTIVE, 1);
            // pass the key to DOM
            // pass the key to DOM
            mWebViewCore.sendMessage(EventHub.KEY_DOWN, event);
            mWebViewCore.sendMessage(EventHub.KEY_DOWN, event);
            // return true as DOM handles the key
            // return true as DOM handles the key
@@ -3362,7 +3356,6 @@ public class WebView extends AbsoluteLayout
        if (child == this) {
        if (child == this) {
            if (inEditingMode()) {
            if (inEditingMode()) {
                clearTextEntry();
                clearTextEntry();
                mNeedsRebuildWebTextView = true;
            }
            }
        }
        }
    }
    }
@@ -3383,16 +3376,11 @@ public class WebView extends AbsoluteLayout
        if (hasWindowFocus) {
        if (hasWindowFocus) {
            if (hasFocus()) {
            if (hasFocus()) {
                // If our window regained focus, and we have focus, then begin
                // If our window regained focus, and we have focus, then begin
                // drawing the cursor ring, and restore the TextView if
                // drawing the cursor ring
                // necessary.
                mDrawCursorRing = true;
                mDrawCursorRing = true;
                if (mNeedsRebuildWebTextView) {
                    rebuildWebTextView();
                }
                if (mNativeClass != 0) {
                if (mNativeClass != 0) {
                    nativeRecordButtons(true, false, true);
                    nativeRecordButtons(true, false, true);
                }
                }
                setFocusControllerActive(true);
            } else {
            } else {
                // If our window gained focus, but we do not have it, do not
                // If our window gained focus, but we do not have it, do not
                // draw the cursor ring.
                // draw the cursor ring.
@@ -3418,23 +3406,23 @@ public class WebView extends AbsoluteLayout
            if (mNativeClass != 0) {
            if (mNativeClass != 0) {
                nativeRecordButtons(false, false, true);
                nativeRecordButtons(false, false, true);
            }
            }
            setFocusControllerActive(false);
            setFocusControllerInactive();
        }
        }
        invalidate();
        invalidate();
        super.onWindowFocusChanged(hasWindowFocus);
        super.onWindowFocusChanged(hasWindowFocus);
    }
    }


    /*
    /*
     * Pass a message to WebCore Thread, determining whether the WebCore::Page's
     * Pass a message to WebCore Thread, telling the WebCore::Page's
     * FocusController is "active" so that it will draw the blinking cursor.
     * FocusController to be  "inactive" so that it will
     * not draw the blinking cursor.  It gets set to "active" to draw the cursor
     * in WebViewCore.cpp, when the WebCore thread receives key events/clicks.
     */
     */
    private void setFocusControllerActive(boolean active) {
    private void setFocusControllerInactive() {
        // Do not need to also check whether mWebViewCore is null, because
        // Do not need to also check whether mWebViewCore is null, because
        // mNativeClass is only set if mWebViewCore is non null
        // mNativeClass is only set if mWebViewCore is non null
        if (mNativeClass == 0) return;
        if (mNativeClass == 0) return;
        active &= nativeCursorMatchesFocus() || !nativeHasFocusNode()
        mWebViewCore.sendMessage(EventHub.SET_INACTIVE);
                || !nativeCursorWantsKeyEvents();
        mWebViewCore.sendMessage(EventHub.SET_ACTIVE, active ? 1 : 0, 0);
    }
    }


    @Override
    @Override
@@ -3445,20 +3433,12 @@ public class WebView extends AbsoluteLayout
        }
        }
        if (focused) {
        if (focused) {
            // When we regain focus, if we have window focus, resume drawing
            // When we regain focus, if we have window focus, resume drawing
            // the cursor ring, and add the TextView if necessary.
            // the cursor ring
            if (hasWindowFocus()) {
            if (hasWindowFocus()) {
                mDrawCursorRing = true;
                mDrawCursorRing = true;
                if (mNeedsRebuildWebTextView) {
                    rebuildWebTextView();
                    mNeedsRebuildWebTextView = false;
                }
                if (mNativeClass != 0) {
                if (mNativeClass != 0) {
                    nativeRecordButtons(true, false, true);
                    nativeRecordButtons(true, false, true);
                }
                }
                // FIXME: This is unnecessary if we are gaining focus from the
                // WebTextView.  How can we tell if it was the last thing in
                // focus?
                setFocusControllerActive(true);
            //} else {
            //} else {
                // The WebView has gained focus while we do not have
                // The WebView has gained focus while we do not have
                // windowfocus.  When our window lost focus, we should have
                // windowfocus.  When our window lost focus, we should have
@@ -3472,7 +3452,7 @@ public class WebView extends AbsoluteLayout
                if (mNativeClass != 0) {
                if (mNativeClass != 0) {
                    nativeRecordButtons(false, false, true);
                    nativeRecordButtons(false, false, true);
                }
                }
                setFocusControllerActive(false);
                setFocusControllerInactive();
            }
            }
            mGotKeyDown = false;
            mGotKeyDown = false;
        }
        }
@@ -5076,9 +5056,9 @@ public class WebView extends AbsoluteLayout
    }
    }


    // called by JNI
    // called by JNI
    private void sendMoveMouseIfLatest() {
    private void sendMoveMouseIfLatest(boolean setFocusControllerInactive) {
        if (!nativeCursorMatchesFocus() && nativeCursorWantsKeyEvents()) {
        if (setFocusControllerInactive) {
            setFocusControllerActive(false);
            setFocusControllerInactive();
        }
        }
        mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE_IF_LATEST, cursorData());
        mWebViewCore.sendMessage(EventHub.SET_MOVE_MOUSE_IF_LATEST, cursorData());
    }
    }
+9 −8
Original line number Original line Diff line number Diff line
@@ -375,7 +375,7 @@ final class WebViewCore {
            String currentText, int keyCode, int keyValue, boolean down,
            String currentText, int keyCode, int keyValue, boolean down,
            boolean cap, boolean fn, boolean sym);
            boolean cap, boolean fn, boolean sym);


    private native void nativeSetFocusControllerActive(boolean active);
    private native void nativeSetFocusControllerInactive();


    private native void nativeSaveDocumentState(int frame);
    private native void nativeSaveDocumentState(int frame);


@@ -615,7 +615,7 @@ final class WebViewCore {
            "LOAD_DATA", // = 139;
            "LOAD_DATA", // = 139;
            "TOUCH_UP", // = 140;
            "TOUCH_UP", // = 140;
            "TOUCH_EVENT", // = 141;
            "TOUCH_EVENT", // = 141;
            "SET_ACTIVE", // = 142;
            "SET_INACTIVE", // = 142;
            "ON_PAUSE",     // = 143
            "ON_PAUSE",     // = 143
            "ON_RESUME",    // = 144
            "ON_RESUME",    // = 144
            "FREE_MEMORY",  // = 145
            "FREE_MEMORY",  // = 145
@@ -670,9 +670,10 @@ final class WebViewCore {
        // message used to pass UI touch events to WebCore
        // message used to pass UI touch events to WebCore
        static final int TOUCH_EVENT = 141;
        static final int TOUCH_EVENT = 141;


        // Used to tell the focus controller whether to draw the blinking cursor
        // Used to tell the focus controller not to draw the blinking cursor,
        // or not, based on whether the WebView has focus.
        // based on whether the WebView has focus and whether the WebView's
        static final int SET_ACTIVE = 142;
        // cursor matches the webpage's focus.
        static final int SET_INACTIVE = 142;


        // lifecycle activities for just this DOM (unlike pauseTimers, which
        // lifecycle activities for just this DOM (unlike pauseTimers, which
        // is global)
        // is global)
@@ -724,7 +725,7 @@ final class WebViewCore {
                public void handleMessage(Message msg) {
                public void handleMessage(Message msg) {
                    if (DebugFlags.WEB_VIEW_CORE) {
                    if (DebugFlags.WEB_VIEW_CORE) {
                        Log.v(LOGTAG, msg.what < LOAD_URL || msg.what
                        Log.v(LOGTAG, msg.what < LOAD_URL || msg.what
                                > SET_ACTIVE ? Integer.toString(msg.what)
                                > SET_INACTIVE ? Integer.toString(msg.what)
                                : HandlerDebugString[msg.what - LOAD_URL]);
                                : HandlerDebugString[msg.what - LOAD_URL]);
                    }
                    }
                    switch (msg.what) {
                    switch (msg.what) {
@@ -950,8 +951,8 @@ final class WebViewCore {
                            break;
                            break;
                        }
                        }


                        case SET_ACTIVE:
                        case SET_INACTIVE:
                            nativeSetFocusControllerActive(msg.arg1 == 1);
                            nativeSetFocusControllerInactive();
                            break;
                            break;


                        case ADD_JS_INTERFACE:
                        case ADD_JS_INTERFACE: