Bug 1378016 - Fix keyboard navigation and selection on 'recent bookmarks'. r=Gijs
authorErica Wright <ewright@mozilla.com>
Mon, 31 Jul 2017 09:47:19 -0400
changeset 372490 d7d0e0ba501a
parent 372489 3fc46b53b7ee
child 372491 47709bd65292
push id32278
push userarchaeopteryx@coole-files.de
push dateThu, 03 Aug 2017 09:44:16 +0000
treeherdermozilla-central@681a2489f6a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1378016
milestone56.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 1378016 - Fix keyboard navigation and selection on 'recent bookmarks'. r=Gijs MozReview-Commit-ID: GJ7vRPz8zuo
browser/components/customizableui/PanelMultiView.jsm
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -1017,22 +1017,20 @@ this.PanelMultiView = class {
       this._keyNavigationMap.set(view, navMap);
     }
 
     let buttons = navMap.buttons;
     if (!buttons || !buttons.length) {
       buttons = navMap.buttons = this._getNavigableElements(view);
       // Set the 'tabindex' attribute on the buttons to make sure they're focussable.
       for (let button of buttons) {
-        if (button.classList.contains("subviewbutton-back"))
-          continue;
-        // If we've been here before, forget about it!
-        if (button.hasAttribute("tabindex"))
-          break;
-        button.setAttribute("tabindex", 0);
+        if (!button.classList.contains("subviewbutton-back") &&
+            !button.hasAttribute("tabindex")) {
+          button.setAttribute("tabindex", 0);
+        }
       }
     }
     if (!buttons.length)
       return;
 
     let stop = () => {
       event.stopPropagation();
       event.preventDefault();
@@ -1073,24 +1071,31 @@ this.PanelMultiView = class {
           break;
         }
         // If the current button is _not_ one that points to a subview, pressing
         // the arrow key shouldn't do anything.
         if (!navMap.selected || !buttons[navMap.selected].classList.contains("subviewbutton-nav"))
           break;
         // Fall-through...
       }
+      case "Space":
       case "Enter": {
         let button = buttons[navMap.selected];
         if (!button)
           break;
         stop();
-        // Unfortunately, 'tabindex' doesn't not execute the default action, so
+
+        // Unfortunately, 'tabindex' doesn't execute the default action, so
         // we explicitly do this here.
-        button.click();
+        // 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.
+        button.doCommand();
+        let clickEvent = new event.target.ownerGlobal.MouseEvent("click", {"bubbles": true});
+        button.dispatchEvent(clickEvent);
         break;
       }
     }
   }
 
   /**
    * Clear all traces of keyboard navigation happening right now.
    *