aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2016-09-20 17:36:17 -0700
committerBobby Holley <bobbyholley@gmail.com>2016-09-21 11:43:52 -0700
commit63124bab66b945dea16ece366a790a693c38a452 (patch)
tree3f29505b62f62fdaebf3800f0056f1a3bd5244c3
parent4aa3e589c047f006fa37c25e5bf1ba1e1b69b8e4 (diff)
downloadservo-63124bab66b945dea16ece366a790a693c38a452.tar.gz
servo-63124bab66b945dea16ece366a790a693c38a452.zip
Filter non-element / non-text nodes in LayoutIterator.
-rw-r--r--components/script/layout_wrapper.rs5
-rw-r--r--components/style/dom.rs11
2 files changed, 15 insertions, 1 deletions
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<Output=Self> + 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<T>(pub T);
impl<T, I> Iterator for LayoutIterator<T> where T: Iterator<Item=I>, I: NodeInfo {
type Item = I;
fn next(&mut self) -> Option<I> {
- 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
+ }
+ }
}
}