Bug 1496055 - Part 2: Remove obsolete StyleRuleActor.modifySelector() and rename modifySelector2(); r=gl
authorRazvan Caliman <rcaliman@mozilla.com>
Wed, 03 Oct 2018 15:11:52 +0000
changeset 487813 dbe7858573bd0918f2a101a62997a8309a2fc517
parent 487812 6dbab52dffb7bf83935c878b20f06621c5327eeb
child 487814 cdea5981e6eb02f73d36674fd57ea0964c180827
child 487851 8a41d62efdd444de64a935f3dbf4da75cbf8c28d
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersgl
bugs1496055
milestone64.0a1
Bug 1496055 - Part 2: Remove obsolete StyleRuleActor.modifySelector() and rename modifySelector2(); r=gl MozReview-Commit-ID: 35VrRw33sV7 Differential Revision: https://phabricator.services.mozilla.com/D7598
devtools/client/inspector/rules/views/rule-editor.js
devtools/server/actors/root.js
devtools/server/actors/styles.js
devtools/shared/fronts/styles.js
devtools/shared/specs/styles.js
--- a/devtools/client/inspector/rules/views/rule-editor.js
+++ b/devtools/client/inspector/rules/views/rule-editor.js
@@ -108,17 +108,16 @@ RuleEditor.prototype = {
       this._sourceMapURLService = this.toolbox.sourceMapURLService;
     }
 
     return this._sourceMapURLService;
   },
 
   get isSelectorEditable() {
     const trait = this.isEditable &&
-      this.ruleView.inspector.target.client.traits.selectorEditable &&
       this.rule.domRule.type !== ELEMENT_STYLE &&
       this.rule.domRule.type !== CSSRule.KEYFRAME_RULE;
 
     // Do not allow editing anonymousselectors until we can
     // detect mutations on  pseudo elements in Bug 1034110.
     return trait && !this.rule.elementStyle.element.isAnonymous;
   },
 
--- a/devtools/server/actors/root.js
+++ b/devtools/server/actors/root.js
@@ -123,19 +123,16 @@ RootActor.prototype = {
     // Whether conditional breakpoints are supported
     conditionalBreakpoints: true,
     // Whether the server supports full source actors (breakpoints on
     // eval scripts, etc)
     debuggerSourceActors: true,
     // Whether the server can return wasm binary source
     wasmBinarySource: true,
     bulk: true,
-    // Whether the style rule actor implements the modifySelector method
-    // that modifies the rule's selector
-    selectorEditable: true,
     // Whether the dom node actor implements the getCssPath method. Added in 53.
     getCssPath: true,
     // Whether the dom node actor implements the getXPath method. Added in 56.
     getXPath: true,
     // Whether the director scripts are supported
     directorScripts: true,
     // Whether the debugger server supports
     // blackboxing/pretty-printing (not supported in Fever Dream yet)
--- a/devtools/server/actors/styles.js
+++ b/devtools/server/actors/styles.js
@@ -1392,17 +1392,17 @@ var StyleRuleActor = protocol.ActorClass
         this.rawStyle.removeProperty(mod.name);
       }
     }
 
     return this;
   },
 
   /**
-   * Helper function for modifySelector and modifySelector2, inserts the new
+   * Helper function for modifySelector, inserts the new
    * rule with the new selector into the parent style sheet and removes the
    * current rule. Returns the newly inserted css rule or null if the rule is
    * unsuccessfully inserted to the parent style sheet.
    *
    * @param {String} value
    *        The new selector value
    * @param {Boolean} editAuthored
    *        True if the selector should be updated by editing the
@@ -1454,54 +1454,16 @@ var StyleRuleActor = protocol.ActorClass
         }
       }
     }
 
     return this._getRuleFromIndex(parentStyleSheet);
   },
 
   /**
-   * Modify the current rule's selector by inserting a new rule with the new
-   * selector value and removing the current rule.
-   *
-   * Note this method was kept for backward compatibility, but unmatched rules
-   * support was added in FF41.
-   *
-   * @param string value
-   *        The new selector value
-   * @returns boolean
-   *        Returns a boolean if the selector in the stylesheet was modified,
-   *        and false otherwise
-   */
-  async modifySelector(value) {
-    if (this.type === ELEMENT_STYLE) {
-      return false;
-    }
-
-    const document = this.getDocument(this._parentSheet);
-    // Extract the selector, and pseudo elements and classes
-    const [selector] = value.split(/(:{1,2}.+$)/);
-    let selectorElement;
-
-    try {
-      selectorElement = document.querySelector(selector);
-    } catch (e) {
-      return false;
-    }
-
-    // Check if the selector is valid and not the same as the original
-    // selector
-    if (selectorElement && this.rawRule.selectorText !== value) {
-      await this._addNewSelector(value, false);
-      return true;
-    }
-    return false;
-  },
-
-  /**
    * Take an object with instructions to modify a CSS declaration and emit a
    * "track-change" event with normalized metadata which describes the change.
    *
    * @param {Object} change
    *        Data about a modification to a rule. @see |modifyProperties()|
    */
   logChange(change) {
     const prevValue = this._declarations[change.index]
@@ -1557,21 +1519,29 @@ var StyleRuleActor = protocol.ActorClass
         data.add.value === data.remove.value) {
       return;
     }
 
     this.emit("track-change", data);
   },
 
   /**
+   * Calls modifySelector2() which needs to be kept around for backwards compatibility.
+   * TODO: Once Firefox 64 is no longer supported, inline that mehtod's content,
+   * then remove its definition from this file and from specs/styles.js
+   */
+  modifySelector: function(node, value, editAuthored = false) {
+    return this.modifySelector2(node, value, editAuthored);
+  },
+
+  /**
    * Modify the current rule's selector by inserting a new rule with the new
    * selector value and removing the current rule.
    *
-   * In contrast with the modifySelector method which was used before FF41,
-   * this method also returns information about the new rule and applied style
+   * Returns information about the new rule and applied style
    * so that consumers can immediately display the new rule, whether or not the
    * selector matches the current element without having to refresh the whole
    * list.
    *
    * @param {DOMNode} node
    *        The current selected element
    * @param {String} value
    *        The new selector value
--- a/devtools/shared/fronts/styles.js
+++ b/devtools/shared/fronts/styles.js
@@ -262,19 +262,19 @@ const StyleRuleFront = FrontClassWithSpe
         this._originalLocation = location;
         return location;
       });
   },
 
   modifySelector: custom(async function(node, value) {
     let response;
     if (this.canSetRuleText) {
-      response = await this.modifySelector2(node, value, true);
+      response = await this._modifySelector(node, value, true);
     } else {
-      response = await this.modifySelector2(node, value);
+      response = await this._modifySelector(node, value);
     }
 
     if (response.ruleProps) {
       response.ruleProps = response.ruleProps.entries[0];
     }
     return response;
   }, {
     impl: "_modifySelector"
--- a/devtools/shared/specs/styles.js
+++ b/devtools/shared/specs/styles.js
@@ -203,19 +203,25 @@ const styleRuleSpec = generateActorSpec(
       },
       response: { rule: RetVal("domstylerule") }
     },
     modifyProperties: {
       request: { modifications: Arg(0, "array:json") },
       response: { rule: RetVal("domstylerule") }
     },
     modifySelector: {
-      request: { selector: Arg(0, "string") },
-      response: { isModified: RetVal("boolean") },
+      request: {
+        node: Arg(0, "domnode"),
+        value: Arg(1, "string"),
+        editAuthored: Arg(2, "boolean")
+      },
+      response: RetVal("modifiedStylesReturn")
     },
+    // Remove once Firefox 64 is no longer supported.
+    // @See StyleRuleActor.modifySelector()
     modifySelector2: {
       request: {
         node: Arg(0, "domnode"),
         value: Arg(1, "string"),
         editAuthored: Arg(2, "boolean")
       },
       response: RetVal("modifiedStylesReturn")
     }