Commit 6b2c1efe authored by James Teh's avatar James Teh
Browse files

Bug 1546633: PanelMultiView: Send mousedown event when activating a button via the keyboard. r=Gijs

Previously, we sent a command event and a click event.
Normally, the command event executes the action, then the click event closes the menu.
However, in some cases (e.g. the Library button), there is no command event handler and the mousedown event executes the action instead.

Differential Revision: https://phabricator.services.mozilla.com/D29151

--HG--
extra : moz-landing-system : lando
parent e5870b20
......@@ -1664,12 +1664,17 @@ var PanelView = class extends AssociatedToNode {
this._doingKeyboardActivation = true;
// Unfortunately, 'tabindex' doesn't execute the default action, so
// we explicitly do this here.
// We are sending a command event and then a click event.
// This is done in order to mimic a "real" mouse click event.
// The command event executes the action, then the click event closes the menu.
// We are sending a command event, a mousedown event and then a click
// event. This is done in order to mimic a "real" mouse click event.
// Normally, the command event executes the action, then the click event
// closes the menu. However, in some cases (e.g. the Library button),
// there is no command event handler and the mousedown event executes the
// action instead.
button.doCommand();
let clickEvent = new event.target.ownerGlobal.MouseEvent("click", {"bubbles": true});
button.dispatchEvent(clickEvent);
let dispEvent = new event.target.ownerGlobal.MouseEvent("mousedown", {"bubbles": true});
button.dispatchEvent(dispEvent);
dispEvent = new event.target.ownerGlobal.MouseEvent("click", {"bubbles": true});
button.dispatchEvent(dispEvent);
this._doingKeyboardActivation = false;
break;
}
......
......@@ -288,6 +288,20 @@ add_task(async function testActivation() {
await hidePopup();
});
// Test that keyboard activation works for buttons responding to mousedown
// events (instead of command or click). The Library button does this, for
// example.
add_task(async function testActivationMousedown() {
await openPopup();
await expectFocusAfterKey("ArrowDown", gMainButton1);
let activated = false;
gMainButton1.onmousedown = function() { activated = true; };
EventUtils.synthesizeKey(" ");
ok(activated, "mousedown activated after space");
gMainButton1.onmousedown = null;
await hidePopup();
});
// Test that tab and the arrow keys aren't overridden in embedded documents.
add_task(async function testTabArrowsBrowser() {
await openPopup();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment