From e59b84de64f7bd5acf02e468f9d43a0e72362d11 Mon Sep 17 00:00:00 2001 From: John Alhroos Date: Fri, 13 Aug 2010 08:03:59 +0000 Subject: [PATCH] Fix for #5433 svn changeset:14483/svn branch:6.4 --- .../terminal/gwt/client/ui/VButton.java | 34 +++++++++++++++---- src/com/vaadin/ui/Button.java | 8 +++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java index 6eb9fb2925..d537997fbc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java @@ -13,6 +13,7 @@ import com.google.gwt.event.dom.client.ClickEvent; 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; @@ -80,6 +81,8 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler, private HandlerRegistration focusHandlerRegistration; private HandlerRegistration blurHandlerRegistration; + private int clickShortcut = 0; + public VButton() { super(DOM.createDiv()); setTabIndex(0); @@ -150,6 +153,10 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler, icon = null; } } + + if (uidl.hasAttribute("keycode")) { + clickShortcut = uidl.getIntAttribute("keycode"); + } } public void setText(String text) { @@ -270,24 +277,39 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler, // 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; diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index a373216908..35843365f2 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -11,14 +11,14 @@ import java.util.Map; 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; @@ -143,6 +143,10 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, target.addAttribute("type", "switch"); } target.addVariable(this, "state", booleanValue()); + + if (clickShortcut != null) { + target.addAttribute("keycode", clickShortcut.getKeyCode()); + } } /** -- 2.39.5