Bug 1053898 - Add _markContainerAsSelected() API in MarkupView;r=gl draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 06 Mar 2018 19:04:48 +0100
changeset 773674 091d67f68ac8ea89128dc2c5ae233a509a70a6a7
parent 773673 4ee3b857ee43ebe981b2148b0a6a1390c69669aa
child 773675 e7db9cd73a0511c1728efa42899c74c0c6f9e7fe
push id104269
push userjdescottes@mozilla.com
push dateWed, 28 Mar 2018 08:16:27 +0000
reviewersgl
bugs1053898
milestone61.0a1
Bug 1053898 - Add _markContainerAsSelected() API in MarkupView;r=gl With shadowdom support, the container will become more specific than the nodeFront. Add a specific API to select directly a container rather than having to use a nodeFront will make the transition easier. MozReview-Commit-ID: DIiKJPsxEYZ
devtools/client/inspector/markup/markup.js
--- a/devtools/client/inspector/markup/markup.js
+++ b/devtools/client/inspector/markup/markup.js
@@ -946,18 +946,17 @@ MarkupView.prototype = {
    * @param  {MarkupContainer} container
    *         The container we're navigating to.
    */
   navigate: function(container) {
     if (!container) {
       return;
     }
 
-    let node = container.node;
-    this.markNodeAsSelected(node, "treepanel");
+    this._markContainerAsSelected(container, "treepanel");
   },
 
   /**
    * Make sure a node is included in the markup tool.
    *
    * @param  {NodeFront} node
    *         The node in the content document.
    * @param  {Boolean} flashNode
@@ -1317,19 +1316,20 @@ MarkupView.prototype = {
       this._removedNodeObserver = null;
 
       // Don't select the new node if the user has already changed the current
       // selection.
       if (this.inspector.selection.nodeFront === parentContainer.node ||
           (this.inspector.selection.nodeFront === removedNode && isHTMLTag)) {
         let childContainers = parentContainer.getChildContainers();
         if (childContainers && childContainers[childIndex]) {
-          this.markNodeAsSelected(childContainers[childIndex].node, reason);
-          if (childContainers[childIndex].hasChildren) {
-            this.expandNode(childContainers[childIndex].node);
+          let childContainer = childContainers[childIndex];
+          this._markContainerAsSelected(childContainer, reason);
+          if (childContainer.hasChildren) {
+            this.expandNode(childContainer.node);
           }
           this.emit("reselectedonremoved");
         }
       }
     };
 
     // Start listening for mutations until we find a childList change that has
     // removedNode removed.
@@ -1502,21 +1502,26 @@ MarkupView.prototype = {
    *         The NodeFront to mark as selected.
    * @param  {String} reason
    *         The reason for marking the node as selected.
    * @return {Boolean} False if the node is already marked as selected, true
    *         otherwise.
    */
   markNodeAsSelected: function(node, reason = "nodeselected") {
     let container = this.getContainer(node);
+    return this._markContainerAsSelected(container);
+  },
 
-    if (this._selectedContainer === container) {
+  _markContainerAsSelected: function(container, reason) {
+    if (!container || this._selectedContainer === container) {
       return false;
     }
 
+    let { node } = container;
+
     // Un-select and remove focus from the previous container.
     if (this._selectedContainer) {
       this._selectedContainer.selected = false;
       this._selectedContainer.clearFocus();
     }
 
     // Select the new container.
     this._selectedContainer = container;