]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #3874 - Two click events is sent for a middle click in a layout
authorArtur Signell <artur.signell@itmill.com>
Thu, 17 Dec 2009 11:16:42 +0000 (11:16 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 17 Dec 2009 11:16:42 +0000 (11:16 +0000)
svn changeset:10379/svn branch:6.2

src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java
tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.html
tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.java

index 0e60246d48b1ce05542d050d672335c8ffb31e4d..85bc0817bcf589367226191a1ff40c5e30def323 100644 (file)
@@ -4,8 +4,6 @@ import java.util.HashMap;
 import java.util.Map;\r
 \r
 import com.google.gwt.dom.client.NativeEvent;\r
-import com.google.gwt.event.dom.client.ClickEvent;\r
-import com.google.gwt.event.dom.client.ClickHandler;\r
 import com.google.gwt.event.dom.client.ContextMenuEvent;\r
 import com.google.gwt.event.dom.client.ContextMenuHandler;\r
 import com.google.gwt.event.dom.client.DomEvent;\r
@@ -19,10 +17,9 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;\r
 import com.vaadin.terminal.gwt.client.Paintable;\r
 \r
-public abstract class ClickEventHandler implements ClickHandler,\r
-        DoubleClickHandler, ContextMenuHandler, MouseUpHandler {\r
+public abstract class ClickEventHandler implements DoubleClickHandler,\r
+        ContextMenuHandler, MouseUpHandler {\r
 \r
-    private HandlerRegistration clickHandlerRegistration;\r
     private HandlerRegistration doubleClickHandlerRegistration;\r
     private HandlerRegistration mouseUpHandlerRegistration;\r
     private HandlerRegistration contextMenuHandlerRegistration;\r
@@ -41,9 +38,7 @@ public abstract class ClickEventHandler implements ClickHandler,
         // Handle registering/unregistering of click handler depending on if\r
         // server side listeners have been added or removed.\r
         if (hasEventListener()) {\r
-            if (clickHandlerRegistration == null) {\r
-                clickHandlerRegistration = registerHandler(this, ClickEvent\r
-                        .getType());\r
+            if (mouseUpHandlerRegistration == null) {\r
                 mouseUpHandlerRegistration = registerHandler(this, MouseUpEvent\r
                         .getType());\r
                 contextMenuHandlerRegistration = registerHandler(this,\r
@@ -52,9 +47,8 @@ public abstract class ClickEventHandler implements ClickHandler,
                         DoubleClickEvent.getType());\r
             }\r
         } else {\r
-            if (clickHandlerRegistration != null) {\r
+            if (mouseUpHandlerRegistration != null) {\r
                 // Remove existing handlers\r
-                clickHandlerRegistration.removeHandler();\r
                 doubleClickHandlerRegistration.removeHandler();\r
                 mouseUpHandlerRegistration.removeHandler();\r
                 contextMenuHandlerRegistration.removeHandler();\r
@@ -62,7 +56,6 @@ public abstract class ClickEventHandler implements ClickHandler,
                 contextMenuHandlerRegistration = null;\r
                 mouseUpHandlerRegistration = null;\r
                 doubleClickHandlerRegistration = null;\r
-                clickHandlerRegistration = null;\r
 \r
             }\r
         }\r
@@ -81,12 +74,6 @@ public abstract class ClickEventHandler implements ClickHandler,
                 clickEventIdentifier);\r
     }\r
 \r
-    public void onClick(ClickEvent event) {\r
-        if (hasEventListener()) {\r
-            fireClick(event.getNativeEvent());\r
-        }\r
-    }\r
-\r
     protected void fireClick(NativeEvent event) {\r
         ApplicationConnection client = getApplicationConnection();\r
         String pid = getApplicationConnection().getPid(paintable);\r
@@ -113,11 +100,8 @@ public abstract class ClickEventHandler implements ClickHandler,
         // occured on this element before this mouseup and that no mouseup\r
         // has occured anywhere after that.\r
         if (hasEventListener()) {\r
-            if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {\r
-                // "Click" with right or middle button\r
-                fireClick(event.getNativeEvent());\r
-\r
-            }\r
+            // "Click" with left, right or middle button\r
+            fireClick(event.getNativeEvent());\r
         }\r
     }\r
 \r
index f488eb9a81d80913cea32f5b9951664050af24f8..28635a9df7afc384af307d9892817e198f7c9338 100644 (file)
@@ -40,7 +40,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:GridLayout: Click on This is label 1</td>
+       <td>exact:GridLayout: left left click on This is label 1</td>
 </tr>
 <tr>
        <td>mouseClick</td>
@@ -55,7 +55,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:GridLayout: Click on This is tf5</td>
+       <td>exact:GridLayout: left left click on This is tf5</td>
 </tr>
 <tr>
        <td>mouseClick</td>
@@ -70,7 +70,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:GridLayout: Click on &lt;none&gt;</td>
+       <td>exact:GridLayout: left left click on &lt;none&gt;</td>
 </tr>
 <!--VerticalLayout-->
 <tr>
@@ -86,7 +86,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:VerticalLayout: Click on This is tf6</td>
+       <td>exact:VerticalLayout: left left click on This is tf6</td>
 </tr>
 <tr>
        <td>mouseClick</td>
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:VerticalLayout: Click on This is label 3</td>
+       <td>exact:VerticalLayout: left left click on This is label 3</td>
 </tr>
 <!--AbsoluteLayout-->
 <tr>
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:AbsoluteLayout: Click on A button with its own click listener</td>
+       <td>exact:AbsoluteLayout: left left click on A button with its own click listener</td>
 </tr>
 <tr>
        <td>mouseClick</td>
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:AbsoluteLayout: Click on This is its caption</td>
+       <td>exact:AbsoluteLayout: left click on This is its caption</td>
 </tr>
 <!--CssLayout-->
 <tr>
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td>
-       <td>exact:CSSLayout: Click on This is its caption</td>
+       <td>exact:CSSLayout: left click on This is its caption</td>
 </tr>
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:CSSLayout: Click on This is its caption</td>
+       <td>exact:CSSLayout: left click on This is its caption</td>
 </tr>
 <tr>
        <td>click</td>
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
-       <td>exact:CSSLayout: Click on A button with its own click listener</td>
+       <td>exact:CSSLayout: left click on A button with its own click listener</td>
 </tr>
 </tbody></table>
 </body>
index ecda096690f6a497062720ca4fe4f4a48b1bb1c1..9a7dca7e30ef30f96e37d78888bae1a9693a1c07 100644 (file)
@@ -105,7 +105,7 @@ public class TestLayoutClickListeners extends AbstractTestCase {
         al.addListener(new LayoutClickListener() {
 
             public void layoutClick(LayoutClickEvent event) {
-                logLayoutClick("AbsoluteLayout", event.getChildComponent());
+                logLayoutClick("AbsoluteLayout", event);
             }
         });
 
@@ -137,7 +137,7 @@ public class TestLayoutClickListeners extends AbstractTestCase {
         cl.addListener(new LayoutClickListener() {
 
             public void layoutClick(LayoutClickEvent event) {
-                logLayoutClick("CSSLayout", event.getChildComponent());
+                logLayoutClick("CSSLayout", event);
             }
         });
 
@@ -160,22 +160,34 @@ public class TestLayoutClickListeners extends AbstractTestCase {
         gl.addListener(new LayoutClickListener() {
 
             public void layoutClick(LayoutClickEvent event) {
-                logLayoutClick("GridLayout", event.getChildComponent());
+                logLayoutClick("GridLayout", event);
             }
         });
         gl.setRowExpandRatio(3, 1);
         return wrap(gl, "GridLayout");
     }
 
-    protected void logLayoutClick(String layout, Component comp) {
+    protected void logLayoutClick(String layout, LayoutClickEvent event) {
         String target = "&lt;none>";
-        if (comp != null) {
-            target = comp.getCaption();
-            if (target == null && comp instanceof Label) {
-                target = ((Label) comp).getValue().toString();
+        Component component = event.getChildComponent();
+        if (component != null) {
+            target = component.getCaption();
+            if (target == null && component instanceof Label) {
+                target = ((Label) component).getValue().toString();
             }
         }
-        log.log(layout + ": Click on " + target);
+        String button = "left";
+        if (event.getButton() == event.BUTTON_RIGHT) {
+            button = "right";
+        } else if (event.getButton() == event.BUTTON_MIDDLE) {
+            button = "middle";
+
+        }
+        String type = "click";
+        if (event.isDoubleClick()) {
+            type = "double-click";
+        }
+        log.log(layout + ": " + button + " " + type + " on " + target);
 
     }
 
@@ -187,7 +199,7 @@ public class TestLayoutClickListeners extends AbstractTestCase {
         gl.addListener(new LayoutClickListener() {
 
             public void layoutClick(LayoutClickEvent event) {
-                logLayoutClick("VerticalLayout", event.getChildComponent());
+                logLayoutClick("VerticalLayout", event);
 
             }
         });