import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
private HandlerRegistration focusHandlerRegistration;
private HandlerRegistration blurHandlerRegistration;
+ private int clickShortcut = 0;
+
public VButton() {
super(DOM.createDiv());
setTabIndex(0);
icon = null;
}
}
+
+ if (uidl.hasAttribute("keycode")) {
+ clickShortcut = uidl.getIntAttribute("keycode");
+ }
}
public void setText(String text) {
// Synthesize clicks based on keyboard events AFTER the normal key
// handling.
if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
- char keyCode = (char) DOM.eventGetKeyCode(event);
switch (type) {
case Event.ONKEYDOWN:
- if (keyCode == ' ') {
+ if (event.getKeyCode() == 32 /* space */) {
isFocusing = true;
event.preventDefault();
}
break;
case Event.ONKEYUP:
- if (isFocusing && keyCode == ' ') {
+ if (isFocusing && event.getKeyCode() == 32 /* space */) {
isFocusing = false;
- onClick();
+
+ /*
+ * If click shortcut is space then the shortcut handler will
+ * take care of the click.
+ */
+ if (clickShortcut != 32 /* space */) {
+ onClick();
+ }
+
event.preventDefault();
}
break;
case Event.ONKEYPRESS:
- if (keyCode == '\n' || keyCode == '\r') {
- onClick();
+ if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
+
+ /*
+ * If click shortcut is enter then the shortcut handler will
+ * take care of the click.
+ */
+ if (clickShortcut != KeyCodes.KEY_ENTER) {
+ onClick();
+ }
+
event.preventDefault();
}
break;
import com.vaadin.data.Property;
import com.vaadin.event.FieldEvents;
-import com.vaadin.event.ShortcutAction;
-import com.vaadin.event.ShortcutListener;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutAction.KeyCode;
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.ui.VButton;
target.addAttribute("type", "switch");
}
target.addVariable(this, "state", booleanValue());
+
+ if (clickShortcut != null) {
+ target.addAttribute("keycode", clickShortcut.getKeyCode());
+ }
}
/**