Bug 1308407 - part 1: update lwthemetextcolor attribute when devedition theme is used, r?dao draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 01 Nov 2016 17:48:39 +0000
changeset 432338 3fd7261fc6aa0c02db5c018e87ab880656339e4c
parent 431996 2c773b97167252cedcba0be0c7af9d4cab192ef5
child 432339 1ff196a6d0f44c2a61c5ea15bd7b6a2ed986e92a
push id34267
push usergijskruitbosch@gmail.com
push dateTue, 01 Nov 2016 17:50:23 +0000
reviewersdao
bugs1308407
milestone52.0a1
Bug 1308407 - part 1: update lwthemetextcolor attribute when devedition theme is used, r?dao MozReview-Commit-ID: 5xQLXK9YxRe
browser/base/content/browser-devedition.js
--- a/browser/base/content/browser-devedition.js
+++ b/browser/base/content/browser-devedition.js
@@ -20,16 +20,17 @@ var DevEdition = {
     let theme = LightweightThemeManager.currentTheme;
     return theme && theme.id == "firefox-devedition@mozilla.org";
   },
 
   init: function () {
     this.initialized = true;
     Services.prefs.addObserver(this._devtoolsThemePrefName, this, false);
     Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
+    Services.obs.addObserver(this, "lightweight-theme-window-updated", false);
     this._updateDevtoolsThemeAttribute();
 
     if (this.isThemeCurrentlyApplied) {
       this._toggleStyleSheet(true);
     }
   },
 
   createStyleSheet: function() {
@@ -44,16 +45,18 @@ var DevEdition = {
   observe: function (subject, topic, data) {
     if (topic == "lightweight-theme-styling-update") {
       let newTheme = JSON.parse(data);
       if (newTheme && newTheme.id == "firefox-devedition@mozilla.org") {
         this._toggleStyleSheet(true);
       } else {
         this._toggleStyleSheet(false);
       }
+    } else if (topic == "lightweight-theme-window-updated" && subject == window) {
+      this._updateLWTBrightness();
     }
 
     if (topic == "nsPref:changed" && data == this._devtoolsThemePrefName) {
       this._updateDevtoolsThemeAttribute();
     }
   },
 
   _inferBrightness: function() {
@@ -62,24 +65,33 @@ var DevEdition = {
     if (this.isStyleSheetEnabled &&
         document.documentElement.getAttribute("devtoolstheme") == "dark") {
       document.documentElement.setAttribute("brighttitlebarforeground", "true");
     } else {
       document.documentElement.removeAttribute("brighttitlebarforeground");
     }
   },
 
+  _updateLWTBrightness() {
+    if (this.isThemeCurrentlyApplied) {
+      let devtoolsTheme = Services.prefs.getCharPref(this._devtoolsThemePrefName);
+      let textColor = devtoolsTheme == "dark" ? "bright" : "dark";
+      document.documentElement.setAttribute("lwthemetextcolor", textColor);
+    }
+  },
+
   _updateDevtoolsThemeAttribute: function() {
     // Set an attribute on root element to make it possible
     // to change colors based on the selected devtools theme.
     let devtoolsTheme = Services.prefs.getCharPref(this._devtoolsThemePrefName);
     if (devtoolsTheme != "dark") {
       devtoolsTheme = "light";
     }
     document.documentElement.setAttribute("devtoolstheme", devtoolsTheme);
+    this._updateLWTBrightness();
     this._inferBrightness();
   },
 
   handleEvent: function(e) {
     if (e.type === "load") {
       this.styleSheet.removeEventListener("load", this);
       this.refreshBrowserDisplay();
     }
@@ -108,16 +120,17 @@ var DevEdition = {
       this.styleSheet.sheet.disabled = true;
       this.refreshBrowserDisplay();
     }
   },
 
   uninit: function () {
     Services.prefs.removeObserver(this._devtoolsThemePrefName, this);
     Services.obs.removeObserver(this, "lightweight-theme-styling-update", false);
+    Services.obs.removeObserver(this, "lightweight-theme-window-updated", false);
     if (this.styleSheet) {
       this.styleSheet.removeEventListener("load", this);
     }
     this.styleSheet = null;
   }
 };
 
 // If the DevEdition theme is going to be applied in gBrowserInit.onLoad,