Deduplicate the loop in iterate_through_fragments

This commit is contained in:
Simon Sapin 2020-02-10 17:44:57 +01:00
parent ef8c51c4b1
commit d353e08529

View file

@ -204,52 +204,44 @@ impl FragmentTreeRoot {
where where
F: FnMut(&Fragment, &PhysicalRect<Length>) -> bool, F: FnMut(&Fragment, &PhysicalRect<Length>) -> bool,
{ {
fn do_iteration<M>( fn recur<M>(
fragment: &Fragment, fragments: &[Fragment],
containing_block: &PhysicalRect<Length>, containing_block: &PhysicalRect<Length>,
process_func: &mut M, process_func: &mut M,
) -> bool ) -> bool
where where
M: FnMut(&Fragment, &PhysicalRect<Length>) -> bool, M: FnMut(&Fragment, &PhysicalRect<Length>) -> bool,
{ {
if !process_func(fragment, containing_block) { for fragment in fragments {
return false; if !process_func(fragment, containing_block) {
} return false;
}
match fragment { match fragment {
Fragment::Box(fragment) => { Fragment::Box(fragment) => {
let new_containing_block = fragment let new_containing_block = fragment
.content_rect .content_rect
.to_physical(fragment.style.writing_mode, containing_block) .to_physical(fragment.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector()); .translate(containing_block.origin.to_vector());
for child in &fragment.children { if !recur(&fragment.children, &new_containing_block, process_func) {
if !do_iteration(child, &new_containing_block, process_func) {
return false; return false;
} }
} },
}, Fragment::Anonymous(fragment) => {
Fragment::Anonymous(fragment) => { let new_containing_block = fragment
let new_containing_block = fragment .rect
.rect .to_physical(fragment.mode, containing_block)
.to_physical(fragment.mode, containing_block) .translate(containing_block.origin.to_vector());
.translate(containing_block.origin.to_vector()); if !recur(&fragment.children, &new_containing_block, process_func) {
for child in &fragment.children {
if !do_iteration(child, &new_containing_block, process_func) {
return false; return false;
} }
} },
}, _ => {},
_ => {}, }
} }
true true
} }
recur(&self.children, &self.initial_containing_block, process_func);
for child in &self.children {
if !do_iteration(child, &self.initial_containing_block, process_func) {
break;
}
}
} }
pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect<Au> { pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect<Au> {