From ccf8a436490992d01ad4bd99e79a2b4e2e649361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 4 Mar 2019 14:22:52 +0100 Subject: [PATCH] Document owner_shadow_root --- components/script/dom/node.rs | 10 +++++++--- components/script/dom/shadowroot.rs | 7 +++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 7c50e4ae69d..22e157f3132 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -125,6 +125,8 @@ pub struct Node { owner_doc: MutNullableDom, /// The shadow root this node belongs to. + /// This is None if the node is not in a shadow tree or + /// if it is a ShadowRoot. owner_shadow_root: MutNullableDom, /// The live list of children return by .childNodes. @@ -284,11 +286,10 @@ impl Node { for node in new_child.traverse_preorder(ShadowIncluding::No) { if parent_in_shadow_tree { - if let Some(shadow_root) = self.downcast::() { - node.set_owner_shadow_root(&*shadow_root); - } else if let Some(shadow_root) = self.owner_shadow_root() { + if let Some(shadow_root) = self.owner_shadow_root() { node.set_owner_shadow_root(&*shadow_root); } + debug_assert!(node.owner_shadow_root().is_some()); } node.set_flag(NodeFlags::IS_IN_DOC, parent_in_doc); node.set_flag(NodeFlags::IS_IN_SHADOW_TREE, parent_in_shadow_tree); @@ -930,6 +931,9 @@ impl Node { } pub fn owner_shadow_root(&self) -> Option> { + if let Some(ref shadow_root) = self.downcast::() { + return Some(DomRoot::from_ref(shadow_root)); + } self.owner_shadow_root.get() } diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index fb38c5531c6..078c937d701 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -44,10 +44,9 @@ impl ShadowRoot { #[allow(unrooted_must_root)] fn new_inherited(host: &Element, document: &Document) -> ShadowRoot { let document_fragment = DocumentFragment::new_inherited(document); - document_fragment - .upcast::() - .set_flag(NodeFlags::IS_IN_SHADOW_TREE, true); - document_fragment.upcast::().set_flag( + let node = document_fragment.upcast::(); + node.set_flag(NodeFlags::IS_IN_SHADOW_TREE, true); + node.set_flag( NodeFlags::IS_CONNECTED, host.upcast::().is_connected(), );