tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit c476444271964862cc91284c341a019473e63008
parent 395526c9cd3f973091f61da54b35522bc7619672
Author: Kyler Riggs <100742516+ky-ler@users.noreply.github.com>
Date:   Wed, 22 Oct 2025 14:40:52 +0000

Bug 1995753 - Hide the context menu options "Remove from Toolbar" and "Pin to Overflow Menu" if they are both disabled. r=nsharpley

Differential Revision: https://phabricator.services.mozilla.com/D267156

Diffstat:
Mbrowser/base/content/main-popupset.js | 4+++-
Mbrowser/components/customizableui/ToolbarContextMenu.sys.mjs | 57+++++++++++++++++++++++++++++++++++++++++++++++----------
Mbrowser/components/customizableui/test/browser_customization_context_menus.js | 18++----------------
3 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/browser/base/content/main-popupset.js b/browser/base/content/main-popupset.js @@ -501,8 +501,10 @@ document.addEventListener( ToolbarContextMenu.updateDownloadsAlwaysOpenPanel(event.target); ToolbarContextMenu.updateExtensionsButtonContextMenu(event.target); ToolbarContextMenu.updateExtension(event.target); - // hideLeadingSeparatorIfNeeded must be called last after updating the menu items above, + + // The following methods must be called last after updating the menu items above, // as they may change which items are visible. + ToolbarContextMenu.updateCustomizationItemsVisibility(event.target); ToolbarContextMenu.hideLeadingSeparatorIfNeeded(event.target); break; case "pageActionContextMenu": diff --git a/browser/components/customizableui/ToolbarContextMenu.sys.mjs b/browser/components/customizableui/ToolbarContextMenu.sys.mjs @@ -271,8 +271,10 @@ export var ToolbarContextMenu = { !showSidebarActions || isVerticalTabStripMenu; document.getElementById("customizationMenuSeparator").hidden = toolbarItem?.id == "tabbrowser-tabs" || - ((toolbarItem?.localName == "toolbarspring" || isMenuBarSpacer) && - !CustomizationHandler.isCustomizing()); + (toolbarItem?.localName == "toolbarspring" && + !CustomizationHandler.isCustomizing()) || + isMenuBarSpacer || + isTitlebarSpacer; // View -> Toolbars menu doesn't have the moveToPanel or removeFromToolbar items. if (!moveToPanel || !removeFromToolbar) { @@ -307,13 +309,18 @@ export var ToolbarContextMenu = { document.getElementById("toolbarNavigatorItemsMenuSeparator").hidden = !showTabStripItems; - if ( - !CustomizationHandler.isCustomizing() && - (toolbarItem?.localName.includes("separator") || - toolbarItem?.localName.includes("spring") || - toolbarItem?.localName.includes("spacer") || - toolbarItem?.id.startsWith("customizableui-special")) - ) { + let isSpacerItem = + toolbarItem?.localName.includes("separator") || + toolbarItem?.localName.includes("spring") || + toolbarItem?.localName.includes("spacer") || + toolbarItem?.id.startsWith("customizableui-special"); + + // For spacer items, customization items should only appear + // when the user is actively customizing the toolbar. + let shouldHideCustomizationItems = + isSpacerItem && !CustomizationHandler.isCustomizing(); + + if (shouldHideCustomizationItems) { moveToPanel.hidden = true; removeFromToolbar.hidden = true; menuSeparator.hidden = !showTabStripItems; @@ -354,7 +361,11 @@ export var ToolbarContextMenu = { } else { moveToPanel.removeAttribute("disabled"); } - removeFromToolbar.removeAttribute("disabled"); + if (shouldHideCustomizationItems) { + removeFromToolbar.setAttribute("disabled", true); + } else { + removeFromToolbar.removeAttribute("disabled"); + } } else { removeFromToolbar.setAttribute("disabled", true); moveToPanel.setAttribute("disabled", true); @@ -590,4 +601,30 @@ export var ToolbarContextMenu = { firstVisibleElement.hidden = true; } }, + + /** + * Hides the "Move to Panel" and "Remove from Toolbar" items if both are + * disabled. This prevents showing a menu with no useful items. If at least + * one of the items is enabled, both items are shown for consistency. + * + * This is its own method to allow it to be called after other methods + * that may change the disabled state of either menu item. + * + * @param {Element} popup + * The toolbar-context-menu element for a window. + */ + updateCustomizationItemsVisibility(popup) { + let moveToPanel = popup.querySelector(".customize-context-moveToPanel"); + let removeFromToolbar = popup.querySelector( + ".customize-context-removeFromToolbar" + ); + + if ( + removeFromToolbar?.getAttribute("disabled") && + moveToPanel.getAttribute("disabled") + ) { + removeFromToolbar.hidden = true; + moveToPanel.hidden = true; + } + }, }; diff --git a/browser/components/customizableui/test/browser_customization_context_menus.js b/browser/components/customizableui/test/browser_customization_context_menus.js @@ -149,9 +149,6 @@ add_task(async function titlebar_spacer_context() { let expectedEntries = [ ["#toolbar-context-toggle-vertical-tabs", true], ["---"], - [".customize-context-moveToPanel", false], - [".customize-context-removeFromToolbar", false], - ["---"], ]; if (!isOSX) { expectedEntries.push(["#toggle_toolbar-menubar", true]); @@ -183,11 +180,7 @@ add_task(async function empty_toolbar_context() { }); await shownPromise; - let expectedEntries = [ - [".customize-context-moveToPanel", false], - [".customize-context-removeFromToolbar", false], - ["---"], - ]; + let expectedEntries = []; if (!isOSX) { expectedEntries.push(["#toggle_toolbar-menubar", true]); } @@ -218,11 +211,7 @@ add_task(async function urlbar_context() { }); await shownPromise; - let expectedEntries = [ - [".customize-context-moveToPanel", false], - [".customize-context-removeFromToolbar", false], - ["---"], - ]; + let expectedEntries = []; if (!isOSX) { expectedEntries.push(["#toggle_toolbar-menubar", true]); } @@ -818,9 +807,6 @@ add_task(async function menu_bar_spacer_context_menu_customize_mode() { let expectedEntries = [ ["#toolbar-context-toggle-vertical-tabs", true], ["---"], - [".customize-context-moveToPanel", false], - [".customize-context-removeFromToolbar", false], - ["---"], ["#toggle_toolbar-menubar", true], ["#toggle_PersonalToolbar", true], ["---"],