From b8c10d6474207acb4b9edea528ec23acb6541860 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 29 Feb 2012 13:13:31 -0800 Subject: [PATCH] Bug 725458 - Start touch timeout during action_down. r=mbrubeck --- mobile/android/base/gfx/LayerController.java | 63 ++++++-------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/mobile/android/base/gfx/LayerController.java b/mobile/android/base/gfx/LayerController.java index b24e180308a..af825ed8f65 100644 --- a/mobile/android/base/gfx/LayerController.java +++ b/mobile/android/base/gfx/LayerController.java @@ -390,15 +390,29 @@ public class LayerController implements Tabs.OnTabsChangedListener { int action = event.getAction(); PointF point = new PointF(event.getX(), event.getY()); + // this will only match the first touchstart in a series if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { - mView.clearEventQueue(); initialTouchLocation = point; allowDefaultActions = !mWaitForTouchListeners; - post(new Runnable() { + + // if we have a timer, this may be a double tap, + // cancel the current timer but don't clear the event queue + if (allowDefaultTimer != null) { + allowDefaultTimer.cancel(); + } else { + // if we don't have a timer, make sure we remove any old events + mView.clearEventQueue(); + } + allowDefaultTimer = new Timer(); + allowDefaultTimer.schedule(new TimerTask() { public void run() { - preventPanning(mWaitForTouchListeners); + post(new Runnable() { + public void run() { + preventPanning(false); + } + }); } - }); + }, mTimeout); } // After the initial touch, ignore touch moves until they exceed a minimum distance. @@ -410,55 +424,16 @@ public class LayerController implements Tabs.OnTabsChangedListener { } } + // send the event to content if (mOnTouchListener != null) mOnTouchListener.onTouch(mView, event); - if (!mWaitForTouchListeners) - return !allowDefaultActions; - - boolean createTimer = false; - switch (action & MotionEvent.ACTION_MASK) { - case MotionEvent.ACTION_MOVE: { - if (!inTouchSession && allowDefaultTimer == null) { - inTouchSession = true; - createTimer = true; - } - break; - } - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_UP: { - // if we still have initialTouchLocation, we haven't fired any - // touchmove events. We should start the timer to wait for preventDefault - // from touchstart. If we don't hear from it we fire mouse events - if (initialTouchLocation != null) - createTimer = true; - inTouchSession = false; - } - } - - if (createTimer) { - if (allowDefaultTimer != null) { - allowDefaultTimer.cancel(); - } - allowDefaultTimer = new Timer(); - allowDefaultTimer.schedule(new TimerTask() { - public void run() { - post(new Runnable() { - public void run() { - preventPanning(false); - } - }); - } - }, PREVENT_DEFAULT_TIMEOUT); - } - return !allowDefaultActions; } public void preventPanning(boolean aValue) { if (allowDefaultTimer != null) { allowDefaultTimer.cancel(); - allowDefaultTimer.purge(); allowDefaultTimer = null; } if (aValue == allowDefaultActions) {