Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | (function() { |
michael@0 | 6 | const DEVTOOLS_SKIN_URL = "chrome://browser/skin/devtools/"; |
michael@0 | 7 | |
michael@0 | 8 | function forceStyle() { |
michael@0 | 9 | let computedStyle = window.getComputedStyle(document.documentElement); |
michael@0 | 10 | if (!computedStyle) { |
michael@0 | 11 | // Null when documentElement is not ready. This method is anyways not |
michael@0 | 12 | // required then as scrollbars would be in their state without flushing. |
michael@0 | 13 | return; |
michael@0 | 14 | } |
michael@0 | 15 | let display = computedStyle.display; // Save display value |
michael@0 | 16 | document.documentElement.style.display = "none"; |
michael@0 | 17 | window.getComputedStyle(document.documentElement).display; // Flush |
michael@0 | 18 | document.documentElement.style.display = display; // Restore |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function switchTheme(newTheme, oldTheme) { |
michael@0 | 22 | if (newTheme === oldTheme) { |
michael@0 | 23 | return; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | if (oldTheme && newTheme != oldTheme) { |
michael@0 | 27 | StylesheetUtils.removeSheet( |
michael@0 | 28 | window, |
michael@0 | 29 | DEVTOOLS_SKIN_URL + oldTheme + "-theme.css", |
michael@0 | 30 | "author" |
michael@0 | 31 | ); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | StylesheetUtils.loadSheet( |
michael@0 | 35 | window, |
michael@0 | 36 | DEVTOOLS_SKIN_URL + newTheme + "-theme.css", |
michael@0 | 37 | "author" |
michael@0 | 38 | ); |
michael@0 | 39 | |
michael@0 | 40 | // Floating scrollbars à la osx |
michael@0 | 41 | let hiddenDOMWindow = Cc["@mozilla.org/appshell/appShellService;1"] |
michael@0 | 42 | .getService(Ci.nsIAppShellService) |
michael@0 | 43 | .hiddenDOMWindow; |
michael@0 | 44 | if (!hiddenDOMWindow.matchMedia("(-moz-overlay-scrollbars)").matches) { |
michael@0 | 45 | let scrollbarsUrl = Services.io.newURI( |
michael@0 | 46 | DEVTOOLS_SKIN_URL + "floating-scrollbars-light.css", null, null); |
michael@0 | 47 | |
michael@0 | 48 | if (newTheme == "dark") { |
michael@0 | 49 | StylesheetUtils.loadSheet( |
michael@0 | 50 | window, |
michael@0 | 51 | scrollbarsUrl, |
michael@0 | 52 | "agent" |
michael@0 | 53 | ); |
michael@0 | 54 | } else if (oldTheme == "dark") { |
michael@0 | 55 | StylesheetUtils.removeSheet( |
michael@0 | 56 | window, |
michael@0 | 57 | scrollbarsUrl, |
michael@0 | 58 | "agent" |
michael@0 | 59 | ); |
michael@0 | 60 | } |
michael@0 | 61 | forceStyle(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | document.documentElement.classList.remove("theme-" + oldTheme); |
michael@0 | 65 | document.documentElement.classList.add("theme-" + newTheme); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function handlePrefChange(event, data) { |
michael@0 | 69 | if (data.pref == "devtools.theme") { |
michael@0 | 70 | switchTheme(data.newValue, data.oldValue); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
michael@0 | 75 | |
michael@0 | 76 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 77 | Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
michael@0 | 78 | const {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 79 | const StylesheetUtils = devtools.require("sdk/stylesheet/utils"); |
michael@0 | 80 | |
michael@0 | 81 | let theme = Services.prefs.getCharPref("devtools.theme"); |
michael@0 | 82 | switchTheme(theme); |
michael@0 | 83 | |
michael@0 | 84 | gDevTools.on("pref-changed", handlePrefChange); |
michael@0 | 85 | window.addEventListener("unload", function() { |
michael@0 | 86 | gDevTools.off("pref-changed", handlePrefChange); |
michael@0 | 87 | }); |
michael@0 | 88 | })(); |