OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Bundle; | 8 import android.os.Bundle; |
9 import android.os.Handler; | 9 import android.os.Handler; |
10 import android.os.SystemClock; | 10 import android.os.SystemClock; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 // set this flag and defer the "last event for vsync" signal until the touch event is fully | 157 // set this flag and defer the "last event for vsync" signal until the touch event is fully |
158 // processed. This allows multiple such gestures to be sent in a given frame . | 158 // processed. This allows multiple such gestures to be sent in a given frame . |
159 private boolean mSentGestureNeedsVSync; | 159 private boolean mSentGestureNeedsVSync; |
160 private long mLastVSyncGestureTimeMs; | 160 private long mLastVSyncGestureTimeMs; |
161 | 161 |
162 // Incremented and decremented when the methods onTouchEvent() and confirmTo uchEvent() start | 162 // Incremented and decremented when the methods onTouchEvent() and confirmTo uchEvent() start |
163 // and finish execution, respectively. This provides accounting for synchron ous calls to | 163 // and finish execution, respectively. This provides accounting for synchron ous calls to |
164 // confirmTouchEvent(), from either itself or onTouchEvent(). | 164 // confirmTouchEvent(), from either itself or onTouchEvent(). |
165 private int mTouchEventHandlingStackDepth; | 165 private int mTouchEventHandlingStackDepth; |
166 | 166 |
167 // Keeps track of the last long press event, if we end up opening a context menu, we would need | |
168 // to potentially use the event to send GESUTRE_SHOW_PRESS_CANCEL to remove ::active styling | |
169 private MotionEvent mLastLongPressEvent; | |
170 | |
167 static final int GESTURE_SHOW_PRESSED_STATE = 0; | 171 static final int GESTURE_SHOW_PRESSED_STATE = 0; |
168 static final int GESTURE_DOUBLE_TAP = 1; | 172 static final int GESTURE_DOUBLE_TAP = 1; |
169 static final int GESTURE_SINGLE_TAP_UP = 2; | 173 static final int GESTURE_SINGLE_TAP_UP = 2; |
170 static final int GESTURE_SINGLE_TAP_CONFIRMED = 3; | 174 static final int GESTURE_SINGLE_TAP_CONFIRMED = 3; |
171 static final int GESTURE_SINGLE_TAP_UNCONFIRMED = 4; | 175 static final int GESTURE_SINGLE_TAP_UNCONFIRMED = 4; |
172 static final int GESTURE_LONG_PRESS = 5; | 176 static final int GESTURE_LONG_PRESS = 5; |
173 static final int GESTURE_SCROLL_START = 6; | 177 static final int GESTURE_SCROLL_START = 6; |
174 static final int GESTURE_SCROLL_BY = 7; | 178 static final int GESTURE_SCROLL_BY = 7; |
175 static final int GESTURE_SCROLL_END = 8; | 179 static final int GESTURE_SCROLL_END = 8; |
176 static final int GESTURE_FLING_START = 9; | 180 static final int GESTURE_FLING_START = 9; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 /** | 363 /** |
360 * Used to override the default long press detector, gesture detector and li stener. | 364 * Used to override the default long press detector, gesture detector and li stener. |
361 * This is used for testing only. | 365 * This is used for testing only. |
362 * @param longPressDetector The new LongPressDetector to be assigned. | 366 * @param longPressDetector The new LongPressDetector to be assigned. |
363 * @param gestureDetector The new GestureDetector to be assigned. | 367 * @param gestureDetector The new GestureDetector to be assigned. |
364 * @param listener The new onGestureListener to be assigned. | 368 * @param listener The new onGestureListener to be assigned. |
365 */ | 369 */ |
366 void setTestDependencies( | 370 void setTestDependencies( |
367 LongPressDetector longPressDetector, GestureDetector gestureDetector , | 371 LongPressDetector longPressDetector, GestureDetector gestureDetector , |
368 OnGestureListener listener) { | 372 OnGestureListener listener) { |
369 mLongPressDetector = longPressDetector; | 373 if (longPressDetector != null) mLongPressDetector = longPressDetector; |
370 mGestureDetector = gestureDetector; | 374 if (gestureDetector != null) mGestureDetector = gestureDetector; |
371 mListener = listener; | 375 if (listener != null) mListener = listener; |
372 } | 376 } |
373 | 377 |
374 private void initGestureDetectors(final Context context) { | 378 private void initGestureDetectors(final Context context) { |
375 final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouc hSlop(); | 379 final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouc hSlop(); |
376 mScaledTouchSlopSquare = scaledTouchSlop * scaledTouchSlop; | 380 mScaledTouchSlopSquare = scaledTouchSlop * scaledTouchSlop; |
377 try { | 381 try { |
378 TraceEvent.begin(); | 382 TraceEvent.begin(); |
379 GestureDetector.SimpleOnGestureListener listener = | 383 GestureDetector.SimpleOnGestureListener listener = |
380 new GestureDetector.SimpleOnGestureListener() { | 384 new GestureDetector.SimpleOnGestureListener() { |
381 @Override | 385 @Override |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 } | 605 } |
602 mDoubleTapY = e.getY(); | 606 mDoubleTapY = e.getY(); |
603 return true; | 607 return true; |
604 } | 608 } |
605 | 609 |
606 @Override | 610 @Override |
607 public void onLongPress(MotionEvent e) { | 611 public void onLongPress(MotionEvent e) { |
608 if (!mZoomManager.isScaleGestureDetectionInProgress() && | 612 if (!mZoomManager.isScaleGestureDetectionInProgress() && |
609 (mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_NONE || | 613 (mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_NONE || |
610 isDoubleTapDragDisabled())) { | 614 isDoubleTapDragDisabled())) { |
611 sendShowPressCancelIfNecessary(e); | 615 mLastLongPressEvent = e; |
612 sendMotionEventAsGesture(GESTURE_LONG_PRESS, e, null ); | 616 sendMotionEventAsGesture(GESTURE_LONG_PRESS, e, null ); |
613 } | 617 } |
614 } | 618 } |
615 | 619 |
616 /** | 620 /** |
617 * This method inspects the distance between where the user started touching | 621 * This method inspects the distance between where the user started touching |
618 * the surface, and where she released. If the points are to o far apart, we | 622 * the surface, and where she released. If the points are to o far apart, we |
619 * should assume that the web page has consumed the scroll-e vents in-between, | 623 * should assume that the web page has consumed the scroll-e vents in-between, |
620 * and as such, this should not be considered a single-tap. | 624 * and as such, this should not be considered a single-tap. |
621 * | 625 * |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 // processTouchEvent asynchronously. | 855 // processTouchEvent asynchronously. |
852 return true; | 856 return true; |
853 } | 857 } |
854 return processTouchEvent(event); | 858 return processTouchEvent(event); |
855 } finally { | 859 } finally { |
856 onTouchEventHandlingEnd(); | 860 onTouchEventHandlingEnd(); |
857 TraceEvent.end("onTouchEvent"); | 861 TraceEvent.end("onTouchEvent"); |
858 } | 862 } |
859 } | 863 } |
860 | 864 |
865 /** | |
866 * Handle content view losing focus -- ensure that any remaining active stat e is removed. | |
867 */ | |
868 void onWindowFocusLost() { | |
869 if (mLongPressDetector.isInLongPress() && mLastLongPressEvent != null) { | |
Ted C
2013/09/13 23:50:26
+2 indent for the conditional
Maria
2013/09/14 01:09:34
Done.
| |
870 sendShowPressCancelIfNecessary(mLastLongPressEvent); | |
871 } | |
872 } | |
873 | |
861 private MotionEvent obtainActionCancelMotionEvent() { | 874 private MotionEvent obtainActionCancelMotionEvent() { |
862 return MotionEvent.obtain( | 875 return MotionEvent.obtain( |
863 SystemClock.uptimeMillis(), | 876 SystemClock.uptimeMillis(), |
864 SystemClock.uptimeMillis(), | 877 SystemClock.uptimeMillis(), |
865 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); | 878 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
866 } | 879 } |
867 | 880 |
868 /** | 881 /** |
869 * Resets gesture handlers state; called on didStartLoading(). | 882 * Resets gesture handlers state; called on didStartLoading(). |
870 * Note that this does NOT clear the pending motion events queue; | 883 * Note that this does NOT clear the pending motion events queue; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1154 mSentGestureNeedsVSync = mInputEventsDeliveredAtVSync && mTouchEventHand lingStackDepth > 0; | 1167 mSentGestureNeedsVSync = mInputEventsDeliveredAtVSync && mTouchEventHand lingStackDepth > 0; |
1155 mLastVSyncGestureTimeMs = timeMs; | 1168 mLastVSyncGestureTimeMs = timeMs; |
1156 return mMotionEventDelegate.sendGesture(type, timeMs, x, y, extraParams) ; | 1169 return mMotionEventDelegate.sendGesture(type, timeMs, x, y, extraParams) ; |
1157 } | 1170 } |
1158 | 1171 |
1159 void sendShowPressCancelIfNecessary(MotionEvent e) { | 1172 void sendShowPressCancelIfNecessary(MotionEvent e) { |
1160 if (!mShowPressIsCalled) return; | 1173 if (!mShowPressIsCalled) return; |
1161 | 1174 |
1162 if (sendMotionEventAsGesture(GESTURE_SHOW_PRESS_CANCEL, e, null)) { | 1175 if (sendMotionEventAsGesture(GESTURE_SHOW_PRESS_CANCEL, e, null)) { |
1163 mShowPressIsCalled = false; | 1176 mShowPressIsCalled = false; |
1177 mLastLongPressEvent = null; | |
1164 } | 1178 } |
1165 } | 1179 } |
1166 | 1180 |
1167 /** | 1181 /** |
1168 * @return Whether the ContentViewGestureHandler can handle a MotionEvent ri ght now. True only | 1182 * @return Whether the ContentViewGestureHandler can handle a MotionEvent ri ght now. True only |
1169 * if it's the start of a new stream (ACTION_DOWN), or a continuation of the current stream. | 1183 * if it's the start of a new stream (ACTION_DOWN), or a continuation of the current stream. |
1170 */ | 1184 */ |
1171 boolean canHandle(MotionEvent ev) { | 1185 boolean canHandle(MotionEvent ev) { |
1172 return ev.getAction() == MotionEvent.ACTION_DOWN || | 1186 return ev.getAction() == MotionEvent.ACTION_DOWN || |
1173 (mCurrentDownEvent != null && mCurrentDownEvent.getDownTime() == ev.getDownTime()); | 1187 (mCurrentDownEvent != null && mCurrentDownEvent.getDownTime() == ev.getDownTime()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1233 assert (mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_DISABLED || | 1247 assert (mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_DISABLED || |
1234 mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_NONE); | 1248 mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_NONE); |
1235 mDoubleTapDragMode = supportDoubleTapDrag ? | 1249 mDoubleTapDragMode = supportDoubleTapDrag ? |
1236 DOUBLE_TAP_DRAG_MODE_NONE : DOUBLE_TAP_DRAG_MODE_DISABLED; | 1250 DOUBLE_TAP_DRAG_MODE_NONE : DOUBLE_TAP_DRAG_MODE_DISABLED; |
1237 } | 1251 } |
1238 | 1252 |
1239 private boolean isDoubleTapDragDisabled() { | 1253 private boolean isDoubleTapDragDisabled() { |
1240 return mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_DISABLED; | 1254 return mDoubleTapDragMode == DOUBLE_TAP_DRAG_MODE_DISABLED; |
1241 } | 1255 } |
1242 } | 1256 } |
OLD | NEW |