Bug 1663173 - disable commands that don't need to be enabled in customize mode, r=mconley
Differential Revision: https://phabricator.services.mozilla.com/D89289
This commit is contained in:
@@ -34,9 +34,6 @@ var CustomizationHandler = {
|
||||
childNode.setAttribute("disabled", true);
|
||||
}
|
||||
|
||||
let cmd = document.getElementById("cmd_CustomizeToolbars");
|
||||
cmd.setAttribute("disabled", "true");
|
||||
|
||||
UpdateUrlbarSearchSplitterState();
|
||||
|
||||
PlacesToolbarHelper.customizeStart();
|
||||
@@ -51,14 +48,11 @@ var CustomizationHandler = {
|
||||
PlacesToolbarHelper.customizeDone();
|
||||
|
||||
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");
|
||||
|
||||
gBrowser.selectedBrowser.focus();
|
||||
|
||||
|
||||
@@ -198,6 +198,25 @@ CustomizeMode.prototype = {
|
||||
_skipSourceNodeCheck: null,
|
||||
_mainViewContext: null,
|
||||
|
||||
// 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",
|
||||
]),
|
||||
|
||||
get _handler() {
|
||||
return this.window.CustomizationHandler;
|
||||
},
|
||||
@@ -828,6 +847,11 @@ CustomizeMode.prototype = {
|
||||
this.visiblePalette.appendChild(fragment);
|
||||
this._stowedPalette = this.window.gNavToolbox.palette;
|
||||
this.window.gNavToolbox.palette = this.visiblePalette;
|
||||
|
||||
// Now that the palette items are all here, disable all commands.
|
||||
// We do this here rather than directly in `enter` because we
|
||||
// need to do/undo this when we're called from reset(), too.
|
||||
this._updateCommandsDisabledState(true);
|
||||
} catch (ex) {
|
||||
log.error(ex);
|
||||
}
|
||||
@@ -856,6 +880,9 @@ CustomizeMode.prototype = {
|
||||
},
|
||||
|
||||
_depopulatePalette() {
|
||||
// Quick, undo the command disabling before we depopulate completely:
|
||||
this._updateCommandsDisabledState(false);
|
||||
|
||||
this.visiblePalette.hidden = true;
|
||||
let paletteChild = this.visiblePalette.firstElementChild;
|
||||
let nextChild;
|
||||
@@ -880,6 +907,24 @@ CustomizeMode.prototype = {
|
||||
this.window.gNavToolbox.palette = this._stowedPalette;
|
||||
},
|
||||
|
||||
_updateCommandsDisabledState(shouldBeDisabled) {
|
||||
for (let command of this.document.querySelectorAll("command")) {
|
||||
if (!command.id || !this._enabledCommands.has(command.id)) {
|
||||
if (shouldBeDisabled) {
|
||||
if (command.getAttribute("disabled") != "true") {
|
||||
command.setAttribute("disabled", true);
|
||||
} else {
|
||||
command.setAttribute("wasdisabled", true);
|
||||
}
|
||||
} else if (command.getAttribute("wasdisabled") != "true") {
|
||||
command.removeAttribute("disabled");
|
||||
} else {
|
||||
command.removeAttribute("wasdisabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
isCustomizableItem(aNode) {
|
||||
return (
|
||||
aNode.localName == "toolbarbutton" ||
|
||||
|
||||
@@ -144,6 +144,7 @@ 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]
|
||||
|
||||
@@ -40,13 +40,12 @@ add_task(async function() {
|
||||
|
||||
zoomInButton.click();
|
||||
let pageZoomLevel = parseInt(ZoomManager.zoom * 100);
|
||||
console.log("Page oom level is: ", pageZoomLevel);
|
||||
info("Page zoom level is: " + pageZoomLevel);
|
||||
|
||||
let zoomResetButton = document.getElementById("zoom-reset-button");
|
||||
await TestUtils.waitForCondition(() => {
|
||||
console.log(
|
||||
"Current zoom is ",
|
||||
parseInt(zoomResetButton.getAttribute("label"), 10)
|
||||
info(
|
||||
"Current zoom is " + parseInt(zoomResetButton.getAttribute("label"), 10)
|
||||
);
|
||||
return parseInt(zoomResetButton.getAttribute("label"), 10) == pageZoomLevel;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/* 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() {
|
||||
let disabledCommands = ["cmd_print", "Browser:SavePage", "Browser:SendLink"];
|
||||
let enabledCommands = [
|
||||
"cmd_newNavigatorTab",
|
||||
"cmd_newNavigator",
|
||||
"cmd_quitApplication",
|
||||
"cmd_close",
|
||||
"cmd_closeWindow",
|
||||
];
|
||||
|
||||
function checkDisabled() {
|
||||
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 startCustomizing();
|
||||
|
||||
checkDisabled();
|
||||
|
||||
// Do a reset just for fun, making sure we don't accidentally
|
||||
// break things:
|
||||
await gCustomizeMode.reset();
|
||||
|
||||
checkDisabled();
|
||||
|
||||
await endCustomizing();
|
||||
for (let cmd of disabledCommands.concat(enabledCommands)) {
|
||||
ok(
|
||||
!document.getElementById(cmd).hasAttribute("disabled"),
|
||||
`Command ${cmd} should NOT be disabled after customize mode`
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user