aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2020-07-15 12:15:37 +0300
committerGitHub <noreply@github.com>2020-07-15 12:15:37 +0300
commit47af00706b9ab5bddf63cd9ebc463c5373cda3ed (patch)
treeb5960e76746c3c098d2c1780fdcbded666b9fcec
parent70fa99868a11671ed7bc8875ee24e971f78ba77f (diff)
downloadvaadin-framework-47af00706b9ab5bddf63cd9ebc463c5373cda3ed.tar.gz
vaadin-framework-47af00706b9ab5bddf63cd9ebc463c5373cda3ed.zip
Revert 'Rewrote debouncing of onResize (#11899)' (#12051) (#12056)
Fixes #12049
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java48
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledResize.java186
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledResizeTest.java55
3 files changed, 256 insertions, 33 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java
index 9f36864bc8..1226920bd1 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -4387,9 +4387,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private boolean refreshBodyRequested = false;
- private boolean resizeRequested = false;
- private boolean resizeRefreshScheduled = false;
-
private DragAndDropHandler.DragAndDropCallback headerCellDndCallback = new DragAndDropCallback() {
private final AutoScrollerCallback autoScrollerCallback = new AutoScrollerCallback() {
@@ -9325,38 +9322,23 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
/*
* Delay calculation to be deferred so Escalator can do it's magic.
*/
- resizeRequested = true;
- if (!resizeRefreshScheduled) {
- resizeRefreshScheduled = true;
- Scheduler.get().scheduleFixedDelay(() -> {
- if (!resizeRequested) {
- doRefreshOnResize();
- resizeRefreshScheduled = false;
- return false;
- } else {
- resizeRequested = false;
- return true;
- }
- }, 50);
- }
- }
-
- private void doRefreshOnResize() {
- if (escalator
- .getInnerWidth() != autoColumnWidthsRecalculator.lastCalculatedInnerWidth) {
- recalculateColumnWidths();
- }
+ Scheduler.get().scheduleFinally(() -> {
+ if (escalator
+ .getInnerWidth() != autoColumnWidthsRecalculator.lastCalculatedInnerWidth) {
+ recalculateColumnWidths();
+ }
- // Vertical resizing could make editor positioning invalid so it
- // needs to be recalculated on resize
- if (isEditorActive()) {
- editor.updateVerticalScrollPosition();
- }
+ // Vertical resizing could make editor positioning invalid so it
+ // needs to be recalculated on resize
+ if (isEditorActive()) {
+ editor.updateVerticalScrollPosition();
+ }
- // if there is a resize, we need to refresh the body to avoid an
- // off-by-one error which occurs when the user scrolls all the
- // way to the bottom.
- refreshBody();
+ // if there is a resize, we need to refresh the body to avoid an
+ // off-by-one error which occurs when the user scrolls all the
+ // way to the bottom.
+ refreshBody();
+ });
}
private double getEscalatorInnerHeight() {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledResize.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledResize.java
new file mode 100644
index 0000000000..c6900d4adf
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledResize.java
@@ -0,0 +1,186 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+
+public class GridScrolledResize extends AbstractTestUI {
+
+ private Label spaceGrabber;
+
+ @Override
+ public void setup(VaadinRequest vaadinRequest) {
+
+ Grid<Person> grid = new Grid<>(Person.class);
+ grid.setWidth(100, Unit.PERCENTAGE);
+ grid.setItems(createPersons());
+
+ HorizontalLayout splitter = new HorizontalLayout();
+ splitter.setWidthFull();
+ splitter.addComponent(grid);
+ splitter.setExpandRatio(grid, 1f);
+
+ addComponent(splitter);
+
+ addComponent(new Button("Toggle component", e -> {
+
+ if (spaceGrabber == null) {
+ spaceGrabber = new Label("I'm a space grabber...");
+ spaceGrabber.setWidth(500, Unit.PIXELS);
+ }
+
+ if (spaceGrabber.isAttached()) {
+ splitter.removeComponent(spaceGrabber);
+ } else {
+ splitter.addComponent(spaceGrabber);
+ }
+
+ }));
+
+ }
+
+ private List<Person> createPersons() {
+ ArrayList<Person> people = new ArrayList<>();
+
+ for (int i = 0; i < 100; i++) {
+ people.add(new Person("First", "Last"));
+ }
+
+ return people;
+
+ }
+
+ public static class Person {
+ private String fName;
+ private String lName;
+ private String col3;
+ private String col4;
+ private String col5;
+ private String col6;
+ private String col7;
+ private String col8;
+ private String col9;
+ private String col10;
+ private String col11;
+ private String col12;
+
+ public String getCol8() {
+ return col8;
+ }
+
+ public void setCol8(String col8) {
+ this.col8 = col8;
+ }
+
+ public String getCol9() {
+ return col9;
+ }
+
+ public void setCol9(String col9) {
+ this.col9 = col9;
+ }
+
+ public String getCol10() {
+ return col10;
+ }
+
+ public void setCol10(String col10) {
+ this.col10 = col10;
+ }
+
+ public String getCol11() {
+ return col11;
+ }
+
+ public void setCol11(String col11) {
+ this.col11 = col11;
+ }
+
+ public String getCol12() {
+ return col12;
+ }
+
+ public void setCol12(String col12) {
+ this.col12 = col12;
+ }
+
+ public Person(String fName, String lName) {
+ this.fName = fName;
+ this.lName = lName;
+
+ int i = 3;
+ col3 = fName + " " + lName + i++;
+ col4 = col3 + i++;
+ col5 = col3 + i++;
+ col6 = col3 + i++;
+ col7 = col3 + i++;
+ col8 = col3 + i++;
+ col9 = col3 + i++;
+ col10 = col3 + i++;
+ col11 = col3 + i++;
+ col12 = col3 + i++;
+ }
+
+ public String getfName() {
+ return fName;
+ }
+
+ public void setfName(String fName) {
+ this.fName = fName;
+ }
+
+ public String getlName() {
+ return lName;
+ }
+
+ public void setlName(String lName) {
+ this.lName = lName;
+ }
+
+ public String getCol3() {
+ return col3;
+ }
+
+ public void setCol3(String col3) {
+ this.col3 = col3;
+ }
+
+ public String getCol4() {
+ return col4;
+ }
+
+ public void setCol4(String col4) {
+ this.col4 = col4;
+ }
+
+ public String getCol5() {
+ return col5;
+ }
+
+ public void setCol5(String col5) {
+ this.col5 = col5;
+ }
+
+ public String getCol6() {
+ return col6;
+ }
+
+ public void setCol6(String col6) {
+ this.col6 = col6;
+ }
+
+ public String getCol7() {
+ return col7;
+ }
+
+ public void setCol7(String col7) {
+ this.col7 = col7;
+ }
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledResizeTest.java
new file mode 100644
index 0000000000..2693ad0b02
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledResizeTest.java
@@ -0,0 +1,55 @@
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridScrolledResizeTest extends MultiBrowserTest {
+
+ @Test
+ public void scrollUpdatedAfterResize() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+ ButtonElement button = $(ButtonElement.class).first();
+ WebElement scrollbar = grid
+ .findElement(By.className("v-grid-scroller-horizontal"));
+ TestBenchElement header = grid.getHeader();
+
+ int initialHeaderRight = header.getLocation().getX()
+ + header.getSize().getWidth();
+
+ // resize to include scrollbar
+ button.click();
+ assertEquals("No visible scrollbar when one expected.", "block",
+ scrollbar.getCssValue("display"));
+
+ int scrolledHeaderRight = header.getLocation().getX()
+ + header.getSize().getWidth();
+ assertLessThan("Header should have moved with the resize.",
+ scrolledHeaderRight, initialHeaderRight);
+
+ // ensure the contents are scrolled
+ ((JavascriptExecutor) driver)
+ .executeScript("arguments[0].scrollLeft = 1000", scrollbar);
+
+ // resize to not include scrollbar
+ button.click();
+ waitUntilNot(ExpectedConditions.visibilityOf(scrollbar));
+
+ // ensure the contents move with the resize
+ int newHeaderRight = header.getLocation().getX()
+ + header.getSize().getWidth();
+ assertEquals("Header should have expanded back.", initialHeaderRight,
+ newHeaderRight);
+ }
+}