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);
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;
/**
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);
}