Skip to content

Commit

Permalink
Bug 625151 Reset accesskey state at blur and alt keydown r=enn
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki-nakano committed Feb 14, 2012
1 parent 80ce6c0 commit cdef5df
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
41 changes: 28 additions & 13 deletions layout/xul/base/src/nsMenuBarListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,34 @@ nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);

if (!mAccessKeyDownCanceled && theChar == (PRUint32)mAccessKey &&
(GetModifiers(keyEvent) & ~mAccessKeyMask) == 0) {
// No other modifiers can be down.
// Especially CTRL. CTRL+ALT == AltGR, and
// we'll fuck up on non-US enhanced 102-key
// keyboards if we don't check this.
// No other modifiers can be down.
// Especially CTRL. CTRL+ALT == AltGR, and we'll fuck up on non-US
// enhanced 102-key keyboards if we don't check this.
bool isAccessKeyDownEvent =
((theChar == (PRUint32)mAccessKey) &&
(GetModifiers(keyEvent) & ~mAccessKeyMask) == 0);

if (!mAccessKeyDown) {
// If accesskey isn't being pressed and the key isn't the accesskey,
// ignore the event.
if (!isAccessKeyDownEvent) {
return NS_OK;
}

// Otherwise, accept the accesskey state.
mAccessKeyDown = true;
mAccessKeyDownCanceled = false;
return NS_OK;
}
else {
// Some key other than the access key just went down,
// so we won't activate the menu bar when the access
// key is released.

mAccessKeyDownCanceled = true;
// If the pressed accesskey was canceled already, ignore the event.
if (mAccessKeyDownCanceled) {
return NS_OK;
}

// Some key other than the access key just went down,
// so we won't activate the menu bar when the access key is released.
mAccessKeyDownCanceled = !isAccessKeyDownEvent;
}

return NS_OK; // means I am NOT consuming event
Expand All @@ -371,9 +384,11 @@ nsMenuBarListener::Blur(nsIDOMEvent* aEvent)
{
if (!mMenuBarFrame->IsMenuOpen() && mMenuBarFrame->IsActive()) {
ToggleMenuActiveState();
mAccessKeyDown = false;
mAccessKeyDownCanceled = false;
}
// Reset the accesskey state because we cannot receive the keyup event for
// the pressing accesskey.
mAccessKeyDown = false;
mAccessKeyDownCanceled = false;
return NS_OK; // means I am NOT consuming event
}

Expand Down
31 changes: 31 additions & 0 deletions toolkit/content/tests/widgets/window_menubar.xul
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,37 @@ var popupTests = [
test: function() {
synthesizeKey("VK_ALT", { });
}
},
// bug 625151
{
testname: "Alt key state before deactivating the window shouldn't prevent " +
"next Alt key handling",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: function() {
return [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ];
},
test: function() {
synthesizeKey("VK_ALT", { type: "keydown" });
synthesizeKey("VK_TAB", { type: "keydown" }); // cancels the Alt key
var thisWindow = window;
var newWindow =
window.open("data:text/html,", "_blank", "width=100,height=100");
newWindow.addEventListener("focus", function () {
newWindow.removeEventListener("focus", arguments.callee, false);
thisWindow.addEventListener("focus", function () {
thisWindow.removeEventListener("focus", arguments.callee, false);
setTimeout(function () {
synthesizeKey("VK_ALT", { }, thisWindow);
}, 0);
}, false);
newWindow.close();
thisWindow.focus();
// Note that our window dispatches a hacky key event if IMM is installed
// on the system during focus change only if Alt key is pressed.
synthesizeKey("`", { type: "keypress" }, thisWindow);
}, false);
}
}
];
Expand Down

0 comments on commit cdef5df

Please sign in to comment.