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

Commit 4b90378a authored by Patrick Scott's avatar Patrick Scott
Browse files

Allow one finger to scroll layers.

TODO: Add velocity.
Change-Id: I548ef6332b260a2aecc39422012523cb6f8e2523
parent 8458ce74
Loading
Loading
Loading
Loading
+12 −49
Original line number Diff line number Diff line
@@ -4990,10 +4990,10 @@ public class WebView extends AbsoluteLayout
        startTouch(detector.getFocusX(), detector.getFocusY(), mLastTouchTime);
    }

    private void startScrollingLayer(float gestureX, float gestureY) {
    private void startScrollingLayer(float x, float y) {
        if (mTouchMode != TOUCH_DRAG_LAYER_MODE) {
            int contentX = viewToContentX((int) gestureX + mScrollX);
            int contentY = viewToContentY((int) gestureY + mScrollY);
            int contentX = viewToContentX((int) x + mScrollX);
            int contentY = viewToContentY((int) y + mScrollY);
            mScrollingLayer = nativeScrollableLayer(contentX, contentY);
            if (mScrollingLayer != 0) {
                mTouchMode = TOUCH_DRAG_LAYER_MODE;
@@ -5026,52 +5026,12 @@ public class WebView extends AbsoluteLayout
        float y = ev.getY();
        long eventTime = ev.getEventTime();

        final ScaleGestureDetector detector =
                mZoomManager.getMultiTouchGestureDetector();
        boolean isScrollGesture = false;
        // Set to the mid-point of a two-finger gesture used to detect if the
        // user has touched a layer.
        float gestureX = x;
        float gestureY = y;
        if (detector == null || !detector.isInProgress()) {
            // The gesture for scrolling a layer is two fingers close together.
            // FIXME: we may consider giving WebKit an option to handle
            // multi-touch events later.
            if (ev.getPointerCount() > 1) {
                float dx = ev.getX(1) - ev.getX(0);
                float dy = ev.getY(1) - ev.getY(0);
                float dist = (dx * dx + dy * dy) *
                        DRAG_LAYER_INVERSE_DENSITY_SQUARED;
                // Use the approximate center to determine if the gesture is in
                // a layer.
                gestureX = ev.getX(0) + (dx * .5f);
                gestureY = ev.getY(0) + (dy * .5f);
                // Now use a consistent point for tracking movement.
                if (ev.getX(0) < ev.getX(1)) {
                    x = ev.getX(0);
                    y = ev.getY(0);
                } else {
                    x = ev.getX(1);
                    y = ev.getY(1);
                }
                action = ev.getActionMasked();
                if (dist < DRAG_LAYER_FINGER_DISTANCE) {
                    isScrollGesture = true;
                } else if (mTouchMode == TOUCH_DRAG_LAYER_MODE) {
                    // Fingers moved too far apart while dragging, the user
                    // might be trying to zoom.
                    mTouchMode = TOUCH_INIT_MODE;
                }
            }
        }

        // If the page disallows zoom, pass multi-touch events to webkit.
        // mDeferMultitouch is a hack for layout tests, where it is used to
        // force passing multi-touch events to webkit.
        // FIXME: always pass multi-touch events to webkit and remove everything
        // related to mDeferMultitouch.
        if (ev.getPointerCount() > 1 &&
                (mDeferMultitouch || (!isScrollGesture && mZoomManager.isZoomScaleFixed()))) {
                (mDeferMultitouch || mZoomManager.isZoomScaleFixed())) {
            if (DebugFlags.WEB_VIEW) {
                Log.v(LOGTAG, "passing " + ev.getPointerCount() + " points to webkit");
            }
@@ -5079,8 +5039,11 @@ public class WebView extends AbsoluteLayout
            return true;
        }

        final ScaleGestureDetector detector =
                mZoomManager.getMultiTouchGestureDetector();

        if (mZoomManager.supportsMultiTouchZoom() && ev.getPointerCount() > 1 &&
                mTouchMode != TOUCH_DRAG_LAYER_MODE && !isScrollGesture) {
                mTouchMode != TOUCH_DRAG_LAYER_MODE) {
            if (!detector.isInProgress() &&
                    ev.getActionMasked() != MotionEvent.ACTION_POINTER_DOWN) {
                // Insert a fake pointer down event in order to start
@@ -5370,9 +5333,7 @@ public class WebView extends AbsoluteLayout
                    deltaX = 0;
                    deltaY = 0;

                    if (isScrollGesture) {
                        startScrollingLayer(gestureX, gestureY);
                    }
                    startScrollingLayer(x, y);
                    startDrag();
                }

@@ -5668,9 +5629,11 @@ public class WebView extends AbsoluteLayout
                deltaY = viewToContentDimension(deltaY);
                if (nativeScrollLayer(mScrollingLayer, deltaX, deltaY)) {
                    invalidate();
                }
                    return;
                }
                // Switch to drag mode and fall through.
                mTouchMode = TOUCH_DRAG_MODE;
            }

            final int oldX = mScrollX;
            final int oldY = mScrollY;