summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2014-04-07 17:32:29 +0300
committerVaadin Code Review <review@vaadin.com>2014-04-11 12:36:39 +0000
commit7e5d44d19bd02ecc7b900ba4926380d2fa7e7668 (patch)
treecb7ffa7b06d01519902565abc034978db450c7c1 /client
parentf227f0c1068f17e5491bd399d9f5bde16a0c8272 (diff)
downloadvaadin-framework-7e5d44d19bd02ecc7b900ba4926380d2fa7e7668.tar.gz
vaadin-framework-7e5d44d19bd02ecc7b900ba4926380d2fa7e7668.zip
Introduce a drag threshold for Drag and Drop (#13381)
Based on partial fix by Fabian Lange. Change-Id: I1a18c6ea105d87496b196b93e701aaccb987b3e7
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java74
1 files changed, 37 insertions, 37 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..47fd3c88a2 100644
--- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java
+++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java
@@ -31,7 +31,6 @@ import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
-import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
@@ -345,10 +344,7 @@ public class VDragAndDropManager {
.addNativePreviewHandler(defaultDragAndDropEventHandler);
if (dragElement != null
&& dragElement.getParentElement() == null) {
- // deferred attaching drag image is on going, we can
- // hurry with it now
- lazyAttachDragElement.cancel();
- lazyAttachDragElement.run();
+ attachDragElement();
}
}
// just capture something to prevent text selection in IE
@@ -370,6 +366,13 @@ public class VDragAndDropManager {
deferredStartRegistration = Event
.addNativePreviewHandler(new NativePreviewHandler() {
+ private int startX = Util
+ .getTouchOrMouseClientX(currentDrag
+ .getCurrentGwtEvent());
+ private int startY = Util
+ .getTouchOrMouseClientY(currentDrag
+ .getCurrentGwtEvent());
+
@Override
public void onPreviewNativeEvent(
NativePreviewEvent event) {
@@ -422,13 +425,23 @@ public class VDragAndDropManager {
}
case Event.ONMOUSEMOVE:
case Event.ONTOUCHMOVE:
- if (deferredStartRegistration != null) {
- deferredStartRegistration.removeHandler();
- deferredStartRegistration = null;
+ int currentX = Util
+ .getTouchOrMouseClientX(event
+ .getNativeEvent());
+ int currentY = Util
+ .getTouchOrMouseClientY(event
+ .getNativeEvent());
+ if (Math.abs(startX - currentX) > 3
+ || Math.abs(startY - currentY) > 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
@@ -718,16 +731,7 @@ public class VDragAndDropManager {
updateDragImagePosition();
if (isStarted) {
- lazyAttachDragElement.run();
- } else {
- /*
- * To make our default dnd handler as compatible as possible, we
- * need to defer the appearance of dragElement. Otherwise events
- * that are derived from sequences of other events might not
- * fire as domchanged will fire between them or mouse up might
- * happen on dragElement.
- */
- lazyAttachDragElement.schedule(300);
+ attachDragElement();
}
}
}
@@ -736,24 +740,20 @@ public class VDragAndDropManager {
return dragElement;
}
- private final Timer lazyAttachDragElement = new Timer() {
-
- @Override
- public void run() {
- if (dragElement != null && dragElement.getParentElement() == null) {
- ApplicationConnection connection = getCurrentDragApplicationConnection();
- Element dragImageParent;
- if (connection == null) {
- VConsole.error("Could not determine ApplicationConnection for current drag operation. The drag image will likely look broken");
- dragImageParent = RootPanel.getBodyElement();
- } else {
- dragImageParent = VOverlay.getOverlayContainer(connection);
- }
- dragImageParent.appendChild(dragElement);
+ public void attachDragElement() {
+ if (dragElement != null && dragElement.getParentElement() == null) {
+ ApplicationConnection connection = getCurrentDragApplicationConnection();
+ Element dragImageParent;
+ if (connection == null) {
+ VConsole.error("Could not determine ApplicationConnection for current drag operation. The drag image will likely look broken");
+ dragImageParent = RootPanel.getBodyElement();
+ } else {
+ dragImageParent = VOverlay.getOverlayContainer(connection);
}
-
+ dragImageParent.appendChild(dragElement);
}
- };
+
+ }
private Command deferredCommand;