From 82a001d2dc4e9e207e26107b6a31d6619ba6e7a4 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 19 Oct 2016 22:50:22 +0300 Subject: [PATCH] Make Grid isWorkPending wait for scroll events to complete (#20417) Change-Id: I3cfdac539111ff2e88c7ff81e6d6b9a579160423 --- .../client/widget/escalator/ScrollbarBundle.java | 13 ++++++++++++- .../grid/basicfeatures/server/GridScrollTest.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java index c8bc8462e9..6e2fb14f8f 100644 --- a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -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; } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java index e394be36de..fbd36f87f9 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java @@ -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); + } + } -- 2.39.5