Bug 719240 - Delay sending touchmove events until touches have moved a minimum distance. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Wed, 25 Jan 2012 01:31:33 +0100
changeset 86514 1b16c4bd7aa2748041812e2e0bf54707c63faf51
parent 86513 a63b9ee257e8414ae610b0c4dcda0c06fb5b901e
child 86515 bfa8aedbff44a8da5a55a4f0f571f17a895d9ba6
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs719240
milestone12.0a1
Bug 719240 - Delay sending touchmove events until touches have moved a minimum distance. r=mfinkle
mobile/android/base/gfx/LayerController.java
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/gfx/LayerController.java
+++ b/mobile/android/base/gfx/LayerController.java
@@ -107,16 +107,17 @@ public class LayerController {
 
     /* 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 boolean allowDefaultActions = true;
     private Timer allowDefaultTimer =  null;
     private boolean inTouchSession = false;
+    private PointF initialTouchLocation = null;
 
     public LayerController(Context context) {
         mContext = context;
 
         mForceRedraw = true;
         mViewportMetrics = new ViewportMetrics();
         mPanZoomController = new PanZoomController(this);
         mView = new LayerView(context, this);
@@ -357,25 +358,35 @@ public class LayerController {
     }
 
     /*
      * Gesture detection. This is handled only at a high level in this class; we dispatch to the
      * pan/zoom controller to do the dirty work.
      */
     public boolean onTouchEvent(MotionEvent event) {
         int action = event.getAction();
+        PointF point = new PointF(event.getX(), event.getY());
         if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
+            initialTouchLocation = point;
             post(new Runnable() {
                 public void run() {
                     mView.clearEventQueue();
                     preventPanning(mWaitForTouchListeners);
                 }
             });
         }
 
+        if (initialTouchLocation != null && (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) {
+            if (PointUtils.subtract(point, initialTouchLocation).length() > PanZoomController.PAN_THRESHOLD * 240) {
+                initialTouchLocation = null;
+            } else {
+                return !allowDefaultActions;
+            }
+        }
+
         if (mOnTouchListener != null)
             mOnTouchListener.onTouch(mView, event);
 
         if (!mWaitForTouchListeners)
             return !allowDefaultActions;
 
         switch (action & MotionEvent.ACTION_MASK) {
             case MotionEvent.ACTION_MOVE: {
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -74,17 +74,17 @@ public class PanZoomController
     private static String MESSAGE_ZOOM_PAGE = "Browser:ZoomToPageWidth";
 
     // Animation stops if the velocity is below this value when overscrolled or panning.
     private static final float STOPPED_THRESHOLD = 4.0f;
     // Animation stops is the velocity is below this threshold when flinging.
     private static final float FLING_STOPPED_THRESHOLD = 0.1f;
     // The distance the user has to pan before we recognize it as such (e.g. to avoid
     // 1-pixel pans between the touch-down and touch-up of a click). In units of inches.
-    private static final float PAN_THRESHOLD = 0.1f;
+    public static final float PAN_THRESHOLD = 0.1f;
     // Angle from axis within which we stay axis-locked
     private static final double AXIS_LOCK_ANGLE = Math.PI / 6.0; // 30 degrees
     // The maximum amount we allow you to zoom into a page
     private static final float MAX_ZOOM = 4.0f;
 
     /* 16 precomputed frames of the _ease-out_ animation from the CSS Transitions specification. */
     private static final float[] EASE_OUT_ANIMATION_FRAMES = {
         0.00000f,   /* 0 */