Bug 1053898 - Update framework/selection to support slotted selections;r=gl draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 05 Mar 2018 13:56:00 +0100
changeset 773671 95259e33e084038d7a71e89b90affb60c38894a3
parent 773670 232795c1ee91a41ec667c8bcdc21eb73bcfcbf9a
child 773672 e5bde9e74369e1b0fb2e1d1a0a2b31a0131caacd
push id104269
push userjdescottes@mozilla.com
push dateWed, 28 Mar 2018 08:16:27 +0000
reviewersgl
bugs1053898
milestone61.0a1
Bug 1053898 - Update framework/selection to support slotted selections;r=gl With shadow dom support, a node front can be represented twice in the markup view, once as a "slotted" version inserted in a <slot> element and once a regular element. We should be able to know if the selection was made on the regular or on the slotted version. MozReview-Commit-ID: CUpREkL0TzL
devtools/client/framework/selection.js
--- a/devtools/client/framework/selection.js
+++ b/devtools/client/framework/selection.js
@@ -51,16 +51,21 @@ var EventEmitter = require("devtools/sha
 
 /**
  * A Selection object. Hold a reference to a node.
  * Includes some helpers, fire some helpful events.
  */
 function Selection(walker) {
   EventEmitter.decorate(this);
 
+  // A single node front can be represented twice on the client when the node is a slotted
+  // element. It will be displayed once as a direct child of the host element, and once as
+  // a child of a slot in the "shadow DOM". The latter is called the slotted version.
+  this._isSlotted = false;
+
   this._onMutations = this._onMutations.bind(this);
   this.setNodeFront = this.setNodeFront.bind(this);
   this.setWalker(walker);
 }
 
 exports.Selection = Selection;
 
 Selection.prototype = {
@@ -110,18 +115,30 @@ Selection.prototype = {
       this._walker.off("mutations", this._onMutations);
     }
     this._walker = walker;
     if (this._walker) {
       this._walker.on("mutations", this._onMutations);
     }
   },
 
-  setNodeFront: function(value, reason = "unknown") {
+  /**
+   * Update the currently selected node-front.
+   *
+   * @param {NodeFront} nodeFront
+   *        The NodeFront being selected.
+   * @param {String} reason
+   *        Reason that triggered the selection, will be fired with the "new-node-front"
+   *        event.
+   * @param {Boolean} isSlotted
+   *        Is the selection representing the slotted version of the node.
+   */
+  setNodeFront: function(value, reason = "unknown", isSlotted = false) {
     this.reason = reason;
+    this._isSlotted = isSlotted;
 
     // If an inlineTextChild text node is being set, then set it's parent instead.
     let parentNode = value && value.parentNode();
     if (value && parentNode && parentNode.inlineTextChild === value) {
       value = parentNode;
     }
 
     this._nodeFront = value;
@@ -240,9 +257,13 @@ Selection.prototype = {
   isDocumentFragmentNode: function() {
     return this.isNode() &&
       this.nodeFront.nodeType == nodeConstants.DOCUMENT_FRAGMENT_NODE;
   },
 
   isNotationNode: function() {
     return this.isNode() && this.nodeFront.nodeType == nodeConstants.NOTATION_NODE;
   },
+
+  isSlotted: function() {
+    return this._isSlotted;
+  },
 };