Skip to content

Commit

Permalink
chore: followup bug 1932600 - Use customtitlebar rather than tabsinti…
Browse files Browse the repository at this point in the history
…tlebar in front-end code
  • Loading branch information
onemen committed Nov 29, 2024
1 parent 26160f0 commit 722cae7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 34 deletions.
13 changes: 7 additions & 6 deletions addon/chrome/content/changecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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, "")))
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
5 changes: 0 additions & 5 deletions addon/chrome/content/overlay/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions addon/chrome/content/overlay/browser_before_119.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 18 additions & 3 deletions addon/chrome/content/places/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
21 changes: 15 additions & 6 deletions addon/chrome/content/tab/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}`
);
Expand Down
4 changes: 2 additions & 2 deletions types/addon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion types/extraTabmixUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ declare namespace ChangeCodeNS {
type: "__lookupSetter__" | "__lookupGetter__" | "";
_value: string;
errMsg: string;
errMsgContent: string;
notFound: (string | RegExp)[];

get value(): string;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions types/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions types/override.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 722cae7

Please sign in to comment.