diff options
author | michaelvogt <michael@vaadin.com> | 2013-05-14 16:36:58 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-05-17 07:52:09 +0000 |
commit | f1130fab63088a3830deff0ae348e99eedaf9c73 (patch) | |
tree | 4d74fa3ec3ed434cd51d0816f2bf0c2c4ff1e0f2 /client | |
parent | 4235382c0a0f39fbf040f9915cb12e0ba01baccf (diff) | |
download | vaadin-framework-f1130fab63088a3830deff0ae348e99eedaf9c73.tar.gz vaadin-framework-f1130fab63088a3830deff0ae348e99eedaf9c73.zip |
Reset focus after selection from ContextMenu (#11476)
Change-Id: I591d82363939bf264a5080c7fc4e06de25d93500
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VContextMenu.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VContextMenu.java b/client/src/com/vaadin/client/ui/VContextMenu.java index e601c8027a..a89854e1c8 100644 --- a/client/src/com/vaadin/client/ui/VContextMenu.java +++ b/client/src/com/vaadin/client/ui/VContextMenu.java @@ -35,6 +35,8 @@ import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.dom.client.KeyPressHandler; import com.google.gwt.event.dom.client.LoadEvent; import com.google.gwt.event.dom.client.LoadHandler; +import com.google.gwt.event.logical.shared.CloseEvent; +import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; @@ -43,6 +45,7 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.MenuBar; import com.google.gwt.user.client.ui.MenuItem; import com.google.gwt.user.client.ui.PopupPanel; +import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.impl.FocusImpl; import com.vaadin.client.Focusable; import com.vaadin.client.Util; @@ -57,6 +60,8 @@ public class VContextMenu extends VOverlay implements SubPartAware { private int top; + private Element focusedElement; + private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor(100, new ScheduledCommand() { @Override @@ -77,6 +82,20 @@ public class VContextMenu extends VOverlay implements SubPartAware { setWidget(menu); setStyleName("v-contextmenu"); getElement().setId(DOM.createUniqueId()); + + addCloseHandler(new CloseHandler<PopupPanel>() { + @Override + public void onClose(CloseEvent<PopupPanel> event) { + Element currentFocus = Util.getFocusedElement(); + if (focusedElement != null + && (currentFocus == null + || menu.getElement().isOrHasChild(currentFocus) || RootPanel + .getBodyElement().equals(currentFocus))) { + focusedElement.focus(); + focusedElement = null; + } + } + }); } protected void imagesLoaded() { @@ -117,6 +136,10 @@ public class VContextMenu extends VOverlay implements SubPartAware { // Attach onload listeners to all images Util.sinkOnloadForImages(menu.getElement()); + // Store the currently focused element, which will be re-focused when + // context menu is closed + focusedElement = Util.getFocusedElement(); + setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { |