Bug 705092 - Kinetic scrolling is too slow. r=pcwalton a=java-only
authorChris Lord <chrislord.net@gmail.com>
Mon, 12 Dec 2011 18:56:15 +0000
changeset 82450 9989f0fed131156639b53096291d631beccfe2ae
parent 82449 e67d90275715cea1b0bf8d62db6d1c5d6cf637f4
child 82451 2662a7249e7d7c6a0a59954fe5dff92d693198af
push id21609
push userchrislord.net@gmail.com
push dateMon, 12 Dec 2011 18:58:54 +0000
treeherdermozilla-central@9989f0fed131 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton, java-only
bugs705092
milestone11.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 705092 - Kinetic scrolling is too slow. r=pcwalton a=java-only This introduces a friction factor, so that the deceleration is relative to the current velocity. Now, the faster you scroll, the slower the view decelerates, allowing you to page through longer pages easier.
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -70,16 +70,17 @@ public class PanZoomController
     extends GestureDetector.SimpleOnGestureListener
     implements ScaleGestureDetector.OnScaleGestureListener, GeckoEventListener
 {
     private static final String LOGTAG = "GeckoPanZoomController";
 
     private LayerController mController;
 
     private static final float FRICTION = 0.85f;
+    private static final float FRICTION_FACTOR = 6.0f;
     // Animation stops if the velocity is below this value.
     private static final float STOPPED_THRESHOLD = 4.0f;
     // The percentage of the surface which can be overscrolled before it must snap back.
     private static final float SNAP_LIMIT = 0.75f;
     // The rate of deceleration when the surface has overscrolled.
     private static final float OVERSCROLL_DECEL_RATE = 0.04f;
     // 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.
@@ -767,17 +768,21 @@ public class PanZoomController
                 setFlingState(FlingStates.WAITING_TO_SNAP);
         }
 
         /* Advances a fling animation by one step. */
         public void advanceFling() {
             // If we aren't overscrolled, just apply friction.
             float excess = getExcess();
             if (disableSnap || FloatUtils.fuzzyEquals(excess, 0.0f)) {
-                velocity *= FRICTION;
+                float absvelocity = (float)
+                    Math.pow(Math.pow(velocity, FRICTION_FACTOR) * FRICTION,
+                             1 / FRICTION_FACTOR);
+                velocity = Math.copySign(absvelocity, velocity);
+
                 if (Math.abs(velocity) < 0.1f) {
                     velocity = 0.0f;
                     setFlingState(FlingStates.STOPPED);
                 }
                 return;
             }
 
             // Otherwise, decrease the velocity linearly.