From 51603fe898c645d5b2f3964c76ee0bb72fef7a02 Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Fri, 20 May 2011 11:40:45 +0000 Subject: [PATCH] New fix for #5535. Added the flag for indicating whether the focus is via mouse or other means. svn changeset:18967/svn branch:6.6 --- .../terminal/gwt/client/ui/VMenuBar.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index 44870ef350..932a54cd5b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -90,6 +90,12 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, private boolean openRootOnHover; + /* + * Flag to disable first root item selection when clicking on the menubar + * (tabbing to the menubar should select the first item) + */ + private boolean preventFocusSelection = false; + public VMenuBar() { // Create an empty horizontal menubar this(false, null); @@ -480,6 +486,7 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, while (parent.getParentMenu() != null) { parent = parent.getParentMenu(); } + preventFocusSelection = true; parent.setFocus(true); } @@ -504,6 +511,7 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, while (parent.getParentMenu() != null) { parent = parent.getParentMenu(); } + preventFocusSelection = true; parent.setFocus(true); } } @@ -553,7 +561,9 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, * @param item */ public void itemOver(CustomMenuItem item) { + preventFocusSelection = true; if ((openRootOnHover || subMenu || menuVisible) && !item.isSeparator()) { + preventFocusSelection = true; setSelected(item); if (!subMenu && openRootOnHover && !menuVisible) { menuVisible = true; // start opening menus @@ -1432,7 +1442,19 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, * .dom.client.FocusEvent) */ public void onFocus(FocusEvent event) { + if (!preventFocusSelection) { + setSelected(items.get(0)); + } + preventFocusSelection = false; + } + @Override + public void setFocus(boolean focus) { + super.setFocus(focus); + if (!focus) { + setSelected(null); + preventFocusSelection = false; + } } private final String SUBPART_PREFIX = "item"; -- 2.39.5