From 5254061ed4df93d579b114f1fa665712e5458950 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 17 Dec 2009 11:16:42 +0000 Subject: [PATCH] Fix for #3874 - Two click events is sent for a middle click in a layout svn changeset:10379/svn branch:6.2 --- .../gwt/client/ui/ClickEventHandler.java | 28 ++++------------ .../layouts/TestLayoutClickListeners.html | 20 ++++++------ .../layouts/TestLayoutClickListeners.java | 32 +++++++++++++------ 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java b/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java index 0e60246d48..85bc0817bc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java +++ b/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java @@ -4,8 +4,6 @@ import java.util.HashMap; import java.util.Map; import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ContextMenuEvent; import com.google.gwt.event.dom.client.ContextMenuHandler; import com.google.gwt.event.dom.client.DomEvent; @@ -19,10 +17,9 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; -public abstract class ClickEventHandler implements ClickHandler, - DoubleClickHandler, ContextMenuHandler, MouseUpHandler { +public abstract class ClickEventHandler implements DoubleClickHandler, + ContextMenuHandler, MouseUpHandler { - private HandlerRegistration clickHandlerRegistration; private HandlerRegistration doubleClickHandlerRegistration; private HandlerRegistration mouseUpHandlerRegistration; private HandlerRegistration contextMenuHandlerRegistration; @@ -41,9 +38,7 @@ public abstract class ClickEventHandler implements ClickHandler, // Handle registering/unregistering of click handler depending on if // server side listeners have been added or removed. if (hasEventListener()) { - if (clickHandlerRegistration == null) { - clickHandlerRegistration = registerHandler(this, ClickEvent - .getType()); + if (mouseUpHandlerRegistration == null) { mouseUpHandlerRegistration = registerHandler(this, MouseUpEvent .getType()); contextMenuHandlerRegistration = registerHandler(this, @@ -52,9 +47,8 @@ public abstract class ClickEventHandler implements ClickHandler, DoubleClickEvent.getType()); } } else { - if (clickHandlerRegistration != null) { + if (mouseUpHandlerRegistration != null) { // Remove existing handlers - clickHandlerRegistration.removeHandler(); doubleClickHandlerRegistration.removeHandler(); mouseUpHandlerRegistration.removeHandler(); contextMenuHandlerRegistration.removeHandler(); @@ -62,7 +56,6 @@ public abstract class ClickEventHandler implements ClickHandler, contextMenuHandlerRegistration = null; mouseUpHandlerRegistration = null; doubleClickHandlerRegistration = null; - clickHandlerRegistration = null; } } @@ -81,12 +74,6 @@ public abstract class ClickEventHandler implements ClickHandler, clickEventIdentifier); } - public void onClick(ClickEvent event) { - if (hasEventListener()) { - fireClick(event.getNativeEvent()); - } - } - protected void fireClick(NativeEvent event) { ApplicationConnection client = getApplicationConnection(); String pid = getApplicationConnection().getPid(paintable); @@ -113,11 +100,8 @@ public abstract class ClickEventHandler implements ClickHandler, // occured on this element before this mouseup and that no mouseup // has occured anywhere after that. if (hasEventListener()) { - if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) { - // "Click" with right or middle button - fireClick(event.getNativeEvent()); - - } + // "Click" with left, right or middle button + fireClick(event.getNativeEvent()); } } diff --git a/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.html b/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.html index f488eb9a81..28635a9df7 100644 --- a/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.html +++ b/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.html @@ -40,7 +40,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:GridLayout: Click on This is label 1 + exact:GridLayout: left left click on This is label 1 mouseClick @@ -55,7 +55,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:GridLayout: Click on This is tf5 + exact:GridLayout: left left click on This is tf5 mouseClick @@ -70,7 +70,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:GridLayout: Click on <none> + exact:GridLayout: left left click on <none> @@ -86,7 +86,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:VerticalLayout: Click on This is tf6 + exact:VerticalLayout: left left click on This is tf6 mouseClick @@ -101,7 +101,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:VerticalLayout: Click on This is label 3 + exact:VerticalLayout: left left click on This is label 3 @@ -122,7 +122,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:AbsoluteLayout: Click on A button with its own click listener + exact:AbsoluteLayout: left left click on A button with its own click listener mouseClick @@ -137,7 +137,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:AbsoluteLayout: Click on This is its caption + exact:AbsoluteLayout: left click on This is its caption @@ -168,12 +168,12 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0] - exact:CSSLayout: Click on This is its caption + exact:CSSLayout: left click on This is its caption assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:CSSLayout: Click on This is its caption + exact:CSSLayout: left click on This is its caption click @@ -193,7 +193,7 @@ assertText vaadin=runcomvaadintestslayoutsTestLayoutClickListeners::/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0] - exact:CSSLayout: Click on A button with its own click listener + exact:CSSLayout: left click on A button with its own click listener diff --git a/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.java b/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.java index ecda096690..9a7dca7e30 100644 --- a/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.java +++ b/tests/src/com/vaadin/tests/layouts/TestLayoutClickListeners.java @@ -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 = "<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); } }); -- 2.39.5