diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-12-17 11:16:42 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-12-17 11:16:42 +0000 |
commit | 5254061ed4df93d579b114f1fa665712e5458950 (patch) | |
tree | e5113a392c21f8b27f087afaf6cd287e7e30582f | |
parent | eb754fc044516f0c501ad50f4c6358e4f827e386 (diff) | |
download | vaadin-framework-5254061ed4df93d579b114f1fa665712e5458950.tar.gz vaadin-framework-5254061ed4df93d579b114f1fa665712e5458950.zip |
Fix for #3874 - Two click events is sent for a middle click in a layout
svn changeset:10379/svn branch:6.2
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 @@ <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 <none></td> + <td>exact:GridLayout: left left click on <none></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> @@ -101,7 +101,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 label 3</td> + <td>exact:VerticalLayout: left left click on This is label 3</td> </tr> <!--AbsoluteLayout--> <tr> @@ -122,7 +122,7 @@ <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> @@ -137,7 +137,7 @@ <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> @@ -168,12 +168,12 @@ <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> @@ -193,7 +193,7 @@ <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> 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); } }); |