Bug 1546633: PanelMultiView: Send mousedown event when activating a button via the keyboard. r=Gijs
☠☠ backed out by 47ea779dc66b ☠ ☠
authorJames Teh <jteh@mozilla.com>
Wed, 01 May 2019 04:01:35 +0000
changeset 530865 041741ce164674137968c39aab0a9c80e84c99db
parent 530864 fbc294a6fe785b56a5ef52b5b1ea61d511bebc52
child 530866 47ea779dc66b06fdcc4a247fbe29bf9770cefa8b
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1546633
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
browser/components/customizableui/PanelMultiView.jsm
browser/components/customizableui/test/browser_PanelMultiView_keyboard.js
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -1659,22 +1659,27 @@ var PanelView = class extends Associated
         let button = this.selectedElement;
         if (!button)
           break;
         stop();
 
         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;
       }
     }
   }
 
   /**
    * Focus the last selected element in the view, if any.
--- a/browser/components/customizableui/test/browser_PanelMultiView_keyboard.js
+++ b/browser/components/customizableui/test/browser_PanelMultiView_keyboard.js
@@ -283,16 +283,30 @@ add_task(async function testActivation()
   await openPopup();
   await expectFocusAfterKey("ArrowDown", gMainButton1);
   checkActivated(gMainButton1, () => EventUtils.synthesizeKey("KEY_Enter"), "pressing enter");
   checkActivated(gMainButton1, () => EventUtils.synthesizeKey(" "), "pressing space");
   checkActivated(gMainButton1, () => EventUtils.synthesizeKey("KEY_Enter", {code: "NumpadEnter"}), "pressing numpad enter");
   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();
   await showSubView(gDocView);
   let backButton = gDocView.querySelector(".subviewbutton-back");
   backButton.id = "docBack";
   await expectFocusAfterKey("Tab", backButton);
   let doc = gDocBrowser.contentDocument;