Bug 904245 - Take touch radius into account when calculating pan threshold. r=kats
authorWes Johnston <wjohnston@mozilla.com>
Tue, 15 Oct 2013 08:06:01 -0700
changeset 164650 e6406d223b5056e57b11145967f73c48d9429551
parent 164649 50abdc9ee4054f9743f1b9ba185921eaf8fc8c46
child 164651 863087fdc7da7df0ced69f09c4e7d63b560db297
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs904245
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 904245 - Take touch radius into account when calculating pan threshold. r=kats
mobile/android/base/gfx/LayerView.java
mobile/android/base/gfx/PanZoomController.java
--- a/mobile/android/base/gfx/LayerView.java
+++ b/mobile/android/base/gfx/LayerView.java
@@ -16,22 +16,24 @@ import org.mozilla.gecko.mozglue.Generat
 import org.mozilla.gecko.util.EventDispatcher;
 
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.PixelFormat;
+import android.graphics.Point;
 import android.graphics.PointF;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
 import android.os.Build;
 import android.os.Handler;
 import android.util.AttributeSet;
+import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.TextureView;
 import android.view.View;
 import android.view.ViewGroup;
@@ -120,16 +122,28 @@ public class LayerView extends FrameLayo
         mInputConnectionHandler = null;
 
         setFocusable(true);
         setFocusableInTouchMode(true);
 
         GeckoAccessibility.setDelegate(this);
     }
 
+    private Point getEventRadius(MotionEvent event) {
+        if (Build.VERSION.SDK_INT >= 9) {
+            return new Point((int)event.getToolMajor()/2,
+                             (int)event.getToolMinor()/2);
+        }
+
+        float size = event.getSize();
+        DisplayMetrics displaymetrics = getContext().getResources().getDisplayMetrics();
+        size = size*Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
+        return new Point((int)size,(int)size);
+    }
+
     public void geckoConnected() {
         // See if we want to force 16-bit colour before doing anything
         PrefsHelper.getPref("gfx.android.rgb16.force", new PrefsHelper.PrefHandlerBase() {
             @Override public void prefValue(String pref, boolean force16bit) {
                 if (force16bit) {
                     GeckoAppShell.setScreenDepthOverride(16);
                 }
             }
@@ -152,18 +166,20 @@ public class LayerView extends FrameLayo
 
                 int action = event.getActionMasked();
                 PointF point = new PointF(event.getX(), event.getY());
                 if (action == MotionEvent.ACTION_DOWN) {
                     mInitialTouchPoint = point;
                 }
 
                 if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
+                    Point p = getEventRadius(event);
+
                     if (PointUtils.subtract(point, mInitialTouchPoint).length() <
-                        PanZoomController.PAN_THRESHOLD) {
+                        Math.max(PanZoomController.CLICK_THRESHOLD, Math.min(Math.min(p.x, p.y), PanZoomController.PAN_THRESHOLD))) {
                         // Don't send the touchmove event if if the users finger hasn't moved far.
                         // Necessary for Google Maps to work correctly. See bug 771099.
                         return true;
                     } else {
                         mInitialTouchPoint = null;
                     }
                 }
 
--- a/mobile/android/base/gfx/PanZoomController.java
+++ b/mobile/android/base/gfx/PanZoomController.java
@@ -13,16 +13,19 @@ import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.View;
 
 public interface PanZoomController {
     // 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 density-independent pixels.
     public static final float PAN_THRESHOLD = 1/16f * GeckoAppShell.getDpi();
 
+    // Threshold for sending touch move events to content
+    public static final float CLICK_THRESHOLD = 1/50f * GeckoAppShell.getDpi();
+
     static class Factory {
         static PanZoomController create(PanZoomTarget target, View view, EventDispatcher dispatcher) {
             return new JavaPanZoomController(target, view, dispatcher);
         }
     }
 
     public void destroy();