michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: (function() { michael@0: const DEVTOOLS_SKIN_URL = "chrome://browser/skin/devtools/"; michael@0: michael@0: function forceStyle() { michael@0: let computedStyle = window.getComputedStyle(document.documentElement); michael@0: if (!computedStyle) { michael@0: // Null when documentElement is not ready. This method is anyways not michael@0: // required then as scrollbars would be in their state without flushing. michael@0: return; michael@0: } michael@0: let display = computedStyle.display; // Save display value michael@0: document.documentElement.style.display = "none"; michael@0: window.getComputedStyle(document.documentElement).display; // Flush michael@0: document.documentElement.style.display = display; // Restore michael@0: } michael@0: michael@0: function switchTheme(newTheme, oldTheme) { michael@0: if (newTheme === oldTheme) { michael@0: return; michael@0: } michael@0: michael@0: if (oldTheme && newTheme != oldTheme) { michael@0: StylesheetUtils.removeSheet( michael@0: window, michael@0: DEVTOOLS_SKIN_URL + oldTheme + "-theme.css", michael@0: "author" michael@0: ); michael@0: } michael@0: michael@0: StylesheetUtils.loadSheet( michael@0: window, michael@0: DEVTOOLS_SKIN_URL + newTheme + "-theme.css", michael@0: "author" michael@0: ); michael@0: michael@0: // Floating scrollbars à la osx michael@0: let hiddenDOMWindow = Cc["@mozilla.org/appshell/appShellService;1"] michael@0: .getService(Ci.nsIAppShellService) michael@0: .hiddenDOMWindow; michael@0: if (!hiddenDOMWindow.matchMedia("(-moz-overlay-scrollbars)").matches) { michael@0: let scrollbarsUrl = Services.io.newURI( michael@0: DEVTOOLS_SKIN_URL + "floating-scrollbars-light.css", null, null); michael@0: michael@0: if (newTheme == "dark") { michael@0: StylesheetUtils.loadSheet( michael@0: window, michael@0: scrollbarsUrl, michael@0: "agent" michael@0: ); michael@0: } else if (oldTheme == "dark") { michael@0: StylesheetUtils.removeSheet( michael@0: window, michael@0: scrollbarsUrl, michael@0: "agent" michael@0: ); michael@0: } michael@0: forceStyle(); michael@0: } michael@0: michael@0: document.documentElement.classList.remove("theme-" + oldTheme); michael@0: document.documentElement.classList.add("theme-" + newTheme); michael@0: } michael@0: michael@0: function handlePrefChange(event, data) { michael@0: if (data.pref == "devtools.theme") { michael@0: switchTheme(data.newValue, data.oldValue); michael@0: } michael@0: } michael@0: michael@0: const { classes: Cc, interfaces: Ci, utils: Cu } = Components; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource:///modules/devtools/gDevTools.jsm"); michael@0: const {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: const StylesheetUtils = devtools.require("sdk/stylesheet/utils"); michael@0: michael@0: let theme = Services.prefs.getCharPref("devtools.theme"); michael@0: switchTheme(theme); michael@0: michael@0: gDevTools.on("pref-changed", handlePrefChange); michael@0: window.addEventListener("unload", function() { michael@0: gDevTools.off("pref-changed", handlePrefChange); michael@0: }); michael@0: })();