From: Artur Date: Thu, 19 Jan 2017 06:52:35 +0000 (+0200) Subject: Properly end HTML5 drag operations when no drop is performed (#8242) X-Git-Tag: 7.7.7~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5e842da86887c302ca1865c67ebfbac59770487c;p=vaadin-framework.git Properly end HTML5 drag operations when no drop is performed (#8242) * Properly end HTML5 drag operations when no drop is performed No auto test because of https://github.com/SeleniumHQ/selenium/issues/1365 Fixes #4060 --- diff --git a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java index e025d88740..40252d5689 100644 --- a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java +++ b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java @@ -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 index 0000000000..5bca514307 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/draganddropwrapper/Html5DropDenied.java @@ -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); + + } + +}