Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for some basic queries to layout_2020 #25690

Merged
merged 5 commits into from Feb 11, 2020

Deduplicate the loop in iterate_through_fragments

  • Loading branch information
SimonSapin committed Feb 11, 2020
commit d353e0852950f0e148ae1bbef41c087749cc4970
@@ -204,52 +204,44 @@ impl FragmentTreeRoot {
where
F: FnMut(&Fragment, &PhysicalRect<Length>) -> bool,
{
fn do_iteration<M>(
fragment: &Fragment,
fn recur<M>(
fragments: &[Fragment],
containing_block: &PhysicalRect<Length>,
process_func: &mut M,
) -> bool
where
M: FnMut(&Fragment, &PhysicalRect<Length>) -> bool,
{
if !process_func(fragment, containing_block) {
return false;
}

match fragment {
Fragment::Box(fragment) => {
let new_containing_block = fragment
.content_rect
.to_physical(fragment.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());
for child in &fragment.children {
if !do_iteration(child, &new_containing_block, process_func) {
for fragment in fragments {
if !process_func(fragment, containing_block) {
return false;
}

match fragment {
Fragment::Box(fragment) => {
let new_containing_block = fragment
.content_rect
.to_physical(fragment.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());
if !recur(&fragment.children, &new_containing_block, process_func) {
return false;
}
}
},
Fragment::Anonymous(fragment) => {
let new_containing_block = fragment
.rect
.to_physical(fragment.mode, containing_block)
.translate(containing_block.origin.to_vector());
for child in &fragment.children {
if !do_iteration(child, &new_containing_block, process_func) {
},
Fragment::Anonymous(fragment) => {
let new_containing_block = fragment
.rect
.to_physical(fragment.mode, containing_block)
.translate(containing_block.origin.to_vector());
if !recur(&fragment.children, &new_containing_block, process_func) {
return false;
}
}
},
_ => {},
},
_ => {},
}
}

true
}

for child in &self.children {
if !do_iteration(child, &self.initial_containing_block, process_func) {
break;
}
}
recur(&self.children, &self.initial_containing_block, process_func);
}

pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect<Au> {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.