Skip to content

Commit

Permalink
Filter non-element / non-text nodes in LayoutIterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
bholley committed Sep 21, 2016
1 parent 4aa3e58 commit 63124ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions components/script/layout_wrapper.rs
Expand Up @@ -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> {
Expand Down
11 changes: 10 additions & 1 deletion components/style/dom.rs
Expand Up @@ -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
}
}
}
}

Expand Down

0 comments on commit 63124ba

Please sign in to comment.