summaryrefslogtreecommitdiffstats
path: root/application/basilisk/base/content/browser-compacttheme.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-02 03:32:58 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-02 03:32:58 -0500
commite72ef92b5bdc43cd2584198e2e54e951b70299e8 (patch)
tree01ceb4a897c33eca9e7ccf2bc3aefbe530169fe5 /application/basilisk/base/content/browser-compacttheme.js
parent0d19b77d3eaa5b8d837bf52c19759e68e42a1c4c (diff)
downloadUXP-e72ef92b5bdc43cd2584198e2e54e951b70299e8.tar
UXP-e72ef92b5bdc43cd2584198e2e54e951b70299e8.tar.gz
UXP-e72ef92b5bdc43cd2584198e2e54e951b70299e8.tar.lz
UXP-e72ef92b5bdc43cd2584198e2e54e951b70299e8.tar.xz
UXP-e72ef92b5bdc43cd2584198e2e54e951b70299e8.zip
Add Basilisk
Diffstat (limited to 'application/basilisk/base/content/browser-compacttheme.js')
-rw-r--r--application/basilisk/base/content/browser-compacttheme.js106
1 files changed, 106 insertions, 0 deletions
diff --git a/application/basilisk/base/content/browser-compacttheme.js b/application/basilisk/base/content/browser-compacttheme.js
new file mode 100644
index 000000000..87095df51
--- /dev/null
+++ b/application/basilisk/base/content/browser-compacttheme.js
@@ -0,0 +1,106 @@
+/* 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/. */
+
+/**
+ * Listeners for the compact theme. This adds an extra stylesheet
+ * to browser.xul if a pref is set and no other themes are applied.
+ */
+var CompactTheme = {
+ styleSheetLocation: "chrome://browser/skin/compacttheme.css",
+ styleSheet: null,
+ initialized: false,
+
+ get isStyleSheetEnabled() {
+ return this.styleSheet && !this.styleSheet.sheet.disabled;
+ },
+
+ get isThemeCurrentlyApplied() {
+ let theme = LightweightThemeManager.currentTheme;
+ return theme && (
+ theme.id == "firefox-compact-dark@mozilla.org" ||
+ theme.id == "firefox-compact-light@mozilla.org");
+ },
+
+ init() {
+ this.initialized = true;
+ Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
+
+ if (this.isThemeCurrentlyApplied) {
+ this._toggleStyleSheet(true);
+ }
+ },
+
+ createStyleSheet() {
+ let styleSheetAttr = `href="${this.styleSheetLocation}" type="text/css"`;
+ this.styleSheet = document.createProcessingInstruction(
+ "xml-stylesheet", styleSheetAttr);
+ this.styleSheet.addEventListener("load", this);
+ document.insertBefore(this.styleSheet, document.documentElement);
+ this.styleSheet.sheet.disabled = 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);
+ }
+
+ }
+ },
+
+ handleEvent(e) {
+ if (e.type === "load") {
+ this.styleSheet.removeEventListener("load", this);
+ this.refreshBrowserDisplay();
+ }
+ },
+
+ refreshBrowserDisplay() {
+ // Don't touch things on the browser if gBrowserInit.onLoad hasn't
+ // yet fired.
+ if (this.initialized) {
+ gBrowser.tabContainer._positionPinnedTabs();
+ }
+ },
+
+ _toggleStyleSheet(enabled) {
+ let wasEnabled = this.isStyleSheetEnabled;
+ if (enabled) {
+ // The stylesheet may not have been created yet if it wasn't
+ // needed on initial load. Make it now.
+ if (!this.styleSheet) {
+ this.createStyleSheet();
+ }
+ this.styleSheet.sheet.disabled = false;
+ this.refreshBrowserDisplay();
+ } else if (!enabled && wasEnabled) {
+ this.styleSheet.sheet.disabled = true;
+ this.refreshBrowserDisplay();
+ }
+ },
+
+ uninit() {
+ Services.obs.removeObserver(this, "lightweight-theme-styling-update");
+ if (this.styleSheet) {
+ this.styleSheet.removeEventListener("load", this);
+ }
+ this.styleSheet = null;
+ }
+};
+
+#ifdef INSTALL_COMPACT_THEMES
+// If the compact theme is going to be applied in gBrowserInit.onLoad,
+// then preload it now. This prevents a flash of unstyled content where the
+// normal theme is applied while the compact theme stylesheet is loading.
+if (this != Services.appShell.hiddenDOMWindow && CompactTheme.isThemeCurrentlyApplied) {
+ CompactTheme.createStyleSheet();
+}
+#endif