Bug 1661618, update shortcut in app menu and toolbar tip for the toolbarbutton r=mstriemer
authorEmma Malysz <emalysz@mozilla.com>
Mon, 31 Aug 2020 19:14:11 +0000
changeset 547084 2ac24d2fdaf7e5602bf8d7ef340408d01c34accc
parent 547083 95c978d7706f0da0f12a212f90cbf51cc383603c
child 547085 0f0b1fa85339ba43198835f1ffb821437d432c19
push id125379
push usercbrindusan@mozilla.com
push dateMon, 31 Aug 2020 19:30:09 +0000
treeherderautoland@2ac24d2fdaf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer
bugs1661618
milestone82.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 1661618, update shortcut in app menu and toolbar tip for the toolbarbutton r=mstriemer Differential Revision: https://phabricator.services.mozilla.com/D88521
browser/base/content/browser.js
browser/base/content/browser.xhtml
browser/components/customizableui/content/panelUI.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6627,16 +6627,17 @@ const nodeToTooltipMap = {
   "urlbar-zoom-button": "urlbar-zoom-button.tooltip",
   "appMenu-cut-button": "cut-button.tooltip",
   "appMenu-copy-button": "copy-button.tooltip",
   "appMenu-paste-button": "paste-button.tooltip",
   "appMenu-zoomEnlarge-button": "zoomEnlarge-button.tooltip",
   "appMenu-zoomReset-button": "zoomReset-button.tooltip",
   "appMenu-zoomReduce-button": "zoomReduce-button.tooltip",
   "reader-mode-button": "reader-mode-button.tooltip",
+  "print-button": "printButton.tooltip",
 };
 const nodeToShortcutMap = {
   "bookmarks-menu-button": "manBookmarkKb",
   "context-reload": "key_reload",
   "context-stop": "key_stop",
   "downloads-button": "key_openDownloads",
   "fullscreen-button": "key_fullScreen",
   "appMenu-fullscreen-button": "key_fullScreen",
@@ -6648,23 +6649,19 @@ const nodeToShortcutMap = {
   "urlbar-zoom-button": "key_fullZoomReset",
   "appMenu-cut-button": "key_cut",
   "appMenu-copy-button": "key_copy",
   "appMenu-paste-button": "key_paste",
   "appMenu-zoomEnlarge-button": "key_fullZoomEnlarge",
   "appMenu-zoomReset-button": "key_fullZoomReset",
   "appMenu-zoomReduce-button": "key_fullZoomReduce",
   "reader-mode-button": "key_toggleReaderMode",
+  "print-button": "printKb",
 };
 
-if (AppConstants.platform == "macosx") {
-  nodeToTooltipMap["print-button"] = "printButton.tooltip";
-  nodeToShortcutMap["print-button"] = "printKb";
-}
-
 const gDynamicTooltipCache = new Map();
 function GetDynamicShortcutTooltipText(nodeId) {
   if (!gDynamicTooltipCache.has(nodeId) && nodeId in nodeToTooltipMap) {
     let strId = nodeToTooltipMap[nodeId];
     let args = [];
     if (nodeId in nodeToShortcutMap) {
       let shortcutId = nodeToShortcutMap[nodeId];
       let shortcut = document.getElementById(shortcutId);
@@ -6678,17 +6675,29 @@ function GetDynamicShortcutTooltipText(n
     );
   }
   return gDynamicTooltipCache.get(nodeId);
 }
 
 function UpdateDynamicShortcutTooltipText(aTooltip) {
   let nodeId =
     aTooltip.triggerNode.id || aTooltip.triggerNode.getAttribute("anonid");
-  aTooltip.setAttribute("label", GetDynamicShortcutTooltipText(nodeId));
+  if (
+    nodeId == "print-button" &&
+    !Services.prefs.getBoolPref("print.tab_modal.enabled") &&
+    AppConstants.platform !== "macosx"
+  ) {
+    // If the new print UI pref is turned off, we should display the old title that did not have the shortcut
+    aTooltip.setAttribute(
+      "label",
+      document.getElementById(nodeId).getAttribute("print-button-title")
+    );
+  } else {
+    aTooltip.setAttribute("label", GetDynamicShortcutTooltipText(nodeId));
+  }
 }
 
 /*
  * - [ Dependencies ] ---------------------------------------------------------
  *  utilityOverlay.js:
  *    - gatherTextUnder
  */
 
--- a/browser/base/content/browser.xhtml
+++ b/browser/base/content/browser.xhtml
@@ -909,18 +909,18 @@
                        class="subviewbutton"
                        data-l10n-id="toolbar-button-page-save"
                        key="key_savePage"
                        command="Browser:SavePage"
                        />
         <toolbarbutton id="appMenu-print-button"
                        class="subviewbutton subviewbutton-iconic"
                        label="&printCmd.label;"
+                       key="printKb"
 #ifdef XP_MACOSX
-                       key="printKb"
                        command="cmd_print"
 #else
                        command="cmd_printPreview"
 #endif
                        />
         <toolbarseparator/>
         <toolbarbutton id="appMenu-find-button"
                        class="subviewbutton subviewbutton-iconic"
@@ -2097,21 +2097,21 @@
       </toolbaritem>
     </toolbar>
 
     <html:template id="BrowserToolbarPalette">
 
       <toolbarbutton id="print-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
 #ifdef XP_MACOSX
                      command="cmd_print"
-                     tooltip="dynamic-shortcut-tooltip"
 #else
                      command="cmd_printPreview"
-                     tooltiptext="&printButton.tooltip;"
+                     print-button-title="&printButton.tooltip;"
 #endif
+                     tooltip="dynamic-shortcut-tooltip"
                      label="&printButton.label;"/>
 
 
       <toolbarbutton id="new-window-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
                      label="&newNavigatorCmd.label;"
                      command="cmd_newNavigator"
                      tooltip="dynamic-shortcut-tooltip"
                      ondrop="newWindowButtonObserver.onDrop(event)"
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -1096,17 +1096,37 @@ const PanelUI = {
   },
 
   _getPanelAnchor(candidate) {
     let iconAnchor = candidate.badgeStack || candidate.icon;
     return iconAnchor || candidate;
   },
 
   _addedShortcuts: false,
+  _formatPrintButtonShortcuts() {
+    let printButton = this.mainView.querySelector("#appMenu-print-button");
+    if (
+      !Services.prefs.getBoolPref("print.tab_modal.enabled") &&
+      AppConstants.platform !== "macosx"
+    ) {
+      printButton.removeAttribute("shortcut");
+    } else if (!printButton.hasAttribute("shortcut")) {
+      printButton.setAttribute(
+        "shortcut",
+        ShortcutUtils.prettifyShortcut(
+          document.getElementById(printButton.getAttribute("key"))
+        )
+      );
+    }
+  },
   _ensureShortcutsShown(view = this.mainView) {
+    // The print button shorcut visibility can change depending on the pref value,
+    // so we need to check this each time, even if we've already added shortcuts.
+    this._formatPrintButtonShortcuts();
+
     if (view.hasAttribute("added-shortcuts")) {
       return;
     }
     view.setAttribute("added-shortcuts", "true");
     for (let button of view.querySelectorAll("toolbarbutton[key]")) {
       let keyId = button.getAttribute("key");
       let key = document.getElementById(keyId);
       if (!key) {