mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
refactor(layout_2020): add depth
parameter to the closure passed to FragmentTree::find
This commit is contained in:
parent
98cffa3d16
commit
638941ac43
3 changed files with 19 additions and 16 deletions
|
@ -437,17 +437,17 @@ impl FragmentTree {
|
||||||
|
|
||||||
pub(crate) fn find<T>(
|
pub(crate) fn find<T>(
|
||||||
&self,
|
&self,
|
||||||
mut process_func: impl FnMut(&Fragment, &PhysicalRect<Length>) -> Option<T>,
|
mut process_func: impl FnMut(&Fragment, usize, &PhysicalRect<Length>) -> Option<T>,
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
self.root_fragments.iter().find_map(|child| {
|
self.root_fragments.iter().find_map(|child| {
|
||||||
child
|
child
|
||||||
.borrow()
|
.borrow()
|
||||||
.find(&self.initial_containing_block, &mut process_func)
|
.find(&self.initial_containing_block, 0, &mut process_func)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_nodes_in_fragment_tree_from_set(&self, set: &mut FxHashSet<AnimationSetKey>) {
|
pub fn remove_nodes_in_fragment_tree_from_set(&self, set: &mut FxHashSet<AnimationSetKey>) {
|
||||||
self.find(|fragment, _| {
|
self.find(|fragment, _, _| {
|
||||||
let (node, pseudo) = match fragment.tag()? {
|
let (node, pseudo) = match fragment.tag()? {
|
||||||
Tag::Node(node) => (node, None),
|
Tag::Node(node) => (node, None),
|
||||||
Tag::BeforePseudo(node) => (node, Some(PseudoElement::Before)),
|
Tag::BeforePseudo(node) => (node, Some(PseudoElement::Before)),
|
||||||
|
@ -461,7 +461,7 @@ impl FragmentTree {
|
||||||
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> {
|
||||||
let mut bounding_box = PhysicalRect::zero();
|
let mut bounding_box = PhysicalRect::zero();
|
||||||
let tag_to_find = Tag::Node(requested_node);
|
let tag_to_find = Tag::Node(requested_node);
|
||||||
self.find(|fragment, containing_block| {
|
self.find(|fragment, _, containing_block| {
|
||||||
if fragment.tag() != Some(tag_to_find) {
|
if fragment.tag() != Some(tag_to_find) {
|
||||||
return None::<()>;
|
return None::<()>;
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ impl FragmentTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_border_dimensions_for_node(&self, requested_node: OpaqueNode) -> Rect<i32> {
|
pub fn get_border_dimensions_for_node(&self, requested_node: OpaqueNode) -> Rect<i32> {
|
||||||
self.find(|fragment, containing_block| {
|
self.find(|fragment, _, containing_block| {
|
||||||
let (style, padding_rect) = match fragment {
|
let (style, padding_rect) = match fragment {
|
||||||
Fragment::Box(fragment) if fragment.tag.node() == requested_node => {
|
Fragment::Box(fragment) if fragment.tag.node() == requested_node => {
|
||||||
(&fragment.style, fragment.padding_rect())
|
(&fragment.style, fragment.padding_rect())
|
||||||
|
|
|
@ -227,9 +227,10 @@ impl Fragment {
|
||||||
pub(crate) fn find<T>(
|
pub(crate) fn find<T>(
|
||||||
&self,
|
&self,
|
||||||
containing_block: &PhysicalRect<Length>,
|
containing_block: &PhysicalRect<Length>,
|
||||||
process_func: &mut impl FnMut(&Fragment, &PhysicalRect<Length>) -> Option<T>,
|
level: usize,
|
||||||
|
process_func: &mut impl FnMut(&Fragment, usize, &PhysicalRect<Length>) -> Option<T>,
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
if let Some(result) = process_func(self, containing_block) {
|
if let Some(result) = process_func(self, level, containing_block) {
|
||||||
return Some(result);
|
return Some(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,20 +240,22 @@ impl 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());
|
||||||
fragment
|
fragment.children.iter().find_map(|child| {
|
||||||
.children
|
child
|
||||||
.iter()
|
.borrow()
|
||||||
.find_map(|child| child.borrow().find(&new_containing_block, process_func))
|
.find(&new_containing_block, level + 1, process_func)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
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());
|
||||||
fragment
|
fragment.children.iter().find_map(|child| {
|
||||||
.children
|
child
|
||||||
.iter()
|
.borrow()
|
||||||
.find_map(|child| child.borrow().find(&new_containing_block, process_func))
|
.find(&new_containing_block, level + 1, process_func)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,7 +299,7 @@ pub fn process_resolved_style_request<'dom>(
|
||||||
None => return computed_style(),
|
None => return computed_style(),
|
||||||
};
|
};
|
||||||
fragment_tree
|
fragment_tree
|
||||||
.find(|fragment, containing_block| {
|
.find(|fragment, _, containing_block| {
|
||||||
let box_fragment = match fragment {
|
let box_fragment = match fragment {
|
||||||
Fragment::Box(ref box_fragment) if box_fragment.tag == tag_to_find => box_fragment,
|
Fragment::Box(ref box_fragment) if box_fragment.tag == tag_to_find => box_fragment,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue