]> source.dussan.org Git - vaadin-framework.git/commitdiff
Wrong floating element pos. on DND column reorder Grid #17693
authorPekka Hyvönen <pekka@vaadin.com>
Wed, 6 May 2015 08:52:47 +0000 (11:52 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 15 May 2015 11:11:23 +0000 (11:11 +0000)
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

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java

index 92827c47f08a9d4413751f6e4334767907490d34..07074eeddf8ec80b8d0af5c1c49a9211ef6d13b8 100644 (file)
@@ -3541,24 +3541,26 @@ public class Grid<T> 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);
index 0d62797ea4f3af6bbb34089009fa7e42d67f7d2e..1714cdaaf348750645d20ee7ce0c3ed615317c6b 100644 (file)
@@ -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);
     }