]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix Button as a Html5 DragSource (#9346)
authorPekka Hyvönen <pekka@vaadin.com>
Wed, 17 May 2017 11:19:50 +0000 (14:19 +0300)
committerGitHub <noreply@github.com>
Wed, 17 May 2017 11:19:50 +0000 (14:19 +0300)
* Fix Button as a Html5 DragSourcei

It was completely broken, not being clickable, and also preventing anything else from being clicked.

client/src/main/java/com/vaadin/client/ui/VButton.java
client/src/main/java/com/vaadin/client/ui/button/ButtonConnector.java
uitest/src/main/java/com/vaadin/tests/dnd/DraggableButton.java

index 3bb6c5a1e81e5c4fb9f5c612466a364ed4135d47..611eb692ccc40e892aaf528844268469b1568d5e 100644 (file)
@@ -207,7 +207,7 @@ public class VButton extends FocusWidget implements ClickHandler {
                 clickPending = true;
                 setFocus(true);
                 DOM.setCapture(getElement());
-                isCapturing = isCapturingEnabled();
+                isCapturing = true;
                 addStyleName(CLASSNAME_PRESSED);
             }
             break;
@@ -225,7 +225,7 @@ public class VButton extends FocusWidget implements ClickHandler {
             break;
         case Event.ONMOUSEMOVE:
             clickPending = false;
-            if (isCapturing) {
+            if (isCapturing && !isDraggable()) {
                 // Prevent dragging (on other browsers);
                 DOM.eventPreventDefault(event);
             }
@@ -421,29 +421,13 @@ public class VButton extends FocusWidget implements ClickHandler {
     }
 
     /**
-     * Enables or disables the widget's capturing of mouse events with the mouse
-     * held down.
-     *
-     * @param enabled
-     *            {@literal true} if capturing enabled, {@literal false}
-     *            otherwise
+     * Returns if this button has been made <code>draggable</code> or not.
      *
-     * @since 8.1
-     */
-    public void setCapturingEnabled(boolean enabled) {
-        capturingEnabled = enabled;
-    }
-
-    /**
-     * Returns if the widget's capturing of mouse events are enabled.
-     *
-     * @return {@literal true} if mouse capturing is enabled, {@literal false}
+     * @return {@literal true} if draggable is enabled, {@literal false}
      *         otherwise
-     *
-     * @since 8.1
      */
-    public boolean isCapturingEnabled() {
-        return capturingEnabled;
+    private boolean isDraggable() {
+        return getElement().getPropertyBoolean("draggable");
     }
 
     private static native int getHorizontalBorderAndPaddingWidth(Element elem)
index f8e51a5dcc60c0d784a34f5d328f95e60e2c8e5f..b0d17465bb343b2fe1ad3d0f2931e46b41953667 100644 (file)
@@ -129,15 +129,4 @@ public class ButtonConnector extends AbstractComponentConnector
 
     }
 
-    @Override
-    public void onDragSourceAttached() {
-        // Disable mouse event capturing to make the widget draggable
-        getWidget().setCapturingEnabled(false);
-    }
-
-    @Override
-    public void onDragSourceDetached() {
-        // Reset mouse event capturing
-        getWidget().setCapturingEnabled(true);
-    }
 }
index b154045b54f480c5d7279ce159fca056fad31a63..bd6b86bd548fc7e71ee766c3d47606f97cdeccbb 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.vaadin.tests.dnd;
 
+import com.vaadin.annotations.Widgetset;
 import com.vaadin.server.Page;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.tests.components.AbstractTestUIWithLog;
@@ -25,12 +26,14 @@ import com.vaadin.ui.Layout;
 import com.vaadin.ui.dnd.DragSourceExtension;
 import com.vaadin.ui.dnd.DropTargetExtension;
 
+@Widgetset("com.vaadin.DefaultWidgetSet")
 public class DraggableButton extends AbstractTestUIWithLog {
 
     @Override
     protected void setup(VaadinRequest request) {
 
-        Button draggableButton = new Button("Draggable Button");
+        Button draggableButton = new Button("Draggable Button",
+                event -> log("clicked draggable button"));
         DragSourceExtension<Button> dragSourceExtension = new DragSourceExtension<>(
                 draggableButton);
         dragSourceExtension.setDataTransferText(
@@ -44,7 +47,8 @@ public class DraggableButton extends AbstractTestUIWithLog {
                 .addDropListener(event -> log(event.getDataTransferText()));
 
         Layout layout = new HorizontalLayout();
-        layout.addComponents(draggableButton, dropTarget);
+        layout.addComponents(draggableButton, dropTarget, new Button(
+                "another button", event -> log("click on another button")));
         addComponent(layout);
 
         // Add styling
@@ -62,6 +66,6 @@ public class DraggableButton extends AbstractTestUIWithLog {
 
     @Override
     protected String getTestDescription() {
-        return "Test if Button is draggable";
+        return "Test if Button is draggable, and it won't steal all other clicks";
     }
 }