diff --git a/src/browser/base/content/ZenStartup.mjs b/src/browser/base/content/ZenStartup.mjs index d00f5ed05..d0fc2758f 100644 --- a/src/browser/base/content/ZenStartup.mjs +++ b/src/browser/base/content/ZenStartup.mjs @@ -1,6 +1,5 @@ { const lazy = {}; - XPCOMUtils.defineLazyPreferenceGetter(lazy, 'sidebarHeightThrottle', 'zen.view.sidebar-height-throttle', 500); var ZenStartup = { init() { this.logHeader(); @@ -41,51 +40,13 @@ gZenVerticalTabsManager.init(); gZenCompactModeManager.init(); - XPCOMUtils.defineLazyPreferenceGetter( - this, - 'contentElementSeparation', - 'zen.theme.content-element-separation', - 0 - ); - document.l10n.setAttributes(document.getElementById('tabs-newtab-button'), 'tabs-toolbar-new-tab'); - - function throttle(f, delay) { - let timer = 0; - return function (...args) { - clearTimeout(timer); - timer = setTimeout(() => f.apply(this, args), delay); - }; - } - - new ResizeObserver(throttle(this._updateTabsToolbar.bind(this), lazy.sidebarHeightThrottle)).observe( - document.getElementById('tabbrowser-tabs') - ); } catch (e) { console.error('ZenThemeModifier: Error initializing browser layout', e); } this.closeWatermark(); }, - _updateTabsToolbar() { - // Set tabs max-height to the "toolbar-items" height - const toolbarItems = document.getElementById('tabbrowser-tabs'); - const tabs = document.getElementById('tabbrowser-arrowscrollbox'); - tabs.style.maxHeight = '0px'; // reset to 0 - const toolbarRect = toolbarItems.getBoundingClientRect(); - let height = toolbarRect.height; - // -5 for the controls padding - let totalHeight = toolbarRect.height - (this.contentElementSeparation * 2) - 5; - // remove the height from other elements that aren't hidden - const otherElements = document.querySelectorAll('#tabbrowser-tabs > *:not([hidden="true"])'); - for (let tab of otherElements) { - if (tabs === tab) continue; - totalHeight -= tab.getBoundingClientRect().height; - } - tabs.style.maxHeight = totalHeight + 'px'; - //console.info('ZenThemeModifier: set tabs max-height to', totalHeight + 'px'); - }, - openWatermark() { if (!Services.prefs.getBoolPref('zen.watermark.enabled', false)) { return; diff --git a/src/browser/base/content/ZenUIManager.mjs b/src/browser/base/content/ZenUIManager.mjs index 93f2d2abe..235b830a3 100644 --- a/src/browser/base/content/ZenUIManager.mjs +++ b/src/browser/base/content/ZenUIManager.mjs @@ -5,6 +5,45 @@ var gZenUIManager = { init() { document.addEventListener('popupshowing', this.onPopupShowing.bind(this)); document.addEventListener('popuphidden', this.onPopupHidden.bind(this)); + XPCOMUtils.defineLazyPreferenceGetter(this, 'sidebarHeightThrottle', 'zen.view.sidebar-height-throttle', 500); + XPCOMUtils.defineLazyPreferenceGetter( + this, + 'contentElementSeparation', + 'zen.theme.content-element-separation', + 0 + ); + + function throttle(f, delay) { + let timer = 0; + return function (...args) { + clearTimeout(timer); + timer = setTimeout(() => f.apply(this, args), delay); + }; + } + + new ResizeObserver(throttle(this.updateTabsToolbar.bind(this), this.sidebarHeightThrottle)).observe( + document.getElementById('tabbrowser-tabs') + ); + }, + + + updateTabsToolbar() { + // Set tabs max-height to the "toolbar-items" height + const toolbarItems = document.getElementById('tabbrowser-tabs'); + const tabs = document.getElementById('tabbrowser-arrowscrollbox'); + tabs.style.maxHeight = '0px'; // reset to 0 + const toolbarRect = toolbarItems.getBoundingClientRect(); + let height = toolbarRect.height; + // -5 for the controls padding + let totalHeight = toolbarRect.height - (this.contentElementSeparation * 2) - 5; + // remove the height from other elements that aren't hidden + const otherElements = document.querySelectorAll('#tabbrowser-tabs > *:not([hidden="true"])'); + for (let tab of otherElements) { + if (tabs === tab) continue; + totalHeight -= tab.getBoundingClientRect().height; + } + tabs.style.maxHeight = totalHeight + 'px'; + //console.info('ZenThemeModifier: set tabs max-height to', totalHeight + 'px'); }, openAndChangeToTab(url, options) { diff --git a/src/browser/base/zen-components/ZenWorkspaces.mjs b/src/browser/base/zen-components/ZenWorkspaces.mjs index 3c4198a13..7765f4d5d 100644 --- a/src/browser/base/zen-components/ZenWorkspaces.mjs +++ b/src/browser/base/zen-components/ZenWorkspaces.mjs @@ -1160,6 +1160,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { await this._updateWorkspacesChangeContextMenu(); document.getElementById('tabbrowser-tabs')._positionPinnedTabs(); + gZenUIManager.updateTabsToolbar(); await this._propagateWorkspaceData({clearCache: onInit}); for (let listener of this._changeListeners ?? []) {