From 3f1fafd72aae2a0efc243e43305921646a3f8f91 Mon Sep 17 00:00:00 2001 From: "jdduke@chromium.org" Date: Wed, 6 Nov 2013 02:17:30 +0000 Subject: [PATCH] [Android] Fix missing onSingleTapConfirmed calls in GestureDetector Eliminate the short period of time between the tap timeout and long press causing onSingleTapConfirmed not to be dispatched when apps expect. Note: This is a cherry-pick of the upstream Android fix for b/8124095. BUG=315124 NOTRY=true Review URL: https://codereview.chromium.org/59173006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233192 0039d316-1c4b-4281-b951-d872f2087c98 --- build/android/findbugs_filter/findbugs_known_bugs.txt | 2 +- .../content/browser/third_party/GestureDetector.java | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/build/android/findbugs_filter/findbugs_known_bugs.txt b/build/android/findbugs_filter/findbugs_known_bugs.txt index b2375f84cbcd..09e403fe6393 100644 --- a/build/android/findbugs_filter/findbugs_known_bugs.txt +++ b/build/android/findbugs_filter/findbugs_known_bugs.txt @@ -17,7 +17,7 @@ M C CSM: Shouldn't use synchronized method, please narrow down the synchronizati M C CSM: Shouldn't use synchronized method, please narrow down the synchronization scope. At TraceEvent.java M C CST: Shouldn't use synchronized(this), please narrow down the synchronization scope. At HttpAuthDatabase.java M C CST: Shouldn't use synchronized(this), please narrow down the synchronization scope. At SimpleSynchronizedThis.java -M C RCN: Nullcheck of GestureDetector.mVelocityTracker at line 630 of value previously dereferenced in org.chromium.content.browser.third_party.GestureDetector.onTouchEvent(MotionEvent) At GestureDetector.java +M C RCN: Nullcheck of GestureDetector.mVelocityTracker at line 639 of value previously dereferenced in org.chromium.content.browser.third_party.GestureDetector.onTouchEvent(MotionEvent) At GestureDetector.java M C USELESS_STRING: Invocation of toString on certChain in org.chromium.net.X509Util.verifyServerCertificates(byte[][], String) At X509Util.java M D DMI: Hard coded reference to an absolute pathname in org.chromium.android_webview.test.ArchiveTest.testAutoBadPath() At ArchiveTest.java M D DMI: Hard coded reference to an absolute pathname in org.chromium.android_webview.test.ArchiveTest.testExplicitBadPath() At ArchiveTest.java diff --git a/content/public/android/java/src/org/chromium/content/browser/third_party/GestureDetector.java b/content/public/android/java/src/org/chromium/content/browser/third_party/GestureDetector.java index 6c98320fa3ff..3a52db4015a8 100644 --- a/content/public/android/java/src/org/chromium/content/browser/third_party/GestureDetector.java +++ b/content/public/android/java/src/org/chromium/content/browser/third_party/GestureDetector.java @@ -225,6 +225,7 @@ public class GestureDetector { private OnDoubleTapListener mDoubleTapListener; private boolean mStillDown; + private boolean mDeferConfirmSingleTap; private boolean mInLongPress; private boolean mAlwaysInTapRegion; private boolean mAlwaysInBiggerTapRegion; @@ -281,8 +282,12 @@ public class GestureDetector { case TAP: // If the user's finger is still down, do not count it as a tap - if (mDoubleTapListener != null && !mStillDown) { - mDoubleTapListener.onSingleTapConfirmed(mCurrentDownEvent); + if (mDoubleTapListener != null) { + if (!mStillDown) { + mDoubleTapListener.onSingleTapConfirmed(mCurrentDownEvent); + } else { + mDeferConfirmSingleTap = true; + } } break; @@ -555,7 +560,8 @@ public class GestureDetector { mAlwaysInBiggerTapRegion = true; mStillDown = true; mInLongPress = false; - + mDeferConfirmSingleTap = false; + if (mIsLongpressEnabled) { mHandler.removeMessages(LONG_PRESS); mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime() @@ -608,6 +614,9 @@ public class GestureDetector { mInLongPress = false; } else if (mAlwaysInTapRegion) { handled = mListener.onSingleTapUp(ev); + if (mDeferConfirmSingleTap && mDoubleTapListener != null) { + mDoubleTapListener.onSingleTapConfirmed(ev); + } } else { // A fling must travel the minimum tap distance @@ -634,6 +643,7 @@ public class GestureDetector { mVelocityTracker = null; } mIsDoubleTapping = false; + mDeferConfirmSingleTap = false; mHandler.removeMessages(SHOW_PRESS); mHandler.removeMessages(LONG_PRESS); break; @@ -661,6 +671,7 @@ public class GestureDetector { mStillDown = false; mAlwaysInTapRegion = false; mAlwaysInBiggerTapRegion = false; + mDeferConfirmSingleTap = false; if (mInLongPress) { mInLongPress = false; } @@ -673,6 +684,7 @@ public class GestureDetector { mIsDoubleTapping = false; mAlwaysInTapRegion = false; mAlwaysInBiggerTapRegion = false; + mDeferConfirmSingleTap = false; if (mInLongPress) { mInLongPress = false; } @@ -695,6 +707,7 @@ public class GestureDetector { private void dispatchLongPress() { mHandler.removeMessages(TAP); + mDeferConfirmSingleTap = false; mInLongPress = true; mListener.onLongPress(mCurrentDownEvent); } -- 2.11.4.GIT