diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index ea22a85c5c5..19e6c7c4e79 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -734,9 +734,14 @@ impl<'ln> NodeInfo for ServoThreadSafeLayoutNode<'ln> { fn is_element(&self) -> bool { if let Some(LayoutNodeType::Element(_)) = self.type_id() { true } else { false } } + fn is_text_node(&self) -> bool { if let Some(LayoutNodeType::Text) = self.type_id() { true } else { false } } + + fn needs_layout(&self) -> bool { + self.pseudo != PseudoElementType::Normal || self.is_element() || self.is_text_node() + } } impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { diff --git a/components/style/dom.rs b/components/style/dom.rs index 38e40c1409a..ec18ae65db6 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -71,13 +71,22 @@ pub trait TRestyleDamage : Debug + PartialEq + BitOr + Copy { pub trait NodeInfo { fn is_element(&self) -> bool; fn is_text_node(&self) -> bool; + + // Comments, doctypes, etc are ignored by layout algorithms. + fn needs_layout(&self) -> bool { self.is_element() || self.is_text_node() } } pub struct LayoutIterator(pub T); impl Iterator for LayoutIterator where T: Iterator, I: NodeInfo { type Item = I; fn next(&mut self) -> Option { - self.0.next() + loop { + // Filter out nodes that layout should ignore. + let n = self.0.next(); + if n.is_none() || n.as_ref().unwrap().needs_layout() { + return n + } + } } }