diff --git a/components/moz.build b/components/moz.build index 11e89c2744..d2fd1008d5 100644 --- a/components/moz.build +++ b/components/moz.build @@ -26,9 +26,11 @@ DIRS += [ "settings", "shortcuts", "startpage", + "status", "storage", "tabs", "toolbar", + "tooltips", "widgets", ] diff --git a/components/tooltips/TooltipLabelProvider.sys.mjs b/components/tooltips/TooltipLabelProvider.sys.mjs new file mode 100644 index 0000000000..c889c39a4c --- /dev/null +++ b/components/tooltips/TooltipLabelProvider.sys.mjs @@ -0,0 +1,43 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const tooltipL10n = new Localization(["dot/tooltips.ftl"], true); + +export const TooltipLabelProvider = { + /** + * Constructs the tooltip text using the supplied values + * @param {string} label + * @param {object} [options] + * @param {string} [options.sublabel] + * @param {string} [options.shortcut] + */ + getTooltipText(label, options) { + let tooltipText = []; + + if (options && options.shortcut) { + tooltipText.push( + tooltipL10n.formatValueSync("tooltip-shortcut-label", { + label, + shortcut: options.shortcut + }) + ); + } else { + tooltipText.push( + tooltipL10n.formatValueSync("tooltip-label", { + label + }) + ); + } + + if (options && options.sublabel) { + tooltipText.push( + tooltipL10n.formatValueSync("tooltip-label", { + label: options.sublabel + }) + ); + } + + return tooltipText.join("\n"); + } +}; diff --git a/components/widgets/content/browser-button.js b/components/widgets/content/browser-button.js index b6c8244023..0269683448 100644 --- a/components/widgets/content/browser-button.js +++ b/components/widgets/content/browser-button.js @@ -2,6 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +var { TooltipLabelProvider } = ChromeUtils.importESModule( + "resource://gre/modules/TooltipLabelProvider.sys.mjs" +); + class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) { constructor() { super(); @@ -103,8 +107,6 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) { * Updates the label of the browser button */ set label(newLabel) { - if (newLabel == this.label) return; - this.setAttribute("label", newLabel); this.elements.label.textContent = newLabel; @@ -122,8 +124,6 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) { * Updates the auxiliary label of the browser button */ set labelAuxiliary(newLabelAuxiliary) { - if (newLabelAuxiliary == this.labelAuxiliary) return; - this.setAttribute("labelauxiliary", newLabelAuxiliary); this._updateTooltipText(); @@ -229,31 +229,20 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) { * Computes the tooltip text for this button */ getTooltipText() { - let tooltipText = ""; - const label = this.getAttribute("label"); const labelAuxiliary = this.getAttribute("labelauxiliary"); const accelerator = this.getAttribute("accelerator"); - if (labelAuxiliary) { - tooltipText = labelAuxiliary; - } else if (label) { - tooltipText = label; - } - - if (accelerator) { - tooltipText += ` (${accelerator})`; - } - - return tooltipText; + return TooltipLabelProvider.getTooltipText( + labelAuxiliary || label || "", + { shortcut: accelerator } + ); } /** * Updates the button's tooltip text */ _updateTooltipText() { - if (this.elements.tooltip.state == "closed") return; - this.elements.tooltip.label = this.getTooltipText(); } diff --git a/locales/en-US/dot/browser.ftl b/locales/en-US/dot/browser.ftl index 3bef422ce0..6b7e7cd84e 100644 --- a/locales/en-US/dot/browser.ftl +++ b/locales/en-US/dot/browser.ftl @@ -45,5 +45,3 @@ browser-window-restore-button = browser-window-close-button = .title = Close - -browser-keybind-label = { $label } ({ $keybind }) \ No newline at end of file diff --git a/locales/en-US/dot/tooltips.ftl b/locales/en-US/dot/tooltips.ftl new file mode 100644 index 0000000000..614ac2278f --- /dev/null +++ b/locales/en-US/dot/tooltips.ftl @@ -0,0 +1,11 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +tooltip-label = { $label } + +tooltip-shortcut-label = + { PLATFORM() -> + [macos] { $label } { $shortcut } + *[other] { $label } ({ $shortcut }) + } \ No newline at end of file