Bug 983761 - Add support for CSSGroupingRules in LightweightThemeListener. r=Gijs
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 14 Mar 2014 16:24:57 -0700
changeset 190935 c56350f64da28f878555c17057943e2fbb26bf10
parent 190934 610649d473ccb3da6ecb11ba19a263913f5188c2
child 190936 8aa53970769cd60d681fdd05515fc3d4b1b8b5eb
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs983761
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 983761 - Add support for CSSGroupingRules in LightweightThemeListener. r=Gijs
browser/base/content/browser-addons.js
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -400,26 +400,40 @@ let LightweightThemeListener = {
    * Append the headerImage to the background-image property of all rulesets in
    * browser-lightweightTheme.css.
    *
    * @param headerImage - a string containing a CSS image for the lightweight theme header.
    */
   updateStyleSheet: function(headerImage) {
     if (!this.styleSheet)
       return;
-    for (let i = 0; i < this.styleSheet.cssRules.length; i++) {
-      let rule = this.styleSheet.cssRules[i];
-      if (!rule.style.backgroundImage)
-        continue;
+    this.substituteRules(this.styleSheet.cssRules, headerImage);
+  },
 
-      if (!this._modifiedStyles[i])
-        this._modifiedStyles[i] = { backgroundImage: rule.style.backgroundImage };
+  substituteRules: function(ruleList, headerImage, existingStyleRulesModified = 0) {
+    let styleRulesModified = 0;
+    for (let i = 0; i < ruleList.length; i++) {
+      let rule = ruleList[i];
+      if (rule instanceof Ci.nsIDOMCSSGroupingRule) {
+        // Add the number of modified sub-rules to the modified count
+        styleRulesModified += this.substituteRules(rule.cssRules, headerImage, existingStyleRulesModified + styleRulesModified);
+      } else if (rule instanceof Ci.nsIDOMCSSStyleRule) {
+        if (!rule.style.backgroundImage)
+          continue;
+        let modifiedIndex = existingStyleRulesModified + styleRulesModified;
+        if (!this._modifiedStyles[modifiedIndex])
+          this._modifiedStyles[modifiedIndex] = { backgroundImage: rule.style.backgroundImage };
 
-      rule.style.backgroundImage = this._modifiedStyles[i].backgroundImage + ", " + headerImage;
+        rule.style.backgroundImage = this._modifiedStyles[modifiedIndex].backgroundImage + ", " + headerImage;
+        styleRulesModified++;
+      } else {
+        Cu.reportError("Unsupported rule encountered");
+      }
     }
+    return styleRulesModified;
   },
 
   // nsIObserver
   observe: function (aSubject, aTopic, aData) {
     if (aTopic != "lightweight-theme-styling-update" || !this.styleSheet)
       return;
 
     let themeData = JSON.parse(aData);