]> source.dussan.org Git - vaadin-framework.git/commitdiff
Explicitly delegate keyboard events from the PopupView popup to the relevant shortcut...
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Fri, 27 Jul 2012 14:39:23 +0000 (14:39 +0000)
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Fri, 27 Jul 2012 14:39:23 +0000 (14:39 +0000)
svn changeset:24031/svn branch:6.8

src/com/vaadin/terminal/gwt/client/ui/VPopupView.java
tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java

index 907e11ac2d85aab3bd58f71e1bcf6bff71a9c69f..06a9c738a1bc4cbe9d9350716cd0edfd6893a525 100644 (file)
@@ -11,6 +11,8 @@ import java.util.Set;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.event.dom.client.KeyDownHandler;
 import com.google.gwt.event.logical.shared.CloseEvent;
 import com.google.gwt.event.logical.shared.CloseHandler;
 import com.google.gwt.user.client.DOM;
@@ -33,6 +35,7 @@ import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VCaption;
 import com.vaadin.terminal.gwt.client.VCaptionWrapper;
 import com.vaadin.terminal.gwt.client.VTooltip;
+import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
 import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextArea;
 
 public class VPopupView extends HTML implements Container, Iterable<Widget> {
@@ -239,8 +242,22 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> {
         private final Set<Element> activeChildren = new HashSet<Element>();
         private boolean hiding = false;
 
+        private ShortcutActionHandler shortcutActionHandler;
+
         public CustomPopup() {
             super(true, false, true); // autoHide, not modal, dropshadow
+
+            // Delegate popup keyboard events to the relevant handler. The
+            // events do not propagate automatically because the popup is
+            // directly attached to the RootPanel.
+            addDomHandler(new KeyDownHandler() {
+                public void onKeyDown(KeyDownEvent event) {
+                    if (shortcutActionHandler != null) {
+                        shortcutActionHandler.handleKeyboardEvent(Event
+                                .as(event.getNativeEvent()));
+                    }
+                }
+            }, KeyDownEvent.getType());
         }
 
         // For some reason ONMOUSEOUT events are not always received, so we have
@@ -290,12 +307,26 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> {
                 remove(popupComponentWidget);
             }
             hasHadMouseOver = false;
+            shortcutActionHandler = null;
             super.hide(autoClosed);
         }
 
         @Override
         public void show() {
             hiding = false;
+
+            // Find the shortcut action handler that should handle keyboard
+            // events from the popup. The events do not propagate automatically
+            // because the popup is directly attached to the RootPanel.
+            Widget widget = VPopupView.this;
+            while (shortcutActionHandler == null && widget != null) {
+                if (widget instanceof ShortcutActionHandlerOwner) {
+                    shortcutActionHandler = ((ShortcutActionHandlerOwner) widget)
+                            .getShortcutActionHandler();
+                }
+                widget = widget.getParent();
+            }
+
             super.show();
         }
 
index 7009d03f772879bd48d443331e8e4c82478ec1ac..c8d4ee985854a244dac85f29ac2a2dba70e97088 100644 (file)
@@ -45,16 +45,18 @@ public class PopupViewClickShortcut extends TestBase {
         l.setCaption(caption);
         l.setWidth(null);
 
-        Button b = new Button("Submit " + caption, new Button.ClickListener() {
-            private int i = 5;
+        Button b = new Button("Submit " + caption + " (Ctrl+Alt+"
+                + String.valueOf(Character.toChars(keyCode)) + ")",
+                new Button.ClickListener() {
+                    private int i = 5;
 
-            public void buttonClick(ClickEvent event) {
-                log.log("Submitted from "
-                        + event.getButton().getParent().getCaption());
-                t.addItem(new String[] { "added " + i++ }, i);
-            }
-        });
-        b.setClickShortcut(keyCode, ModifierKey.ALT);
+                    public void buttonClick(ClickEvent event) {
+                        log.log("Submitted from "
+                                + event.getButton().getParent().getCaption());
+                        t.addItem(new String[] { "added " + i++ }, i);
+                    }
+                });
+        b.setClickShortcut(keyCode, ModifierKey.CTRL, ModifierKey.ALT);
 
         l.addComponent(t);
         l.addComponent(b);