Bug 1053898 - Add setContainer and hasContainer APIs in MarkupView;r=gl draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 06 Mar 2018 19:47:24 +0100
changeset 773675 e7db9cd73a0511c1728efa42899c74c0c6f9e7fe
parent 773674 091d67f68ac8ea89128dc2c5ae233a509a70a6a7
child 773676 b5ee2de3c22c0d6511c48ab5e4ceb64c6bd3143d
push id104269
push userjdescottes@mozilla.com
push dateWed, 28 Mar 2018 08:16:27 +0000
reviewersgl
bugs1053898
milestone61.0a1
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
devtools/client/inspector/markup/markup.js
--- 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();
       }