Bug 1297738 - Removing accesskey from container menus that are not accessible via a keyboard draft
authorJonathan Kingston <jkt@mozilla.com>
Thu, 24 Nov 2016 15:05:06 +0000
changeset 444738 3123df3414607b2a183c5f6a96a7fa0ca4da46e5
parent 444478 05328d3102efd4d5fc0696489734d7771d24459f
child 538371 4616ac9eedb6703491bf1f5e95d60b9f7573e051
push id37345
push userjkingston@mozilla.com
push dateMon, 28 Nov 2016 18:34:43 +0000
bugs1297738
milestone53.0a1
Bug 1297738 - Removing accesskey from container menus that are not accessible via a keyboard MozReview-Commit-ID: KKBw4k61H9N
browser/base/content/nsContextMenu.js
browser/base/content/tabbrowser.xml
browser/base/content/utilityOverlay.js
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1845,12 +1845,15 @@ nsContextMenu.prototype = {
   _checkTelemetryForMenu: function(aXulMenu) {
     this._telemetryClickID = null;
     this._telemetryPageContext = this._getTelemetryPageContextInfo();
     this._telemetryHadCustomItems = this.hasPageMenu;
     this._getTelemetryClickInfo(aXulMenu);
   },
 
   createContainerMenu: function(aEvent) {
-    return createUserContextMenu(aEvent, true,
-                                 gContextMenuContentData.userContextId);
+    let createMenuOptions = {
+      isContextMenu: true,
+      excludeUserContextId: gContextMenuContentData.userContextId,
+    };
+    return createUserContextMenu(aEvent, createMenuOptions);
   },
 };
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -7137,25 +7137,25 @@
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
       <handler event="popupshowing">
       <![CDATA[
         if (event.target.getAttribute("id") == "alltabs_containersMenuTab") {
-          createUserContextMenu(event);
+          createUserContextMenu(event, {useAccessKeys: false});
           return;
         }
 
         let containersEnabled = Services.prefs.getBoolPref("privacy.userContext.enabled");
 
         if (event.target.getAttribute("anonid") == "newtab-popup" ||
             event.target.id == "newtab-popup") {
-          createUserContextMenu(event);
+          createUserContextMenu(event, {useAccessKeys: false});
         } else {
           document.getElementById("alltabs-popup-separator-1").hidden = !containersEnabled;
           let containersTab = document.getElementById("alltabs_containersTab");
 
           containersTab.hidden = !containersEnabled;
           if (PrivateBrowsingUtils.isWindowPrivate(window)) {
             containersTab.setAttribute("disabled", "true");
           }
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -444,17 +444,21 @@ function checkForMiddleClick(node, event
     // If the middle-click was on part of a menu, close the menu.
     // (Menus close automatically with left-click but not with middle-click.)
     closeMenus(event.target);
   }
 }
 
 // Populate a menu with user-context menu items. This method should be called
 // by onpopupshowing passing the event as first argument.
-function createUserContextMenu(event, isContextMenu = false, excludeUserContextId = 0) {
+function createUserContextMenu(event, {
+                                        isContextMenu = false,
+                                        excludeUserContextId = 0,
+                                        useAccessKeys = true
+                                      } = {}) {
   while (event.target.hasChildNodes()) {
     event.target.removeChild(event.target.firstChild);
   }
 
   let bundle = document.getElementById("bundle_browser");
   let docfrag = document.createDocumentFragment();
 
   // If we are excluding a userContextId, we want to add a 'no-container' item.
@@ -478,17 +482,17 @@ function createUserContextMenu(event, is
     if (identity.userContextId == excludeUserContextId) {
       return;
     }
 
     let menuitem = document.createElement("menuitem");
     menuitem.setAttribute("data-usercontextid", identity.userContextId);
     menuitem.setAttribute("label", ContextualIdentityService.getUserContextLabel(identity.userContextId));
 
-    if (identity.accessKey) {
+    if (identity.accessKey && useAccessKeys) {
       menuitem.setAttribute("accesskey", bundle.getString(identity.accessKey));
     }
 
     menuitem.classList.add("menuitem-iconic");
     menuitem.setAttribute("data-identity-color", identity.color);
 
     if (!isContextMenu) {
       menuitem.setAttribute("command", "Browser:NewUserContextTab");
@@ -500,18 +504,20 @@ function createUserContextMenu(event, is
   });
 
   if (!isContextMenu) {
     docfrag.appendChild(document.createElement("menuseparator"));
 
     let menuitem = document.createElement("menuitem");
     menuitem.setAttribute("label",
                           bundle.getString("userContext.aboutPage.label"));
-    menuitem.setAttribute("accesskey",
-                          bundle.getString("userContext.aboutPage.accesskey"));
+    if (useAccessKeys) {
+      menuitem.setAttribute("accesskey",
+                            bundle.getString("userContext.aboutPage.accesskey"));
+    }
     menuitem.setAttribute("command", "Browser:OpenAboutContainers");
     docfrag.appendChild(menuitem);
   }
 
   event.target.appendChild(docfrag);
   return true;
 }