MenuBar focuses itself when a MenuItem is selected for any reason so the user can seamlessly switch between the mouse and keyboard.  However, this means that the SuggestBox loses focus as soon as the first suggestion is automatically highlighted.  This patch makes the focus optional in MenuBar.

Patch by: jlabanca
Review by: ajr

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@3619 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/MenuBar.java b/user/src/com/google/gwt/user/client/ui/MenuBar.java
index 2ed2c17..6f6957d 100644
--- a/user/src/com/google/gwt/user/client/ui/MenuBar.java
+++ b/user/src/com/google/gwt/user/client/ui/MenuBar.java
@@ -329,14 +329,14 @@
 
       case Event.ONMOUSEOVER: {
         if (item != null) {
-          itemOver(item);
+          itemOver(item, true);
         }
         break;
       }
 
       case Event.ONMOUSEOUT: {
         if (item != null) {
-          itemOver(null);
+          itemOver(null, true);
         }
         break;
       }
@@ -555,7 +555,7 @@
     }
   }
 
-  void itemOver(MenuItem item) {
+  void itemOver(MenuItem item, boolean focus) {
     if (item == null) {
       // Don't clear selection if the currently selected item's menu is showing.
       if ((selectedItem != null)
@@ -566,7 +566,9 @@
 
     // Style the item selected when the mouse enters.
     selectItem(item);
-    focus();
+    if (focus) {
+      focus();
+    }
 
     // If child menus are being shown, or this menu is itself
     // a child menu, automatically show an item's child menu
diff --git a/user/src/com/google/gwt/user/client/ui/SuggestBox.java b/user/src/com/google/gwt/user/client/ui/SuggestBox.java
index b1b7d4b..179f4ec 100644
--- a/user/src/com/google/gwt/user/client/ui/SuggestBox.java
+++ b/user/src/com/google/gwt/user/client/ui/SuggestBox.java
@@ -173,7 +173,7 @@
     public void selectItem(int index) {
       List<MenuItem> items = getItems();
       if (index > -1 && index < items.size()) {
-        itemOver(items.get(index));
+        itemOver(items.get(index), false);
       }
     }
   }
diff --git a/user/test/com/google/gwt/user/client/ui/MenuBarTest.java b/user/test/com/google/gwt/user/client/ui/MenuBarTest.java
index e679232..ac9601a 100644
--- a/user/test/com/google/gwt/user/client/ui/MenuBarTest.java
+++ b/user/test/com/google/gwt/user/client/ui/MenuBarTest.java
@@ -114,7 +114,7 @@
     RootPanel.get().add(bar);
     
     // Open the item with a submenu
-    bar.itemOver(top2);
+    bar.itemOver(top2, true);
 
     // Set the Debug Id
     bar.ensureDebugId("myMenu");