From 7112abe944259a615e26342de17d0302ddec3562 Mon Sep 17 00:00:00 2001 From: Fabian Lange Date: Wed, 26 Feb 2014 19:17:21 +0100 Subject: [PATCH] Preventing premature start of drag due to Chrome move event #13381 The drag only actually starts when the mouse move or touch move event is more than 3 pixel away. The purpose is twofold: a) it fixes the glitchy behaviour of Chrome which for some reason sometimes fires a move directly after the mousedown, which starts a drag immediately. b) it helps people with shaky hands or imprecise hardware, why might not want to drag but to select but slightly move the pointer. Some frameworks opted to make the distance configurable. Due to sub pixels (which might be the cause for a) in the first place), a distance of 1 or 2 pixel is not enough. Experiments showed that unaware users did not notice that 3 pixels movement are required for the drag to actually start (the ghost has already a delay of 300ms) Change-Id: I71b50b72486344a7dbe4ed927b34b1f8fab0db20 --- .../client/ui/dd/VDragAndDropManager.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java index b911c28a07..7de40f9496 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java +++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java @@ -422,13 +422,20 @@ public class VDragAndDropManager { } case Event.ONMOUSEMOVE: case Event.ONTOUCHMOVE: - if (deferredStartRegistration != null) { - deferredStartRegistration.removeHandler(); - deferredStartRegistration = null; + // only start the drag if the mouse / touch has moved a minimum distance + int startX = Util.getTouchOrMouseClientX(currentDrag.getCurrentGwtEvent()); + int startY = Util.getTouchOrMouseClientY(currentDrag.getCurrentGwtEvent()); + int nowX = Util.getTouchOrMouseClientX(event.getNativeEvent()); + int nowY = Util.getTouchOrMouseClientY(event.getNativeEvent()); + if (Math.abs(startX - nowX) > 3 || Math.abs(startY - nowY) > 3) { + if (deferredStartRegistration != null) { + deferredStartRegistration.removeHandler(); + deferredStartRegistration = null; + } + currentDrag.setCurrentGwtEvent(event + .getNativeEvent()); + startDrag.execute(); } - currentDrag.setCurrentGwtEvent(event - .getNativeEvent()); - startDrag.execute(); break; default: // on any other events, clean up the -- 2.39.5