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
--- 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;
+ },
};