]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #5433
authorJohn Alhroos <john.ahlroos@itmill.com>
Fri, 13 Aug 2010 08:03:59 +0000 (08:03 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Fri, 13 Aug 2010 08:03:59 +0000 (08:03 +0000)
svn changeset:14483/svn branch:6.4

src/com/vaadin/terminal/gwt/client/ui/VButton.java
src/com/vaadin/ui/Button.java

index 6eb9fb2925b97893c3af61934502fa2eaad6c2c2..d537997fbcb95def9bcdbf08448c1b524ea3ea40 100644 (file)
@@ -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;
index a37321690873f29350e0c61dc609ddb5b777a171..35843365f2d2ea037bdf3b818cef84d728b8e37b 100644 (file)
@@ -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());
+        }
     }
 
     /**