From fa4f74844228e2c0596e673f3967ca2a1d8e9d7a Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 8 Dec 2010 19:49:09 +0900 Subject: [PATCH] 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 | 5 +++ toolkit/content/tests/widgets/popup_shared.js | 3 +- .../content/tests/widgets/window_menubar.xul | 45 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/layout/xul/base/src/nsMenuBarListener.cpp b/layout/xul/base/src/nsMenuBarListener.cpp index 2c657fa7004..3ef2e8af240 100644 --- a/layout/xul/base/src/nsMenuBarListener.cpp +++ b/layout/xul/base/src/nsMenuBarListener.cpp @@ -259,6 +259,11 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent) 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 diff --git a/toolkit/content/tests/widgets/popup_shared.js b/toolkit/content/tests/widgets/popup_shared.js index 01f7e1b055c..9d371b5c262 100644 --- a/toolkit/content/tests/widgets/popup_shared.js +++ b/toolkit/content/tests/widgets/popup_shared.js @@ -111,7 +111,8 @@ function eventOccurred(event) 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; } diff --git a/toolkit/content/tests/widgets/window_menubar.xul b/toolkit/content/tests/widgets/window_menubar.xul index b310cf7ef5b..d3dddf5e884 100644 --- a/toolkit/content/tests/widgets/window_menubar.xul +++ b/toolkit/content/tests/widgets/window_menubar.xul @@ -567,6 +567,51 @@ var popupTests = [ 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 + } } ];