]> source.dussan.org Git - vaadin-framework.git/commitdiff
New fix for #5535. Added the flag for indicating whether the focus is via mouse or...
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Fri, 20 May 2011 11:40:45 +0000 (11:40 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Fri, 20 May 2011 11:40:45 +0000 (11:40 +0000)
svn changeset:18967/svn branch:6.6

src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java

index 44870ef3507dad66058ac2b7ca60272b58a316f3..932a54cd5be11a14cb63d2bdce607daacb5707b7 100644 (file)
@@ -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";