Bug 1053898 - support pseudo elements under shadow host draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 05 Feb 2018 15:44:34 +0100
changeset 753085 09f809168baec375910182513e799bbcc13f898a
parent 753084 c709e7e59a2c05362b4beb9409658e9e62a44a21
child 753086 e51d05bbe4264f08c637b8b737fd3282a5754e35
push id98478
push userjdescottes@mozilla.com
push dateFri, 09 Feb 2018 16:32:07 +0000
bugs1053898
milestone60.0a1
Bug 1053898 - support pseudo elements under shadow host MozReview-Commit-ID: BhuuEFyRIZ7
devtools/server/actors/inspector/walker-actor.js
--- a/devtools/server/actors/inspector/walker-actor.js
+++ b/devtools/server/actors/inspector/walker-actor.js
@@ -642,24 +642,24 @@ var WalkerActor = protocol.ActorClassWit
     if (maxNodes == -1) {
       maxNodes = Number.MAX_VALUE;
     }
 
     let isShadowHost = !!node.rawNode.shadowRoot;
 
     // We're going to create a few document walkers with the same filter,
     // make it easier.
-    let getFilteredWalker = documentWalkerNode => {
+    let getFilteredWalker = (documentWalkerNode, showAnonymousContent) => {
       let { whatToShow } = options;
       // Use SKIP_TO_SIBLING to force the walker to use a sibling of the provided node
       // in case this one is incompatible with the walker's filter function.
       return this.getDocumentWalker(documentWalkerNode, {
         whatToShow,
         skipTo: SKIP_TO_SIBLING,
-        showAnonymousContent: !isShadowHost
+        showAnonymousContent: showAnonymousContent || !isShadowHost
       });
     };
 
     // Need to know the first and last child.
     let rawNode = node.rawNode;
     let firstChild = getFilteredWalker(rawNode).firstChild();
     let lastChild = getFilteredWalker(rawNode).lastChild();
 
@@ -709,21 +709,32 @@ var WalkerActor = protocol.ActorClassWit
       }
       return this._ref(n, true);
     });
 
     if (nodes.length === 0) {
       return { hasFirst: true, hasLast: true, nodes: [] };
     }
 
-    return {
-      hasFirst: nodes[0].rawNode == firstChild,
-      hasLast: nodes[nodes.length - 1].rawNode == lastChild,
-      nodes: isShadowHost ? [this._ref(node.rawNode.shadowRoot), ...nodes] : nodes
-    };
+    let hasFirst = nodes[0].rawNode == firstChild;
+    let hasLast = nodes[nodes.length - 1].rawNode == lastChild;
+
+    if (isShadowHost) {
+      let before = this._ref(getFilteredWalker(rawNode, true).firstChild());
+      let after = this._ref(getFilteredWalker(rawNode, true).lastChild());
+      if (before.isBeforePseudoElement) {
+        nodes = [before, ...nodes];
+      }
+      if (after.isAfterPseudoElement) {
+        nodes.push(after);
+      }
+      nodes = [this._ref(node.rawNode.shadowRoot), ...nodes];
+    }
+
+    return {hasFirst, hasLast, nodes};
   },
 
   /**
    * Return siblings of the given node.  By default this method will return
    * all siblings of the node, but there are options that can restrict this
    * to a more manageable subset.
    *
    * If `start` or `center` are not specified, this method will center on the