Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit cc25f22

Browse files
author
DJ
committed
Bug 1912391 - position tab preview appropriately when in vertical mode. r=tabbrowser-reviewers,dao
Differential Revision: https://phabricator.services.mozilla.com/D219326
1 parent a01138b commit cc25f22

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

browser/components/tabbrowser/content/tab-hover-preview.mjs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ var { XPCOMUtils } = ChromeUtils.importESModule(
66
"resource://gre/modules/XPCOMUtils.sys.mjs"
77
);
88

9-
const POPUP_OPTIONS = {
10-
position: "bottomleft topleft",
11-
x: 0,
12-
y: -2,
13-
};
14-
159
const ZERO_DELAY_ACTIVATION_TIME = 300;
1610

1711
/**
@@ -64,14 +58,40 @@ export default class TabHoverPreviewPanel {
6458

6559
this._panelOpener = new TabPreviewPanelTimedFunction(
6660
() => {
67-
this._panel.openPopup(this._tab, POPUP_OPTIONS);
61+
this._panel.openPopup(this._tab, this.#popupOptions);
6862
},
6963
this._prefPreviewDelay,
7064
ZERO_DELAY_ACTIVATION_TIME,
7165
this._win
7266
);
7367
}
7468

69+
get #verticalMode() {
70+
return this._win.gBrowser.tabContainer.verticalMode;
71+
}
72+
73+
get #popupOptions() {
74+
if (!this.#verticalMode) {
75+
return {
76+
position: "bottomleft topleft",
77+
x: 0,
78+
y: -2,
79+
};
80+
}
81+
if (!this._win.SidebarController._positionStart) {
82+
return {
83+
position: "topleft topright",
84+
x: 0,
85+
y: 4,
86+
};
87+
}
88+
return {
89+
position: "topright topleft",
90+
x: 0,
91+
y: 4,
92+
};
93+
}
94+
7595
getPrettyURI(uri) {
7696
try {
7797
let url = new URL(uri);
@@ -231,9 +251,9 @@ export default class TabHoverPreviewPanel {
231251
if (this._tab) {
232252
this._panel.moveToAnchor(
233253
this._tab,
234-
POPUP_OPTIONS.position,
235-
POPUP_OPTIONS.x,
236-
POPUP_OPTIONS.y
254+
this.#popupOptions.position,
255+
this.#popupOptions.x,
256+
this.#popupOptions.y
237257
);
238258
}
239259
}

browser/components/tabbrowser/test/browser/tabs/browser_tab_preview.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,34 @@ add_task(async function tabContentChangeTests() {
759759
await closePreviews();
760760
BrowserTestUtils.removeTab(tab);
761761
});
762+
763+
/**
764+
* In vertical tabs mode, tab preview should be displayed to the side
765+
* and not beneath the tab.
766+
*/
767+
add_task(async function tabPreview_verticalTabsPositioning() {
768+
await SpecialPowers.pushPrefEnv({
769+
set: [
770+
["sidebar.revamp", true],
771+
["sidebar.verticalTabs", true],
772+
],
773+
});
774+
775+
const previewPanel = document.getElementById("tab-preview-panel");
776+
const tab = await BrowserTestUtils.openNewForegroundTab(
777+
gBrowser,
778+
"about:blank"
779+
);
780+
await openPreview(tab);
781+
782+
let tabRect = tab.getBoundingClientRect();
783+
let panelRect = previewPanel.getBoundingClientRect();
784+
785+
Assert.ok(
786+
Math.abs(tabRect.top - panelRect.top) < 5,
787+
"Preview panel not displayed beneath tab"
788+
);
789+
790+
await closePreviews();
791+
BrowserTestUtils.removeTab(tab);
792+
});

0 commit comments

Comments
 (0)