]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes Escalator flick scroll regression (#13334)
authorHenrik Paul <henrik@vaadin.com>
Mon, 17 Mar 2014 14:50:28 +0000 (16:50 +0200)
committerLeif Åstrand <leif@vaadin.com>
Mon, 17 Mar 2014 19:25:43 +0000 (19:25 +0000)
Change-Id: Icc263c10ec1fb0542f544ddbc2bb705e8968aa40

client/src/com/vaadin/client/ui/grid/Escalator.java

index e02ca52e6b3e2b0d8ce5daf904406e03a6e7c3bb..6112d6b139f7afb5be9b826a3407e5c70d012565 100644 (file)
@@ -322,7 +322,7 @@ public class Escalator extends Widget {
                     deltaY = y - lastY;
                     lastX = x;
                     lastY = y;
-                    lastTime = timestamp;
+                    lastTime = Duration.currentTimeMillis();
 
                     // snap the scroll to the major axes, at first.
                     if (snappedScrollEnabled) {
@@ -416,7 +416,6 @@ public class Escalator extends Widget {
                 animationHandle = AnimationScheduler.get()
                         .requestAnimationFrame(mover, escalator.bodyElem);
                 event.getNativeEvent().preventDefault();
-                mover.execute(Duration.currentTimeMillis());
             }
 
             public void touchEnd(@SuppressWarnings("unused")
@@ -472,6 +471,8 @@ public class Escalator extends Widget {
         private double yFric;
 
         private boolean cancelled = false;
+        private int lastLeft;
+        private int lastTop;
 
         /**
          * Creates a new animation callback to handle touch-scrolling flick with
@@ -491,7 +492,9 @@ public class Escalator extends Widget {
                     MAX_SPEED), -MAX_SPEED);
             velY = Math.max(Math.min(deltaY / (currentTimeMillis - lastTime),
                     MAX_SPEED), -MAX_SPEED);
-            prevTime = lastTime;
+
+            lastLeft = horizontalScrollbar.getScrollPos();
+            lastTop = verticalScrollbar.getScrollPos();
 
             /*
              * If we're scrolling mainly in one of the four major directions,
@@ -520,25 +523,34 @@ public class Escalator extends Widget {
                 return;
             }
 
-            final int lastLeft = tBodyScrollLeft;
-            final int lastTop = tBodyScrollTop;
+            if (prevTime == 0) {
+                prevTime = timestamp;
+                AnimationScheduler.get().requestAnimationFrame(this);
+                return;
+            }
+
+            int currentLeft = horizontalScrollbar.getScrollPos();
+            int currentTop = verticalScrollbar.getScrollPos();
 
             final double timeDiff = timestamp - prevTime;
-            setScrollLeft((int) (tBodyScrollLeft - velX * timeDiff));
+            double left = currentLeft - velX * timeDiff;
+            setScrollLeft((int) left);
             velX -= xFric * timeDiff;
 
-            setScrollTop(tBodyScrollTop - velY * timeDiff);
+            double top = currentTop - velY * timeDiff;
+            setScrollTop(top);
             velY -= yFric * timeDiff;
 
-            cancelBecauseOfEdgeOrCornerMaybe(lastLeft, lastTop);
+            cancelBecauseOfEdgeOrCornerMaybe();
 
             prevTime = timestamp;
             millisLeft -= timeDiff;
+            lastLeft = currentLeft;
+            lastTop = currentTop;
             AnimationScheduler.get().requestAnimationFrame(this);
         }
 
-        private void cancelBecauseOfEdgeOrCornerMaybe(final int lastLeft,
-                final int lastTop) {
+        private void cancelBecauseOfEdgeOrCornerMaybe() {
             if (lastLeft == horizontalScrollbar.getScrollPos()
                     && lastTop == verticalScrollbar.getScrollPos()) {
                 cancel();