gecko-dev/browser/base/content/browser-compacttheme.js
Dão Gottwald 30665b282e Bug 1448059 - Load compacttheme.css directly in browser.xul rather than from browser-compacttheme.js. r=bgrins
MozReview-Commit-ID: FldhNQ3V3v2

--HG--
extra : rebase_source : 1508ecc0f91a44782667ea5fa60f4513918ca2e3
2018-03-22 17:40:36 +01:00

69 lines
1.9 KiB
JavaScript

/* 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/. */
/**
* Enables compacttheme.css when needed.
*/
var CompactTheme = {
get styleSheet() {
delete this.styleSheet;
for (let styleSheet of document.styleSheets) {
if (styleSheet.href == "chrome://browser/skin/compacttheme.css") {
this.styleSheet = styleSheet;
break;
}
}
return this.styleSheet;
},
get isStyleSheetEnabled() {
return this.styleSheet && !this.styleSheet.disabled;
},
get isThemeCurrentlyApplied() {
let theme = LightweightThemeManager.currentTheme;
return theme && (
theme.id == "firefox-compact-dark@mozilla.org" ||
theme.id == "firefox-compact-light@mozilla.org");
},
init() {
Services.obs.addObserver(this, "lightweight-theme-styling-update");
if (this.isThemeCurrentlyApplied) {
this._toggleStyleSheet(true);
}
},
observe(subject, topic, data) {
if (topic == "lightweight-theme-styling-update") {
let newTheme = JSON.parse(data);
if (newTheme && (
newTheme.id == "firefox-compact-light@mozilla.org" ||
newTheme.id == "firefox-compact-dark@mozilla.org")) {
// We are using the theme ID on this object instead of always referencing
// LightweightThemeManager.currentTheme in case this is a preview
this._toggleStyleSheet(true);
} else {
this._toggleStyleSheet(false);
}
}
},
_toggleStyleSheet(enabled) {
let wasEnabled = this.isStyleSheetEnabled;
if (enabled) {
this.styleSheet.disabled = false;
} else if (!enabled && wasEnabled) {
this.styleSheet.disabled = true;
}
},
uninit() {
Services.obs.removeObserver(this, "lightweight-theme-styling-update");
this.styleSheet = null;
}
};