From 1b036355ced7cd6b8195970fef07383ba3561c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 28 Jan 2019 18:12:31 +0100 Subject: [PATCH] Bind/unbind shadow host children to/from tree --- components/script/dom/element.rs | 20 ++++++++++++++++++++ components/script/dom/node.rs | 11 +++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 5d23400e745..dac2d29e51f 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -2784,6 +2784,16 @@ impl VirtualMethods for Element { return; } + if self.is_shadow_host() { + let shadow_root = self.shadow_root.get().unwrap(); + let shadow_root = shadow_root.upcast::(); + shadow_root.set_flag(NodeFlags::IS_CONNECTED, tree_connected); + for node in shadow_root.children() { + node.set_flag(NodeFlags::IS_CONNECTED, tree_connected); + node.bind_to_tree(tree_connected); + } + } + let doc = document_from_node(self); if let Some(ref value) = *self.id_attribute.borrow() { doc.register_named_element(self, value.clone()); @@ -2803,6 +2813,16 @@ impl VirtualMethods for Element { return; } + if self.is_shadow_host() { + let shadow_root = self.shadow_root.get().unwrap(); + let shadow_root = shadow_root.upcast::(); + shadow_root.set_flag(NodeFlags::IS_CONNECTED, false); + for node in shadow_root.children() { + node.set_flag(NodeFlags::IS_CONNECTED, false); + node.unbind_from_tree(context); + } + } + let doc = document_from_node(self); let fullscreen = doc.GetFullscreenElement(); if fullscreen.deref() == Some(self) { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 25a0c4625e8..1585f81693e 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -643,7 +643,8 @@ impl Node { } fn is_shadow_including_inclusive_ancestor_of(&self, node: &Node) -> bool { - node.shadow_including_inclusive_ancestors().any(|ancestor| &*ancestor == self) + node.shadow_including_inclusive_ancestors() + .any(|ancestor| &*ancestor == self) } pub fn following_siblings(&self) -> impl Iterator> { @@ -1117,7 +1118,13 @@ impl Node { return DomRoot::from_ref(&a); } - a = DomRoot::from_ref(a_root.downcast::().unwrap().Host().upcast::()); + a = DomRoot::from_ref( + a_root + .downcast::() + .unwrap() + .Host() + .upcast::(), + ); } } }