Skip to content

Commit 5961462

Browse files
Merge pull request #5842 from Raiden0456/glance-buttons-overflow
Fix: fixed overflowing glance buttons when sidebar is opened
2 parents 75a75d7 + af0eeb7 commit 5961462

File tree

3 files changed

+78
-41
lines changed

3 files changed

+78
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<vbox id="zen-glance-sidebar-container" hidden="true">
2-
<toolbarbutton id="zen-glance-sidebar-close" data-l10n-id="zen-general-confirm" class="toolbarbutton-1" oncommand="gZenGlanceManager.closeGlance({ onTabClose: true })"/>
3-
<toolbarbutton id="zen-glance-sidebar-open" class="toolbarbutton-1" oncommand="gZenGlanceManager.fullyOpenGlance()"/>
1+
<vbox id="glance-wrapper">
2+
<vbox id="zen-glance-sidebar-container" hidden="true">
3+
<toolbarbutton id="zen-glance-sidebar-close" data-l10n-id="zen-general-confrim" class="toolbarbutton-1" oncommand="gZenGlanceManager.closeGlance({ onTabClose: true })"/>
4+
<toolbarbutton id="zen-glance-sidebar-open" class="toolbarbutton-1" oncommand="gZenGlanceManager.fullyOpenGlance()"/>
5+
</vbox>
46
</vbox>

src/browser/base/content/zen-styles/zen-glance.css

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
visibility: inherit;
1010
}
1111

12+
#glance-wrapper {
13+
position: relative;
14+
overflow: visible;
15+
left: 2%;
16+
}
17+
1218
#zen-glance-sidebar-container {
1319
position: absolute;
1420
display: flex;
@@ -23,7 +29,6 @@
2329

2430
padding: 5px;
2531
gap: 12px;
26-
left: 2%;
2732

2833
& toolbarbutton {
2934
width: 32px;
@@ -88,6 +93,10 @@
8893
}
8994
}
9095

96+
#zen-glance-sidebar-container[hidden='true'] {
97+
display: none;
98+
}
99+
91100
.browserSidebarContainer.zen-glance-overlay {
92101
box-shadow: none !important;
93102

src/browser/base/zen-components/ZenGlanceManager.mjs

+63-37
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,30 @@
1212
window.addEventListener('TabClose', this.onTabClose.bind(this));
1313
window.addEventListener('TabSelect', this.onLocationChange.bind(this));
1414

15+
ChromeUtils.defineLazyGetter(this, 'sidebarButtons', () => document.getElementById('zen-glance-sidebar-container'));
16+
document.getElementById('tabbrowser-tabpanels').addEventListener('click', this.onOverlayClick.bind(this));
17+
Services.obs.addObserver(this, 'quit-application-requested');
18+
1519
XPCOMUtils.defineLazyPreferenceGetter(
1620
this._lazyPref,
1721
'SHOULD_OPEN_EXTERNAL_TABS_IN_GLANCE',
1822
'zen.glance.open-essential-external-links',
1923
false
2024
);
21-
22-
ChromeUtils.defineLazyGetter(this, 'sidebarButtons', () => document.getElementById('zen-glance-sidebar-container'));
23-
24-
document.getElementById('tabbrowser-tabpanels').addEventListener('click', this.onOverlayClick.bind(this));
25-
26-
Services.obs.addObserver(this, 'quit-application-requested');
2725
}
2826

2927
get #currentBrowser() {
3028
return this.#glances.get(this.#currentGlanceID)?.browser;
3129
}
32-
3330
get #currentTab() {
3431
return this.#glances.get(this.#currentGlanceID)?.tab;
3532
}
36-
3733
get #currentParentTab() {
3834
return this.#glances.get(this.#currentGlanceID)?.parentTab;
3935
}
4036

4137
onOverlayClick(event) {
38+
// If user clicks outside content area, close glance
4239
if (event.target === this.overlay && event.originalTarget !== this.contentWrapper) {
4340
this.closeGlance({ onTabClose: true });
4441
}
@@ -53,16 +50,18 @@
5350
}
5451

5552
onUnload() {
56-
// clear everything
53+
// Clean up all open Glances
5754
for (let [id, glance] of this.#glances) {
5855
gBrowser.removeTab(glance.tab, { animate: false });
5956
}
6057
}
6158

59+
// Figure out where to insert new tabs
6260
getTabPosition(tab) {
6361
return Math.max(gBrowser.pinnedTabCount, tab._tPos);
6462
}
6563

64+
// Create a new tab for Glance
6665
createBrowserElement(url, currentTab, existingTab = null) {
6766
const newTabOptions = {
6867
userContextId: currentTab.getAttribute('usercontextid') || '',
@@ -72,15 +71,21 @@
7271
index: this.getTabPosition(currentTab) + 1,
7372
};
7473
currentTab._selected = true;
74+
7575
const newUUID = gZenUIManager.generateUuidv4();
7676
const newTab = existingTab ?? gBrowser.addTrustedTab(Services.io.newURI(url).spec, newTabOptions);
77+
78+
// Example: copy any context ID
7779
if (currentTab.hasAttribute('zenDefaultUserContextId')) {
7880
newTab.setAttribute('zenDefaultUserContextId', true);
7981
}
82+
83+
// Insert the new tab as a child of the existing tab's content
8084
currentTab.querySelector('.tab-content').appendChild(newTab);
8185
newTab.setAttribute('zen-glance-tab', true);
8286
newTab.setAttribute('glance-id', newUUID);
8387
currentTab.setAttribute('glance-id', newUUID);
88+
8489
this.#glances.set(newUUID, {
8590
tab: newTab,
8691
parentTab: currentTab,
@@ -92,12 +97,14 @@
9297
}
9398

9499
fillOverlay(browser) {
100+
// Save references to the parent containers
95101
this.overlay = browser.closest('.browserSidebarContainer');
96102
this.browserWrapper = browser.closest('.browserContainer');
97103
this.contentWrapper = browser.closest('.browserStack');
98104
}
99105

100106
showSidebarButtons(animate = false) {
107+
// Animate in if hidden
101108
if (this.sidebarButtons.hasAttribute('hidden') && animate) {
102109
gZenUIManager.motion.animate(
103110
this.sidebarButtons.querySelectorAll('toolbarbutton'),
@@ -113,40 +120,57 @@
113120
}
114121

115122
openGlance(data, existingTab = null, ownerTab = null) {
123+
// If a glance is already open, do nothing
116124
if (this.#currentBrowser) {
117125
return;
118126
}
127+
128+
// If the current parent tab is selected, switch to the glance tab
119129
if (gBrowser.selectedTab === this.#currentParentTab) {
120130
gBrowser.selectedTab = this.#currentTab;
121131
return;
122132
}
133+
123134
this.animatingOpen = true;
124135
this._animating = true;
125136

137+
// Gather initial positions
126138
const initialX = data.x;
127139
const initialY = data.y;
128140
const initialWidth = data.width;
129141
const initialHeight = data.height;
130142

143+
// Clean up any leftover states
131144
this.browserWrapper?.removeAttribute('animate');
132145
this.browserWrapper?.removeAttribute('animate-end');
133146
this.browserWrapper?.removeAttribute('animate-full');
134147
this.browserWrapper?.removeAttribute('has-finished-animation');
135148
this.overlay?.removeAttribute('post-fade-out');
136149

150+
// Create the new tab
137151
const currentTab = ownerTab ?? gBrowser.selectedTab;
138-
139152
const browserElement = this.createBrowserElement(data.url, currentTab, existingTab);
140153

154+
// Fill references
141155
this.fillOverlay(browserElement);
142156

157+
const container = document.getElementById('glance-wrapper');
158+
if (container) {
159+
container.appendChild(this.sidebarButtons);
160+
}
161+
162+
// Start overlay
143163
this.overlay.classList.add('zen-glance-overlay');
144164

165+
// Animate open
145166
this.browserWrapper.removeAttribute('animate-end');
146167
window.requestAnimationFrame(() => {
168+
// "Quick open" logic
147169
this.quickOpenGlance({ dontOpenButtons: true });
170+
// Show the sidebar buttons
148171
this.showSidebarButtons(true);
149172

173+
// Animate the parent container
150174
gZenUIManager.motion.animate(
151175
this.#currentParentTab.linkedBrowser.closest('.browserSidebarContainer'),
152176
{
@@ -160,24 +184,32 @@
160184
bounce: 0.2,
161185
}
162186
);
187+
188+
// Start the transition
163189
this.#currentBrowser.setAttribute('animate-glance-open', true);
164190
this.overlay.removeAttribute('fade-out');
165191
this.browserWrapper.setAttribute('animate', true);
192+
166193
const top = initialY + initialHeight / 2;
167194
const left = initialX + initialWidth / 2;
168195
this.browserWrapper.style.top = `${top}px`;
169196
this.browserWrapper.style.left = `${left}px`;
170197
this.browserWrapper.style.width = `${initialWidth}px`;
171198
this.browserWrapper.style.height = `${initialHeight}px`;
172199
this.browserWrapper.style.opacity = 0.8;
200+
201+
// Save original position for closing animation
173202
this.#glances.get(this.#currentGlanceID).originalPosition = {
174203
top: this.browserWrapper.style.top,
175204
left: this.browserWrapper.style.left,
176205
width: this.browserWrapper.style.width,
177206
height: this.browserWrapper.style.height,
178207
};
208+
179209
this.browserWrapper.style.transform = 'translate(-50%, -50%)';
180210
this.overlay.style.overflow = 'visible';
211+
212+
// Animate up to final size
181213
gZenUIManager.motion
182214
.animate(
183215
this.browserWrapper,
@@ -236,24 +268,27 @@
236268
this.closingGlance = true;
237269
this._animating = true;
238270

271+
// Insert tab at correct index
239272
gBrowser._insertTabAtIndex(this.#currentTab, {
240273
index: this.getTabPosition(this.#currentParentTab),
241274
});
242275

243276
let quikcCloseZen = false;
244277
if (onTabClose) {
245-
// Create new tab if no more ex
278+
// If there's only one tab left, open a new one
246279
if (gBrowser.tabs.length === 1) {
247280
BrowserCommands.openTab();
248281
return;
249282
}
250283
}
251284

252-
// do NOT touch here, I don't know what it does, but it works...
285+
// do NOT touch here, unknown but functional
253286
this.#currentTab.style.display = 'none';
254287
this.overlay.setAttribute('fade-out', true);
255288
this.overlay.style.pointerEvents = 'none';
256289
this.quickCloseGlance({ justAnimateParent: true, clearID: false });
290+
291+
// Animate the parent container
257292
const originalPosition = this.#glances.get(this.#currentGlanceID).originalPosition;
258293
gZenUIManager.motion
259294
.animate(
@@ -289,9 +324,11 @@
289324
return;
290325
}
291326

327+
// Final close
292328
if (!onTabClose || quikcCloseZen) {
293329
this.quickCloseGlance({ clearID: false });
294330
}
331+
295332
this.overlay.removeAttribute('fade-out');
296333
this.browserWrapper.removeAttribute('animate');
297334

@@ -330,6 +367,7 @@
330367
this._animating = false;
331368
this.closingGlance = false;
332369

370+
// If we had another Glance queued, open it
333371
if (this.#currentGlanceID) {
334372
this.quickOpenGlance();
335373
}
@@ -349,6 +387,7 @@
349387
parentBrowserContainer.classList.add('zen-glance-background');
350388
parentBrowserContainer.classList.remove('zen-glance-overlay');
351389
parentBrowserContainer.classList.add('deck-selected');
390+
352391
this.#currentParentTab.linkedBrowser.zenModeActive = true;
353392
this.#currentParentTab.linkedBrowser.docShellIsActive = true;
354393
this.#currentBrowser.zenModeActive = true;
@@ -454,21 +493,16 @@
454493
return false;
455494
}
456495
this.closeGlance({ onTabClose: true, setNewID: isDifferent ? oldGlanceID : null, isDifferent });
457-
// only keep continueing tab close if we are not on the currently selected tab
458496
return !isDifferent;
459497
}
460498
return false;
461499
}
462500

463501
tabDomainsDiffer(tab1, url2) {
464502
try {
465-
if (!tab1) {
466-
return true;
467-
}
503+
if (!tab1) return true;
468504
let url1 = tab1.linkedBrowser.currentURI.spec;
469-
if (url1.startsWith('about:')) {
470-
return true;
471-
}
505+
if (url1.startsWith('about:')) return true;
472506
return Services.io.newURI(url1).host !== url2.host;
473507
} catch (e) {
474508
return true;
@@ -489,9 +523,7 @@
489523

490524
onTabOpen(browser, uri) {
491525
let tab = gBrowser.getTabForBrowser(browser);
492-
if (!tab) {
493-
return;
494-
}
526+
if (!tab) return;
495527
try {
496528
if (this.shouldOpenTabInGlance(tab, uri)) {
497529
const browserRect = gBrowser.tabbox.getBoundingClientRect();
@@ -529,9 +561,11 @@
529561
this.#currentTab.removeAttribute('glance-id');
530562
this.#currentParentTab.removeAttribute('glance-id');
531563
gBrowser.selectedTab = this.#currentTab;
564+
532565
this.#currentParentTab.linkedBrowser.closest('.browserSidebarContainer').classList.remove('zen-glance-background');
533566
this.#currentParentTab._visuallySelected = false;
534567
this.hideSidebarButtons();
568+
535569
if (gReduceMotion) {
536570
this.finishOpeningGlance();
537571
return;
@@ -552,18 +586,11 @@
552586

553587
openGlanceForBookmark(event) {
554588
const activationMethod = Services.prefs.getStringPref('zen.glance.activation-method', 'ctrl');
555-
556-
if (activationMethod === 'ctrl' && !event.ctrlKey) {
557-
return;
558-
} else if (activationMethod === 'alt' && !event.altKey) {
559-
return;
560-
} else if (activationMethod === 'shift' && !event.shiftKey) {
561-
return;
562-
} else if (activationMethod === 'meta' && !event.metaKey) {
563-
return;
564-
} else if (activationMethod === 'mantain' || typeof activationMethod === 'undefined') {
565-
return;
566-
}
589+
if (activationMethod === 'ctrl' && !event.ctrlKey) return;
590+
if (activationMethod === 'alt' && !event.altKey) return;
591+
if (activationMethod === 'shift' && !event.shiftKey) return;
592+
if (activationMethod === 'meta' && !event.metaKey) return;
593+
if (activationMethod === 'mantain' || typeof activationMethod === 'undefined') return;
567594

568595
event.preventDefault();
569596
event.stopPropagation();
@@ -576,9 +603,7 @@
576603
width: rect.width,
577604
height: rect.height,
578605
};
579-
580606
this.openGlance(data);
581-
582607
return false;
583608
}
584609

@@ -587,8 +612,10 @@
587612
}
588613
}
589614

615+
// Expose globally
590616
window.gZenGlanceManager = new ZenGlanceManager();
591617

618+
// Register window actors if needed
592619
function registerWindowActors() {
593620
if (Services.prefs.getBoolPref('zen.glance.enabled', true)) {
594621
gZenActorsManager.addJSWindowActor('ZenGlance', {
@@ -609,6 +636,5 @@
609636
});
610637
}
611638
}
612-
613639
registerWindowActors();
614640
}

0 commit comments

Comments
 (0)