Bug 1292034 - Make the StackScroller flywheel detection code more robust to real user behaviour when flinging. r=rbarker, a=ritu
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 07 Oct 2016 21:43:52 -0400
changeset 358274 f591aa1d3916eb87ed14cb78b8c07bdeca8fb1a7
parent 358273 9a452e8fde0ffd76d25179f5d6165265444a2247
child 358275 12071c89e4c0062c8d409c55a3ad043a2f65189d
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker, ritu
bugs1292034
milestone51.0a2
Bug 1292034 - Make the StackScroller flywheel detection code more robust to real user behaviour when flinging. r=rbarker, a=ritu MozReview-Commit-ID: DdI17RyIxiq
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/StackScroller.java
@@ -256,19 +256,24 @@ public class StackScroller {
      *            direction will be possible.
      */
     public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX,
             int minY, int maxY, int overX, int overY, long time) {
         // Continue a scroll or fling in progress
         if (mFlywheel && !isFinished()) {
             float oldVelocityX = mScrollerX.mCurrVelocity;
             float oldVelocityY = mScrollerY.mCurrVelocity;
-            if (Math.signum(velocityX) == Math.signum(oldVelocityX)
-                    && Math.signum(velocityY) == Math.signum(oldVelocityY)) {
+            boolean sameXDirection = (velocityX == 0) || (oldVelocityX == 0) ||
+                ((velocityX < 0) == (oldVelocityX < 0));
+            boolean sameYDirection = (velocityY == 0) || (oldVelocityY == 0) ||
+                ((velocityY < 0) == (oldVelocityY < 0));
+            if (sameXDirection) {
                 velocityX += oldVelocityX;
+            }
+            if (sameYDirection) {
                 velocityY += oldVelocityY;
             }
         }
 
         mMode = FLING_MODE;
         mScrollerX.fling(startX, velocityX, minX, maxX, overX, time);
         mScrollerY.fling(startY, velocityY, minY, maxY, overY, time);
     }