summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-06-08 13:44:34 +0300
committerVaadin Code Review <review@vaadin.com>2015-06-08 14:28:22 +0000
commitffb4036fe0573c35e759cb89e8b252f5477ecbea (patch)
tree83495a486032640efb0373397643c012b0ac9e33
parent4af793d06a0f4a6577aad13403ca7982c6fce224 (diff)
downloadvaadin-framework-ffb4036fe0573c35e759cb89e8b252f5477ecbea.tar.gz
vaadin-framework-ffb4036fe0573c35e759cb89e8b252f5477ecbea.zip
Fix Grid drag selection with scrolled page (#17895)
Change-Id: I1303781c5a996448e12e86835935702686af3ab7
-rw-r--r--client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java26
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java51
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java57
3 files changed, 111 insertions, 23 deletions
diff --git a/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java b/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
index c8a7ceeca3..1e47d3ad6b 100644
--- a/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
+++ b/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
@@ -535,10 +535,8 @@ public class MultiSelectionRenderer<T> extends
final int topBorder = getBodyClientTop();
final int bottomBorder = getBodyClientBottom();
- final int scrollCompensation = getScrollCompensation();
- topBound = scrollCompensation + topBorder + SCROLL_AREA_GRADIENT_PX;
- bottomBound = scrollCompensation + bottomBorder
- - SCROLL_AREA_GRADIENT_PX;
+ topBound = topBorder + SCROLL_AREA_GRADIENT_PX;
+ bottomBound = bottomBorder - SCROLL_AREA_GRADIENT_PX;
gradientArea = SCROLL_AREA_GRADIENT_PX;
// modify bounds if they're too tightly packed
@@ -551,17 +549,6 @@ public class MultiSelectionRenderer<T> extends
}
}
- private int getScrollCompensation() {
- Element cursor = grid.getElement();
- int scroll = 0;
- while (cursor != null) {
- scroll -= cursor.getScrollTop();
- cursor = cursor.getParentElement();
- }
-
- return scroll;
- }
-
public void stop() {
if (handlerRegistration != null) {
handlerRegistration.removeHandler();
@@ -743,15 +730,8 @@ public class MultiSelectionRenderer<T> extends
}
/** Get the "top" of an element in relation to "client" coordinates. */
- @SuppressWarnings("static-method")
private int getClientTop(final Element e) {
- Element cursor = e;
- int top = 0;
- while (cursor != null) {
- top += cursor.getOffsetTop();
- cursor = cursor.getOffsetParent();
- }
- return top;
+ return e.getAbsoluteTop();
}
private int getBodyClientBottom() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java b/uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java
new file mode 100644
index 0000000000..1af1ad02d6
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid.SelectionMode;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.VerticalLayout;
+
+public class GridDragSelectionWhileScrolled extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Layout layout = new VerticalLayout();
+
+ HorizontalLayout spacer = new HorizontalLayout();
+ spacer.setHeight("1000px");
+ layout.addComponent(spacer);
+
+ PersonTestGrid grid = new PersonTestGrid(100);
+ grid.setSelectionMode(SelectionMode.MULTI);
+ layout.addComponent(grid);
+
+ addComponent(layout);
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 17895;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Drag selecting rows in Grid malfunctions if page is scrolled";
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java
new file mode 100644
index 0000000000..6a452e1fec
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridDragSelectionWhileScrolledTest extends MultiBrowserTest {
+
+ @Override
+ protected boolean requireWindowFocusForIE() {
+ return true;
+ }
+
+ @Test
+ public void testDragSelect() throws IOException {
+ openTestURL();
+
+ // Scroll grid to view
+ GridElement grid = $(GridElement.class).first();
+ ((JavascriptExecutor) getDriver()).executeScript(
+ "arguments[0].scrollIntoView(true);", grid);
+
+ // Drag select 2 rows
+ new Actions(getDriver()).moveToElement(grid.getCell(3, 0), 5, 5)
+ .clickAndHold().moveToElement(grid.getCell(2, 0), 5, 5)
+ .release().perform();
+
+ // Assert only those are selected.
+ assertTrue("Row 3 should be selected", grid.getRow(3).isSelected());
+ assertTrue("Row 2 should be selected", grid.getRow(2).isSelected());
+ assertFalse("Row 4 should not be selected", grid.getRow(4).isSelected());
+ assertFalse("Row 1 should not be selected", grid.getRow(1).isSelected());
+ }
+}