Bug 1415940 Part 7: Change canSetRuleText() to test the sheet for modification by CSSOM. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 19 Dec 2017 13:52:24 -0800
changeset 722744 95620b5d83815ebb160a6138b77779a6867c5a7a
parent 722743 d148d7dd5c0b3ea4e35bb0e8482fb8a12b7d105e
child 722745 c50143f56de464f373f6e122e476949a1a5630d4
push id96224
push userbwerth@mozilla.com
push dateFri, 19 Jan 2018 19:24:40 +0000
bugs1415940
milestone59.0a1
Bug 1415940 Part 7: Change canSetRuleText() to test the sheet for modification by CSSOM. MozReview-Commit-ID: 2tCVgntiRHn
devtools/server/actors/styles.js
devtools/server/actors/stylesheets.js
--- a/devtools/server/actors/styles.js
+++ b/devtools/server/actors/styles.js
@@ -997,20 +997,20 @@ var StyleRuleActor = protocol.ActorClass
     return this.pageStyle;
   },
 
   // True if this rule supports as-authored styles, meaning that the
   // rule text can be rewritten using setRuleText.
   get canSetRuleText() {
     return this.type === ELEMENT_STYLE ||
            (this._parentSheet &&
-            // If a rule does not have source, then it has been modified via
-            // CSSOM; and we should fall back to non-authored editing.
+            // If a rule has been modified via CSSOM, then we should fall
+            // back to non-authored editing.
             // https://bugzilla.mozilla.org/show_bug.cgi?id=1224121
-            this.sheetActor.allRulesHaveSource() &&
+            !this.sheetActor.hasRulesModifiedByCSSOM() &&
             // Special case about:PreferenceStyleSheet, as it is generated on
             // the fly and the URI is not registered with the about:handler
             // https://bugzilla.mozilla.org/show_bug.cgi?id=935803#c37
             this._parentSheet.href !== "about:PreferenceStyleSheet");
   },
 
   getDocument: function (sheet) {
     if (sheet.ownerNode) {
--- a/devtools/server/actors/stylesheets.js
+++ b/devtools/server/actors/stylesheets.js
@@ -232,37 +232,21 @@ var StyleSheetActor = protocol.ActorClas
     if (parentStyleSheet.ownerNode) {
       this.ownerDocument = parentStyleSheet.ownerNode.ownerDocument;
     } else {
       this.ownerDocument = parentActor.window;
     }
   },
 
   /**
-   * Test whether all the rules in this sheet have associated source.
-   * @return {Boolean} true if all the rules have source; false if
-   *         some rule was created via CSSOM.
+   * Test whether this sheet has been modified by CSSOM.
+   * @return {Boolean} true if changed by CSSOM.
    */
-  allRulesHaveSource: function () {
-    let rules;
-    try {
-      rules = this.rawSheet.cssRules;
-    } catch (e) {
-      // sheet isn't loaded yet
-      return true;
-    }
-
-    for (let i = 0; i < rules.length; i++) {
-      let rule = rules[i];
-      if (InspectorUtils.getRelativeRuleLine(rule) === 0) {
-        return false;
-      }
-    }
-
-    return true;
+  hasRulesModifiedByCSSOM: function () {
+    return InspectorUtils.hasRulesModifiedByCSSOM(this.rawSheet);
   },
 
   /**
    * Get the raw stylesheet's cssRules once the sheet has been loaded.
    *
    * @return {Promise}
    *         Promise that resolves with a CSSRuleList
    */