From 08f4b19f52a6a2d64206e69fe7b625627ab6c984 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 29 Feb 2012 14:03:28 -0800 Subject: [PATCH] Bug 725458 - Start touch timeout during action_down. r=mbrubeck --- mobile/android/base/gfx/LayerController.java | 69 +++++++------------- 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/mobile/android/base/gfx/LayerController.java b/mobile/android/base/gfx/LayerController.java index b24e180308ab..22413cb06aa8 100644 --- a/mobile/android/base/gfx/LayerController.java +++ b/mobile/android/base/gfx/LayerController.java @@ -111,11 +111,10 @@ public class LayerController implements Tabs.OnTabsChangedListener { /* The time limit for pages to respond with preventDefault on touchevents * before we begin panning the page */ - private static final int PREVENT_DEFAULT_TIMEOUT = 200; + private int mTimeout = 200; private boolean allowDefaultActions = true; private Timer allowDefaultTimer = null; - private boolean inTouchSession = false; private PointF initialTouchLocation = null; public LayerController(Context context) { @@ -127,6 +126,9 @@ public class LayerController implements Tabs.OnTabsChangedListener { mView = new LayerView(context, this); Tabs.getInstance().registerOnTabsChangedListener(this); + + ViewConfiguration vc = ViewConfiguration.get(mContext); + mTimeout = vc.getLongPressTimeout(); } public void onDestroy() { @@ -390,15 +392,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 +426,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) {