Parcourir la source

Explicitly delegate keyboard events from the PopupView popup to the relevant shortcut action handler (#8193)

svn changeset:24031/svn branch:6.8
tags/7.0.0.beta1
Johannes Dahlström il y a 12 ans
Parent
révision
fbddc9eff6

+ 31
- 0
src/com/vaadin/terminal/gwt/client/ui/VPopupView.java Voir le fichier

@@ -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();
}


+ 11
- 9
tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java Voir le fichier

@@ -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);

Chargement…
Annuler
Enregistrer