Bug 1053898 - Get correct parent node for first level light tree element draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 05 Feb 2018 10:17:34 +0100
changeset 753084 c709e7e59a2c05362b4beb9409658e9e62a44a21
parent 753083 a65b3341de576bb9d36c645c0640980a70942a6b
child 753085 09f809168baec375910182513e799bbcc13f898a
push id98478
push userjdescottes@mozilla.com
push dateFri, 09 Feb 2018 16:32:07 +0000
bugs1053898
milestone60.0a1
Bug 1053898 - Get correct parent node for first level light tree element MozReview-Commit-ID: 32dQykTwGHF
devtools/client/inspector/markup/views/read-only-editor.js
devtools/server/actors/inspector/node-actor.js
devtools/server/actors/inspector/shadow-node-actor.js
devtools/server/actors/inspector/walker-actor.js
devtools/shared/fronts/node.js
--- a/devtools/client/inspector/markup/views/read-only-editor.js
+++ b/devtools/client/inspector/markup/views/read-only-editor.js
@@ -15,16 +15,18 @@ function ReadOnlyEditor(container, node)
   this.buildMarkup();
 
   if (node.isPseudoElement) {
     this.tag.classList.add("theme-fg-color5");
     this.tag.textContent = node.isBeforePseudoElement ? "::before" : "::after";
   } else if (node.nodeType == nodeConstants.DOCUMENT_TYPE_NODE) {
     this.elt.classList.add("comment", "doctype");
     this.tag.textContent = node.doctypeString;
+  } else if (node.isShadowRoot) {
+    this.tag.textContent = "#shadow-root";
   } else {
     this.tag.textContent = node.nodeName;
   }
 
   // Make the "tag" part of this editor focusable.
   this.tag.setAttribute("tabindex", "-1");
 }
 
--- a/devtools/server/actors/inspector/node-actor.js
+++ b/devtools/server/actors/inspector/node-actor.js
@@ -107,16 +107,18 @@ const NodeActor = protocol.ActorClassWit
       name: this.rawNode.name,
       publicId: this.rawNode.publicId,
       systemId: this.rawNode.systemId,
 
       attrs: this.writeAttrs(),
       isBeforePseudoElement: this.isBeforePseudoElement,
       isAfterPseudoElement: this.isAfterPseudoElement,
       isAnonymous: isAnonymous(this.rawNode),
+      isShadowRoot: !!this.rawNode.host,
+      isShadowNode: false,
       isNativeAnonymous: isNativeAnonymous(this.rawNode),
       isXBLAnonymous: isXBLAnonymous(this.rawNode),
       isShadowAnonymous: isShadowAnonymous(this.rawNode),
       pseudoClassLocks: this.writePseudoClassLocks(),
 
       isDisplayed: this.isDisplayed,
       isInHTMLDocument: this.rawNode.ownerDocument &&
         this.rawNode.ownerDocument.contentType === "text/html",
--- a/devtools/server/actors/inspector/shadow-node-actor.js
+++ b/devtools/server/actors/inspector/shadow-node-actor.js
@@ -39,16 +39,17 @@ const ShadowNodeActor = protocol.ActorCl
       return this.actorID;
     }
 
     let form = this.nodeActor.form();
     form.actor = this.actorID;
     form.nodeActor = this.nodeActor.actorID;
     form.numChildren = 0;
     form.inlineTextChild = undefined;
+    form.isShadowNode = true;
 
     return form;
   },
 
   watchDocument: function () {
     // no-op
   },
 
--- a/devtools/server/actors/inspector/walker-actor.js
+++ b/devtools/server/actors/inspector/walker-actor.js
@@ -463,17 +463,23 @@ var WalkerActor = protocol.ActorClassWit
 
       parents.push(this._ref(cur));
     }
     return parents;
   },
 
   parentNode: function (node) {
     try {
-      let walker = this.getDocumentWalker(node.rawNode);
+      let walker;
+      if (node.rawNode && node.rawNode.parentNode &&
+          node.rawNode.parentNode.shadowRoot && !node.nodeActor) {
+        walker = this.getDocumentWalker(node.rawNode, {showAnonymousContent: false});
+      } else {
+        walker = this.getDocumentWalker(node.rawNode);
+      }
       let parent = walker.parentNode();
       if (parent) {
         return this._ref(parent);
       }
     } catch (e) {
       dump("CAUGHT ERROR\n");
     }
     return null;
--- a/devtools/shared/fronts/node.js
+++ b/devtools/shared/fronts/node.js
@@ -267,16 +267,22 @@ const NodeFront = FrontClassWithSpec(nod
   },
   get numChildren() {
     return this._form.numChildren;
   },
   get hasEventListeners() {
     return this._form.hasEventListeners;
   },
 
+  get isShadowRoot() {
+    return this._form.isShadowRoot;
+  },
+  get isShadowNode() {
+    return this._form.isShadowNode;
+  },
   get isBeforePseudoElement() {
     return this._form.isBeforePseudoElement;
   },
   get isAfterPseudoElement() {
     return this._form.isAfterPseudoElement;
   },
   get isPseudoElement() {
     return this.isBeforePseudoElement || this.isAfterPseudoElement;