]> source.dussan.org Git - vaadin-framework.git/commitdiff
Properly end HTML5 drag operations when no drop is performed (#8242)
authorArtur <artur@vaadin.com>
Thu, 19 Jan 2017 06:52:35 +0000 (08:52 +0200)
committerDenis <denis@vaadin.com>
Thu, 19 Jan 2017 06:52:35 +0000 (08:52 +0200)
* Properly end HTML5 drag operations when no drop is performed

No auto test because of https://github.com/SeleniumHQ/selenium/issues/1365

Fixes #4060

client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java
uitest/src/main/java/com/vaadin/tests/components/draganddropwrapper/Html5DropDenied.java [new file with mode: 0644]

index e025d88740db91a17a7990aa6769d19b93beb585..40252d5689b9ad4e9710c002f0d6d0f6b90eee1c 100644 (file)
@@ -392,6 +392,7 @@ public class VDragAndDropWrapper extends VCustomComponent
 
     public boolean html5DragDrop(VHtml5DragEvent event) {
         if (dropHandler == null || !currentlyValid) {
+            VDragAndDropManager.get().interruptDrag();
             return true;
         }
         try {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/draganddropwrapper/Html5DropDenied.java b/uitest/src/main/java/com/vaadin/tests/components/draganddropwrapper/Html5DropDenied.java
new file mode 100644 (file)
index 0000000..5bca514
--- /dev/null
@@ -0,0 +1,80 @@
+package com.vaadin.tests.components.draganddropwrapper;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.acceptcriteria.AcceptAll;
+import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
+import com.vaadin.event.dd.acceptcriteria.ClientSideCriterion;
+import com.vaadin.event.dd.acceptcriteria.Not;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.DragAndDropWrapper;
+import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
+import com.vaadin.ui.Image;
+
+public class Html5DropDenied extends AbstractTestUIWithLog {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        Image sample = new Image();
+        sample.setSource(new ThemeResource("../runo/icons/64/document.png"));
+
+        Button neverButton = new Button("Never accepts drop");
+        neverButton.setId("never");
+        neverButton.addClickListener(new Button.ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                log("click on " + event.getButton().getCaption());
+            }
+        });
+
+        DragAndDropWrapper neverAccept = new DragAndDropWrapper(neverButton);
+        neverAccept.setSizeFull();
+        neverAccept.setDragStartMode(DragStartMode.NONE);
+        neverAccept.setDropHandler(new DropHandler() {
+
+            @Override
+            public AcceptCriterion getAcceptCriterion() {
+                return new Not((ClientSideCriterion) AcceptAll.get());
+            }
+
+            @Override
+            public void drop(DragAndDropEvent event) {
+                log("This should never happen");
+            }
+        });
+        Button alwaysButton = new Button("always accepts drop");
+        alwaysButton.setId("always");
+        alwaysButton.addClickListener(new Button.ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                log("click on " + event.getButton().getCaption());
+            }
+        });
+
+        DragAndDropWrapper alwaysAccept = new DragAndDropWrapper(alwaysButton);
+        alwaysAccept.setSizeFull();
+        alwaysAccept.setDragStartMode(DragStartMode.NONE);
+        alwaysAccept.setDropHandler(new DropHandler() {
+
+            @Override
+            public AcceptCriterion getAcceptCriterion() {
+                return AcceptAll.get();
+            }
+
+            @Override
+            public void drop(DragAndDropEvent event) {
+                log("Drop on always accept");
+            }
+        });
+
+        addComponent(sample);
+        addComponent(neverAccept);
+        addComponent(alwaysAccept);
+
+    }
+
+}