From: Johannes Dahlström Date: Fri, 27 Jul 2012 14:39:23 +0000 (+0000) Subject: Explicitly delegate keyboard events from the PopupView popup to the relevant shortcut... X-Git-Tag: 7.0.0.beta1~79^2~62 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fbddc9eff67a8392246d333d0c826d4e71edafa8;p=vaadin-framework.git Explicitly delegate keyboard events from the PopupView popup to the relevant shortcut action handler (#8193) svn changeset:24031/svn branch:6.8 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java index 907e11ac2d..06a9c738a1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java @@ -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 { @@ -239,8 +242,22 @@ public class VPopupView extends HTML implements Container, Iterable { private final Set activeChildren = new HashSet(); 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 { 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(); } diff --git a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java index 7009d03f77..c8d4ee9858 100644 --- a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java +++ b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java @@ -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);