Bug 1957017 - Prevent sidebar from collasing when context menu is open and expand on hover is enabled r=sidebar-reviewers,nsharpley,jsudiaman

Differential Revision: https://phabricator.services.mozilla.com/D247793
This commit is contained in:
Kelly Cochrane
2025-05-09 15:56:50 +00:00
committed by kcochrane@mozilla.com
parent 401e73a3a5
commit f8a2979106
2 changed files with 60 additions and 34 deletions

View File

@@ -2071,6 +2071,28 @@ var SidebarController = {
};
},
async handleEvent(e) {
switch (e.type) {
case "popupshown":
this.mouseEnterTask?.disarm();
/* Temporarily remove MousePosTracker listener when a context menu is open */
MousePosTracker.removeListener(this);
break;
case "popuphidden":
if (this._state.launcherExpanded) {
if (this._animationEnabled && !window.gReduceMotion) {
this._animateSidebarMain();
}
this._state.launcherExpanded = false;
}
await this.waitUntilStable();
MousePosTracker.addListener(this);
break;
default:
break;
}
},
async toggleExpandOnHover(isEnabled, isDragEnded) {
document.documentElement.toggleAttribute(
"sidebar-expand-on-hover",
@@ -2085,11 +2107,15 @@ var SidebarController = {
if (!isDragEnded) {
await this.setLauncherCollapsedWidth();
}
document.addEventListener("popupshown", this);
document.addEventListener("popuphidden", this);
} else {
MousePosTracker.removeListener(this);
if (!this.mouseOverTask?.isFinalized) {
this.mouseOverTask?.finalize();
}
document.removeEventListener("popupshown", this);
document.removeEventListener("popuphidden", this);
}
document.documentElement.toggleAttribute(

View File

@@ -20,7 +20,7 @@ async function mouseOverSidebarToExpand() {
// Disable non-test mouse events
window.windowUtils.disableNonTestMouseEvents(true);
EventUtils.synthesizeMouse(SidebarController.sidebarContainer, 1, 80, {
EventUtils.synthesizeMouse(SidebarController.sidebarContainer, 1, 150, {
type: "mousemove",
});
@@ -167,6 +167,39 @@ add_task(async function test_enable_expand_on_hover() {
);
});
add_task(async function test_expand_on_hover_context_menu() {
await SidebarController.toggleExpandOnHover(true);
await SidebarController.waitUntilStable();
await mouseOverSidebarToExpand();
await SidebarController.waitUntilStable();
await BrowserTestUtils.waitForMutationCondition(
SidebarController.sidebarContainer,
{ attributes: true },
() => SidebarController._state.launcherExpanded,
"The launcher is expanded"
);
const toolbarContextMenu = document.getElementById("toolbar-context-menu");
await openAndWaitForContextMenu(
toolbarContextMenu,
SidebarController.sidebarMain,
() => {
ok(
!document.getElementById("toolbar-context-customize-sidebar").hidden,
"The sidebar context menu is loaded"
);
ok(
SidebarController._state.launcherExpanded,
"The sidebar launcher is still expanded with the context menu open"
);
}
);
toolbarContextMenu.hidePopup();
await mouseOutSidebarToCollapse();
await SidebarController.toggleExpandOnHover(false);
await SidebarController.waitUntilStable();
});
add_task(async function test_expand_on_hover_pinned_tabs() {
await SidebarController.toggleExpandOnHover(true);
await SidebarController.waitUntilStable();
@@ -216,36 +249,3 @@ add_task(async function test_expand_on_hover_pinned_tabs() {
await SidebarController.toggleExpandOnHover(false);
await SidebarController.waitUntilStable();
});
add_task(async function test_expand_on_hover_context_menu() {
await SidebarController.toggleExpandOnHover(true);
await SidebarController.waitUntilStable();
await mouseOverSidebarToExpand();
await SidebarController.waitUntilStable();
await BrowserTestUtils.waitForMutationCondition(
SidebarController.sidebarContainer,
{ attributes: true },
() => SidebarController._state.launcherExpanded,
"The launcher is expanded"
);
const toolbarContextMenu = document.getElementById("toolbar-context-menu");
await openAndWaitForContextMenu(
toolbarContextMenu,
SidebarController.sidebarMain,
() => {
ok(
!document.getElementById("toolbar-context-customize-sidebar").hidden,
"The sidebar context menu is loaded"
);
ok(
SidebarController._state.launcherExpanded,
"The sidebar launcher is still expanded with the context menu open"
);
}
);
toolbarContextMenu.hidePopup();
await mouseOutSidebarToCollapse();
await SidebarController.toggleExpandOnHover(false);
await SidebarController.waitUntilStable();
});