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

Commit 5d4064c8 authored by Huahui Wu's avatar Huahui Wu
Browse files

b/3377597 Improve zooming performance.

Once WebKit claimed it doesn't want to consume the multi-touch events,
we remember that and handle the events in WebView directly.

Change-Id: Idfc99c16b3f4d7f4719791c64fb2355ff66aba5e
parent a586b7ba
Loading
Loading
Loading
Loading
+91 −80
Original line number Diff line number Diff line
@@ -476,6 +476,7 @@ public class WebView extends AbsoluteLayout
    private static final int TOUCH_DRAG_LAYER_MODE = 9;

    // Whether to forward the touch events to WebCore
    // Can only be set by WebKit via JNI.
    private boolean mForwardTouchEvents = false;

    // Whether to prevent default during touch. The initial value depends on
@@ -5358,26 +5359,26 @@ public class WebView extends AbsoluteLayout
                + " numPointers=" + ev.getPointerCount());
        }

        // Always pass multi-touch event to WebKit first.
        // If WebKit doesn't consume it and set preventDefault to true,
        // WebView's private handler will handle it.
        if (ev.getPointerCount() > 1) {
            if (DebugFlags.WEB_VIEW) {
                Log.v(LOGTAG, "passing " + ev.getPointerCount() + " points to webkit");
            }
            if (!mIsHandlingMultiTouch) {
        int action = ev.getActionMasked();
        if (ev.getPointerCount() > 1) {  // Multi-touch
            mIsHandlingMultiTouch = true;
            }

            // If WebKit already showed no interests in this sequence of events,
            // WebView handles them directly.
            if (mPreventDefault == PREVENT_DEFAULT_NO && action == MotionEvent.ACTION_MOVE) {
                handleMultiTouchInWebView(ev);
            } else {
                passMultiTouchToWebKit(ev);
            }
            return true;
        } else {
        }

        // Skip ACTION_MOVE for single touch if it's still handling multi-touch.
            if (mIsHandlingMultiTouch && ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
        if (mIsHandlingMultiTouch && action == MotionEvent.ACTION_MOVE) {
            return false;
        }
        }

        return handleTouchEventCommon(ev, ev.getActionMasked(), Math.round(ev.getX()), Math.round(ev.getY()));
        return handleTouchEventCommon(ev, action, Math.round(ev.getX()), Math.round(ev.getY()));
    }

    /*
@@ -7346,16 +7347,25 @@ public class WebView extends AbsoluteLayout
                        if (mPreventDefault == PREVENT_DEFAULT_YES) {
                            mTouchHighlightRegion.setEmpty();
                        }
                    } else if (msg.arg2 == 0) {
                        // prevent default is not called in WebCore, so the
                        // message needs to be reprocessed in UI
                    } else {
                        TouchEventData ted = (TouchEventData) msg.obj;

                        if (ted.mPoints.length > 1) {  // for multi-touch.
                        if (ted.mPoints.length > 1) {  // multi-touch
                            if (ted.mAction == MotionEvent.ACTION_POINTER_UP) {
                                mIsHandlingMultiTouch = false;
                            }
                            if (msg.arg2 == 0) {
                                mPreventDefault = PREVENT_DEFAULT_NO;
                                handleMultiTouchInWebView(ted.mMotionEvent);
                            } else {
                                mPreventDefault = PREVENT_DEFAULT_YES;
                            }
                            break;
                        }

                        // prevent default is not called in WebCore, so the
                        // message needs to be reprocessed in UI
                        if (msg.arg2 == 0) {
                            // Following is for single touch.
                            switch (ted.mAction) {
                                case MotionEvent.ACTION_DOWN:
@@ -7417,6 +7427,7 @@ public class WebView extends AbsoluteLayout
                                    break;
                            }
                        }
                    }
                    break;

                case REQUEST_KEYBOARD: