aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flexbox/layout.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-04-18 11:40:29 +0200
committerGitHub <noreply@github.com>2025-04-18 09:40:29 +0000
commit2ee8427665099987f715296d4d55b6388a480c08 (patch)
treea1c3595c8f6837abfcd01c729c2d8edcead26327 /components/layout_2020/flexbox/layout.rs
parentfc201927ae5bdf26f842f9d4e6e52c2255adcde2 (diff)
downloadservo-2ee8427665099987f715296d4d55b6388a480c08.tar.gz
servo-2ee8427665099987f715296d4d55b6388a480c08.zip
layout: Store `Fragment` results in `LayoutBoxBase` and start using them for queries (#36583)
Start storing a link to laid-out `Fragment`s in `LayoutBoxBase`, so that these are accessible for queries and eventually for incremental layout. Some box tree data structures lacked a `LayoutBoxBase`, such as table tracks and table track groups[^1]. In addition, start using these `Fragment`s for queries instead of walking the entire `Fragment` tree. Currently, this isn't possible for most queries as `Fragment`s do not cache their absolute offsets (which are often necessary). This change uses the new box tree `Fragment`s for most resolved style queries. [^1]: Note that only rows and row groups store `Fragment`s as columsn and colgroups do not produce any. Testing: This is covered by existing tests. Fixes: This is part of #36525. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components/layout_2020/flexbox/layout.rs')
-rw-r--r--components/layout_2020/flexbox/layout.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index 34904ae1053..77069236787 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -214,7 +214,7 @@ impl FlexLineItem<'_> {
flex_context: &mut FlexContext,
all_baselines: &mut Baselines,
main_position_cursor: &mut Au,
- ) -> (BoxFragment, PositioningContext) {
+ ) -> (ArcRefCell<BoxFragment>, PositioningContext) {
// https://drafts.csswg.org/css-flexbox/#algo-main-align
// “Align the items along the main-axis”
*main_position_cursor +=
@@ -312,6 +312,12 @@ impl FlexLineItem<'_> {
.to_physical_size(containing_block.style.writing_mode)
}
+ let fragment = ArcRefCell::new(fragment);
+ self.item
+ .box_
+ .independent_formatting_context
+ .base
+ .set_fragment(Fragment::Box(fragment.clone()));
(fragment, self.layout_result.positioning_context)
}
}
@@ -323,7 +329,7 @@ struct FinalFlexLineLayout {
cross_size: Au,
/// The [`BoxFragment`]s and [`PositioningContext`]s of all flex items,
/// one per flex item in "order-modified document order."
- item_fragments: Vec<(BoxFragment, PositioningContext)>,
+ item_fragments: Vec<(ArcRefCell<BoxFragment>, PositioningContext)>,
/// The 'shared alignment baseline' of this flex line. This is the baseline used for
/// baseline-aligned items if there are any, otherwise `None`.
shared_alignment_baseline: Option<Au>,
@@ -935,7 +941,7 @@ impl FlexContainer {
let physical_line_position =
flow_relative_line_position.to_physical_size(self.style.writing_mode);
for (fragment, _) in &mut final_line_layout.item_fragments {
- fragment.content_rect.origin += physical_line_position;
+ fragment.borrow_mut().content_rect.origin += physical_line_position;
}
final_line_layout.item_fragments
})
@@ -957,7 +963,7 @@ impl FlexContainer {
// per flex item, in the original order.
let (fragment, mut child_positioning_context) =
flex_item_fragments.next().unwrap();
- let fragment = Fragment::Box(ArcRefCell::new(fragment));
+ let fragment = Fragment::Box(fragment);
child_positioning_context.adjust_static_position_of_hoisted_fragments(
&fragment,
PositioningContextLength::zero(),