aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/fragments.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-03-26 10:23:23 -0400
committerGitHub <noreply@github.com>2020-03-26 10:23:23 -0400
commit4dbe3b30cd62013f7a8f231b733f1eef3fd80b33 (patch)
tree0a02b6aa0b34819a909dbf360a0a0f2b6ac1e145 /components/layout_2020/fragments.rs
parent0ed0c0d9f01ac5ae906d5b7842aa79c70b119adc (diff)
parent7cb0069be5ede3fd6d2d50e093d5813032e123ed (diff)
downloadservo-4dbe3b30cd62013f7a8f231b733f1eef3fd80b33.tar.gz
servo-4dbe3b30cd62013f7a8f231b733f1eef3fd80b33.zip
Auto merge of #26037 - mrobinson:arcrefcell-fragment-tree, r=SimonSapin
layout_2020: Use ArcRefCell in the fragment tree This will allow mutability which is useful for things like animations. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because they should not change behavior. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/layout_2020/fragments.rs')
-rw-r--r--components/layout_2020/fragments.rs53
1 files changed, 47 insertions, 6 deletions
diff --git a/components/layout_2020/fragments.rs b/components/layout_2020/fragments.rs
index c3c76a975d6..72e6549c7be 100644
--- a/components/layout_2020/fragments.rs
+++ b/components/layout_2020/fragments.rs
@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+use crate::cell::ArcRefCell;
use crate::geom::flow_relative::{Rect, Sides};
use crate::geom::{PhysicalPoint, PhysicalRect};
#[cfg(debug_assertions)]
@@ -41,7 +42,7 @@ pub(crate) struct BoxFragment {
pub debug_id: DebugId,
#[serde(skip_serializing)]
pub style: ServoArc<ComputedValues>,
- pub children: Vec<Fragment>,
+ pub children: Vec<ArcRefCell<Fragment>>,
/// From the containing block’s start corner…?
/// This might be broken when the containing block is in a different writing mode:
@@ -81,7 +82,7 @@ pub(crate) struct CollapsedMargin {
pub(crate) struct AnonymousFragment {
pub debug_id: DebugId,
pub rect: Rect<Length>,
- pub children: Vec<Fragment>,
+ pub children: Vec<ArcRefCell<Fragment>>,
pub mode: WritingMode,
/// The scrollable overflow of this anonymous fragment's children.
@@ -189,6 +190,40 @@ impl Fragment {
_ => None,
}
}
+
+ pub(crate) fn find<T>(
+ &self,
+ containing_block: &PhysicalRect<Length>,
+ process_func: &mut impl FnMut(&Fragment, &PhysicalRect<Length>) -> Option<T>,
+ ) -> Option<T> {
+ if let Some(result) = process_func(self, containing_block) {
+ return Some(result);
+ }
+
+ match self {
+ Fragment::Box(fragment) => {
+ let new_containing_block = fragment
+ .content_rect
+ .to_physical(fragment.style.writing_mode, containing_block)
+ .translate(containing_block.origin.to_vector());
+ fragment
+ .children
+ .iter()
+ .find_map(|child| child.borrow().find(&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());
+ fragment
+ .children
+ .iter()
+ .find_map(|child| child.borrow().find(&new_containing_block, process_func))
+ },
+ _ => None,
+ }
+ }
}
impl AbsoluteOrFixedPositionedFragment {
@@ -223,7 +258,10 @@ impl AnonymousFragment {
AnonymousFragment {
debug_id: DebugId::new(),
rect,
- children,
+ children: children
+ .into_iter()
+ .map(|fragment| ArcRefCell::new(fragment))
+ .collect(),
mode,
scrollable_overflow,
}
@@ -238,7 +276,7 @@ impl AnonymousFragment {
));
for child in &self.children {
- child.print(tree);
+ child.borrow().print(tree);
}
tree.end_level();
}
@@ -267,7 +305,10 @@ impl BoxFragment {
tag,
debug_id: DebugId::new(),
style,
- children,
+ children: children
+ .into_iter()
+ .map(|fragment| ArcRefCell::new(fragment))
+ .collect(),
content_rect,
padding,
border,
@@ -326,7 +367,7 @@ impl BoxFragment {
));
for child in &self.children {
- child.print(tree);
+ child.borrow().print(tree);
}
tree.end_level();
}