diff options
author | Martin Robinson <mrobinson@igalia.com> | 2020-03-25 10:08:13 +0100 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2020-03-25 17:57:17 +0100 |
commit | 7cb0069be5ede3fd6d2d50e093d5813032e123ed (patch) | |
tree | dd23e25b8ea726ab1d072a499736945fb0767853 /components/layout_2020/flow/root.rs | |
parent | 07f6d783a3c553d6e61170767883b2f5d80a8fbd (diff) | |
download | servo-7cb0069be5ede3fd6d2d50e093d5813032e123ed.tar.gz servo-7cb0069be5ede3fd6d2d50e093d5813032e123ed.zip |
layout_2020: Use ArcRefCell in the fragment tree
This will allow mutability which is useful for things like animations.
Diffstat (limited to 'components/layout_2020/flow/root.rs')
-rw-r--r-- | components/layout_2020/flow/root.rs | 61 |
1 files changed, 14 insertions, 47 deletions
diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index 6a8be578630..46db5d4b7d8 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -38,7 +38,7 @@ pub struct BoxTreeRoot(BlockFormattingContext); #[derive(Serialize)] pub struct FragmentTreeRoot { /// The children of the root of the fragment tree. - children: Vec<Fragment>, + children: Vec<ArcRefCell<Fragment>>, /// The scrollable overflow of the root of the fragment tree. scrollable_overflow: PhysicalRect<Length>, @@ -182,7 +182,11 @@ impl BoxTreeRoot { }); FragmentTreeRoot { - children: independent_layout.fragments, + children: independent_layout + .fragments + .into_iter() + .map(|fragment| ArcRefCell::new(fragment)) + .collect(), scrollable_overflow, initial_containing_block: physical_containing_block, } @@ -205,7 +209,8 @@ impl FragmentTreeRoot { }; for fragment in &self.children { - fragment.build_stacking_context_tree( + fragment.borrow().build_stacking_context_tree( + fragment, &mut stacking_context_builder, &containing_block_info, &mut stacking_context, @@ -221,7 +226,7 @@ impl FragmentTreeRoot { pub fn print(&self) { let mut print_tree = PrintTree::new("Fragment Tree".to_string()); for fragment in &self.children { - fragment.print(&mut print_tree); + fragment.borrow().print(&mut print_tree); } } @@ -236,49 +241,11 @@ impl FragmentTreeRoot { &self, mut process_func: impl FnMut(&Fragment, &PhysicalRect<Length>) -> Option<T>, ) -> Option<T> { - fn recur<T>( - fragments: &[Fragment], - containing_block: &PhysicalRect<Length>, - process_func: &mut impl FnMut(&Fragment, &PhysicalRect<Length>) -> Option<T>, - ) -> Option<T> { - for fragment in fragments { - if let Some(result) = process_func(fragment, containing_block) { - return Some(result); - } - - 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 let Some(result) = - recur(&fragment.children, &new_containing_block, process_func) - { - return Some(result); - } - }, - Fragment::Anonymous(fragment) => { - let new_containing_block = fragment - .rect - .to_physical(fragment.mode, containing_block) - .translate(containing_block.origin.to_vector()); - if let Some(result) = - recur(&fragment.children, &new_containing_block, process_func) - { - return Some(result); - } - }, - _ => {}, - } - } - None - } - recur( - &self.children, - &self.initial_containing_block, - &mut process_func, - ) + self.children.iter().find_map(|child| { + child + .borrow() + .find(&self.initial_containing_block, &mut process_func) + }) } pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect<Au> { |