| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewGestureHandler.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewGestureHandler.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewGestureHandler.java
|
| index 6e5c23511c2d3dda2e2d627479d45fbc9bb3de99..fc56cbd0e739088afda8225a2cc46b1b9693762f 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewGestureHandler.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewGestureHandler.java
|
| @@ -7,27 +7,22 @@ package org.chromium.content.browser;
|
| import android.content.Context;
|
| import android.os.Bundle;
|
| import android.os.SystemClock;
|
| -import android.util.Log;
|
| import android.view.InputDevice;
|
| import android.view.MotionEvent;
|
| import android.view.ViewConfiguration;
|
|
|
| import org.chromium.base.CommandLine;
|
| -import org.chromium.base.TraceEvent;
|
| -import org.chromium.content.browser.LongPressDetector.LongPressDelegate;
|
| import org.chromium.content.browser.third_party.GestureDetector;
|
| import org.chromium.content.browser.third_party.GestureDetector.OnDoubleTapListener;
|
| import org.chromium.content.browser.third_party.GestureDetector.OnGestureListener;
|
| import org.chromium.content.common.ContentSwitches;
|
| -
|
| -import java.util.ArrayDeque;
|
| -import java.util.Deque;
|
| +import org.chromium.content.common.TraceEvent;
|
|
|
| /**
|
| * This class handles all MotionEvent handling done in ContentViewCore including the gesture
|
| * recognition. It sends all related native calls through the interface MotionEventDelegate.
|
| */
|
| -class ContentViewGestureHandler implements LongPressDelegate {
|
| +class ContentViewGestureHandler {
|
|
|
| private static final String TAG = "ContentViewGestureHandler";
|
| /**
|
| @@ -77,34 +72,11 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| private final Bundle mExtraParamBundlePinchBy;
|
| private GestureDetector mGestureDetector;
|
| private final ZoomManager mZoomManager;
|
| - private LongPressDetector mLongPressDetector;
|
| private OnGestureListener mListener;
|
| private OnDoubleTapListener mDoubleTapListener;
|
| private MotionEvent mCurrentDownEvent;
|
| private final MotionEventDelegate mMotionEventDelegate;
|
|
|
| - // Queue of motion events.
|
| - private final Deque<MotionEvent> mPendingMotionEvents = new ArrayDeque<MotionEvent>();
|
| -
|
| - // All events are forwarded to the GestureDetector, bypassing Javascript.
|
| - private static final int NO_TOUCH_HANDLER = 0;
|
| -
|
| - // All events are forwarded as normal to Javascript, and if unconsumed to the GestureDetector.
|
| - // * Activated from the renderer by way of |hasTouchEventHandlers(true)|.
|
| - private static final int HAS_TOUCH_HANDLER = 1;
|
| -
|
| - // Events in the current gesture are forwarded to the GestureDetector, bypassing Javascript.
|
| - // * Activated if the touch down for the current gesture had no Javascript consumer.
|
| - private static final int NO_TOUCH_HANDLER_FOR_GESTURE = 2;
|
| -
|
| - // Events in the current gesture are forwarded to Javascript, and not to the GestureDetector.
|
| - // * Activated if *any* touch event in the current sequence was consumed by Javascript.
|
| - private static final int JAVASCRIPT_CONSUMING_GESTURE = 3;
|
| -
|
| - private static final int TOUCH_HANDLING_STATE_DEFAULT = NO_TOUCH_HANDLER;
|
| -
|
| - private int mTouchHandlingState = TOUCH_HANDLING_STATE_DEFAULT;
|
| -
|
| // Remember whether onShowPress() is called. If it is not, in onSingleTapConfirmed()
|
| // we will first show the press state, then trigger the click.
|
| private boolean mShowPressIsCalled;
|
| @@ -126,19 +98,11 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| // True from right before we send the first scroll event until the last finger is raised.
|
| private boolean mTouchScrolling;
|
|
|
| - // TODO(wangxianzhu): For now it is true after a fling is started until the next
|
| - // touch. Should reset it to false on end of fling if the UI is able to know when the
|
| - // fling ends.
|
| - private boolean mFlingMayBeActive;
|
| -
|
| // Used to remove the touch slop from the initial scroll event in a scroll gesture.
|
| private boolean mSeenFirstScrollEvent;
|
|
|
| private boolean mPinchInProgress = false;
|
|
|
| - // Guard against nested |trySendPendingEventsToNative()| loops.
|
| - private boolean mSendingPendingEventsToNative = false;
|
| -
|
| private static final int DOUBLE_TAP_TIMEOUT = ViewConfiguration.getDoubleTapTimeout();
|
|
|
| //On single tap this will store the x, y coordinates of the touch.
|
| @@ -189,14 +153,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| // action after a double tap.
|
| private long mLastDoubleTapTimeMs;
|
|
|
| - // Coordinates of the start of a touch sequence offered to native (i.e. the touchdown).
|
| - private float mTouchDownToNativeX;
|
| - private float mTouchDownToNativeY;
|
| -
|
| - // True iff a (potential) touchmove offered to native has exceeded the touch slop distance
|
| - // OR it had multiple pointers.
|
| - private boolean mTouchMoveToNativeConfirmed;
|
| -
|
| static final int GESTURE_SHOW_PRESSED_STATE = 0;
|
| static final int GESTURE_DOUBLE_TAP = 1;
|
| static final int GESTURE_SINGLE_TAP_UP = 2;
|
| @@ -215,18 +171,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| static final int GESTURE_LONG_TAP = 15;
|
| static final int GESTURE_TAP_DOWN = 16;
|
|
|
| - // These have to be kept in sync with content/port/common/input_event_ack_state.h
|
| - static final int INPUT_EVENT_ACK_STATE_UNKNOWN = 0;
|
| - static final int INPUT_EVENT_ACK_STATE_CONSUMED = 1;
|
| - static final int INPUT_EVENT_ACK_STATE_NOT_CONSUMED = 2;
|
| - static final int INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS = 3;
|
| - static final int INPUT_EVENT_ACK_STATE_IGNORED = 4;
|
| -
|
| - // Return values of sendPendingEventToNative();
|
| - static final int EVENT_FORWARDED_TO_NATIVE = 0;
|
| - static final int EVENT_DROPPED = 1;
|
| - static final int EVENT_NOT_FORWARDED = 2;
|
| -
|
| private final float mPxToDp;
|
|
|
| static final int DOUBLE_TAP_MODE_NONE = 0;
|
| @@ -244,9 +188,13 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| * @param timeMs Time of the event in ms.
|
| * @param action The action type for the event.
|
| * @param pts The TouchPoint array to be sent for the event.
|
| - * @return Whether the event was sent to the native side successfully or not.
|
| */
|
| - public boolean sendTouchEvent(long timeMs, int action, TouchPoint[] pts);
|
| + public void onTouchEventHandlingBegin(long timeMs, int action, TouchPoint[] pts);
|
| +
|
| + /**
|
| + * Signal that all gestures for the current {@link MotionEvent} have been dispatchd.
|
| + */
|
| + public void onTouchEventHandlingEnd();
|
|
|
| /**
|
| * Send a gesture event to the native side.
|
| @@ -262,11 +210,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| boolean sendGesture(int type, long timeMs, int x, int y, Bundle extraParams);
|
|
|
| /**
|
| - * Show the zoom picker UI.
|
| - */
|
| - public void invokeZoomPicker();
|
| -
|
| - /**
|
| * Send action after dobule tap for UMA stat tracking.
|
| * @param type The action that occured
|
| * @param clickDelayEnabled Whether the tap down delay is active
|
| @@ -289,7 +232,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| mExtraParamBundleDoubleTapDragZoom = new Bundle();
|
| mExtraParamBundlePinchBy = new Bundle();
|
|
|
| - mLongPressDetector = new LongPressDetector(context, this);
|
| mMotionEventDelegate = delegate;
|
| mZoomManager = zoomManager;
|
| mSnapScrollController = new SnapScrollController(context, mZoomManager);
|
| @@ -304,14 +246,12 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| /**
|
| * Used to override the default long press detector, gesture detector and listener.
|
| * This is used for testing only.
|
| - * @param longPressDetector The new LongPressDetector to be assigned.
|
| * @param gestureDetector The new GestureDetector to be assigned.
|
| * @param listener The new onGestureListener to be assigned.
|
| */
|
| void setTestDependencies(
|
| - LongPressDetector longPressDetector, GestureDetector gestureDetector,
|
| + GestureDetector gestureDetector,
|
| OnGestureListener listener) {
|
| - if (longPressDetector != null) mLongPressDetector = longPressDetector;
|
| if (gestureDetector != null) mGestureDetector = gestureDetector;
|
| if (listener != null) mListener = listener;
|
| }
|
| @@ -329,12 +269,12 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| mIgnoreSingleTap = false;
|
| mTouchScrolling = false;
|
| mSeenFirstScrollEvent = false;
|
| - mSnapScrollController.resetSnapScrollMode();
|
| mLastRawX = e.getRawX();
|
| mLastRawY = e.getRawY();
|
| mAccumulatedScrollErrorX = 0;
|
| mAccumulatedScrollErrorY = 0;
|
| - mNeedsTapEndingEvent = false;
|
| + mLastLongPressEvent = null;
|
| + mNeedsTapEndingEvent = true;
|
| if (sendMotionEventAsGesture(GESTURE_TAP_DOWN, e, null)) {
|
| mNeedsTapEndingEvent = true;
|
| }
|
| @@ -373,8 +313,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| mLastRawX = e2.getRawX();
|
| mLastRawY = e2.getRawY();
|
| if (!mTouchScrolling) {
|
| - sendTapCancelIfNecessary(e1);
|
| - endFlingIfNecessary(e2.getEventTime());
|
| // Note that scroll start hints are in distance traveled, where
|
| // scroll deltas are in the opposite direction.
|
| mExtraParamBundleScrollStart.putInt(DELTA_HINT_X, (int) -rawDistanceX);
|
| @@ -408,8 +346,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| e2.getEventTime(), x, y, mExtraParamBundleScroll);
|
| }
|
|
|
| - mMotionEventDelegate.invokeZoomPicker();
|
| -
|
| return true;
|
| }
|
|
|
| @@ -439,7 +375,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| @Override
|
| public boolean onSingleTapUp(MotionEvent e) {
|
| if (isDistanceBetweenDownAndUpTooLong(e.getRawX(), e.getRawY())) {
|
| - sendTapCancelIfNecessary(e);
|
| mIgnoreSingleTap = true;
|
| return true;
|
| }
|
| @@ -449,7 +384,7 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| // want to trigger the tap event at UP. So we override
|
| // onSingleTapUp() in this case. This assumes singleTapUp
|
| // gets always called before singleTapConfirmed.
|
| - if (!mIgnoreSingleTap && !mLongPressDetector.isInLongPress()) {
|
| + if (!mIgnoreSingleTap) {
|
| if (e.getEventTime() - e.getDownTime() > DOUBLE_TAP_TIMEOUT) {
|
| float x = e.getX();
|
| float y = e.getY();
|
| @@ -475,17 +410,11 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| }
|
| }
|
|
|
| - return triggerLongTapIfNeeded(e);
|
| + return true;
|
| }
|
|
|
| @Override
|
| public boolean onSingleTapConfirmed(MotionEvent e) {
|
| - // Long taps in the edges of the screen have their events delayed by
|
| - // ContentViewHolder for tab swipe operations. As a consequence of the delay
|
| - // this method might be called after receiving the up event.
|
| - // These corner cases should be ignored.
|
| - if (mLongPressDetector.isInLongPress() || mIgnoreSingleTap) return true;
|
| -
|
| mMotionEventDelegate.sendSingleTapUMA(
|
| isDoubleTapDisabled() ?
|
| ContentViewCore.UMASingleTapType.UNDELAYED_TAP :
|
| @@ -508,7 +437,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| public boolean onDoubleTapEvent(MotionEvent e) {
|
| switch (e.getActionMasked()) {
|
| case MotionEvent.ACTION_DOWN:
|
| - sendTapCancelIfNecessary(e);
|
| mDoubleTapDragZoomAnchorX = e.getX();
|
| mDoubleTapDragZoomAnchorY = e.getY();
|
| mDoubleTapMode = DOUBLE_TAP_MODE_DRAG_DETECTION_IN_PROGRESS;
|
| @@ -521,8 +449,8 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
|
|
| // Begin double tap drag zoom mode if the move distance is
|
| // further than the threshold.
|
| - if (isDistanceGreaterThanTouchSlop(distanceX, distanceY)) {
|
| - sendTapCancelIfNecessary(e);
|
| + if (distanceX * distanceX + distanceY * distanceY >
|
| + mScaledTouchSlopSquare) {
|
| mExtraParamBundleScrollStart.putInt(DELTA_HINT_X,
|
| (int) -distanceX);
|
| mExtraParamBundleScrollStart.putInt(DELTA_HINT_Y,
|
| @@ -560,7 +488,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| endDoubleTapDragIfNecessary(e);
|
| break;
|
| case MotionEvent.ACTION_CANCEL:
|
| - sendTapCancelIfNecessary(e);
|
| endDoubleTapDragIfNecessary(e);
|
| break;
|
| default:
|
| @@ -594,41 +521,20 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| * @return true if the distance is too long to be considered a single tap
|
| */
|
| private boolean isDistanceBetweenDownAndUpTooLong(float x, float y) {
|
| - return isDistanceGreaterThanTouchSlop(mLastRawX - x, mLastRawY - y);
|
| + double deltaX = mLastRawX - x;
|
| + double deltaY = mLastRawY - y;
|
| + return deltaX * deltaX + deltaY * deltaY > mScaledTouchSlopSquare;
|
| }
|
| };
|
| mListener = listener;
|
| mDoubleTapListener = listener;
|
| mGestureDetector = new GestureDetector(context, listener);
|
| - mGestureDetector.setIsLongpressEnabled(false);
|
| } finally {
|
| TraceEvent.end();
|
| }
|
| }
|
|
|
| /**
|
| - * @return LongPressDetector handling setting up timers for and canceling LongPress gestures.
|
| - */
|
| - LongPressDetector getLongPressDetector() {
|
| - return mLongPressDetector;
|
| - }
|
| -
|
| - /**
|
| - * @param event Start a LongPress gesture event from the listener.
|
| - */
|
| - @Override
|
| - public void onLongPress(MotionEvent event) {
|
| - mListener.onLongPress(event);
|
| - }
|
| -
|
| - /**
|
| - * Cancels any ongoing LongPress timers.
|
| - */
|
| - void cancelLongPress() {
|
| - mLongPressDetector.cancelLongPress();
|
| - }
|
| -
|
| - /**
|
| * Fling the ContentView from the current position.
|
| * @param x Fling touch starting position
|
| * @param y Fling touch starting position
|
| @@ -636,8 +542,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| * @param velocityY Initial velocity of the fling (Y) measured in pixels per second.
|
| */
|
| void fling(long timeMs, int x, int y, int velocityX, int velocityY) {
|
| - endFlingIfNecessary(timeMs);
|
| -
|
| if (velocityX == 0 && velocityY == 0) {
|
| endTouchScrollIfNecessary(timeMs, true);
|
| return;
|
| @@ -654,8 +558,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| }
|
| endTouchScrollIfNecessary(timeMs, false);
|
|
|
| - mFlingMayBeActive = true;
|
| -
|
| mExtraParamBundleFling.putInt(VELOCITY_X, velocityX);
|
| mExtraParamBundleFling.putInt(VELOCITY_Y, velocityY);
|
| assert mExtraParamBundleFling.size() == 2;
|
| @@ -663,24 +565,14 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| }
|
|
|
| /**
|
| - * Send a GESTURE_FLING_CANCEL event if necessary.
|
| - * @param timeMs The time in ms for the event initiating this gesture.
|
| - */
|
| - void endFlingIfNecessary(long timeMs) {
|
| - if (!mFlingMayBeActive) return;
|
| - mFlingMayBeActive = false;
|
| - sendGesture(GESTURE_FLING_CANCEL, timeMs, 0, 0, null);
|
| - }
|
| -
|
| - /**
|
| * End DOUBLE_TAP_MODE_DRAG_ZOOM by sending GESTURE_SCROLL_END and GESTURE_PINCH_END events.
|
| * @param event A hint event that its x, y, and eventTime will be used for the ending events
|
| * to send. This argument is an optional and can be null.
|
| */
|
| void endDoubleTapDragIfNecessary(MotionEvent event) {
|
| + assert event != null;
|
| if (!isDoubleTapActive()) return;
|
| if (mDoubleTapMode == DOUBLE_TAP_MODE_DRAG_ZOOM) {
|
| - if (event == null) event = obtainActionCancelMotionEvent();
|
| pinchEnd(event.getEventTime());
|
| sendGesture(GESTURE_SCROLL_END, event.getEventTime(),
|
| (int) event.getX(), (int) event.getY(), null);
|
| @@ -805,19 +697,7 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| }
|
| }
|
|
|
| - mLongPressDetector.cancelLongPressIfNeeded(event);
|
| - mSnapScrollController.setSnapScrollingMode(event);
|
| - // Notify native that scrolling has stopped whenever a down action is processed prior to
|
| - // passing the event to native as it will drop them as an optimization if scrolling is
|
| - // enabled. Ending the fling ensures scrolling has stopped as well as terminating the
|
| - // current fling if applicable.
|
| - if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
| - endFlingIfNecessary(event.getEventTime());
|
| - } else if (event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
|
| - endDoubleTapDragIfNecessary(null);
|
| - }
|
| -
|
| - return queueEvent(event);
|
| + return processTouchEvent(event);
|
| } finally {
|
| TraceEvent.end("onTouchEvent");
|
| }
|
| @@ -827,16 +707,19 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| * Handle content view losing focus -- ensure that any remaining active state is removed.
|
| */
|
| void onWindowFocusLost() {
|
| - if (mLongPressDetector.isInLongPress() && mLastLongPressEvent != null) {
|
| + if (mLastLongPressEvent != null) {
|
| sendTapCancelIfNecessary(mLastLongPressEvent);
|
| }
|
| }
|
|
|
| private MotionEvent obtainActionCancelMotionEvent() {
|
| - return MotionEvent.obtain(
|
| + MotionEvent me = MotionEvent.obtain(
|
| SystemClock.uptimeMillis(),
|
| SystemClock.uptimeMillis(),
|
| MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
|
| + me.setSource(mCurrentDownEvent != null ?
|
| + mCurrentDownEvent.getSource() : InputDevice.SOURCE_CLASS_POINTER);
|
| + return me;
|
| }
|
|
|
| /**
|
| @@ -847,140 +730,44 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| */
|
| void resetGestureHandlers() {
|
| MotionEvent me = obtainActionCancelMotionEvent();
|
| - me.setSource(InputDevice.SOURCE_CLASS_POINTER);
|
| mGestureDetector.onTouchEvent(me);
|
| mZoomManager.processTouchEvent(me);
|
| me.recycle();
|
| - mLongPressDetector.cancelLongPress();
|
| - if (mCurrentDownEvent != null) recycleEvent(mCurrentDownEvent);
|
| - mCurrentDownEvent = null;
|
| - }
|
| -
|
| - /**
|
| - * Sets the flag indicating that the content has registered listeners for touch events.
|
| - */
|
| - void hasTouchEventHandlers(boolean hasTouchHandlers) {
|
| - if (hasTouchHandlers) {
|
| - // If no touch handler was previously registered, ensure that we
|
| - // don't send a partial gesture to Javascript.
|
| - if (mTouchHandlingState == NO_TOUCH_HANDLER)
|
| - mTouchHandlingState = NO_TOUCH_HANDLER_FOR_GESTURE;
|
| - } else {
|
| - // When mainframe is loading, FrameLoader::transitionToCommitted will
|
| - // call this method with |hasTouchHandlers| of false. We use this as
|
| - // an indicator to clear the pending motion events so that events from
|
| - // the previous page will not be carried over to the new page.
|
| - mTouchHandlingState = NO_TOUCH_HANDLER;
|
| - mPendingMotionEvents.clear();
|
| - }
|
| }
|
|
|
| - /**
|
| - * Queues or coalesces |event| into the pending queue.
|
| - * - If there are no touch handlers, |event| will skip the queue and be processed immediately.
|
| - * - If there are no pending events, |event| will be sent to native or processed immediately,
|
| - * depending on the disposition of the current gesture sequence.
|
| - * @return Whether the event was queued OR processed.
|
| - */
|
| - private boolean queueEvent(MotionEvent event) {
|
| - if (mTouchHandlingState == NO_TOUCH_HANDLER) {
|
| - assert mPendingMotionEvents.isEmpty();
|
| - return processTouchEvent(event);
|
| - }
|
| -
|
| - if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
| - // Avoid flooding the renderer process with move events: if the previous pending
|
| - // command is also a move (common case) that has not yet been forwarded, skip sending
|
| - // this event to the webkit side and collapse it into the pending event.
|
| - MotionEvent previousEvent = mPendingMotionEvents.peekLast();
|
| - if (previousEvent != null
|
| - && previousEvent != mPendingMotionEvents.peekFirst()
|
| - && previousEvent.getActionMasked() == MotionEvent.ACTION_MOVE
|
| - && previousEvent.getPointerCount() == event.getPointerCount()) {
|
| - TraceEvent.instant("queueEvent:EventCoalesced",
|
| - "QueueSize = " + mPendingMotionEvents.size());
|
| - MotionEvent.PointerCoords[] coords =
|
| - new MotionEvent.PointerCoords[event.getPointerCount()];
|
| - for (int i = 0; i < coords.length; ++i) {
|
| - coords[i] = new MotionEvent.PointerCoords();
|
| - event.getPointerCoords(i, coords[i]);
|
| - }
|
| - previousEvent.addBatch(event.getEventTime(), coords, event.getMetaState());
|
| - return true;
|
| - }
|
| - }
|
| -
|
| - // Copy the event, as the original may get mutated after this method returns.
|
| - MotionEvent clone = MotionEvent.obtain(event);
|
| - mPendingMotionEvents.add(clone);
|
| - if (mPendingMotionEvents.size() == 1) {
|
| - trySendPendingEventsToNative();
|
| - } else {
|
| - TraceEvent.instant("queueEvent:EventQueued",
|
| - "QueueSize = " + mPendingMotionEvents.size());
|
| - }
|
| - return true;
|
| - }
|
| + private boolean processTouchEvent(MotionEvent event) {
|
| + TouchPoint[] pts = new TouchPoint[event.getPointerCount()];
|
| + int type = TouchPoint.createTouchPoints(event, pts);
|
| + assert type != TouchPoint.CONVERSION_ERROR;
|
| + mMotionEventDelegate.onTouchEventHandlingBegin(event.getEventTime(), type, pts);
|
|
|
| - private int sendPendingEventToNative() {
|
| - MotionEvent event = mPendingMotionEvents.peekFirst();
|
| - if (event == null) {
|
| - assert false : "Cannot send from an empty pending event queue";
|
| - return EVENT_NOT_FORWARDED;
|
| - }
|
| - assert mTouchHandlingState != NO_TOUCH_HANDLER;
|
| + mSnapScrollController.setSnapScrollingMode(event);
|
|
|
| - // The start of a new (multi)touch sequence will reset the touch handling state, and
|
| - // should always be offered to Javascript (when there is any touch handler).
|
| if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
| - mTouchHandlingState = HAS_TOUCH_HANDLER;
|
| - mTouchMoveToNativeConfirmed = false;
|
| - mTouchDownToNativeX = event.getX();
|
| - mTouchDownToNativeY = event.getY();
|
| + if (mCurrentDownEvent != null) recycleEvent(mCurrentDownEvent);
|
| + mCurrentDownEvent = null;
|
| + } else if (event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
|
| + endDoubleTapDragIfNecessary(event);
|
| }
|
|
|
| - if (mTouchHandlingState == NO_TOUCH_HANDLER_FOR_GESTURE) return EVENT_NOT_FORWARDED;
|
| -
|
| - if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
| - if (!mTouchMoveToNativeConfirmed) {
|
| - if (event.getPointerCount() > 1) {
|
| - mTouchMoveToNativeConfirmed = true;
|
| - } else {
|
| - final float distanceX = event.getX() - mTouchDownToNativeX;
|
| - final float distanceY = event.getY() - mTouchDownToNativeY;
|
| - if (isDistanceGreaterThanTouchSlop(distanceX, distanceY)) {
|
| - mTouchMoveToNativeConfirmed = true;
|
| - }
|
| - }
|
| - }
|
| - // If javascript has not yet prevent-defaulted the touch sequence, only send move events
|
| - // if the move has exceeded the slop threshold OR there are multiple pointers.
|
| - if (mTouchHandlingState != JAVASCRIPT_CONSUMING_GESTURE
|
| - && !mTouchMoveToNativeConfirmed) {
|
| - return EVENT_DROPPED;
|
| + boolean handled = false;
|
| + // The last "finger up" is an end to scrolling but may not be
|
| + // an end to movement (e.g. fling scroll). We do not tell
|
| + // native code to end scrolling until we are sure we did not
|
| + // fling.
|
| + boolean possiblyEndMovement = false;
|
| + // "Last finger raised" could be an end to movement. However,
|
| + // give the mSimpleTouchDetector a chance to continue
|
| + // scrolling with a fling.
|
| + if (event.getAction() == MotionEvent.ACTION_UP
|
| + || event.getAction() == MotionEvent.ACTION_CANCEL) {
|
| + if (mTouchScrolling) {
|
| + possiblyEndMovement = true;
|
| }
|
| }
|
|
|
| - TouchPoint[] pts = new TouchPoint[event.getPointerCount()];
|
| - int type = TouchPoint.createTouchPoints(event, pts);
|
| -
|
| - if (type == TouchPoint.CONVERSION_ERROR) return EVENT_NOT_FORWARDED;
|
| -
|
| - if (mMotionEventDelegate.sendTouchEvent(event.getEventTime(), type, pts)) {
|
| - return EVENT_FORWARDED_TO_NATIVE;
|
| - }
|
| - return EVENT_NOT_FORWARDED;
|
| - }
|
| -
|
| - private boolean processTouchEvent(MotionEvent event) {
|
| - final boolean wasTouchScrolling = mTouchScrolling;
|
| -
|
| - mLongPressDetector.cancelLongPressIfNeeded(event);
|
| - mLongPressDetector.startLongPressTimerIfNeeded(event);
|
| -
|
| // Use the framework's GestureDetector to detect pans and zooms not already
|
| // handled by the WebKit touch events gesture manager.
|
| - boolean handled = false;
|
| if (canHandle(event)) {
|
| handled |= mGestureDetector.onTouchEvent(event);
|
| if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
| @@ -990,120 +777,15 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
|
|
| handled |= mZoomManager.processTouchEvent(event);
|
|
|
| - if (event.getAction() == MotionEvent.ACTION_UP
|
| - || event.getAction() == MotionEvent.ACTION_CANCEL) {
|
| - if (mCurrentDownEvent != null) recycleEvent(mCurrentDownEvent);
|
| - mCurrentDownEvent = null;
|
| -
|
| - // "Last finger raised" could be an end to movement, but it should
|
| - // only terminate scrolling if the event did not cause a fling.
|
| - if (wasTouchScrolling && !handled) {
|
| - endTouchScrollIfNecessary(event.getEventTime(), true);
|
| - }
|
| + if (possiblyEndMovement && !handled) {
|
| + endTouchScrollIfNecessary(event.getEventTime(), true);
|
| }
|
|
|
| - return handled;
|
| - }
|
| + triggerLongTapIfNeeded(event);
|
|
|
| - /**
|
| - * Respond to a MotionEvent being returned from the native side.
|
| - * @param ackResult The status acknowledgment code.
|
| - */
|
| - void confirmTouchEvent(int ackResult) {
|
| - try {
|
| - TraceEvent.begin("confirmTouchEvent");
|
| + mMotionEventDelegate.onTouchEventHandlingEnd();
|
|
|
| - if (mPendingMotionEvents.isEmpty()) {
|
| - Log.w(TAG, "confirmTouchEvent with Empty pending list!");
|
| - return;
|
| - }
|
| - assert mTouchHandlingState != NO_TOUCH_HANDLER;
|
| - assert mTouchHandlingState != NO_TOUCH_HANDLER_FOR_GESTURE;
|
| -
|
| - MotionEvent ackedEvent = mPendingMotionEvents.removeFirst();
|
| - switch (ackResult) {
|
| - case INPUT_EVENT_ACK_STATE_UNKNOWN:
|
| - // This should never get sent.
|
| - assert (false);
|
| - break;
|
| - case INPUT_EVENT_ACK_STATE_CONSUMED:
|
| - case INPUT_EVENT_ACK_STATE_IGNORED:
|
| - if (mTouchHandlingState != JAVASCRIPT_CONSUMING_GESTURE
|
| - && ackedEvent.getActionMasked() != MotionEvent.ACTION_DOWN) {
|
| - sendTapCancelIfNecessary(ackedEvent);
|
| - resetGestureHandlers();
|
| - } else {
|
| - mZoomManager.passTouchEventThrough(ackedEvent);
|
| - }
|
| - mTouchHandlingState = JAVASCRIPT_CONSUMING_GESTURE;
|
| - trySendPendingEventsToNative();
|
| - break;
|
| - case INPUT_EVENT_ACK_STATE_NOT_CONSUMED:
|
| - if (mTouchHandlingState != JAVASCRIPT_CONSUMING_GESTURE) {
|
| - processTouchEvent(ackedEvent);
|
| - }
|
| - trySendPendingEventsToNative();
|
| - break;
|
| - case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS:
|
| - if (mTouchHandlingState != JAVASCRIPT_CONSUMING_GESTURE) {
|
| - processTouchEvent(ackedEvent);
|
| - }
|
| - if (ackedEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
| - drainAllPendingEventsUntilNextDown();
|
| - } else {
|
| - trySendPendingEventsToNative();
|
| - }
|
| - break;
|
| - default:
|
| - break;
|
| - }
|
| -
|
| - mLongPressDetector.cancelLongPressIfNeeded(mPendingMotionEvents.iterator());
|
| - recycleEvent(ackedEvent);
|
| - } finally {
|
| - TraceEvent.end("confirmTouchEvent");
|
| - }
|
| - }
|
| -
|
| - private void trySendPendingEventsToNative() {
|
| - // Avoid nested send loops (possible when acks are synchronous), instead
|
| - // relying on the top-most call to dispatch any queued events.
|
| - if (mSendingPendingEventsToNative) return;
|
| - try {
|
| - mSendingPendingEventsToNative = true;
|
| - while (!mPendingMotionEvents.isEmpty()) {
|
| - int forward = sendPendingEventToNative();
|
| - if (forward == EVENT_FORWARDED_TO_NATIVE) break;
|
| -
|
| - // Even though we missed sending one event to native, as long as we haven't
|
| - // received INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, we should keep sending
|
| - // events on the queue to native.
|
| - MotionEvent event = mPendingMotionEvents.removeFirst();
|
| - if (mTouchHandlingState != JAVASCRIPT_CONSUMING_GESTURE
|
| - && forward != EVENT_DROPPED) {
|
| - processTouchEvent(event);
|
| - }
|
| - recycleEvent(event);
|
| - }
|
| - } finally {
|
| - mSendingPendingEventsToNative = false;
|
| - }
|
| - }
|
| -
|
| - private void drainAllPendingEventsUntilNextDown() {
|
| - assert mTouchHandlingState == HAS_TOUCH_HANDLER;
|
| - mTouchHandlingState = NO_TOUCH_HANDLER_FOR_GESTURE;
|
| -
|
| - // Now process all events that are in the queue until the next down event.
|
| - MotionEvent nextEvent = mPendingMotionEvents.peekFirst();
|
| - while (nextEvent != null && nextEvent.getActionMasked() != MotionEvent.ACTION_DOWN) {
|
| - processTouchEvent(nextEvent);
|
| - mPendingMotionEvents.removeFirst();
|
| - recycleEvent(nextEvent);
|
| - nextEvent = mPendingMotionEvents.peekFirst();
|
| - }
|
| -
|
| - trySendPendingEventsToNative();
|
| + return handled;
|
| }
|
|
|
| private void recycleEvent(MotionEvent event) {
|
| @@ -1152,10 +834,10 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| * will be consumed.
|
| */
|
| boolean triggerLongTapIfNeeded(MotionEvent ev) {
|
| - if (mLongPressDetector.isInLongPress() && ev.getAction() == MotionEvent.ACTION_UP &&
|
| - !mZoomManager.isScaleGestureDetectionInProgress()) {
|
| - sendTapCancelIfNecessary(ev);
|
| - sendMotionEventAsGesture(GESTURE_LONG_TAP, ev, null);
|
| + if (mLastLongPressEvent != null
|
| + && ev.getAction() == MotionEvent.ACTION_UP
|
| + && !mZoomManager.isScaleGestureDetectionInProgress()) {
|
| + sendTapEndingEventAsGesture(GESTURE_LONG_TAP, ev, null);
|
| return true;
|
| }
|
| return false;
|
| @@ -1163,22 +845,6 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
|
|
| /**
|
| * This is for testing only.
|
| - * @return The first motion event on the pending motion events queue.
|
| - */
|
| - MotionEvent peekFirstInPendingMotionEventsForTesting() {
|
| - return mPendingMotionEvents.peekFirst();
|
| - }
|
| -
|
| - /**
|
| - * This is for testing only.
|
| - * @return The number of motion events on the pending motion events queue.
|
| - */
|
| - int getNumberOfPendingMotionEventsForTesting() {
|
| - return mPendingMotionEvents.size();
|
| - }
|
| -
|
| - /**
|
| - * This is for testing only.
|
| * Sends a show pressed state gesture through mListener. This should always be called after
|
| * a down event;
|
| */
|
| @@ -1187,7 +853,7 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| mListener.onShowPress(mCurrentDownEvent);
|
| }
|
|
|
| - /**
|
| + /**
|
| * This is for testing only.
|
| * @return Whether a sent TapDown event has been accompanied by a tap-ending event.
|
| */
|
| @@ -1283,8 +949,4 @@ class ContentViewGestureHandler implements LongPressDelegate {
|
| mLastDoubleTapTimeMs = 0;
|
| }
|
| }
|
| -
|
| - private boolean isDistanceGreaterThanTouchSlop(float distanceX, float distanceY) {
|
| - return distanceX * distanceX + distanceY * distanceY > mScaledTouchSlopSquare;
|
| - }
|
| }
|
|
|