Bug 616797 Menubar doesn't appear by Alt key after using accelerator to open a popup menu and closing it by click r=enn, a=final+
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Dec 2010 19:49:09 +0900
changeset 58884 f25461268434fbcfcbc7f2e72a3851a253dee458
parent 58883 efcc5c73f0f4d524f195c8269e3c5b3b5d72dffe
child 58885 897cca5152805461346524a78148ef8966427bc3
push id17444
push usermasayuki@d-toybox.com
push dateWed, 08 Dec 2010 10:49:26 +0000
treeherdermozilla-central@f25461268434 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn, final
bugs616797
milestone2.0b8pre
first release with
nightly win64
f25461268434 / 4.0b8pre / 20101208044747 / files
nightly linux32
nightly linux64
nightly mac
nightly win32
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly win64
Bug 616797 Menubar doesn't appear by Alt key after using accelerator to open a popup menu and closing it by click r=enn, a=final+
layout/xul/base/src/nsMenuBarListener.cpp
toolkit/content/tests/widgets/popup_shared.js
toolkit/content/tests/widgets/window_menubar.xul
--- a/layout/xul/base/src/nsMenuBarListener.cpp
+++ b/layout/xul/base/src/nsMenuBarListener.cpp
@@ -254,16 +254,21 @@ nsMenuBarListener::KeyPress(nsIDOMEvent*
       if (IsAccessKeyPressed(keyEvent) && hasAccessKeyCandidates) {
         // Do shortcut navigation.
         // A letter was pressed. We want to see if a shortcut gets matched. If
         // so, we'll know the menu got activated.
         nsMenuFrame* result = mMenuBarFrame->FindMenuWithShortcut(keyEvent);
         if (result) {
           mMenuBarFrame->SetActive(PR_TRUE);
           result->OpenMenu(PR_TRUE);
+
+          // The opened menu will listen next keyup event.
+          // Therefore, we should clear the keydown flags here.
+          mAccessKeyDown = mAccessKeyDownCanceled = PR_FALSE;
+
           aKeyEvent->StopPropagation();
           aKeyEvent->PreventDefault();
           retVal = NS_OK;       // I am consuming event
         }
       }    
 #ifndef XP_MACOSX
       // Also need to handle F10 specially on Non-Mac platform.
       else if (keyCode == NS_VK_F10) {
--- a/toolkit/content/tests/widgets/popup_shared.js
+++ b/toolkit/content/tests/widgets/popup_shared.js
@@ -106,17 +106,18 @@ function eventOccurred(event)
     return;
   }
 
   var events = test.events;
   if (typeof events == "function")
     events = events();
   if (events) {
     if (events.length <= gTestEventIndex) {
-      ok(false, "Extra " + event.type + " event fired " + gPopupTests[gTestIndex].testname);
+      ok(false, "Extra " + event.type + " event fired for " + event.target.id +
+                  " " +gPopupTests[gTestIndex].testname);
       return;
     }
 
     var eventitem = events[gTestEventIndex].split(" ");
     var matches;
     if (eventitem[1] == "#tooltip") {
       is(event.originalTarget.localName, "tooltip",
          test.testname + " event.originalTarget.localName is 'tooltip'");
--- a/toolkit/content/tests/widgets/window_menubar.xul
+++ b/toolkit/content/tests/widgets/window_menubar.xul
@@ -562,16 +562,61 @@ var popupTests = [
     synthesizeKey("VK_ALT", { type: "keydown" });
     synthesizeMouse(document.getElementById("menubar"), 8, -30, { type: "mouseup", altKey: true });
     synthesizeKey("VK_ALT", { type: "keydown" });
     synthesizeKey("VK_ALT", { type: "keyup" });
   },
   result: function (testname) {
     checkActive(document.getElementById("menubar"), "", testname);
   }
+},
+
+// Fllowing 3 tests are a test of bug 616797, don't insert any new tests
+// between them.
+{
+  testname: "Open file menu by accelerator",
+  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
+  events: function() {
+    return [ "DOMMenuBarActive menubar", "popupshowing filepopup",
+             "DOMMenuItemActive filemenu", "DOMMenuItemActive item1",
+             "popupshown filepopup" ];
+  },
+  test: function() {
+    synthesizeKey("VK_ALT", { type: "keydown" });
+    synthesizeKey("F", { altKey: true });
+    synthesizeKey("VK_ALT", { type: "keyup" });
+  }
+},
+{
+  testname: "Close file menu by click at outside of popup menu",
+  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
+  events: function() {
+    return [ "popuphiding filepopup", "popuphidden filepopup",
+             "DOMMenuItemInactive item1", "DOMMenuInactive filepopup",
+             "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu",
+             "DOMMenuItemInactive filemenu" ];
+  },
+  test: function() {
+    // XXX hidePopup() causes DOMMenuItemInactive event to be fired twice.
+    document.getElementById("filepopup").hidePopup();
+  }
+},
+{
+  testname: "Alt keydown set focus the menubar",
+  condition: function() { return (navigator.platform.indexOf("Win") == 0) },
+  events: function() {
+    return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
+  },
+  test: function() {
+    synthesizeKey("VK_ALT", {  });
+  },
+  result: function (testname) {
+    checkClosed("filemenu", testname);
+    synthesizeKey("VK_ALT", {  }); // unfocus menubar
+  }
 }
 
 ];
 
 ]]>
 </script>