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