Bug 590777 (part 4) - Convert swipe thresholds from pixels to inches. r=blassey a=blocking-fennec
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 18 Nov 2010 09:18:31 -0800
changeset 57857 035fcd2ac561262edabca127f061ebbafe1f6554
parent 57856 b80c7aadda8311e73658e0b8d2a500eef511634b
child 57858 d18bdf583d87426b4cd110309518e94fe5c9d2de
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersblassey, blocking-fennec
bugs590777
milestone2.0b8pre
Bug 590777 (part 4) - Convert swipe thresholds from pixels to inches. r=blassey a=blocking-fennec
widget/src/android/nsWindow.cpp
widget/src/android/nsWindow.h
--- a/widget/src/android/nsWindow.cpp
+++ b/widget/src/android/nsWindow.cpp
@@ -83,19 +83,19 @@ static PRBool gMenuConsumed;
 // stacking order, so the window at gAndroidBounds[0] is the topmost
 // one.
 static nsTArray<nsWindow*> gTopLevelWindows;
 static nsWindow* gFocusedWindow = nsnull;
 
 static nsRefPtr<gl::GLContext> sGLContext;
 static bool sFailedToCreateGLContext = false;
 
-// Multitouch swipe thresholds (in screen pixels)
-static const double SWIPE_MAX_PINCH_DELTA = 100;
-static const double SWIPE_MIN_DISTANCE = 150;
+// Multitouch swipe thresholds in inches
+static const double SWIPE_MAX_PINCH_DELTA_INCHES = 0.4;
+static const double SWIPE_MIN_DISTANCE_INCHES = 0.6;
 
 static nsWindow*
 TopWindow()
 {
     if (!gTopLevelWindows.IsEmpty())
         return gTopLevelWindows[0];
     return nsnull;
 }
@@ -194,16 +194,20 @@ nsWindow::Create(nsIWidget *aParent,
         gTopLevelWindows.AppendElement(this);
     }
 
     if (parent) {
         parent->mChildren.AppendElement(this);
         mParent = parent;
     }
 
+    float dpi = GetDPI();
+    mSwipeMaxPinchDelta = SWIPE_MAX_PINCH_DELTA_INCHES * dpi;
+    mSwipeMinDistance = SWIPE_MIN_DISTANCE_INCHES * dpi;
+
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::Destroy(void)
 {
     for (PRUint32 i = 0; i < mChildren.Length(); ++i) {
         // why do we still have children?
@@ -1098,24 +1102,24 @@ void nsWindow::OnMultitouchEvent(Android
             return;
     }
 
     if (!mGestureFinished) {
         DispatchGestureEvent(msg, 0, pinchDelta, refPoint, ae->Time());
 
         // If the cumulative pinch delta goes past the threshold, treat this
         // as a pinch only, and not a swipe.
-        if (fabs(pinchDist - mStartDist) > SWIPE_MAX_PINCH_DELTA)
+        if (fabs(pinchDist - mStartDist) > mSwipeMaxPinchDelta)
             mStartPoint = nsnull;
 
         // If we have traveled more than SWIPE_MIN_DISTANCE from the start
         // point, stop the pinch gesture and fire a swipe event.
         if (mStartPoint) {
             double swipeDistance = getDistance(midPoint, *mStartPoint);
-            if (swipeDistance > SWIPE_MIN_DISTANCE) {
+            if (swipeDistance > mSwipeMinDistance) {
                 PRUint32 direction = 0;
                 nsIntPoint motion = midPoint - *mStartPoint;
 
                 if (motion.x < -swipeDistance/2)
                     direction |= nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
                 if (motion.x > swipeDistance/2)
                     direction |= nsIDOMSimpleGestureEvent::DIRECTION_RIGHT;
                 if (motion.y < -swipeDistance/2)
--- a/widget/src/android/nsWindow.h
+++ b/widget/src/android/nsWindow.h
@@ -181,16 +181,20 @@ protected:
     nsTArray<nsWindow*> mChildren;
     nsWindow* mParent;
 
     bool mGestureFinished;
     double mStartDist;
     double mLastDist;
     nsAutoPtr<nsIntPoint> mStartPoint;
 
+    // Multitouch swipe thresholds in screen pixels
+    double mSwipeMaxPinchDelta;
+    double mSwipeMinDistance;
+
     nsCOMPtr<nsIdleService> mIdleService;
 
     PRUint32 mIMEEnabled;
     PRBool mIMEComposing;
     nsString mIMEComposingText;
     nsAutoTArray<nsTextRange, 4> mIMERanges;
 
     static void DumpWindows();