Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewGestureHandler.java

Issue 18850005: Disable double tap zoom on mobile sites, to remove 300ms click delay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 // Remember whether onShowPress() is called. If it is not, in onSingleTapCon firmed() 80 // Remember whether onShowPress() is called. If it is not, in onSingleTapCon firmed()
81 // we will first show the press state, then trigger the click. 81 // we will first show the press state, then trigger the click.
82 private boolean mShowPressIsCalled; 82 private boolean mShowPressIsCalled;
83 83
84 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch , 84 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch ,
85 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT apUp() 85 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT apUp()
86 // will be mistakenly fired. 86 // will be mistakenly fired.
87 private boolean mIgnoreSingleTap; 87 private boolean mIgnoreSingleTap;
88 88
89 private boolean mDoubleTapZoomEnabled = true;
klobag.chromium 2013/07/10 18:26:21 This should be set by "mListener instanceof Gestur
johnme 2013/07/10 19:19:16 Done (though that should always be true, as mListe
90
89 // Does native think we are scrolling? True from right before we 91 // Does native think we are scrolling? True from right before we
90 // send the first scroll event until the last finger is raised. 92 // send the first scroll event until the last finger is raised.
91 // Call nativeScrollBegin() when setting this to true, and use 93 // Call nativeScrollBegin() when setting this to true, and use
92 // tellNativeScrollingHasEnded() to set it to false. 94 // tellNativeScrollingHasEnded() to set it to false.
93 private boolean mNativeScrolling; 95 private boolean mNativeScrolling;
94 96
95 private boolean mFlingMayBeActive; 97 private boolean mFlingMayBeActive;
96 98
97 private boolean mSeenFirstScrollEvent; 99 private boolean mSeenFirstScrollEvent;
98 100
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 * @param x The amount scrolled in the X direction. 270 * @param x The amount scrolled in the X direction.
269 * @param y The amount scrolled in the Y direction. 271 * @param y The amount scrolled in the Y direction.
270 * @return Whether or not the UI consumed and handled this event. 272 * @return Whether or not the UI consumed and handled this event.
271 */ 273 */
272 boolean didUIStealScroll(float x, float y); 274 boolean didUIStealScroll(float x, float y);
273 275
274 /** 276 /**
275 * Show the zoom picker UI. 277 * Show the zoom picker UI.
276 */ 278 */
277 public void invokeZoomPicker(); 279 public void invokeZoomPicker();
278
279 /**
280 * @return Whether changing the page scale is not possible on the curren t page.
281 */
282 public boolean hasFixedPageScale();
283 } 280 }
284 281
285 ContentViewGestureHandler( 282 ContentViewGestureHandler(
286 Context context, MotionEventDelegate delegate, ZoomManager zoomManag er, 283 Context context, MotionEventDelegate delegate, ZoomManager zoomManag er,
287 int inputEventDeliveryMode) { 284 int inputEventDeliveryMode) {
288 mExtraParamBundle = new Bundle(); 285 mExtraParamBundle = new Bundle();
289 mLongPressDetector = new LongPressDetector(context, this); 286 mLongPressDetector = new LongPressDetector(context, this);
290 mMotionEventDelegate = delegate; 287 mMotionEventDelegate = delegate;
291 mZoomManager = zoomManager; 288 mZoomManager = zoomManager;
292 mSnapScrollController = new SnapScrollController(context, mZoomManager); 289 mSnapScrollController = new SnapScrollController(context, mZoomManager);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 mShowPressIsCalled = true; 413 mShowPressIsCalled = true;
417 sendMotionEventAsGesture(GESTURE_SHOW_PRESSED_STATE, e, null); 414 sendMotionEventAsGesture(GESTURE_SHOW_PRESSED_STATE, e, null);
418 } 415 }
419 416
420 @Override 417 @Override
421 public boolean onSingleTapUp(MotionEvent e) { 418 public boolean onSingleTapUp(MotionEvent e) {
422 if (isDistanceBetweenDownAndUpTooLong(e.getRawX(), e.get RawY())) { 419 if (isDistanceBetweenDownAndUpTooLong(e.getRawX(), e.get RawY())) {
423 mIgnoreSingleTap = true; 420 mIgnoreSingleTap = true;
424 return true; 421 return true;
425 } 422 }
423
424 if (!mDoubleTapZoomEnabled && !mLongPressDetector.isInLo ngPress()) {
425 return onSingleTapConfirmed(e);
426 }
427
426 // This is a hack to address the issue where user hovers 428 // This is a hack to address the issue where user hovers
427 // over a link for longer than DOUBLE_TAP_TIMEOUT, then 429 // over a link for longer than DOUBLE_TAP_TIMEOUT, then
428 // onSingleTapConfirmed() is not triggered. But we still 430 // onSingleTapConfirmed() is not triggered. But we still
429 // want to trigger the tap event at UP. So we override 431 // want to trigger the tap event at UP. So we override
430 // onSingleTapUp() in this case. This assumes singleTapU p 432 // onSingleTapUp() in this case. This assumes singleTapU p
431 // gets always called before singleTapConfirmed. 433 // gets always called before singleTapConfirmed.
432 if (!mIgnoreSingleTap && !mLongPressDetector.isInLongPre ss()) { 434 if (!mIgnoreSingleTap && !mLongPressDetector.isInLongPre ss()) {
433 if (e.getEventTime() - e.getDownTime() > DOUBLE_TAP_ TIMEOUT) { 435 if (e.getEventTime() - e.getDownTime() > DOUBLE_TAP_ TIMEOUT) {
434 float x = e.getX(); 436 float x = e.getX();
435 float y = e.getY(); 437 float y = e.getY();
436 if (sendMotionEventAsGesture(GESTURE_SINGLE_TAP_ UP, e, null)) { 438 if (sendMotionEventAsGesture(GESTURE_SINGLE_TAP_ UP, e, null)) {
437 mIgnoreSingleTap = true; 439 mIgnoreSingleTap = true;
438 } 440 }
439 setClickXAndY((int) x, (int) y); 441 setClickXAndY((int) x, (int) y);
440 return true; 442 return true;
441 } else if (mMotionEventDelegate.hasFixedPageScale()) {
442 // If page is not user scalable, we don't need t o wait
443 // for double tap timeout.
444 float x = e.getX();
445 float y = e.getY();
446 mExtraParamBundle.clear();
447 mExtraParamBundle.putBoolean(SHOW_PRESS, mShowPr essIsCalled);
448 if (sendMotionEventAsGesture(GESTURE_SINGLE_TAP_ CONFIRMED, e,
449 mExtraParamBundle)) {
450 mIgnoreSingleTap = true;
451 }
452 setClickXAndY((int) x, (int) y);
453 } else { 443 } else {
454 // Notify Blink about this tapUp event anyway, 444 // Notify Blink about this tapUp event anyway,
455 // when none of the above conditions applied. 445 // when none of the above conditions applied.
456 sendMotionEventAsGesture(GESTURE_SINGLE_TAP_UNCO NFIRMED, e, null); 446 sendMotionEventAsGesture(GESTURE_SINGLE_TAP_UNCO NFIRMED, e, null);
457 } 447 }
458 } 448 }
459 449
460 return triggerLongTapIfNeeded(e); 450 return triggerLongTapIfNeeded(e);
461 } 451 }
462 452
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 503 }
514 }; 504 };
515 mListener = listener; 505 mListener = listener;
516 mGestureDetector = new GestureDetector(context, listener); 506 mGestureDetector = new GestureDetector(context, listener);
517 mGestureDetector.setIsLongpressEnabled(false); 507 mGestureDetector.setIsLongpressEnabled(false);
518 } finally { 508 } finally {
519 TraceEvent.end(); 509 TraceEvent.end();
520 } 510 }
521 } 511 }
522 512
513 public void setDoubleTapZoomEnabled(boolean enable) {
514 if (enable == mDoubleTapZoomEnabled) {
515 return;
516 }
517
518 GestureDetector.OnDoubleTapListener listener = null;
519 if (enable && mListener instanceof GestureDetector.OnDoubleTapListener) {
520 listener = (GestureDetector.OnDoubleTapListener)mListener;
521 }
522 mGestureDetector.setOnDoubleTapListener(listener);
523 mDoubleTapZoomEnabled = enable;
524
525 // Clean up state, in particular, prevent GestureDetector from getting
526 // left with mIsDoubleTapping == true but mDoubleTapListener == null.
527 resetGestureHandlers();
528 }
529
523 /** 530 /**
524 * @return LongPressDetector handling setting up timers for and canceling Lo ngPress gestures. 531 * @return LongPressDetector handling setting up timers for and canceling Lo ngPress gestures.
525 */ 532 */
526 LongPressDetector getLongPressDetector() { 533 LongPressDetector getLongPressDetector() {
527 return mLongPressDetector; 534 return mLongPressDetector;
528 } 535 }
529 536
530 /** 537 /**
531 * @param event Start a LongPress gesture event from the listener. 538 * @param event Start a LongPress gesture event from the listener.
532 */ 539 */
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 /** 1023 /**
1017 * This is for testing only. 1024 * This is for testing only.
1018 * Sends a show pressed state gesture through mListener. This should always be called after 1025 * Sends a show pressed state gesture through mListener. This should always be called after
1019 * a down event; 1026 * a down event;
1020 */ 1027 */
1021 void sendShowPressedStateGestureForTesting() { 1028 void sendShowPressedStateGestureForTesting() {
1022 if (mCurrentDownEvent == null) return; 1029 if (mCurrentDownEvent == null) return;
1023 mListener.onShowPress(mCurrentDownEvent); 1030 mListener.onShowPress(mCurrentDownEvent);
1024 } 1031 }
1025 } 1032 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698