Browse Source

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
tags/7.1.13
Fabian Lange 10 years ago
parent
commit
7112abe944
1 changed files with 13 additions and 6 deletions
  1. 13
    6
      client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java

+ 13
- 6
client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java View File

@@ -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

Loading…
Cancel
Save