diff options
author | Fabian Lange <lange.fabian@gmail.com> | 2014-02-26 19:17:21 +0100 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-03-13 10:45:46 +0000 |
commit | 7112abe944259a615e26342de17d0302ddec3562 (patch) | |
tree | cd1a75e60a2b9f824aaf217cda2d47fac09459d7 /client | |
parent | 49973354b22e8aba9cc71f83571020b0414c54e0 (diff) | |
download | vaadin-framework-7112abe944259a615e26342de17d0302ddec3562.tar.gz vaadin-framework-7112abe944259a615e26342de17d0302ddec3562.zip |
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
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java | 19 |
1 files 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 |