]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make Grid isWorkPending wait for scroll events to complete (#20417)
authorArtur Signell <artur@vaadin.com>
Wed, 19 Oct 2016 19:50:22 +0000 (22:50 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 20 Oct 2016 05:11:35 +0000 (05:11 +0000)
Change-Id: I3cfdac539111ff2e88c7ff81e6d6b9a579160423

client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java

index c8bc8462e9f16eb80510a4ca5fd4c07c944d5310..6e2fb14f8f5ecd6fc4179560ed18d9871d12a1a6 100644 (file)
@@ -368,6 +368,7 @@ public abstract class ScrollbarBundle implements DeferredWorker {
 
     private HandlerRegistration scrollSizeTemporaryScrollHandler;
     private HandlerRegistration offsetSizeTemporaryScrollHandler;
+    private HandlerRegistration scrollInProgress;
 
     private ScrollbarBundle() {
         root.appendChild(scrollSizeElement);
@@ -530,6 +531,16 @@ public abstract class ScrollbarBundle implements DeferredWorker {
         scrollPos = Math.max(0, Math.min(maxScrollPos, truncate(px)));
 
         if (!WidgetUtil.pixelValuesEqual(oldScrollPos, scrollPos)) {
+            if (scrollInProgress == null) {
+                // Only used for tracking that there is "workPending"
+                scrollInProgress = addScrollHandler(new ScrollHandler() {
+                    @Override
+                    public void onScroll(ScrollEvent event) {
+                        scrollInProgress.removeHandler();
+                        scrollInProgress = null;
+                    }
+                });
+            }
             if (isInvisibleScrollbar) {
                 invisibleScrollbarTemporaryResizer.show();
             }
@@ -919,6 +930,6 @@ public abstract class ScrollbarBundle implements DeferredWorker {
         // requestAnimationFrame - which is not automatically checked
         return scrollSizeTemporaryScrollHandler != null
                 || offsetSizeTemporaryScrollHandler != null
-                || scrollEventFirer.isBeingFired;
+                || scrollInProgress != null || scrollEventFirer.isBeingFired;
     }
 }
index e394be36de008b67d162da3c80357898b933cdd7..fbd36f87f9ac2fad7bd2370c03e8dcdac726b388 100644 (file)
@@ -54,4 +54,18 @@ public class GridScrollTest extends GridBasicFeaturesTest {
                 "0. Requested items 247 - 346", getLogRow(0));
         assertEquals("There should be only one log row", " ", getLogRow(1));
     }
+
+    @Test
+    public void workPendingWhileScrolling() {
+        openTestURL("theme=valo");
+        String script = "var c = window.vaadin.clients.runcomvaadintestscomponentsgridbasicfeaturesGridBasicFeatures;\n"
+                // Scroll down and cause lazy loading
+                + "c.getElementByPath(\"//Grid[0]#cell[21]\"); \n"
+                + "return c.isActive();";
+
+        Boolean active = (Boolean) executeScript(script);
+        assertTrue("Grid should be marked to have workPending while scrolling",
+                active);
+    }
+
 }