Bug 1053898 - Add setContainer and hasContainer APIs in MarkupView;r=gl
With shadowdom support, a single nodeFront can have several containers.
This will complexify the logic to manipulate the _containers map in
markup.js. Introducing basic getters and setters to interact with this
map will make the transition easier.
MozReview-Commit-ID: FTphQgCsHNL
--- a/devtools/client/inspector/markup/markup.js
+++ b/devtools/client/inspector/markup/markup.js
@@ -480,16 +480,24 @@ MarkupView.prototype = {
/**
* Get the MarkupContainer object for a given node, or undefined if
* none exists.
*/
getContainer: function(node) {
return this._containers.get(node);
},
+ setContainer: function(node, container) {
+ return this._containers.set(node, container);
+ },
+
+ hasContainer: function(node) {
+ return this._containers.has(node);
+ },
+
update: function() {
let updateChildren = (node) => {
this.getContainer(node).update();
for (let child of node.treeChildren()) {
updateChildren(child);
}
};
@@ -963,17 +971,17 @@ MarkupView.prototype = {
* Whether the newly imported node should be flashed
* @return {MarkupContainer} The MarkupContainer object for this element.
*/
importNode: function(node, flashNode) {
if (!node) {
return null;
}
- if (this._containers.has(node)) {
+ if (this.hasContainer(node)) {
return this.getContainer(node);
}
let container;
let {nodeType, isPseudoElement} = node;
if (node === this.walker.rootNode) {
container = new RootContainer(this, node);
this._elt.appendChild(container.elt);
@@ -986,17 +994,17 @@ MarkupView.prototype = {
} else {
container = new MarkupReadOnlyContainer(this, node, this.inspector);
}
if (flashNode) {
container.flashMutation();
}
- this._containers.set(node, container);
+ this.setContainer(node, container);
container.childrenDirty = true;
this._updateChildren(container);
this.inspector.emit("container-created", container);
return container;
},
@@ -1648,17 +1656,17 @@ MarkupView.prototype = {
// this container will do double duty as the container for the single
// text child.
while (container.children.firstChild) {
container.children.firstChild.remove();
}
container.setInlineTextChild(container.node.inlineTextChild);
- this._containers.set(container.node.inlineTextChild, container);
+ this.setContainer(container.node.inlineTextChild, container);
container.childrenDirty = false;
return promise.resolve(container);
}
if (!container.hasChildren) {
while (container.children.firstChild) {
container.children.firstChild.remove();
}