2015-12-01 22:05:45 +00:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2021-04-11 11:42:57 +00:00
|
|
|
var TabsInTitlebar = {
|
|
|
|
init() {
|
|
|
|
this._readPref();
|
|
|
|
Services.prefs.addObserver(this._prefName, this);
|
|
|
|
|
|
|
|
this._initialized = true;
|
|
|
|
this._update();
|
|
|
|
},
|
|
|
|
|
|
|
|
allowedBy(condition, allow) {
|
|
|
|
if (allow) {
|
|
|
|
if (condition in this._disallowed) {
|
|
|
|
delete this._disallowed[condition];
|
2018-11-08 18:41:04 +00:00
|
|
|
this._update();
|
2015-12-01 22:05:45 +00:00
|
|
|
}
|
2021-04-11 11:42:57 +00:00
|
|
|
} else if (!(condition in this._disallowed)) {
|
|
|
|
this._disallowed[condition] = null;
|
|
|
|
this._update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get systemSupported() {
|
|
|
|
let isSupported = false;
|
|
|
|
switch (AppConstants.MOZ_WIDGET_TOOLKIT) {
|
|
|
|
case "windows":
|
|
|
|
case "cocoa":
|
|
|
|
isSupported = true;
|
|
|
|
break;
|
|
|
|
case "gtk":
|
|
|
|
isSupported = window.matchMedia("(-moz-gtk-csd-available)").matches;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete this.systemSupported;
|
|
|
|
return (this.systemSupported = isSupported);
|
|
|
|
},
|
|
|
|
|
|
|
|
get enabled() {
|
|
|
|
return document.documentElement.getAttribute("tabsintitlebar") == "true";
|
|
|
|
},
|
|
|
|
|
|
|
|
observe(subject, topic, data) {
|
|
|
|
if (topic == "nsPref:changed") {
|
|
|
|
this._readPref();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_initialized: false,
|
|
|
|
_disallowed: {},
|
|
|
|
_prefName: "browser.tabs.drawInTitlebar",
|
|
|
|
|
|
|
|
_readPref() {
|
|
|
|
let hiddenTitlebar = Services.prefs.getBoolPref(
|
|
|
|
"browser.tabs.drawInTitlebar",
|
|
|
|
window.matchMedia("(-moz-gtk-csd-hide-titlebar-by-default)").matches
|
|
|
|
);
|
|
|
|
this.allowedBy("pref", hiddenTitlebar);
|
|
|
|
},
|
|
|
|
|
|
|
|
_update() {
|
|
|
|
if (!this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let allowed =
|
|
|
|
this.systemSupported &&
|
|
|
|
!window.fullScreen &&
|
|
|
|
!Object.keys(this._disallowed).length;
|
|
|
|
if (allowed) {
|
|
|
|
document.documentElement.setAttribute("tabsintitlebar", "true");
|
|
|
|
if (AppConstants.platform == "macosx") {
|
|
|
|
document.documentElement.setAttribute("chromemargin", "0,-1,-1,-1");
|
|
|
|
document.documentElement.removeAttribute("drawtitle");
|
2021-04-10 07:50:31 +00:00
|
|
|
} else {
|
2021-04-11 11:42:57 +00:00
|
|
|
document.documentElement.setAttribute("chromemargin", "0,2,2,2");
|
2021-04-10 06:10:15 +00:00
|
|
|
}
|
2021-04-11 11:42:57 +00:00
|
|
|
} else {
|
|
|
|
document.documentElement.removeAttribute("tabsintitlebar");
|
|
|
|
document.documentElement.removeAttribute("chromemargin");
|
|
|
|
if (AppConstants.platform == "macosx") {
|
|
|
|
document.documentElement.setAttribute("drawtitle", "true");
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 07:48:57 +00:00
|
|
|
|
2021-04-11 11:42:57 +00:00
|
|
|
ToolbarIconColor.inferFromText("tabsintitlebar", allowed);
|
|
|
|
},
|
2021-04-10 07:50:31 +00:00
|
|
|
|
2021-04-11 11:42:57 +00:00
|
|
|
uninit() {
|
|
|
|
Services.prefs.removeObserver(this._prefName, this);
|
|
|
|
},
|
|
|
|
};
|