From 796063f898ef34bbbe457164976ae96c802c1bc7 Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Mon, 17 Mar 2014 16:50:28 +0200 Subject: [PATCH] Fixes Escalator flick scroll regression (#13334) Change-Id: Icc263c10ec1fb0542f544ddbc2bb705e8968aa40 --- .../com/vaadin/client/ui/grid/Escalator.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/client/src/com/vaadin/client/ui/grid/Escalator.java b/client/src/com/vaadin/client/ui/grid/Escalator.java index e02ca52e6b..6112d6b139 100644 --- a/client/src/com/vaadin/client/ui/grid/Escalator.java +++ b/client/src/com/vaadin/client/ui/grid/Escalator.java @@ -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(); -- 2.39.5