Skip to content

Truly independent web browser

LibWeb: Return a run root's paint payload from its algorithm

Aliaksandr Kalenik9c3b8e8a0764
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 35001b84521..f3fd51a2784 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -813,9 +813,11 @@ fn lay_out_in_flow_child_ahead(pass: LayoutPass<'_>, job: InFlowChildJob) -> Opt
outcome.content_offset,
containing_block_position_in_root,
);
- let root = fragments
- .take_run_contents(&run.pass)
- .into_run_root_fragment(&run.pass, outcome.geometry);
+ let root = fragments.take_run_contents(&run.pass).into_run_root_fragment(
+ &run.pass,
+ outcome.geometry,
+ fragment_tree::PendingPayload::default(),
+ );
let entry = in_flow_block_cache::InFlowBlockEntry {
key,
validity,
@@ -1056,6 +1058,8 @@ pub(crate) struct BlockFormattingContext<'pass> {
root_lines: RefCell<used_values::LineDataState>,
column_early_breaks: RefCell<ColumnEarlyBreaks>,
multicol_automatic_content_block_size: Cell<Option<CssPixels>>,
+ /// The columns of a multi-column root, which its fragment shows.
+ multicol_layout_data: Cell<Option<std::sync::Arc<fragmentation::MulticolLayoutData>>>,
discard_block_start_margin_of_next_child: Cell<bool>,
fragmentainer_has_content: Cell<bool>,
propagated_break_values: RefCell<HashMap<(Node, bool), u8>>,
@@ -1171,7 +1175,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for BlockForma
run: &FormattingContextRun<'pass>,
input: formatting_context::AlgorithmInput<'_>,
) -> formatting_context::AlgorithmOutput {
- self.run(run, input.body_input);
+ self.lay_out_root_contents(run, input.body_input);
let laid_out_content_block_size = self.block_size_of_contents(false);
let mut result = formatting_context::ChildLayoutResult {
automatic_content_block_size: self.automatic_content_block_size(),
@@ -1184,11 +1188,25 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for BlockForma
..formatting_context::ChildLayoutResult::default()
};
let mut root_cells = input.root_cells;
+ let mut root_payload = fragment_tree::PendingPayload::default();
+ if let Some(multicol_layout_data) = self.multicol_layout_data.take() {
+ root_payload.set(fragment_tree::FcPayload::Multicol(multicol_layout_data));
+ }
+ let has_line_clamp_point = self.line_clamp_point_found.get();
+ if has_line_clamp_point || self.clamped_content_is_scrollable_overflow {
+ root_payload.line_clamp = fragment_tree::LineClampFacts {
+ has_line_clamp_point,
+ clamped_content_is_scrollable_overflow: self.clamped_content_is_scrollable_overflow,
+ };
+ }
// https://w3c.github.io/mathml-core/#layout-of-operators
// NB: An operator lays out its text in a block formatting context, unless it is drawn with a stretched or large
// glyph.
- if self.facts(run.box_).display().is_math_inside() {
- math_formatting_context::layout_operator(run, input.root_input, &mut result, &mut root_cells);
+ if self.facts(run.box_).display().is_math_inside()
+ && let Some(paint_data) =
+ math_formatting_context::layout_operator(run, input.root_input, &mut result, &mut root_cells)
+ {
+ root_payload.set(fragment_tree::FcPayload::Math(paint_data));
}
formatting_context::AlgorithmOutput {
result,
@@ -1197,6 +1215,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for BlockForma
// them.
root_lines: std::mem::take(&mut *self.root_lines.borrow_mut()),
laid_out_content_block_size: Some(laid_out_content_block_size),
+ root_payload,
}
}
}
@@ -1258,6 +1277,7 @@ impl<'pass> BlockFormattingContext<'pass> {
root_lines: RefCell::new(used_values::LineDataState::Empty),
column_early_breaks: RefCell::new(ColumnEarlyBreaks::default()),
multicol_automatic_content_block_size: Cell::new(None),
+ multicol_layout_data: Cell::new(None),
discard_block_start_margin_of_next_child: Cell::new(false),
fragmentainer_has_content: Cell::new(false),
propagated_break_values: RefCell::new(HashMap::default()),
@@ -5924,10 +5944,11 @@ impl<'pass> BlockFormattingContext<'pass> {
inline_content::InlineContent::concatenate_translated(&root_line_data_of_columns),
);
}
- let multicol_layout_data = std::sync::Arc::new(fragmentation::MulticolLayoutData { geometry, rows });
- self.run.set_fragment_payload_of(self.run.box_, || {
- fragment_tree::FcPayload::Multicol(multicol_layout_data)
- });
+ self.multicol_layout_data
+ .set(Some(std::sync::Arc::new(fragmentation::MulticolLayoutData {
+ geometry,
+ rows,
+ })));
self.multicol_automatic_content_block_size.set(Some(row_block_offset));
self.record_derived_baselines_of_root_box(baselines);
}
@@ -6396,20 +6417,6 @@ impl<'pass> BlockFormattingContext<'pass> {
summary
}
- fn run(&self, run: &FormattingContextRun<'pass>, input: LayoutInput) {
- self.lay_out_root_contents(run, input);
- let has_line_clamp_point = self.line_clamp_point_found.get();
- if has_line_clamp_point || self.clamped_content_is_scrollable_overflow {
- run.set_line_clamp_facts_of(
- self.run.box_,
- fragment_tree::LineClampFacts {
- has_line_clamp_point,
- clamped_content_is_scrollable_overflow: self.clamped_content_is_scrollable_overflow,
- },
- );
- }
- }
-
fn lay_out_root_contents(&self, run: &FormattingContextRun<'pass>, input: LayoutInput) {
let available_space = input.available_space;
if self.is_line_clamp_container && self.style(self.run.box_).max_lines() == 0 {
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 2f52ac1e5b5..5491d423b2e 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -409,6 +409,8 @@ pub(super) struct FlexFormattingContext<'pass> {
flex_items: Vec<FlexItem>,
flex_item_details: Vec<FlexItemDetails<'pass>>,
derived_baselines_of_root_box: DerivedBaselines,
+ /// The lines and items the devtools show of the container, where the run collects devtools data.
+ flex_layout_data: Option<std::sync::Arc<formatting_context::FlexLayoutData>>,
container: FlexContainerConstants<'pass>,
available_space_for_items: Option<AxisAgnosticAvailableSpace>,
available_space: Option<AvailableSpace>,
@@ -461,6 +463,10 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for FlexFormat
) -> formatting_context::AlgorithmOutput {
self.run(run, input.body_input, input.flex_self_block_size_resolution_space);
let container_cells = self.container_cells.get();
+ let mut root_payload = fragment_tree::PendingPayload::default();
+ if let Some(flex_layout_data) = self.flex_layout_data.take() {
+ root_payload.set(fragment_tree::FcPayload::Flex(flex_layout_data));
+ }
formatting_context::AlgorithmOutput::of_root(
formatting_context::ChildLayoutResult {
automatic_content_block_size: container_cells.content_block_size,
@@ -470,6 +476,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for FlexFormat
},
container_cells,
)
+ .with_root_payload(root_payload)
}
fn after_root_is_dimensioned(
@@ -486,6 +493,7 @@ impl<'pass> FlexFormattingContext<'pass> {
pub(super) fn new(run: &FormattingContextRun<'pass>, container_cells: used_values::RootInputCells) -> Self {
Self {
run: run.clone(),
+ flex_layout_data: None,
flex_lines: Vec::new(),
flex_items: Vec::new(),
flex_item_details: Vec::new(),
@@ -3440,7 +3448,7 @@ impl<'pass> FlexFormattingContext<'pass> {
}
}
- fn save_flex_layout_data(&self) {
+ fn layout_data_for_devtools(&self) -> formatting_context::FlexLayoutData {
let mut lines = Vec::with_capacity(self.flex_lines.len());
for line in &self.flex_lines {
let mut items = Vec::with_capacity(line.items.len());
@@ -3517,7 +3525,7 @@ impl<'pass> FlexFormattingContext<'pass> {
});
}
let style = self.container.style;
- let data = formatting_context::FlexLayoutData {
+ formatting_context::FlexLayoutData {
align_content: style.align_content(),
align_items: style.align_items(),
flex_direction: style.effective_flex_direction(),
@@ -3528,10 +3536,7 @@ impl<'pass> FlexFormattingContext<'pass> {
cross_axis_direction: Self::axis_direction(self.cross_axis_is_horizontal(), self.cross_axis_is_reverse())
as u8,
lines,
- };
- self.run.set_fragment_payload_of(self.run.box_, || {
- fragment_tree::FcPayload::Flex(std::sync::Arc::new(data))
- });
+ }
}
// https://drafts.csswg.org/css-sizing-4/#aspect-ratio-automatic
@@ -4167,7 +4172,7 @@ impl<'pass> FlexFormattingContext<'pass> {
self.layout_items_and_derive_baselines(run, container_cross_size_is_auto);
if self.run.collects_devtools_layout_data() {
- self.save_flex_layout_data();
+ self.flex_layout_data = Some(std::sync::Arc::new(self.layout_data_for_devtools()));
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 7419cb70ed6..e258339bbf4 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1436,32 +1436,14 @@ impl<'pass> FormattingContextRun<'pass> {
)
}
- /// Hands what the layout of `node` produced besides its geometry to the box's fragment, where this run builds
- /// fragments.
- pub(crate) fn set_fragment_payload_of(&self, node: Node, payload: impl FnOnce() -> fragment_tree::FcPayload) {
- if let Some(fragments) = self.fragments {
- fragments.update_fragment_payload_of(node, |pending| pending.set(payload()));
- }
- }
-
- pub(crate) fn update_grid_payload_of(&self, node: Node, update: impl FnOnce(&mut fragment_tree::GridPayload)) {
- if let Some(fragments) = self.fragments {
- fragments.update_fragment_payload_of(node, |pending| update(pending.grid_mut()));
- }
- }
-
+ /// Hands what the layout of `node`, a box inside the run's root, produced besides its geometry to the box's
+ /// fragment, where this run builds fragments.
pub(crate) fn update_svg_payload_of(&self, node: Node, update: impl FnOnce(&mut fragment_tree::SvgPayload)) {
if let Some(fragments) = self.fragments {
fragments.update_fragment_payload_of(node, |pending| update(pending.svg_mut()));
}
}
- pub(crate) fn set_line_clamp_facts_of(&self, node: Node, facts: fragment_tree::LineClampFacts) {
- if let Some(fragments) = self.fragments {
- fragments.update_fragment_payload_of(node, |pending| pending.line_clamp = facts);
- }
- }
-
pub(crate) fn outputs(
&self,
result: ChildLayoutResult,
@@ -1593,6 +1575,8 @@ pub(crate) struct AlgorithmOutput {
pub(crate) root_lines: used_values::LineDataState,
/// For a block container, the block size of the contents it laid out, which it aligns in its content box.
pub(crate) laid_out_content_block_size: Option<CssPixels>,
+ /// What the layout of the root hands the root's fragment besides its geometry, where the run builds fragments.
+ pub(crate) root_payload: fragment_tree::PendingPayload,
}
impl AlgorithmOutput {
@@ -1603,8 +1587,14 @@ impl AlgorithmOutput {
root_cells,
root_lines: used_values::LineDataState::Empty,
laid_out_content_block_size: None,
+ root_payload: fragment_tree::PendingPayload::default(),
}
}
+
+ /// The output with `root_payload` handed to the root's fragment.
+ pub(crate) fn with_root_payload(self, root_payload: fragment_tree::PendingPayload) -> Self {
+ Self { root_payload, ..self }
+ }
}
/// Whether the run of a root goes on to lay out the absolutely positioned boxes the root contains once the root is
@@ -2595,6 +2585,7 @@ fn lay_out_run_root_and_contents<'pass>(
root_cells: own_root_after_body,
mut root_lines,
laid_out_content_block_size,
+ root_payload,
} = if empty_root_needs_no_formatting_context_algorithm(&pass, box_, fc_type, input, request.mode) {
// An empty root context has no body output. Root sizing and finalization still
// run through the shared paths around this branch.
@@ -2802,6 +2793,7 @@ fn lay_out_run_root_and_contents<'pass>(
cells: root_cells_left_by_run,
line_data: root_line_data.clone(),
},
+ root_payload,
))
};
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 9d80d2d44b8..2642d6e1984 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -229,16 +229,6 @@ impl PendingPayload {
variant(payload).expect("the payload is of the kind just made")
}
- pub(crate) fn grid_mut(&mut self) -> &mut GridPayload {
- self.variant_mut(
- || FcPayload::Grid(GridPayload::default()),
- |payload| match payload {
- FcPayload::Grid(grid) => Some(grid),
- _ => None,
- },
- )
- }
-
pub(crate) fn svg_mut(&mut self) -> &mut SvgPayload {
self.variant_mut(
|| FcPayload::Svg(SvgPayload::default()),
@@ -1296,27 +1286,29 @@ impl PayloadsPastRun {
}
/// What a run laid out inside its root, before the root's fragment exists: the links at the top of the run's
-/// fragments, what goes past the run, and what the run's layout of its root hands the root's fragment. A normal run
-/// turns them into its root's fragment, a fragmentainer's run hands them to the run of the box it belongs to, and a
-/// whole layout pass hands its links to commit.
+/// fragments and what goes past the run. A normal run turns them into its root's fragment, a fragmentainer's run hands
+/// them to the run of the box it belongs to, and a whole layout pass hands its links to commit.
pub(crate) struct RunContents {
pub(crate) node: crate::layout::node_data::NodeSlotId,
pub(crate) scoped_descendants: Vec<PendingLink>,
pub(crate) holds_links_beside_their_sealed_containing_blocks: bool,
pub(crate) payloads_past_run: PayloadsPastRun,
- /// What the run's layout of its root hands the root's fragment.
- pub(crate) root_payload: PendingPayload,
}
impl RunContents {
- /// The root's fragment around what the run laid out inside it, showing the root's own layout `geometry`.
- pub(crate) fn into_run_root_fragment(self, pass: &LayoutPass<'_>, geometry: FragmentGeometry) -> RunRootFragment {
+ /// The root's fragment around what the run laid out inside it, showing the root's own layout `geometry` and what
+ /// the formatting context of the root handed it as `root_payload`.
+ pub(crate) fn into_run_root_fragment(
+ self,
+ pass: &LayoutPass<'_>,
+ geometry: FragmentGeometry,
+ root_payload: PendingPayload,
+ ) -> RunRootFragment {
let Self {
node,
scoped_descendants,
holds_links_beside_their_sealed_containing_blocks,
payloads_past_run,
- root_payload,
} = self;
let content_size = geometry
.cells
@@ -1465,8 +1457,6 @@ struct RunFragmentBuilderInner {
/// What the layouts of children the run laid out but never placed handed their placements, which close() links at
/// the top of the run's fragments.
children_left_unplaced: Vec<ChildLeftUnplaced>,
- /// What the run's layout of its root hands the root's fragment.
- root_payload: PendingPayload,
/// Where the run placed each box it placed so far, from the moment it places the box, before the placement drains
/// the absolutely positioned boxes the box contains.
placed_boxes: PlacedBoxes,
@@ -2088,17 +2078,18 @@ impl RunFragmentBuilder {
node: crate::layout::node_data::NodeSlotId,
update: impl FnOnce(&mut PendingPayload),
) {
+ debug_assert!(
+ node != self.root_node || self.is_entry_accumulator,
+ "a run's root takes its payload from its formatting context"
+ );
let mut inner = self.inner.borrow_mut();
- let payload = if node == self.root_node && !self.is_entry_accumulator {
- &mut inner.root_payload
- } else {
+ update(
&mut inner
.pending_fragments
.entry(node.slot_index())
.or_insert_with(|| PendingFragment::new(node))
- .payload
- };
- update(payload);
+ .payload,
+ );
}
fn merge_child_root_into_pending_fragment(
@@ -2438,7 +2429,6 @@ impl RunFragmentBuilder {
scoped_descendants: inner.top_scope_links,
holds_links_beside_their_sealed_containing_blocks: inner.holds_links_beside_their_sealed_containing_blocks,
payloads_past_run,
- root_payload: inner.root_payload,
}
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 683651b9a05..bfd7d3e3c7a 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -1106,6 +1106,8 @@ type SubgridBlockSizeMemo = std::rc::Rc<std::cell::RefCell<HashMap<SubgridBlockS
pub(crate) struct GridFormattingContext<'pass> {
run: FormattingContextRun<'pass>,
+ /// What the grid container's fragment shows of its tracks, where the run builds fragments.
+ root_payload: fragment_tree::GridPayload,
/// The cells of the grid container, in the frame its items are laid out in. The grid does not resize its container,
/// but takes it again after the run sizes the container's own box.
container_cells: Cell<used_values::RootInputCells>,
@@ -1306,6 +1308,11 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for GridFormat
input: formatting_context::AlgorithmInput<'_>,
) -> formatting_context::AlgorithmOutput {
self.run(run, input.body_input);
+ let mut root_payload = fragment_tree::PendingPayload::default();
+ let grid_payload = std::mem::take(&mut self.root_payload);
+ if grid_payload.layout_data.is_some() || grid_payload.used_tracks.is_some() {
+ root_payload.set(fragment_tree::FcPayload::Grid(grid_payload));
+ }
formatting_context::AlgorithmOutput::of_root(
formatting_context::ChildLayoutResult {
automatic_content_block_size: self.automatic_content_block_size(),
@@ -1315,6 +1322,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for GridFormat
},
input.root_cells,
)
+ .with_root_payload(root_payload)
}
fn after_root_is_dimensioned(
@@ -1339,6 +1347,7 @@ impl<'pass> GridFormattingContext<'pass> {
run: run.clone(),
container_cells: Cell::new(container_cells),
container_constraints_for_cells: Cell::new(None),
+ root_payload: fragment_tree::GridPayload::default(),
derived_baselines_of_root_box: DerivedBaselines::default(),
container_style,
parent_grid: subgrid_parent.map(|parent| parent.grid.clone()),
@@ -5302,12 +5311,12 @@ impl<'pass> GridFormattingContext<'pass> {
}
}
- fn save_used_tracks(&self, grid_style: &GridValues) {
+ fn used_tracks(&self, grid_style: &GridValues) -> OwnedUsedGridTracks {
// getComputedStyle() needs to return the resolved values of grid-template-columns and grid-template-rows
// so they need to be saved in the state, and then assigned to paintables by the Rust commit walk.
let start = |axis: Axis| self.content_start_offset(axis, self.grid_container_alignment_size(axis));
let column_axis = self.select_grid_axis(Axis::Column, Axis::Column, Axis::Row);
- let tracks = OwnedUsedGridTracks {
+ OwnedUsedGridTracks {
columns: self.used_track_list_data(column_axis, self.is_subgridded(column_axis, grid_style)),
rows: self.used_track_list_data(
column_axis.opposite(),
@@ -5319,16 +5328,10 @@ impl<'pass> GridFormattingContext<'pass> {
self.track_sum(Axis::Column),
self.track_sum(Axis::Row),
),
- };
- self.run.update_grid_payload_of(self.run.box_, |grid| {
- grid.used_tracks = Some(std::sync::Arc::new(tracks));
- });
+ }
}
- fn save_devtools_data(&self, grid_style: &GridValues) {
- if !self.run.collects_devtools_layout_data() {
- return;
- }
+ fn layout_data_for_devtools(&self, grid_style: &GridValues) -> GridLayoutData {
let serialize = |axis: Axis| {
let tracks = self.axis_tracks(axis);
let gaps = self.axis_gaps(axis);
@@ -5417,15 +5420,12 @@ impl<'pass> GridFormattingContext<'pass> {
.collect::<Vec<_>>();
let fragment = GridLayoutFragment { areas, columns, rows };
let style = self.container_style;
- let data = GridLayoutData {
+ GridLayoutData {
direction: style.direction(),
writing_mode: style.writing_mode(),
is_subgrid: self.is_subgridded(Axis::Column, grid_style) || self.is_subgridded(Axis::Row, grid_style),
fragments: vec![fragment],
- };
- self.run.update_grid_payload_of(self.run.box_, |grid| {
- grid.layout_data = Some(std::sync::Arc::new(data));
- });
+ }
}
pub(crate) fn content_inline_size(
@@ -5578,8 +5578,12 @@ impl<'pass> GridFormattingContext<'pass> {
}
self.layout_items(run);
- self.save_used_tracks(grid_style);
- self.save_devtools_data(grid_style);
+ if self.run.fragments.is_some() {
+ self.root_payload.used_tracks = Some(std::sync::Arc::new(self.used_tracks(grid_style)));
+ }
+ if self.run.collects_devtools_layout_data() {
+ self.root_payload.layout_data = Some(std::sync::Arc::new(self.layout_data_for_devtools(grid_style)));
+ }
}
fn derived_baselines_of_root_box(&self) -> DerivedBaselines {
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index f0946e5f830..35805dc4e46 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -1404,22 +1404,21 @@ struct OperatorGlyph {
/// Lays out an <mo> whose text was laid out in a block formatting context with the glyph it is drawn with instead,
/// if it is stretched or a large operator.
// https://w3c.github.io/mathml-core/#layout-of-operators
+/// Lays out the root of `run`, an operator, where it is drawn with a stretched or large glyph, and answers what it
+/// paints where the run builds fragments.
pub(super) fn layout_operator(
run: &FormattingContextRun<'_>,
input: &LayoutInput,
result: &mut ChildLayoutResult,
root: &mut used_values::RootInputCells,
-) {
+) -> Option<std::sync::Arc<MathPaintData>> {
let context = MathFormattingContext::new(run, *root);
let operator = run.box_;
if context.kind(operator) != MathLayoutKind::Mo {
- return;
+ return None;
}
- let Some(OperatorGlyph { glyph, baseline_shift }) =
- context.operator_glyph(operator, input.sizing.math_stretch_size_constraint)
- else {
- return;
- };
+ let OperatorGlyph { glyph, baseline_shift } =
+ context.operator_glyph(operator, input.sizing.math_stretch_size_constraint)?;
let glyphs = glyph;
let ascent = glyphs.ascent - baseline_shift;
let descent = glyphs.descent + baseline_shift;
@@ -1434,28 +1433,24 @@ pub(super) fn layout_operator(
first: Some(ascent),
last: Some(ascent),
};
- if run.fragments.is_none() {
- return;
- }
- let content = MathContent {
- inline_size,
- ascent,
- descent,
- glyph_runs: vec![PlacedGlyphRun {
- line_left_offset: CssPixels::default(),
- baseline_shift,
- glyphs,
- }],
- ..MathContent::default()
- };
- let is_rtl = context.style(operator).direction() == direction::RTL;
- let paint_data = MathPaintData {
- replaces_text: true,
- ..content.paint_data(CssPixels::default(), inline_size, is_rtl)
- };
- run.set_fragment_payload_of(operator, || {
- fragment_tree::FcPayload::Math(std::sync::Arc::new(paint_data))
- });
+ run.fragments.is_some().then(|| {
+ let content = MathContent {
+ inline_size,
+ ascent,
+ descent,
+ glyph_runs: vec![PlacedGlyphRun {
+ line_left_offset: CssPixels::default(),
+ baseline_shift,
+ glyphs,
+ }],
+ ..MathContent::default()
+ };
+ let is_rtl = context.style(operator).direction() == direction::RTL;
+ std::sync::Arc::new(MathPaintData {
+ replaces_text: true,
+ ..content.paint_data(CssPixels::default(), inline_size, is_rtl)
+ })
+ })
}
pub(super) struct MathFormattingContext<'pass> {
@@ -1468,6 +1463,8 @@ pub(super) struct MathFormattingContext<'pass> {
placed_children: RefCell<HashMap<Node, formatting_context::PlacedChild>>,
/// The cells in which this context sizes the run's root, in the frame the root lays its contents out in.
root_cells: Cell<used_values::RootInputCells>,
+ /// What the run's root paints, where the run builds fragments.
+ root_paint_data: Option<std::sync::Arc<MathPaintData>>,
}
impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for MathFormattingContext<'pass> {
@@ -1477,6 +1474,10 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for MathFormat
input: formatting_context::AlgorithmInput<'_>,
) -> formatting_context::AlgorithmOutput {
self.run(run, input.body_input);
+ let mut root_payload = fragment_tree::PendingPayload::default();
+ if let Some(paint_data) = self.root_paint_data.take() {
+ root_payload.set(fragment_tree::FcPayload::Math(paint_data));
+ }
formatting_context::AlgorithmOutput::of_root(
ChildLayoutResult {
automatic_content_block_size: self.automatic_content_block_size(),
@@ -1485,6 +1486,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for MathFormat
},
self.root_cells(),
)
+ .with_root_payload(root_payload)
}
fn after_root_is_dimensioned(
@@ -1521,6 +1523,7 @@ impl<'pass> MathFormattingContext<'pass> {
fragment_arrivals_of_children: RefCell::new(Vec::new()),
placed_children: RefCell::new(HashMap::default()),
root_cells: Cell::new(root_cells),
+ root_paint_data: None,
}
}
@@ -2373,10 +2376,11 @@ impl<'pass> MathFormattingContext<'pass> {
} else {
content.inline_size
};
- let paint_data = content.paint_data(math_content_line_left, bar_inline_size, is_rtl);
- run.set_fragment_payload_of(run.box_, || {
- fragment_tree::FcPayload::Math(std::sync::Arc::new(paint_data))
- });
+ self.root_paint_data = Some(std::sync::Arc::new(content.paint_data(
+ math_content_line_left,
+ bar_inline_size,
+ is_rtl,
+ )));
}
self.derived_baselines_of_root_box = DerivedBaselines {
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index 5daa4c7e24c..e9087c987e1 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -596,6 +596,8 @@ pub(super) struct SvgFormattingContext<'pass> {
/// sets it once the root is definite. A nested context takes it from the context that creates it.
percentage_block_insets_of_run_root_children_have_definite_basis: bool,
current_text_position: FfiFloatPoint,
+ /// What the run's root, where this is the context of the root, hands the root's fragment.
+ root_payload: RefCell<fragment_tree::PendingPayload>,
}
impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for SvgFormattingContext<'pass> {
@@ -607,6 +609,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for SvgFormatt
let root = Cell::new(input.root_cells);
self.lay_out_contents(run, input.body_input, &root);
formatting_context::AlgorithmOutput::of_root(formatting_context::ChildLayoutResult::default(), root.get())
+ .with_root_payload(self.root_payload.take())
}
}
@@ -629,6 +632,23 @@ impl<'pass> SvgFormattingContext<'pass> {
viewport_is_committed_viewport: false,
percentage_block_insets_of_run_root_children_have_definite_basis,
current_text_position: FfiFloatPoint::default(),
+ root_payload: RefCell::new(fragment_tree::PendingPayload::default()),
+ }
+ }
+
+ /// Hands `node` what its layout produced besides its geometry, where the run builds fragments: the run's root through
+ /// the output of this context, and any other box through the run's fragment builder.
+ fn update_svg_payload_of(&self, node: Node, update: impl FnOnce(&mut fragment_tree::SvgPayload)) {
+ if node != self.run.state.root() {
+ self.run.update_svg_payload_of(node, update);
+ return;
+ }
+ debug_assert_eq!(
+ node, self.run.box_,
+ "only the context of a run's root hands the root its payload"
+ );
+ if self.run.fragments.is_some() {
+ update(self.root_payload.borrow_mut().svg_mut());
}
}
@@ -1860,13 +1880,11 @@ impl<'pass> SvgFormattingContext<'pass> {
}
fn set_svg_viewport_transform(&self, node: Node, transform: FfiAffineTransform) {
- self.run
- .update_svg_payload_of(node, |svg| svg.facts.viewport_transform = Some(transform));
+ self.update_svg_payload_of(node, |svg| svg.facts.viewport_transform = Some(transform));
}
fn set_svg_viewport_size(&self, node: Node, viewport_size: FfiCssPixelSize) {
- self.run
- .update_svg_payload_of(node, |svg| svg.facts.viewport_size = Some(viewport_size));
+ self.update_svg_payload_of(node, |svg| svg.facts.viewport_size = Some(viewport_size));
}
fn commit_svg_element_facts(&self, node: Node, facts: SvgElementFacts, attributes: FfiSvgAttributeFacts) {
@@ -1877,7 +1895,7 @@ impl<'pass> SvgFormattingContext<'pass> {
width: attributes.mask_width,
height: attributes.mask_height,
});
- self.run.update_svg_payload_of(node, |svg| {
+ self.update_svg_payload_of(node, |svg| {
let svg = &mut svg.facts;
svg.view_box = attributes.has_active_view_box.then_some(attributes.active_view_box);
svg.element_transform = (!facts.element_transform.is_identity()).then_some(facts.element_transform);
@@ -2330,7 +2348,7 @@ impl<'pass> SvgFormattingContext<'pass> {
}
}
- self.run.update_svg_payload_of(graphics_box, |svg| {
+ self.update_svg_payload_of(graphics_box, |svg| {
svg.path = Some(std::sync::Arc::new(path));
svg.text_character_cells = character_cells.map(std::sync::Arc::new);
});
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 38f8440a04c..c2695bde565 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -1048,6 +1048,8 @@ pub(super) struct TableFormattingContext<'pass> {
available_space: AvailableSpace,
table_block_size: CssPixels,
pub(super) automatic_content_block_size: CssPixels,
+ /// The collapsed borders the table box's fragment paints, once they are materialized.
+ collapsed_table_borders: Option<std::sync::Arc<OwnedCollapsedTableBorders>>,
table_box_content_block_offset_in_wrapper: CssPixels,
min_border_box_block_size_from_flex_item: Option<CssPixels>,
needs_fixed_mode_row_measurement: bool,
@@ -1167,6 +1169,10 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for TableForma
input: formatting_context::AlgorithmInput<'_>,
) -> formatting_context::AlgorithmOutput {
self.run(run, input.body_input, input.table_inline_layout);
+ let mut root_payload = fragment_tree::PendingPayload::default();
+ if let Some(collapsed_table_borders) = self.collapsed_table_borders.take() {
+ root_payload.set(fragment_tree::FcPayload::Table(collapsed_table_borders));
+ }
formatting_context::AlgorithmOutput::of_root(
formatting_context::ChildLayoutResult {
automatic_content_block_size: self.automatic_content_block_size,
@@ -1175,6 +1181,7 @@ impl<'pass> formatting_context::FormattingContextAlgorithm<'pass> for TableForma
},
self.table_box_cells(),
)
+ .with_root_payload(root_payload)
}
fn after_root_is_dimensioned(
@@ -1211,6 +1218,7 @@ impl<'pass> TableFormattingContext<'pass> {
available_space: AvailableSpace::default(),
table_block_size: CssPixels::default(),
automatic_content_block_size: CssPixels::default(),
+ collapsed_table_borders: None,
table_box_content_block_offset_in_wrapper: CssPixels::default(),
min_border_box_block_size_from_flex_item: None,
needs_fixed_mode_row_measurement: false,
@@ -1632,15 +1640,12 @@ impl<'pass> TableFormattingContext<'pass> {
}
}));
let (horizontal_edges, vertical_edges) = grid.take_edges();
- let collapsed_table_borders = std::sync::Arc::new(OwnedCollapsedTableBorders {
+ self.collapsed_table_borders = Some(std::sync::Arc::new(OwnedCollapsedTableBorders {
row_offsets,
column_offsets,
horizontal_edges,
vertical_edges,
- });
- self.run.set_fragment_payload_of(self.run.box_, || {
- fragment_tree::FcPayload::Table(collapsed_table_borders)
- });
+ }));
}
// Participants resolve percentages against the table's input basis inside this context, so