From 70a08bf916232fdc4ba960c24ebcc62084a33c3b Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Fri, 13 Apr 2018 19:07:44 +0200 Subject: Fix: Developer Toolbar (the command: `cookie`; themes) Issue #102 --- .../base/content/browser-devtools-theme.js | 92 ++++++++++++++++++++++ application/palemoon/base/content/browser.js | 12 +++ application/palemoon/base/content/browser.xul | 3 + .../base/content/global-devtools-theme-scripts.inc | 6 ++ .../palemoon/base/content/macBrowserOverlay.xul | 3 + application/palemoon/base/content/tabbrowser.xml | 4 + application/palemoon/base/jar.mn | 3 + 7 files changed, 123 insertions(+) create mode 100644 application/palemoon/base/content/browser-devtools-theme.js create mode 100644 application/palemoon/base/content/global-devtools-theme-scripts.inc (limited to 'application/palemoon') diff --git a/application/palemoon/base/content/browser-devtools-theme.js b/application/palemoon/base/content/browser-devtools-theme.js new file mode 100644 index 000000000..247cf200d --- /dev/null +++ b/application/palemoon/base/content/browser-devtools-theme.js @@ -0,0 +1,92 @@ +/* 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 DevEdition theme. This adds an extra stylesheet + * to browser.xul if a pref is set and no other themes are applied. + */ +var DevToolsTheme = { + _devtoolsThemePrefName: "devtools.theme", + styleSheet: null, + initialized: false, + + get isStyleSheetEnabled() { + return this.styleSheet && !this.styleSheet.sheet.disabled; + }, + + init: function () { + this.initialized = true; + Services.prefs.addObserver(this._devtoolsThemePrefName, this, false); + Services.obs.addObserver(this, "lightweight-theme-styling-update", false); + Services.obs.addObserver(this, "lightweight-theme-window-updated", false); + this._updateDevtoolsThemeAttribute(); + }, + + observe: function (subject, topic, data) { + if (topic == "lightweight-theme-styling-update") { + let newTheme = JSON.parse(data); + this._toggleStyleSheet(); + } + + if (topic == "nsPref:changed" && data == this._devtoolsThemePrefName) { + this._updateDevtoolsThemeAttribute(); + } + }, + + _inferBrightness: function() { + ToolbarIconColor.inferFromText(); + // Get an inverted full screen button if the dark theme is applied. + if (this.isStyleSheetEnabled && + document.documentElement.getAttribute("devtoolstheme") == "dark") { + document.documentElement.setAttribute("brighttitlebarforeground", "true"); + } else { + document.documentElement.removeAttribute("brighttitlebarforeground"); + } + }, + + _updateDevtoolsThemeAttribute: function() { + // Set an attribute on root element to make it possible + // to change colors based on the selected devtools theme. + let devtoolsTheme = Services.prefs.getCharPref(this._devtoolsThemePrefName); + if (devtoolsTheme != "dark") { + devtoolsTheme = "light"; + } + document.documentElement.setAttribute("devtoolstheme", devtoolsTheme); + this._inferBrightness(); + }, + + handleEvent: function(e) { + if (e.type === "load") { + this.styleSheet.removeEventListener("load", this); + this.refreshBrowserDisplay(); + } + }, + + refreshBrowserDisplay: function() { + // Don't touch things on the browser if gBrowserInit.onLoad hasn't + // yet fired. + if (this.initialized) { + gBrowser.tabContainer._positionPinnedTabs(); + this._inferBrightness(); + } + }, + + _toggleStyleSheet: function() { + let wasEnabled = this.isStyleSheetEnabled; + if (wasEnabled) { + this.styleSheet.sheet.disabled = true; + this.refreshBrowserDisplay(); + } + }, + + uninit: function () { + Services.prefs.removeObserver(this._devtoolsThemePrefName, this); + Services.obs.removeObserver(this, "lightweight-theme-styling-update", false); + Services.obs.removeObserver(this, "lightweight-theme-window-updated", false); + if (this.styleSheet) { + this.styleSheet.removeEventListener("load", this); + } + this.styleSheet = null; + } +}; diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index cdf139bbb..6af11af3d 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -722,6 +722,14 @@ var gBrowserInit = { window.addEventListener("AppCommand", HandleAppCommandEvent, true); + // These routines add message listeners. They must run before + // loading the frame script to ensure that we don't miss any + // message sent between when the frame script is loaded and when + // the listener is registered. +#ifdef MOZ_DEVTOOLS + DevToolsTheme.init(); +#endif + messageManager.loadFrameScript("chrome://browser/content/content.js", true); messageManager.loadFrameScript("chrome://browser/content/content-sessionStore.js", true); @@ -1281,6 +1289,10 @@ var gBrowserInit = { ToolbarIconColor.uninit(); +#ifdef MOZ_DEVTOOLS + DevToolsTheme.uninit(); +#endif + var enumerator = Services.wm.getEnumerator(null); enumerator.getNext(); if (!enumerator.hasMoreElements()) { diff --git a/application/palemoon/base/content/browser.xul b/application/palemoon/base/content/browser.xul index 0a0ce01dc..df152bbaa 100644 --- a/application/palemoon/base/content/browser.xul +++ b/application/palemoon/base/content/browser.xul @@ -65,6 +65,9 @@ # wishes to include *must* go into the global-scripts.inc file # so that they can be shared by macBrowserOverlay.xul. #include global-scripts.inc +#ifdef MOZ_DEVTOOLS +#include global-devtools-theme-scripts.inc +#endif