summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2011-04-26 12:18:47 +0000
committerJohn Alhroos <john.ahlroos@itmill.com>2011-04-26 12:18:47 +0000
commit10a673df3643fb67f1a054bbb3fef6da90f693e8 (patch)
tree5afd5b3ab24e06989c57fdfdce2f6f2a4afdb440 /src
parentf1d990db156500ad456dc2567b246b73c3ea2a8f (diff)
downloadvaadin-framework-10a673df3643fb67f1a054bbb3fef6da90f693e8.tar.gz
vaadin-framework-10a673df3643fb67f1a054bbb3fef6da90f693e8.zip
Adds mouse event details to button clicks #6605
svn changeset:18466/svn branch:6.6
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VButton.java10
-rw-r--r--src/com/vaadin/ui/Button.java110
2 files changed, 115 insertions, 5 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java
index 5a5eb0eda6..46492a707c 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -23,6 +23,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.EventHelper;
import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
@@ -353,7 +354,12 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler,
if (BrowserInfo.get().isSafari()) {
VButton.this.setFocus(true);
}
- client.updateVariable(id, "state", true, true);
+ client.updateVariable(id, "state", true, false);
+
+ // Add mouse details
+ MouseEventDetails details = new MouseEventDetails(
+ event.getNativeEvent(), getElement());
+ client.updateVariable(id, "mousedetails", details.serialize(), true);
clickPending = false;
}
diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java
index cf354750a8..8fa9e2afb9 100644
--- a/src/com/vaadin/ui/Button.java
+++ b/src/com/vaadin/ui/Button.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -21,6 +21,7 @@ import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.event.ShortcutListener;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VButton;
import com.vaadin.ui.ClientWidget.LoadStyle;
import com.vaadin.ui.themes.BaseTheme;
@@ -175,13 +176,15 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
if (newValue != null && !newValue.equals(oldValue)
&& !isReadOnly()) {
setValue(newValue);
- fireClick();
+ fireClick(MouseEventDetails.deSerialize((String) variables
+ .get("mousedetails")));
}
} else {
// Only send click event if the button is pushed
if (newValue.booleanValue()) {
- fireClick();
+ fireClick(MouseEventDetails.deSerialize((String) variables
+ .get("mousedetails")));
}
// If the button is true for some reason, release it
@@ -300,6 +303,8 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
*/
public class ClickEvent extends Component.Event {
+ private MouseEventDetails details;
+
/**
* New instance of text change event.
*
@@ -311,6 +316,19 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
}
/**
+ * Constructor with mouse details
+ *
+ * @param source
+ * The source where the click took place
+ * @param details
+ * Details about the mouse click
+ */
+ public ClickEvent(Component source, MouseEventDetails details) {
+ super(source);
+ this.details = details;
+ }
+
+ /**
* Gets the Button where the event occurred.
*
* @return the Source of the event.
@@ -318,6 +336,87 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
public Button getButton() {
return (Button) getSource();
}
+
+ /**
+ * Returns the mouse position (x coordinate) when the click took place.
+ * The position is relative to the browser client area.
+ *
+ * @return The mouse cursor x position
+ */
+ public int getClientX() {
+ return details.getClientX();
+ }
+
+ /**
+ * Returns the mouse position (y coordinate) when the click took place.
+ * The position is relative to the browser client area.
+ *
+ * @return The mouse cursor y position
+ */
+ public int getClientY() {
+ return details.getClientY();
+ }
+
+ /**
+ * Returns the relative mouse position (x coordinate) when the click
+ * took place. The position is relative to the clicked component.
+ *
+ * @return The mouse cursor x position relative to the clicked layout
+ * component or -1 if no x coordinate available
+ */
+ public int getRelativeX() {
+ return details.getRelativeX();
+ }
+
+ /**
+ * Returns the relative mouse position (y coordinate) when the click
+ * took place. The position is relative to the clicked component.
+ *
+ * @return The mouse cursor y position relative to the clicked layout
+ * component or -1 if no y coordinate available
+ */
+ public int getRelativeY() {
+ return details.getRelativeY();
+ }
+
+ /**
+ * Checks if the Alt key was down when the mouse event took place.
+ *
+ * @return true if Alt was down when the event occured, false otherwise
+ */
+ public boolean isAltKey() {
+ return details.isAltKey();
+ }
+
+ /**
+ * Checks if the Ctrl key was down when the mouse event took place.
+ *
+ * @return true if Ctrl was pressed when the event occured, false
+ * otherwise
+ */
+ public boolean isCtrlKey() {
+ return details.isCtrlKey();
+ }
+
+ /**
+ * Checks if the Meta key was down when the mouse event took place.
+ *
+ * @return true if Meta was pressed when the event occured, false
+ * otherwise
+ */
+ public boolean isMetaKey() {
+ return details.isMetaKey();
+ }
+
+ /**
+ * Checks if the Shift key was down when the mouse event took place.
+ *
+ * @return true if Shift was pressed when the event occured, false
+ * otherwise
+ */
+ public boolean isShiftKey() {
+ return details.isShiftKey();
+ }
}
/**
@@ -339,6 +438,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
* An event containing information about the click.
*/
public void buttonClick(ClickEvent event);
+
}
/**
@@ -368,6 +468,10 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
fireEvent(new Button.ClickEvent(this));
}
+ private void fireClick(MouseEventDetails details) {
+ fireEvent(new Button.ClickEvent(this, details));
+ }
+
@Override
protected void setInternalValue(Object newValue) {
// Make sure only booleans get through