aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2010-07-01 10:53:48 +0000
committerJohn Alhroos <john.ahlroos@itmill.com>2010-07-01 10:53:48 +0000
commit2b52bdcb0aebba7cb93862d95d3ada3a456877b8 (patch)
tree83a36ea6073af2e3cba3156f292ff5e48f68e449 /src
parent213be8c40cb79f3a2c93272bc1d4141b46c2aed7 (diff)
downloadvaadin-framework-2b52bdcb0aebba7cb93862d95d3ada3a456877b8.tar.gz
vaadin-framework-2b52bdcb0aebba7cb93862d95d3ada3a456877b8.zip
Fix for #5110
svn changeset:14000/svn branch:6.4
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java70
1 files changed, 69 insertions, 1 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java b/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java
index fe5678bdc0..b841aa3e84 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java
@@ -7,11 +7,28 @@ package com.vaadin.terminal.gwt.client.ui;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.dom.client.TableSectionElement;
+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.dom.client.HasBlurHandlers;
+import com.google.gwt.event.dom.client.HasFocusHandlers;
+import com.google.gwt.event.dom.client.HasKeyDownHandlers;
+import com.google.gwt.event.dom.client.HasKeyPressHandlers;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.event.dom.client.KeyDownHandler;
+import com.google.gwt.event.dom.client.KeyPressEvent;
+import com.google.gwt.event.dom.client.KeyPressHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Element;
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.impl.FocusImpl;
+import com.vaadin.terminal.gwt.client.Focusable;
public class VContextMenu extends VOverlay implements SubPartAware {
@@ -81,6 +98,22 @@ public class VContextMenu extends VOverlay implements SubPartAware {
}
}
setPopupPosition(left, top);
+
+ /*
+ * Move keyboard focus to menu, deferring the focus setting so
+ * the focus is certainly moved to the menu in all browser after
+ * the positioning has been done.
+ */
+ DeferredCommand.addCommand(new Command() {
+ public void execute() {
+ // Focus the menu.
+ menu.setFocus(true);
+
+ // Unselect previously selected items
+ menu.selectItem(null);
+ }
+ });
+
}
});
}
@@ -94,7 +127,8 @@ public class VContextMenu extends VOverlay implements SubPartAware {
* Extend standard Gwt MenuBar to set proper settings and to override
* onPopupClosed method so that PopupPanel gets closed.
*/
- class CMenuBar extends MenuBar {
+ class CMenuBar extends MenuBar implements HasFocusHandlers,
+ HasBlurHandlers, HasKeyDownHandlers, HasKeyPressHandlers, Focusable {
public CMenuBar() {
super(true);
}
@@ -102,6 +136,12 @@ public class VContextMenu extends VOverlay implements SubPartAware {
@Override
public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
super.onPopupClosed(sender, autoClosed);
+
+ // make focusable, as we don't need access key magic we don't need
+ // to
+ // use FocusImpl.createFocusable
+ getElement().setTabIndex(0);
+
hide();
}
@@ -119,6 +159,34 @@ public class VContextMenu extends VOverlay implements SubPartAware {
private MenuItem getItem(int index) {
return super.getItems().get(index);
}
+
+ public HandlerRegistration addFocusHandler(FocusHandler handler) {
+ return addDomHandler(handler, FocusEvent.getType());
+ }
+
+ public HandlerRegistration addBlurHandler(BlurHandler handler) {
+ return addDomHandler(handler, BlurEvent.getType());
+ }
+
+ public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
+ return addDomHandler(handler, KeyDownEvent.getType());
+ }
+
+ public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
+ return addDomHandler(handler, KeyPressEvent.getType());
+ }
+
+ public void setFocus(boolean focus) {
+ if (focus) {
+ FocusImpl.getFocusImplForPanel().focus(getElement());
+ } else {
+ FocusImpl.getFocusImplForPanel().blur(getElement());
+ }
+ }
+
+ public void focus() {
+ setFocus(true);
+ }
}
public Element getSubPartElement(String subPart) {