diff options
author | Anna Miroshnik <anna.miroshnik@arcadia.spb.ru> | 2015-03-06 16:05:09 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2015-03-26 16:24:35 +0200 |
commit | 4a4661dc9e3d5f8312f9a472e703a3b61cec3d38 (patch) | |
tree | 4382b324fc2844c43eeb8f516838f393aaff1ec2 /client/src | |
parent | f08b524d70b457b729b9ef4a67252c85f9df3f01 (diff) | |
download | vaadin-framework-4a4661dc9e3d5f8312f9a472e703a3b61cec3d38.tar.gz vaadin-framework-4a4661dc9e3d5f8312f9a472e703a3b61cec3d38.zip |
Fix Table column header sorting on Chrome (#14796)
This fix is similar to the fix that has been made for other similar
cases (i.e. #13381).
Couldn't find a reliable way to reproduce the problem. Hopefully this
will fix the issue.
Was reproduced (before fix) on Google Chrome 40.0.2214.115 m on
TableSortingStopsWorkingOnChrome test one time (but then suddenly it
started to work again).
Was reproduced (before fix) on Project TableSorting once, as described
in the ticket. That project has been attached to the ticket.
Change-Id: Id901c9ce4a0a7c369572bf4374223851658aa703
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/com/vaadin/client/ui/VScrollTable.java | 88 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java | 12 |
2 files changed, 60 insertions, 40 deletions
diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 12de2724fc..13561dcd0f 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -2774,7 +2774,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private boolean sortable = false; private final String cid; + private boolean dragging; + private Integer currentDragX = null; // is used to resolve #14796 private int dragStartX; private int colIndex; @@ -3146,6 +3148,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, event.stopPropagation(); } dragging = true; + currentDragX = WidgetUtil.getTouchOrMouseClientX(event); moved = false; colIndex = getColIndexByKey(cid); DOM.setCapture(getElement()); @@ -3160,6 +3163,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (columnReordering && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { dragging = false; + currentDragX = null; DOM.releaseCapture(getElement()); if (WidgetUtil.isTouchEvent(event)) { @@ -3227,47 +3231,57 @@ public class VScrollTable extends FlowPanel implements HasWidgets, break; case Event.ONTOUCHMOVE: case Event.ONMOUSEMOVE: - if (dragging && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { - if (event.getTypeInt() == Event.ONTOUCHMOVE) { - /* - * prevent using this event in e.g. scrolling - */ - event.stopPropagation(); - } - if (!moved) { - createFloatingCopy(); - moved = true; - } + // only start the drag if the mouse / touch has moved a minimum + // distance in x-axis (the same idea as in #13381) + int currentX = WidgetUtil.getTouchOrMouseClientX(event); - final int clientX = WidgetUtil - .getTouchOrMouseClientX(event); - final int x = clientX + tHead.hTableWrapper.getScrollLeft(); - int slotX = headerX; - closestSlot = colIndex; - int closestDistance = -1; - int start = 0; - if (showRowHeaders) { - start++; - } - final int visibleCellCount = tHead.getVisibleCellCount(); - for (int i = start; i <= visibleCellCount; i++) { - if (i > 0) { - final String colKey = getColKeyByIndex(i - 1); - // getColWidth only returns the internal width - // without padding, not the offset width of the - // whole td (#10890) - slotX += getColWidth(colKey) - + scrollBody.getCellExtraWidth(); + if (currentDragX == null + || Math.abs(currentDragX - currentX) > VDragAndDropManager.MINIMUM_DISTANCE_TO_START_DRAG) { + if (dragging + && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { + if (event.getTypeInt() == Event.ONTOUCHMOVE) { + /* + * prevent using this event in e.g. scrolling + */ + event.stopPropagation(); } - final int dist = Math.abs(x - slotX); - if (closestDistance == -1 || dist < closestDistance) { - closestDistance = dist; - closestSlot = i; + if (!moved) { + createFloatingCopy(); + moved = true; } - } - tHead.focusSlot(closestSlot); - updateFloatingCopysPosition(clientX, -1); + final int clientX = WidgetUtil + .getTouchOrMouseClientX(event); + final int x = clientX + + tHead.hTableWrapper.getScrollLeft(); + int slotX = headerX; + closestSlot = colIndex; + int closestDistance = -1; + int start = 0; + if (showRowHeaders) { + start++; + } + final int visibleCellCount = tHead + .getVisibleCellCount(); + for (int i = start; i <= visibleCellCount; i++) { + if (i > 0) { + final String colKey = getColKeyByIndex(i - 1); + // getColWidth only returns the internal width + // without padding, not the offset width of the + // whole td (#10890) + slotX += getColWidth(colKey) + + scrollBody.getCellExtraWidth(); + } + final int dist = Math.abs(x - slotX); + if (closestDistance == -1 || dist < closestDistance) { + closestDistance = dist; + closestSlot = i; + } + } + tHead.focusSlot(closestSlot); + + updateFloatingCopysPosition(clientX, -1); + } } break; default: diff --git a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java index 844f4c1b9c..3a0b52b6af 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java +++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java @@ -38,9 +38,9 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.MouseEventDetailsBuilder; import com.vaadin.client.Profiler; import com.vaadin.client.UIDL; -import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.ValueMap; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.VOverlay; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.MouseEventDetails; @@ -240,6 +240,12 @@ public class VDragAndDropManager { } + /* + * #13381, #14796. The drag only actually starts when the mouse move or + * touch move event is more than 3 pixel away. + */ + public static final int MINIMUM_DISTANCE_TO_START_DRAG = 3; + private static VDragAndDropManager instance; private HandlerRegistration handlerRegistration; private VDragEvent currentDrag; @@ -425,8 +431,8 @@ public class VDragAndDropManager { int currentY = WidgetUtil .getTouchOrMouseClientY(event .getNativeEvent()); - if (Math.abs(startX - currentX) > 3 - || Math.abs(startY - currentY) > 3) { + if (Math.abs(startX - currentX) > MINIMUM_DISTANCE_TO_START_DRAG + || Math.abs(startY - currentY) > MINIMUM_DISTANCE_TO_START_DRAG) { if (deferredStartRegistration != null) { deferredStartRegistration .removeHandler(); |