From bdc28f77c6c629eec0a0129a1a791855a6fc435d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Hyv=C3=B6nen?= Date: Wed, 6 May 2015 11:52:47 +0300 Subject: [PATCH] Wrong floating element pos. on DND column reorder Grid #17693 When Grid was wider, the floating element did follow mouse to the right after some point. Also makes sure floating element is not shown on top of frozen columns when auto scrolling left. Change-Id: Ied779222c484f1f22119f89c0e720f868bbc898e --- .../src/com/vaadin/client/widgets/Grid.java | 18 ++++++------ .../server/GridColumnReorderTest.java | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 92827c47f0..07074eeddf 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -3541,24 +3541,26 @@ public class Grid extends ResizeComposite implements private void resolveDragElementHorizontalPosition(final int clientX) { double left = clientX - table.getAbsoluteLeft(); - final double frozenColumnsWidth = getFrozenColumnsWidth(); - if (left < frozenColumnsWidth) { - left = (int) frozenColumnsWidth; - } - // do not show the drag element beyond a spanned header cell + // Do not show the drag element beyond a spanned header cell // limitation final Double leftBound = possibleDropPositions.firstKey(); final Double rightBound = possibleDropPositions.lastKey(); - double scrollLeft = getScrollLeft(); + final double scrollLeft = getScrollLeft(); if (left + scrollLeft < leftBound) { left = leftBound - scrollLeft + autoScrollX; } else if (left + scrollLeft > rightBound) { left = rightBound - scrollLeft + autoScrollX; } - // do not show the drag element beyond the grid - left = Math.max(0, Math.min(left, table.getClientWidth())); + // Do not show the drag element beyond the grid + final int bodyOffsetWidth = getEscalator().getBody().getElement() + .getOffsetWidth(); + // Do not show on left of the frozen columns (even if scrolled) + final int frozenColumnsWidth = (int) getFrozenColumnsWidth(); + + left = Math + .max(frozenColumnsWidth, Math.min(left, bodyOffsetWidth)); left -= dragElement.getClientWidth() / 2; dragElement.getStyle().setLeft(left, Unit.PX); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java index 0d62797ea4..1714cdaaf3 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java @@ -22,8 +22,12 @@ import java.util.List; import org.junit.Before; 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.GridCellElement; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; /** @@ -320,6 +324,30 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest { assertColumnHeaderOrder(1, 2, 0, 3); } + @Test + public void testColumnReordering_bigWidth_dragElementPositionCorrect() { + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "Size", "Width", "900px"); + assertColumnHeaderOrder(0, 1, 2, 3); + + GridCellElement draggedHeaderCell = getGridElement() + .getHeaderCell(0, 1); + final int xOffset = 500; + new Actions(getDriver()).moveToElement(draggedHeaderCell, 5, 5) + .clickAndHold().moveByOffset(xOffset, 0).build().perform(); + + WebElement floatingDragElement = findElement(By + .className("dragged-column-header")); + + int expectedLeft = draggedHeaderCell.getLocation().getX() + xOffset + 5 + - (floatingDragElement.getSize().getWidth() / 2); + int realLeft = floatingDragElement.getLocation().getX(); + + assertTrue("Dragged element location wrong, expected " + expectedLeft + + " was " + realLeft, Math.abs(expectedLeft - realLeft) < 5); + } + private void toggleColumnReordering() { selectMenuPath(COLUMN_REORDERING_PATH); } -- 2.39.5