mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Filter non-element / non-text nodes in LayoutIterator.
This commit is contained in:
parent
4aa3e589c0
commit
63124bab66
2 changed files with 15 additions and 1 deletions
|
@ -734,9 +734,14 @@ impl<'ln> NodeInfo for ServoThreadSafeLayoutNode<'ln> {
|
||||||
fn is_element(&self) -> bool {
|
fn is_element(&self) -> bool {
|
||||||
if let Some(LayoutNodeType::Element(_)) = self.type_id() { true } else { false }
|
if let Some(LayoutNodeType::Element(_)) = self.type_id() { true } else { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_text_node(&self) -> bool {
|
fn is_text_node(&self) -> bool {
|
||||||
if let Some(LayoutNodeType::Text) = self.type_id() { true } else { false }
|
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> {
|
impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
||||||
|
|
|
@ -71,13 +71,22 @@ pub trait TRestyleDamage : Debug + PartialEq + BitOr<Output=Self> + Copy {
|
||||||
pub trait NodeInfo {
|
pub trait NodeInfo {
|
||||||
fn is_element(&self) -> bool;
|
fn is_element(&self) -> bool;
|
||||||
fn is_text_node(&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);
|
pub struct LayoutIterator<T>(pub T);
|
||||||
impl<T, I> Iterator for LayoutIterator<T> where T: Iterator<Item=I>, I: NodeInfo {
|
impl<T, I> Iterator for LayoutIterator<T> where T: Iterator<Item=I>, I: NodeInfo {
|
||||||
type Item = I;
|
type Item = I;
|
||||||
fn next(&mut self) -> Option<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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue