Bug 1954056 - Avoid closing the sidebar launcher when just closing the open panel. r=sidebar-reviewers,kcochrane

* Remove some of the overloading of SidebarState.updateVisibility
* Remove the no-longer-used #previousLauncherExpanded property
* SidebarController.hide() just hides the panel (same as legacy/original API)
* Skip the browser_toolbarKeyNav.js test when sidebar.revamp=true, this should have been failing all along.

Differential Revision: https://phabricator.services.mozilla.com/D242240
This commit is contained in:
Sam Foster
2025-03-28 00:27:49 +00:00
parent 0109b4ad3b
commit 829925fc2c
9 changed files with 91 additions and 93 deletions

View File

@@ -595,7 +595,7 @@ var SidebarController = {
// The <tree> component used in history and bookmarks, but it does not
// support live switching the app locale. Reload the entire sidebar to
// invalidate any old text.
this.hide();
this.hide({ dismissPanel: false });
this.showInitially(this.lastOpenedId);
break;
}
@@ -773,7 +773,7 @@ var SidebarController = {
await this.promiseInitialized;
let wasOpen = this.isOpen;
if (wasOpen) {
this.hide();
this.hide({ dismissPanel: false });
}
// Reset sidebars map but preserve any existing extensions
let extensionsArr = [];
@@ -993,7 +993,10 @@ var SidebarController = {
}
if (this.isOpen && commandID == this.currentID) {
this.hide(triggerNode);
// Revamp sidebar: this case is a dismissal of the current sidebar panel. The launcher should stay open
// For legacy sidebar, this is a "sidebar" toggle and the current panel should be remembered
this.hide({ triggerNode, dismissPanel: this.sidebarRevampEnabled });
this.updateToolbarButton();
return Promise.resolve();
}
return this.show(commandID, triggerNode);
@@ -1183,25 +1186,42 @@ var SidebarController = {
* For sidebar.revamp=true only, handle the keyboard or sidebar-button command to toggle the sidebar state
*/
async handleToolbarButtonClick() {
let initialExpandedValue = this._state.launcherExpanded;
if (this.inSingleTabWindow || this.uninitializing) {
return;
}
const initialExpandedValue = this._state.launcherExpanded;
// What toggle means depends on the sidebar.visibility pref.
const expandOnToggle = ["always-show", "expand-on-hover"].includes(
this.sidebarRevampVisibility
);
// when the launcher is toggled open by the user, we disable expand-on-hover interactions.
if (this.sidebarRevampVisibility === "expand-on-hover") {
await this.toggleExpandOnHover(initialExpandedValue);
}
if (this._animationEnabled && !window.gReduceMotion) {
this._animateSidebarMain();
}
const showLauncher = !this._state.launcherVisible;
this._state.updateVisibility(showLauncher, true);
if (showLauncher && this._state.command) {
this._show(this._state.command);
}
if (this.sidebarRevampVisibility === "expand-on-hover") {
await this.toggleExpandOnHover(initialExpandedValue);
if (expandOnToggle) {
// just expand/collapse the launcher
this._state.updateVisibility(true, !initialExpandedValue);
} else {
const shouldShowLauncher = !this._state.launcherVisible;
// show/hide the launcher
this._state.updateVisibility(shouldShowLauncher);
// if we're showing and there was panel open, open it again
if (shouldShowLauncher && this._state.command) {
this._show(this._state.command);
} else if (!shouldShowLauncher) {
// hide the open panel. It will re-open next time as we don't change the command value
this.hide({ dismissPanel: false });
}
}
this.updateToolbarButton();
if (this.lastOpenedId == "viewReviewCheckerSidebar") {
@@ -1561,7 +1581,9 @@ var SidebarController = {
return;
}
if (this.currentID === commandID) {
this.hide();
// If the extension removal is a update, we don't want to forget this panel.
// So, let the sidebarAction extension API code remove the lastOpenedId as needed
this.hide({ dismissPanel: false });
}
document.getElementById(sidebar.menuId)?.remove();
document.getElementById(sidebar.switcherMenuId)?.remove();
@@ -1584,7 +1606,7 @@ var SidebarController = {
if (this.inSingleTabWindow) {
return false;
}
if (this.currentID) {
if (this.currentID && commandID !== this.currentID) {
// If there is currently a panel open, we are about to hide it in order
// to show another one, so record a "hide" event on the current panel.
this._recordPanelToggle(this.currentID, false);
@@ -1726,10 +1748,12 @@ var SidebarController = {
/**
* Hide the sidebar.
*
* @param {DOMNode} [triggerNode] Node, usually a button, that triggered the
* hiding of the sidebar.
* @param {object} options - Parameter object.
* @param {DOMNode} options.triggerNode - Node, usually a button, that triggered the
* hiding of the sidebar.
* @param {boolean} options.dismissPanel -Only close the panel or close the whole sidebar (the default.)
*/
hide(triggerNode) {
hide({ triggerNode, dismissPanel = true } = {}) {
if (!this.isOpen) {
return;
}
@@ -1745,6 +1769,13 @@ var SidebarController = {
this.hideSwitcherPanel();
this._recordPanelToggle(this.currentID, false);
this._state.panelOpen = false;
if (dismissPanel) {
// The user is explicitly closing this panel so we don't want it to
// automatically re-open next time the sidebar is shown
this._state.command = "";
this.lastOpenedId = null;
}
if (this.sidebarRevampEnabled) {
this._box.dispatchEvent(new CustomEvent("sidebar-hide"));
}
@@ -1767,17 +1798,6 @@ var SidebarController = {
if (triggerNode) {
updateToggleControlLabel(triggerNode);
}
let showLauncher = false;
if (
this.sidebarRevampEnabled &&
this.sidebarRevampVisibility !== "hide-sidebar"
) {
showLauncher = true;
}
this._state.updateVisibility(
showLauncher,
false // onUserToggle param means "did the user click the sidebar-button", which is false here
);
this.updateToolbarButton();
},
@@ -1862,8 +1882,11 @@ var SidebarController = {
onWidgetRemoved(aWidgetId) {
if (aWidgetId == "sidebar-button") {
if (this.isOpen) {
this.hide();
}
this._state.loadInitialState({ ...this.SidebarState.defaultProperties });
Services.prefs.setStringPref("sidebar.visibility", "hide-sidebar");
this._state.updateVisibility(false, false, true);
}
},
@@ -2139,7 +2162,15 @@ XPCOMUtils.defineLazyPreferenceGetter(
) {
SidebarController._animateSidebarMain();
}
const forceExpand = isVerticalTabs && newValue === "always-show";
// launcher is always initially expanded with vertical tabs unless we're doing expand-on-hover
let forceExpand = false;
if (
isVerticalTabs &&
["always-show", "hide-sidebar"].includes(newValue)
) {
forceExpand = true;
}
// horizontal tabs and hide-sidebar = visible initially.
// vertical tab and hide-sidebar = not visible initially
@@ -2147,12 +2178,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
if (newValue == "hide-sidebar" && isVerticalTabs) {
showLauncher = false;
}
SidebarController._state.updateVisibility(
showLauncher,
false,
false,
forceExpand
);
SidebarController._state.updateVisibility(showLauncher, forceExpand);
}
SidebarController.updateToolbarButton();
}