mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Deduplicate the loop in iterate_through_fragments
This commit is contained in:
parent
ef8c51c4b1
commit
d353e08529
1 changed files with 24 additions and 32 deletions
|
@ -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> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue