Bug 1663173 - disable commands that don't need to be enabled in customize mode, r=mconley
☠☠ backed out by 3a2d17ccc986 ☠ ☠
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 09 Sep 2020 20:02:22 +0000
changeset 548051 ffe1c9f9f9df79a486eb0c074c805e72fece9be8
parent 548050 097432c2242d05f6294d6f433a8ab6839a94f9c2
child 548052 4cb5453e4c947f6ec609b7f99b1943c4032cb173
push id125956
push usergijskruitbosch@gmail.com
push dateWed, 09 Sep 2020 20:21:38 +0000
treeherderautoland@ffe1c9f9f9df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1663173
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 1663173 - disable commands that don't need to be enabled in customize mode, r=mconley Differential Revision: https://phabricator.services.mozilla.com/D89289
browser/base/content/browser-customization.js
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_disable_commands_customize.js
--- a/browser/base/content/browser-customization.js
+++ b/browser/base/content/browser-customization.js
@@ -7,16 +7,35 @@
 /* eslint-env mozilla/browser-window */
 
 /**
  * Customization handler prepares this browser window for entering and exiting
  * customization mode by handling customizationstarting and aftercustomization
  * events.
  */
 var CustomizationHandler = {
+  // These are the commands we continue to leave enabled while in customize mode.
+  // All other commands are disabled, and we remove the disabled attribute when
+  // leaving customize mode.
+  enabledCommands: new Set([
+    "cmd_newNavigator",
+    "cmd_newNavigatorTab",
+    "cmd_newNavigatorTabNoEvent",
+    "cmd_close",
+    "cmd_closeWindow",
+    "cmd_quitApplication",
+    "View:FullScreen",
+    "Browser:NextTab",
+    "Browser:PrevTab",
+    "Browser:NewUserContextTab",
+    "Tools:PrivateBrowsing",
+    "minimizeWindow",
+    "zoomWindow",
+  ]),
+
   handleEvent(aEvent) {
     switch (aEvent.type) {
       case "customizationstarting":
         this._customizationStarting();
         break;
       case "aftercustomization":
         this._afterCustomization();
         break;
@@ -29,34 +48,53 @@ var CustomizationHandler = {
 
   _customizationStarting() {
     // Disable the toolbar context menu items
     let menubar = document.getElementById("main-menubar");
     for (let childNode of menubar.children) {
       childNode.setAttribute("disabled", true);
     }
 
+    for (let command of document.querySelectorAll("command")) {
+      if (!command.id || !this.enabledCommands.has(command.id)) {
+        if (command.getAttribute("disabled") != "true") {
+          command.setAttribute("disabled", true);
+        } else {
+          command.setAttribute("wasdisabled", true);
+        }
+      }
+    }
+
     let cmd = document.getElementById("cmd_CustomizeToolbars");
     cmd.setAttribute("disabled", "true");
 
     UpdateUrlbarSearchSplitterState();
 
     PlacesToolbarHelper.customizeStart();
   },
 
   _afterCustomization() {
     // Update global UI elements that may have been added or removed
     if (AppConstants.platform != "macosx") {
       updateEditUIVisibility();
     }
 
     PlacesToolbarHelper.customizeDone();
 
+    for (let command of document.querySelectorAll("command")) {
+      if (!command.id || !this.enabledCommands.has(command.id)) {
+        if (command.getAttribute("wasdisabled") != "true") {
+          command.removeAttribute("disabled");
+        } else {
+          command.removeAttribute("wasdisabled");
+        }
+      }
+    }
+
     XULBrowserWindow.asyncUpdateUI();
-
     // Re-enable parts of the UI we disabled during the dialog
     let menubar = document.getElementById("main-menubar");
     for (let childNode of menubar.children) {
       childNode.setAttribute("disabled", false);
     }
     let cmd = document.getElementById("cmd_CustomizeToolbars");
     cmd.removeAttribute("disabled");
 
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -139,16 +139,17 @@ skip-if = verify
 [browser_character_encoding_ctrl_click.js]
 [browser_ctrl_click_panel_opening.js]
 [browser_currentset_post_reset.js]
 [browser_customizemode_contextmenu_menubuttonstate.js]
 skip-if = os == "win" && bits == 64 # 1526429
 [browser_customizemode_dragspace.js]
 skip-if = os == "linux" # linux doesn't get drag space (no tabsintitlebar)
 [browser_customizemode_uidensity.js]
+[browser_disable_commands_customize.js]
 [browser_drag_outside_palette.js]
 [browser_exit_background_customize_mode.js]
 [browser_flexible_space_area.js]
 [browser_insert_before_moved_node.js]
 [browser_library_after_appMenu.js]
 [browser_overflow_use_subviews.js]
 skip-if = verify
 [browser_panel_keyboard_navigation.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_disable_commands_customize.js
@@ -0,0 +1,42 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Most commands don't make sense in customize mode. Check that they're
+ * disabled, so shortcuts can't activate them either. Also check that
+ * some basic commands (close tab/window, quit, new tab, new window)
+ * remain functional.
+ */
+add_task(async function test_disable_commands() {
+  await startCustomizing();
+  let disabledCommands = ["cmd_print", "Browser:SavePage", "Browser:SendLink"];
+  let enabledCommands = [
+    "cmd_newNavigatorTab",
+    "cmd_newNavigator",
+    "cmd_quitApplication",
+    "cmd_close",
+    "cmd_closeWindow",
+  ];
+  for (let cmd of disabledCommands) {
+    is(
+      document.getElementById(cmd).getAttribute("disabled"),
+      "true",
+      `Command ${cmd} should be disabled`
+    );
+  }
+  for (let cmd of enabledCommands) {
+    ok(
+      !document.getElementById(cmd).hasAttribute("disabled"),
+      `Command ${cmd} should NOT be disabled`
+    );
+  }
+  await endCustomizing();
+  for (let cmd of disabledCommands.concat(enabledCommands)) {
+    ok(
+      !document.getElementById(cmd).hasAttribute("disabled"),
+      `Command ${cmd} should NOT be disabled after customize mode`
+    );
+  }
+});