diff options
author | Ms2ger <ms2ger@gmail.com> | 2015-07-17 23:08:54 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2015-07-21 19:53:34 +0200 |
commit | 930e1117139f5c7da2eda5c70f8c07a1b455048c (patch) | |
tree | ce14208886888378803becf187a20f24e3240a04 | |
parent | b3892b74f7367c67603eff049454b3e9135f8d78 (diff) | |
download | servo-930e1117139f5c7da2eda5c70f8c07a1b455048c.tar.gz servo-930e1117139f5c7da2eda5c70f8c07a1b455048c.zip |
Scope ThreadSafeLayoutNode::first_child to ThreadSafeLayoutNodeChildrenIterator::new.
It is only used there.
-rw-r--r-- | components/layout/wrapper.rs | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 5d75b7a29fb..33414f64673 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -656,26 +656,9 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { self.node.flow_debug_id() } - fn first_child(&self) -> Option<ThreadSafeLayoutNode<'ln>> { - if self.pseudo != PseudoElementType::Normal { - return None - } - - if self.has_before_pseudo() { - return Some(self.with_pseudo(PseudoElementType::Before(self.get_before_display()))); - } - - unsafe { - self.get_jsmanaged().first_child_ref().map(|node| self.new_with_this_lifetime(&node)) - } - } - /// Returns an iterator over this node's children. pub fn children(&self) -> ThreadSafeLayoutNodeChildrenIterator<'ln> { - ThreadSafeLayoutNodeChildrenIterator { - current_node: self.first_child(), - parent_node: self.clone(), - } + ThreadSafeLayoutNodeChildrenIterator::new(*self) } /// If this is an element, accesses the element data. Fails if this is not an element node. @@ -961,6 +944,32 @@ pub struct ThreadSafeLayoutNodeChildrenIterator<'a> { parent_node: ThreadSafeLayoutNode<'a>, } +impl<'a> ThreadSafeLayoutNodeChildrenIterator<'a> { + fn new(parent: ThreadSafeLayoutNode<'a>) -> ThreadSafeLayoutNodeChildrenIterator<'a> { + fn first_child<'a>(parent: ThreadSafeLayoutNode<'a>) + -> Option<ThreadSafeLayoutNode<'a>> { + if parent.pseudo != PseudoElementType::Normal { + return None + } + + if parent.has_before_pseudo() { + let pseudo = PseudoElementType::Before(parent.get_before_display()); + return Some(parent.with_pseudo(pseudo)); + } + + unsafe { + parent.get_jsmanaged().first_child_ref() + .map(|node| parent.new_with_this_lifetime(&node)) + } + } + + ThreadSafeLayoutNodeChildrenIterator { + current_node: first_child(parent), + parent_node: parent, + } + } +} + impl<'a> Iterator for ThreadSafeLayoutNodeChildrenIterator<'a> { type Item = ThreadSafeLayoutNode<'a>; fn next(&mut self) -> Option<ThreadSafeLayoutNode<'a>> { |