From 59c634b259f3b481a228c50b32dc8e68c013a609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Sat, 23 Mar 2019 06:39:38 +0100 Subject: [PATCH] Set dirty descendants if node is connected --- components/layout_thread/dom_wrapper.rs | 2 +- components/script/dom/document.rs | 2 +- components/script/dom/node.rs | 22 ++++++++-------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 58f3ed7327e..9b0f2f67131 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -569,7 +569,7 @@ impl<'le> TElement for ServoLayoutElement<'le> { } unsafe fn set_dirty_descendants(&self) { - debug_assert!(self.as_node().is_in_document()); + debug_assert!(self.as_node().is_connected()); self.as_node() .node .set_flag(NodeFlags::HAS_DIRTY_DESCENDANTS, true) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a54ffcd8cf5..21144f79a67 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -645,7 +645,7 @@ impl Document { } pub fn content_and_heritage_changed(&self, node: &Node) { - if node.is_in_doc() { + if node.is_connected() { node.note_dirty_descendants(); } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 3238727267e..d3ef77696ce 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -572,7 +572,7 @@ impl Node { // FIXME(emilio): This and the function below should move to Element. pub fn note_dirty_descendants(&self) { - debug_assert!(self.is_in_doc()); + debug_assert!(self.is_connected()); for ancestor in self.inclusive_ancestors(ShadowIncluding::Yes) { if ancestor.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS) { @@ -611,11 +611,15 @@ impl Node { match self.type_id() { NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => { - if let Some(parent) = self.composed_parent_node() { - parent.downcast::().unwrap().restyle(damage) - } + self.parent_node.get().unwrap().dirty(damage) }, NodeTypeId::Element(_) => self.downcast::().unwrap().restyle(damage), + NodeTypeId::DocumentFragment(DocumentFragmentTypeId::ShadowRoot) => self + .downcast::() + .unwrap() + .Host() + .upcast::() + .restyle(damage), _ => {}, }; } @@ -965,16 +969,6 @@ impl Node { self.is_connected() && self.owner_doc().browsing_context().is_some() } - fn composed_parent_node(&self) -> Option> { - let parent = self.parent_node.get(); - if let Some(ref parent) = parent { - if let Some(shadow_root) = parent.downcast::() { - return Some(DomRoot::from_ref(shadow_root.Host().upcast::())); - } - } - parent - } - pub fn children(&self) -> impl Iterator> { SimpleNodeIterator { current: self.GetFirstChild(),