Bug 1415940 Part 7: Change canSetRuleText() to test the sheet for modification by CSSOM.
MozReview-Commit-ID: 2tCVgntiRHn
--- 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
*/