browser/devtools/shared/theme-switching.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 (function() {
     6   const DEVTOOLS_SKIN_URL = "chrome://browser/skin/devtools/";
     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   }
    21   function switchTheme(newTheme, oldTheme) {
    22     if (newTheme === oldTheme) {
    23       return;
    24     }
    26     if (oldTheme && newTheme != oldTheme) {
    27       StylesheetUtils.removeSheet(
    28         window,
    29         DEVTOOLS_SKIN_URL + oldTheme + "-theme.css",
    30         "author"
    31       );
    32     }
    34     StylesheetUtils.loadSheet(
    35       window,
    36       DEVTOOLS_SKIN_URL + newTheme + "-theme.css",
    37       "author"
    38     );
    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);
    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     }
    64     document.documentElement.classList.remove("theme-" + oldTheme);
    65     document.documentElement.classList.add("theme-" + newTheme);
    66   }
    68   function handlePrefChange(event, data) {
    69     if (data.pref == "devtools.theme") {
    70       switchTheme(data.newValue, data.oldValue);
    71     }
    72   }
    74   const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
    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");
    81   let theme = Services.prefs.getCharPref("devtools.theme");
    82   switchTheme(theme);
    84   gDevTools.on("pref-changed", handlePrefChange);
    85   window.addEventListener("unload", function() {
    86     gDevTools.off("pref-changed", handlePrefChange);
    87   });
    88 })();

mercurial