summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-10-01 13:34:22 +0300
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2018-10-01 13:34:22 +0300
commit2aa7a0696a729a3c70ae8bf0ea6293e4a82e0075 (patch)
treea63b65171b45ec637d57e16a40a72a1918af567c
parente093bef0ccabd0843baee19318b61ef254911ab9 (diff)
downloadvaadin-framework-2aa7a0696a729a3c70ae8bf0ea6293e4a82e0075.tar.gz
vaadin-framework-2aa7a0696a729a3c70ae8bf0ea6293e4a82e0075.zip
Replaced Grid's internal size calculation fix with an indexing fix. (#11154)
- More lightweight, and fixes things for any custom implementations of Escalator as well. Fixes #11044
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Escalator.java2
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java21
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledToBottom.java47
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledToBottomTest.java97
4 files changed, 149 insertions, 18 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
index 819e7f8d32..a3ecfab902 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
@@ -67,7 +67,6 @@ import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComputedStyle;
import com.vaadin.client.DeferredWorker;
-import com.vaadin.client.LayoutManager;
import com.vaadin.client.Profiler;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.ui.SubPartAware;
@@ -3896,6 +3895,7 @@ public class Escalator extends Widget
visualRowOrder.getLast()) + 1;
moveAndUpdateEscalatorRows(Range.withOnly(0),
visualRowOrder.size(), newLogicalIndex);
+ updateTopRowLogicalIndex(1);
}
}
}
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 e382d2a4f1..e6efe4cbc0 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -76,7 +76,10 @@ import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.client.*;
+import com.vaadin.client.BrowserInfo;
+import com.vaadin.client.DeferredWorker;
+import com.vaadin.client.Focusable;
+import com.vaadin.client.WidgetUtil;
import com.vaadin.client.WidgetUtil.Reference;
import com.vaadin.client.data.DataChangeHandler;
import com.vaadin.client.data.DataSource;
@@ -3339,7 +3342,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
*/
private class AutoColumnWidthsRecalculator {
private double lastCalculatedInnerWidth = -1;
- private double lastCalculatedInnerHeight = -1;
private final ScheduledCommand calculateCommand = new ScheduledCommand() {
@@ -3434,7 +3436,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
// Update latest width to prevent recalculate on height change.
lastCalculatedInnerWidth = escalator.getInnerWidth();
- lastCalculatedInnerHeight = getEscalatorInnerHeight();
}
private boolean columnsAreGuaranteedToBeWiderThanGrid() {
@@ -9147,15 +9148,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
recalculateColumnWidths();
}
- if (getEscalatorInnerHeight() != autoColumnWidthsRecalculator.lastCalculatedInnerHeight) {
- Scheduler.get().scheduleFinally(() -> {
- // Trigger re-calculation of all row positions.
- RowContainer.BodyRowContainer body = getEscalator()
- .getBody();
- body.setDefaultRowHeight(body.getDefaultRowHeight());
- });
- }
-
// Vertical resizing could make editor positioning invalid so it
// needs to be recalculated on resize
if (isEditorActive()) {
@@ -9169,11 +9161,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
});
}
- private double getEscalatorInnerHeight() {
- return new ComputedStyle(getEscalator().getTableWrapper())
- .getHeightIncludingBorderPadding();
- }
-
/**
* Grid does not support adding Widgets this way.
* <p>
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledToBottom.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledToBottom.java
new file mode 100644
index 0000000000..b1bf8738f1
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolledToBottom.java
@@ -0,0 +1,47 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalSplitPanel;
+
+public class GridScrolledToBottom extends SimpleGridUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<Person> grid = createGrid();
+ grid.setSizeFull();
+
+ VerticalSplitPanel splitPanel = new VerticalSplitPanel(grid,
+ new Label("Foo"));
+ splitPanel.setHeight("200px");
+ splitPanel.setSplitPosition(100);
+ getLayout().addComponent(splitPanel);
+ }
+
+ @Override
+ protected List<Person> createPersons() {
+ List<Person> persons = new ArrayList<>();
+ for (int i = 0; i < 100; ++i) {
+ Person person = new Person();
+ person.setFirstName("Person " + i);
+ person.setAge(i);
+ persons.add(person);
+ }
+ return persons;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Resizing a Grid when it's scrolled to bottom shouldn't cause indexing to jump.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11044;
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledToBottomTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledToBottomTest.java
new file mode 100644
index 0000000000..e4fd2fc2dd
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrolledToBottomTest.java
@@ -0,0 +1,97 @@
+package com.vaadin.tests.components.grid;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridElement.GridRowElement;
+import com.vaadin.testbench.elements.VerticalSplitPanelElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridScrolledToBottomTest extends MultiBrowserTest {
+
+ @Test
+ public void testResizingAndBack() {
+ openTestURL();
+ GridElement grid = $(GridElement.class).first();
+ grid.scrollToRow(99);
+
+ GridRowElement row99 = grid.getRow(99);
+ int rowHeight = row99.getSize().getHeight();
+ assertThat(grid.getLocation().getY() + grid.getSize().getHeight(),
+ greaterThan(row99.getLocation().getY() + rowHeight - 2));
+
+ VerticalSplitPanelElement splitPanel = $(
+ VerticalSplitPanelElement.class).first();
+ TestBenchElement splitter = splitPanel.getSplitter();
+ // resize by three rows
+ Actions actions = new Actions(driver);
+ actions.clickAndHold(splitter).moveByOffset(0, -rowHeight * 3).release()
+ .perform();
+ // resize back by two rows
+ actions.clickAndHold(splitter).moveByOffset(0, rowHeight * 2).release()
+ .perform();
+
+ GridRowElement row95 = grid.getRow(95);
+ GridRowElement row97 = grid.getRow(97);
+ assertThat((double) row97.getLocation().getY(),
+ greaterThan(row95.getLocation().getY() + rowHeight * 1.5));
+ }
+
+ @Test
+ public void testResizingHalfRow() {
+ openTestURL();
+ GridElement grid = $(GridElement.class).first();
+ grid.scrollToRow(99);
+
+ GridRowElement row99 = grid.getRow(99);
+ int rowHeight = row99.getSize().getHeight();
+ int gridBottomY = grid.getLocation().getY()
+ + grid.getSize().getHeight();
+
+ // ensure that grid really is scrolled to bottom
+ assertThat((double) gridBottomY,
+ closeTo((double) row99.getLocation().getY() + rowHeight, 1d));
+
+ VerticalSplitPanelElement splitPanel = $(
+ VerticalSplitPanelElement.class).first();
+ TestBenchElement splitter = splitPanel.getSplitter();
+ // resize by half a row
+ Actions actions = new Actions(driver);
+ actions.clickAndHold(splitter).moveByOffset(0, -rowHeight / 2).release()
+ .perform();
+ // the last row is now only half visible, and in DOM tree it's actually
+ // the first row now but positioned to the bottom
+
+ // can't query grid.getRow(99) now or it moves the row position,
+ // have to use element query instead
+ List<WebElement> rows = grid.findElement(By.className("v-grid-body"))
+ .findElements(By.className("v-grid-row"));
+ WebElement firstRow = rows.get(0);
+ WebElement lastRow = rows.get(rows.size() - 1);
+
+ // ensure the scrolling didn't jump extra
+ assertEquals("Person 99",
+ firstRow.findElement(By.className("v-grid-cell")).getText());
+ assertEquals("Person 98",
+ lastRow.findElement(By.className("v-grid-cell")).getText());
+
+ // re-calculate current end position
+ gridBottomY = grid.getLocation().getY() + grid.getSize().getHeight();
+ // ensure the correct final row really is only half visible at the
+ // bottom
+ assertThat(gridBottomY, greaterThan(firstRow.getLocation().getY()));
+ assertThat(firstRow.getLocation().getY() + rowHeight,
+ greaterThan(gridBottomY));
+ }
+}