Bug 1030716 - Prevent dark theme in sourceeditor for WebIDE. r=paul
authorBrian Grinstead <bgrinstead@mozilla.com>
Thu, 26 Jun 2014 06:14:00 +0200
changeset 191172 25e196a33884d1c5a39739ac92e258e20ad701d0
parent 191171 ccbe51e7e5412433240d8be8dddaf67e881386df
child 191173 fe37b883556e6df22f45c178d518b008558390e1
push id8436
push usercbook@mozilla.com
push dateFri, 27 Jun 2014 13:56:57 +0000
treeherderb2g-inbound@22ea396750e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul
bugs1030716
milestone33.0a1
Bug 1030716 - Prevent dark theme in sourceeditor for WebIDE. r=paul
browser/devtools/shared/theme-switching.js
browser/devtools/sourceeditor/editor.js
--- a/browser/devtools/shared/theme-switching.js
+++ b/browser/devtools/shared/theme-switching.js
@@ -1,26 +1,27 @@
 /* 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/. */
 
 (function() {
   const DEVTOOLS_SKIN_URL = "chrome://browser/skin/devtools/";
+  let documentElement = document.documentElement;
 
   function forceStyle() {
-    let computedStyle = window.getComputedStyle(document.documentElement);
+    let computedStyle = window.getComputedStyle(documentElement);
     if (!computedStyle) {
       // Null when documentElement is not ready. This method is anyways not
       // required then as scrollbars would be in their state without flushing.
       return;
     }
     let display = computedStyle.display; // Save display value
-    document.documentElement.style.display = "none";
-    window.getComputedStyle(document.documentElement).display; // Flush
-    document.documentElement.style.display = display; // Restore
+    documentElement.style.display = "none";
+    window.getComputedStyle(documentElement).display; // Flush
+    documentElement.style.display = display; // Restore
   }
 
   function switchTheme(newTheme, oldTheme) {
     if (newTheme === oldTheme) {
       return;
     }
 
     if (oldTheme && newTheme != oldTheme) {
@@ -56,33 +57,36 @@
           window,
           scrollbarsUrl,
           "agent"
         );
       }
       forceStyle();
     }
 
-    document.documentElement.classList.remove("theme-" + oldTheme);
-    document.documentElement.classList.add("theme-" + newTheme);
+    documentElement.classList.remove("theme-" + oldTheme);
+    documentElement.classList.add("theme-" + newTheme);
   }
 
   function handlePrefChange(event, data) {
     if (data.pref == "devtools.theme") {
       switchTheme(data.newValue, data.oldValue);
     }
   }
 
   const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
   Cu.import("resource://gre/modules/Services.jsm");
   Cu.import("resource:///modules/devtools/gDevTools.jsm");
   const {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
   const StylesheetUtils = devtools.require("sdk/stylesheet/utils");
 
-  let theme = Services.prefs.getCharPref("devtools.theme");
-  switchTheme(theme);
+  if (documentElement.hasAttribute("force-theme")) {
+    switchTheme(documentElement.getAttribute("force-theme"));
+  } else {
+    switchTheme(Services.prefs.getCharPref("devtools.theme"));
 
-  gDevTools.on("pref-changed", handlePrefChange);
-  window.addEventListener("unload", function() {
-    gDevTools.off("pref-changed", handlePrefChange);
-  });
+    gDevTools.on("pref-changed", handlePrefChange);
+    window.addEventListener("unload", function() {
+      gDevTools.off("pref-changed", handlePrefChange);
+    });
+  }
 })();
--- a/browser/devtools/sourceeditor/editor.js
+++ b/browser/devtools/sourceeditor/editor.js
@@ -152,16 +152,17 @@ function Editor(config) {
     contextMenu:       null,
     matchBrackets:     true,
     extraKeys:         {},
     indentWithTabs:    useTabs,
     styleActiveLine:   true,
     autoCloseBrackets: "()[]{}''\"\"",
     autoCloseEnabled:  useAutoClose,
     theme:             "mozilla",
+    themeSwitching:    true,
     autocomplete:      false
   };
 
   // Additional shortcuts.
   this.config.extraKeys[Editor.keyFor("jumpToLine")] = () => this.jumpToLine();
   this.config.extraKeys[Editor.keyFor("moveLineUp", { noaccel: true })] = () => this.moveLineUp();
   this.config.extraKeys[Editor.keyFor("moveLineDown", { noaccel: true })] = () => this.moveLineDown();
   this.config.extraKeys[Editor.keyFor("toggleComment")] = "toggleComment";
@@ -253,16 +254,19 @@ Editor.prototype = {
 
     let onLoad = () => {
       // Once the iframe is loaded, we can inject CodeMirror
       // and its dependencies into its DOM.
 
       env.removeEventListener("load", onLoad, true);
       let win = env.contentWindow.wrappedJSObject;
 
+      if (!this.config.themeSwitching)
+        win.document.documentElement.setAttribute("force-theme", "light");
+
       CM_SCRIPTS.forEach((url) =>
         Services.scriptloader.loadSubScript(url, win, "utf8"));
 
       // Replace the propertyKeywords, colorKeywords and valueKeywords
       // properties of the CSS MIME type with the values provided by Gecko.
       let cssSpec = win.CodeMirror.resolveMode("text/css");
       cssSpec.propertyKeywords = cssProperties;
       cssSpec.colorKeywords = cssColors;