From 722cae70ba23850203046cccd8f6bace92103712 Mon Sep 17 00:00:00 2001 From: onemen Date: Fri, 29 Nov 2024 09:59:41 +0200 Subject: [PATCH] chore: followup bug 1932600 - Use customtitlebar rather than tabsintitlebar in front-end code --- addon/chrome/content/changecode.js | 13 ++++++------ addon/chrome/content/overlay/browser.css | 5 ----- .../content/overlay/browser_before_119.css | 5 ----- addon/chrome/content/places/places.js | 21 ++++++++++++++++--- addon/chrome/content/tab/tab.js | 21 +++++++++++++------ types/addon.d.ts | 4 ++-- types/extraTabmixUtils.d.ts | 2 +- types/general.d.ts | 18 ++++++++++------ types/override.d.ts | 3 +++ 9 files changed, 58 insertions(+), 34 deletions(-) diff --git a/addon/chrome/content/changecode.js b/addon/chrome/content/changecode.js index e00ef9b7..088abe5a 100644 --- a/addon/chrome/content/changecode.js +++ b/addon/chrome/content/changecode.js @@ -8,6 +8,10 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) { let console = TabmixSvc.console; let debugMode = this._debugMode; + let errMsgContent = + "\n\nTry Tabmix latest development version from https://bitbucket.org/onemen/tabmixplus-for-firefox/downloads/," + + "\nReport about this to Tabmix developer at https://github.com/onemen/TabMixPlus/issues"; + let customTitlebar = TabmixSvc.version(1350) ? "CustomTitlebar._update" : "TabsInTitlebar._update"; /** * @constructor @@ -43,9 +47,6 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) { type: "", _value: "", errMsg: "", - errMsgContent: - "\n\nTry Tabmix latest development version from https://bitbucket.org/onemen/tabmixplus-for-firefox/downloads/," + - "\nReport about this to Tabmix developer at https://github.com/onemen/TabMixPlus/issues", /** @this {ChangeCodeNS.ChangeCodeClass} */ get value() { @@ -96,7 +97,7 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) { // list of function that we don't warp with try-catch let dontDebug = ["gBrowser.tabContainer._animateTabMove, gURLBar.handleCommand"]; if (debugMode && !dontDebug.includes(this.fullName)) { - let excludeReturn = ["TabsInTitlebar._update", "gBrowser._blurTab"]; + let excludeReturn = [customTitlebar, "gBrowser._blurTab"]; let addReturn = "", re = new RegExp("//.*", "g"); if (!excludeReturn.includes(this.fullName) && /return\s.+/.test(this._value.replace(re, ""))) @@ -182,7 +183,7 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) { if (notFoundCount && !this.silent) { let str = (notFoundCount > 1 ? "s" : "") + "\n "; ex.message = ex.fnName + " was unable to change " + aName + "." + - (this.errMsg || "\ncan't find string" + str + this.notFound.join("\n ")) + this.errMsgContent; + (this.errMsg || "\ncan't find string" + str + this.notFound.join("\n ")) + errMsgContent; console.reportError(ex); if (debugMode) { console.clog(ex.fnName + "\nfunction " + aName + " = " + this._value, ex); @@ -209,7 +210,7 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) { const ex = this.getCallerData(Components.stack.caller); for (const methods of privateMethods) { if (typeof aParent[`_${methods}`] === "undefined") { - ex.message = `Implement replacement for private method #${methods} in ${parentName} it is used by ${this.fullName}${this.errMsgContent}`; + ex.message = `Implement replacement for private method #${methods} in ${parentName} it is used by ${this.fullName}${errMsgContent}`; console.reportError(ex); } } diff --git a/addon/chrome/content/overlay/browser.css b/addon/chrome/content/overlay/browser.css index 0a413ee3..737fbb9f 100644 --- a/addon/chrome/content/overlay/browser.css +++ b/addon/chrome/content/overlay/browser.css @@ -309,11 +309,6 @@ so display: none !important; does not hide the button */ /* :::: tabbar on bottom :::: */ -#main-window[tabsintitlebar][tabmix-tabbaronbottom] .tabbrowser-tabbox, -#main-window[tabsintitlebar] #TabsToolbar-customization-target[tabmix-disallow-drag] { - -moz-window-dragging: no-drag; -} - /* we don't need rule for toolbar-drag - when tabbar on bottom */ #TabsToolbar[tabbaronbottom] { display: block; diff --git a/addon/chrome/content/overlay/browser_before_119.css b/addon/chrome/content/overlay/browser_before_119.css index 1c51fc06..5d9f94b9 100644 --- a/addon/chrome/content/overlay/browser_before_119.css +++ b/addon/chrome/content/overlay/browser_before_119.css @@ -303,11 +303,6 @@ so display: none !important; does not hide the button */ /* :::: tabbar on bottom :::: */ -#main-window[tabsintitlebar][tabmix-tabbaronbottom] .tabbrowser-tabbox, -#main-window[tabsintitlebar] #TabsToolbar-customization-target[tabmix-disallow-drag] { - -moz-window-dragging: no-drag; -} - /* we don't need rule for toolbar-drag - when tabbar on bottom */ #TabsToolbar[tabbaronbottom] { display: block; diff --git a/addon/chrome/content/places/places.js b/addon/chrome/content/places/places.js index 0cebd37b..c8fa0df5 100644 --- a/addon/chrome/content/places/places.js +++ b/addon/chrome/content/places/places.js @@ -811,11 +811,26 @@ Tabmix.onContentLoaded = { }, change_miscellaneous() { - if ("_update" in TabsInTitlebar) { + const [customTitlebar, updateTitlebar] = TabmixSvc.version(1350) ? + [window.CustomTitlebar, "CustomTitlebar._update"] : + [window.TabsInTitlebar, "TabsInTitlebar._update"]; + + if ("_update" in customTitlebar) { + if (!TabmixSvc.version(1350)) { + Tabmix.changeCode(TabmixTabbar, "TabmixTabbar.updateTabsInTitlebarAppearance")._replace( + 'window.CustomTitlebar', + 'window.TabsInTitlebar' + ).toCode(); + + Tabmix.changeCode(TabmixTabbar, "TabmixTabbar.getTabsPosition")._replace( + /customtitlebar/g, + 'tabsintitlebar' + ).toCode(); + } // set option to Prevent double click on Tab-bar from changing window size. - Tabmix.changeCode(TabsInTitlebar, "TabsInTitlebar._update")._replace( + Tabmix.changeCode(customTitlebar, updateTitlebar)._replace( /(})(\)?)$/, - // when we get in and out of tabsintitlebar mode call updateScrollStatus + // when we get in and out of customTitlebar mode call updateScrollStatus // force another update when rows number changed by Tabmix to update // titlebar and titlebarContent height ' TabmixTabbar.updateTabsInTitlebarAppearance();\n ' + diff --git a/addon/chrome/content/tab/tab.js b/addon/chrome/content/tab/tab.js index bcaa7d37..f6185c7a 100644 --- a/addon/chrome/content/tab/tab.js +++ b/addon/chrome/content/tab/tab.js @@ -216,12 +216,13 @@ var TabmixTabbar = { updateTabsInTitlebarAppearance() { if (this.isMultiRow && !this._updatingAppearance || this.getTabsPosition() != this._tabsPosition) { + this._tabsPosition = this.getTabsPosition(); const rows = this.visibleRows; gBrowser.tabContainer.arrowScrollbox._singleRowHeight = null; this.updateScrollStatus(); if (!this._updatingAppearance && rows != this.visibleRows) { this._updatingAppearance = true; - TabsInTitlebar._update(); + window.CustomTitlebar._update(); this._updatingAppearance = false; } } @@ -252,7 +253,7 @@ var TabmixTabbar = { _tabsPosition: "tabsonbottom", getTabsPosition: function TMP_getTabsPosition() { const docElement = document.documentElement; - return docElement?.getAttribute("tabsintitlebar") == "true" ? "tabsintitlebar" : "tabsonbottom"; + return docElement?.getAttribute("customtitlebar") == "true" ? "customtitlebar" : "tabsonbottom"; }, get singleRowHeight() { @@ -329,6 +330,7 @@ Tabmix.tabsUtils = { _show_newtabbutton: "aftertabs", checkNewtabButtonVisibility: false, closeButtonsEnabled: false, + customTitlebar: TabmixSvc.version(1350) ? window.CustomTitlebar : window.TabsInTitlebar, initialized: false, get tabBar() { @@ -470,7 +472,7 @@ Tabmix.tabsUtils = { Tabmix.prefs.getBoolPref("tabbar.dblclick_changesize") && !TabmixSvc.isMac && aEvent.target?.localName === "arrowscrollbox") { let displayAppButton = !document.getElementById("titlebar").hidden; - if (TabsInTitlebar.enabled || displayAppButton) { + if (this.customTitlebar.enabled || displayAppButton) { return; } } @@ -525,8 +527,8 @@ Tabmix.tabsUtils = { } if (Tabmix.extensions.verticalTabs) { - // when Vertical Tabs Reloaded installed TabsInTitlebar was not initialized - TabsInTitlebar.init(); + // when Vertical Tabs Reloaded installed CustomTitlebar/TabsInTitlebar was not initialized + this.customTitlebar.init(); } this.updateProtonValues(); @@ -1984,8 +1986,15 @@ window.gTMPprefObserver = { }` ); + const customtitlebar = Tabmix.isVersion(1350) ? "customtitlebar" : "tabsintitlebar"; this.insertRule( - `#main-window[tabsintitlebar] #toolbar-menubar[autohide="true"][inactive="true"]:not([customizing="true"]) + #TabsToolbar { + `#main-window[${customtitlebar}][tabmix-tabbaronbottom] .tabbrowser-tabbox, + #main-window[${customtitlebar}] #TabsToolbar-customization-target[tabmix-disallow-drag] { + -moz-window-dragging: no-drag; + }` + ); + this.insertRule( + `#main-window[${customtitlebar}] #toolbar-menubar[autohide="true"][inactive="true"]:not([customizing="true"]) + #TabsToolbar { --tabmix-multirow-margin: 0px; }` ); diff --git a/types/addon.d.ts b/types/addon.d.ts index 433fac96..a98e6f44 100644 --- a/types/addon.d.ts +++ b/types/addon.d.ts @@ -651,8 +651,8 @@ declare namespace TabmixTabbarNS { function updateTabsInTitlebarAppearance(): void; let _updateScrollStatusTimeout: number | null; function updateScrollStatus(delay?: boolean): void; - const _tabsPosition: "tabsonbottom"; - function getTabsPosition(): "tabsonbottom" | "tabsintitlebar"; + let _tabsPosition: "tabsonbottom" | "customtitlebar"; + function getTabsPosition(): "tabsonbottom" | "customtitlebar"; const singleRowHeight: number; let _waitAfterMaximized: boolean; function _handleResize(): void; diff --git a/types/extraTabmixUtils.d.ts b/types/extraTabmixUtils.d.ts index 7379f049..dd026a04 100644 --- a/types/extraTabmixUtils.d.ts +++ b/types/extraTabmixUtils.d.ts @@ -35,7 +35,6 @@ declare namespace ChangeCodeNS { type: "__lookupSetter__" | "__lookupGetter__" | ""; _value: string; errMsg: string; - errMsgContent: string; notFound: (string | RegExp)[]; get value(): string; @@ -433,6 +432,7 @@ declare namespace TabsUtils { let _show_newtabbutton: string | null; let checkNewtabButtonVisibility: boolean; let closeButtonsEnabled: boolean; + let customTitlebar: CustomTitlebar; let initialized: boolean; const tabBar: MockedGeckoTypes.TabContainer; diff --git a/types/general.d.ts b/types/general.d.ts index 0fadd38b..88201c5e 100644 --- a/types/general.d.ts +++ b/types/general.d.ts @@ -747,6 +747,13 @@ interface CustomizableUI { removeWidgetFromArea: (aWidgetId: string) => void; } +interface CustomTitlebar { + _updatingAppearance: boolean; + _update: () => void; + enabled: boolean; + init: () => void; +} + interface E10SUtils { SERIALIZED_SYSTEMPRINCIPAL: string; DEFAULT_REMOTE_TYPE: string; @@ -949,12 +956,11 @@ declare var SessionStartup: { willRestore: () => boolean; }; declare var TAB_DROP_TYPE: string; -declare var TabsInTitlebar: { - _updatingAppearance: boolean; - _update: () => void; - enabled: boolean; - init: () => void; -}; + +declare var CustomTitlebar: CustomTitlebar; +/** @deprecated - use CustomTitlebar instead from Firefox 135 */ +declare var TabsInTitlebar: CustomTitlebar; + declare var UrlbarUtils: { RESULT_TYPE: { TAB_SWITCH: number; diff --git a/types/override.d.ts b/types/override.d.ts index 1dbc6f14..f3473f6a 100644 --- a/types/override.d.ts +++ b/types/override.d.ts @@ -54,4 +54,7 @@ declare var performance: Performance; interface Window { readonly document: Document; readonly performance: Performance; + CustomTitlebar: CustomTitlebar; + /** @deprecated - use CustomTitlebar instead from Firefox 135 */ + TabsInTitlebar: CustomTitlebar; }