Skip to content

Truly independent web browser

LibWeb: Own a run's fragment builder in its run state

Aliaksandr Kalenika5c0d6ec596d
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index dff3b5e1289..6a82420b2d7 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -171,7 +171,7 @@ impl<'a> OutOfFlowBox<'a> {
pub(crate) struct AbsposEngine<'pass> {
state: &'pass RunState,
callbacks: LayoutPass<'pass>,
- fragments: Option<std::rc::Rc<fragment_tree::RunFragmentBuilder>>,
+ fragments: Option<&'pass fragment_tree::RunFragmentBuilder>,
}
impl<'pass> AbsposEngine<'pass> {
@@ -179,7 +179,7 @@ impl<'pass> AbsposEngine<'pass> {
Self {
state: run.state,
callbacks: run.callbacks,
- fragments: run.fragments.clone(),
+ fragments: run.fragments,
}
}
@@ -278,7 +278,6 @@ impl<'pass> AbsposEngine<'pass> {
/// The fragments of the run this engine lays out boxes in, where its placements are kept.
fn placed_box_fragments(&self) -> &fragment_tree::RunFragmentBuilder {
self.fragments
- .as_deref()
.expect("absolutely positioned boxes are laid out in runs that build fragments")
}
@@ -525,7 +524,6 @@ impl AbsposEngine<'_> {
.is_some_and(|kind| super::node_facts::kind_is_box(kind) || kind == NodeKind::InlineNode)
|| !self
.fragments
- .as_deref()
.is_some_and(|fragments| fragments.find_anchor_candidate(anchor_box).is_some())
{
return false;
@@ -562,7 +560,6 @@ impl AbsposEngine<'_> {
) -> CssPixelRect {
let (rect, coordinate_space_box) = self
.fragments
- .as_deref()
.and_then(|fragments| fragments.find_anchor_candidate(anchor_box))
.expect("an accepted anchor is placed in the draining subtree and propagated here");
let fold_into_entry_space =
@@ -3623,7 +3620,7 @@ impl<'pass> AbsposEngine<'pass> {
callback(&AbsposEngine {
state: self.state,
callbacks,
- fragments: self.fragments.clone(),
+ fragments: self.fragments,
})
})
}
@@ -3774,7 +3771,6 @@ impl<'pass> AbsposEngine<'pass> {
);
let containing_block_info_override = child.containing_block_info_override.or_else(|| {
self.fragments
- .as_deref()
.and_then(|fragments| fragments.find_abspos_containing_block_info(child_box))
});
let unresolved_containing_block_info = containing_block_info_override.unwrap_or_else(|| {
@@ -3888,7 +3884,7 @@ impl<'pass> AbsposEngine<'pass> {
if child.inline_containing_block().is_invalid() {
return None;
}
- let fragments = self.fragments.as_deref()?;
+ let fragments = self.fragments?;
let (rect, payload_space) = fragments.find_inline_containing_block_rect(child.inline_containing_block())?;
let fold_into_entry_space =
self.translation_between_payload_resting_spaces(payload_space, child.coordinate_space_box);
@@ -4016,7 +4012,7 @@ pub(crate) fn drain_abspos_with_placed_containing_blocks(
state: &RunState,
callbacks: LayoutPass<'_>,
should_collect_devtools_layout_data: bool,
- entry_fragments: &std::rc::Rc<fragment_tree::RunFragmentBuilder>,
+ entry_fragments: &fragment_tree::RunFragmentBuilder,
) {
let accumulator_root = entry_fragments.root_node();
let run = FormattingContextRun {
@@ -4025,7 +4021,7 @@ pub(crate) fn drain_abspos_with_placed_containing_blocks(
callbacks,
should_collect_devtools_layout_data,
treat_block_axis_percentage_insets_as_auto_beyond_root: false,
- fragments: Some(entry_fragments.clone()),
+ fragments: Some(entry_fragments),
fragmentainer: None,
};
loop {
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index aed26c5e5ac..d6f3a9a9ae3 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -969,7 +969,7 @@ impl<'pass> BlockFormattingContext<'pass> {
};
formatting_context::register_contained_abspos_child(
&self.run.callbacks,
- self.run.fragments.as_deref(),
+ self.run.fragments,
coordinate_space_box,
node,
static_position,
@@ -3452,7 +3452,7 @@ impl<'pass> BlockFormattingContext<'pass> {
}
fn abspos_containing_block_info_contributions_received(&self) -> u64 {
- self.run.fragments.as_deref().map_or(0, |fragments| {
+ self.run.fragments.map_or(0, |fragments| {
fragments.abspos_containing_block_info_contributions_received()
})
}
@@ -4192,7 +4192,7 @@ impl<'pass> BlockFormattingContext<'pass> {
incoming.take(),
column_index,
);
- if let (Some(fragments), Some(contents)) = (self.run.fragments.as_deref(), contents) {
+ if let (Some(fragments), Some(contents)) = (self.run.fragments, contents) {
fragments.adopt_fragmentainer_contents(contents, origin, root_line_count);
}
let filled_column = outcome
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 0349256e068..0bfb99a8a1b 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -4473,7 +4473,7 @@ impl<'pass> FlexFormattingContext<'pass> {
if facts.is_box() && facts.is_absolutely_positioned() {
formatting_context::register_contained_abspos_child(
&self.run.callbacks,
- self.run.fragments.as_deref(),
+ self.run.fragments,
self.run.box_,
child,
self.calculate_static_position_rect(child),
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index ae0a2cca1b4..8e6911ecf46 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -440,7 +440,7 @@ pub(crate) fn place_child(
content_offset_in_containing_block: offset,
containing_block,
};
- let Some(fragments) = run.fragments.as_deref() else {
+ let Some(fragments) = run.fragments else {
debug_assert!(
fragment_arrival.is_none(),
"a run that builds no fragments is handed none"
@@ -1266,7 +1266,7 @@ pub(crate) struct FormattingContextRun<'pass> {
pub(crate) callbacks: LayoutPass<'pass>,
pub(crate) should_collect_devtools_layout_data: bool,
pub(crate) treat_block_axis_percentage_insets_as_auto_beyond_root: bool,
- pub(crate) fragments: Option<std::rc::Rc<fragment_tree::RunFragmentBuilder>>,
+ pub(crate) fragments: Option<&'pass fragment_tree::RunFragmentBuilder>,
pub(crate) fragmentainer: Option<std::rc::Rc<fragmentation::FragmentainerContext>>,
}
@@ -1288,7 +1288,7 @@ impl<'pass> FormattingContextRun<'pass> {
should_collect_devtools_layout_data: self.should_collect_devtools_layout_data,
treat_block_axis_percentage_insets_as_auto_beyond_root: self
.treat_block_axis_percentage_insets_as_auto_beyond_root,
- fragments: self.fragments.clone(),
+ fragments: self.fragments,
fragmentainer: self.fragmentainer.clone(),
}
}
@@ -1319,7 +1319,7 @@ impl<'pass> FormattingContextRun<'pass> {
node: Node,
update: impl FnOnce(&mut fragment_tree::FragmentPayloads),
) {
- if let Some(fragments) = self.fragments.as_deref() {
+ if let Some(fragments) = self.fragments {
fragments.update_fragment_payloads_of(node, update);
}
}
@@ -1487,7 +1487,7 @@ fn register_table_abspos_descendants(run: &FormattingContextRun, parent: Node) {
if facts.is_absolutely_positioned() {
register_contained_abspos_child(
&run.callbacks,
- run.fragments.as_deref(),
+ run.fragments,
run.box_,
child,
abspos_inputs::StaticPositionRect {
@@ -2137,19 +2137,24 @@ fn execute_formatting_context_run(
}
_ => None,
};
- let (outputs, root_cells_left_by_run) = RunState::with_root(
+ let fragments = builds_fragments.then(|| {
+ fragment_tree::RunFragmentBuilder::new(
+ box_,
+ (!root_containing_block.is_invalid()).then_some(root_containing_block),
+ )
+ });
+ let (outputs, root_cells_left_by_run) = RunState::with_root_building_fragments(
callbacks,
box_,
root_containing_block,
root_anchor_resolved_values,
+ fragments,
|state, callbacks| {
lay_out_run_root_and_contents(
state,
callbacks,
- builds_fragments,
root_cells,
box_,
- root_containing_block,
parent_grid,
fc_type,
should_collect_devtools_layout_data,
@@ -2201,10 +2206,8 @@ fn sizes_and_box_sides(cells: used_values::RootInputCells) -> used_values::RootI
fn lay_out_run_root_and_contents<'pass>(
state: &'pass RunState,
callbacks: LayoutPass<'pass>,
- builds_fragments: bool,
root_cells: used_values::RootInputCells,
box_: Node,
- root_containing_block: Node,
parent_grid: Option<&grid_formatting_context::GridFormattingContext<'pass>>,
fc_type: FormattingContextType,
should_collect_devtools_layout_data: bool,
@@ -2223,12 +2226,7 @@ fn lay_out_run_root_and_contents<'pass>(
treat_block_axis_percentage_insets_as_auto_beyond_root: input
.sizing
.treat_block_axis_percentage_insets_as_auto_beyond_root,
- fragments: builds_fragments.then(|| {
- std::rc::Rc::new(fragment_tree::RunFragmentBuilder::new(
- box_,
- (!root_containing_block.is_invalid()).then_some(root_containing_block),
- ))
- }),
+ fragments: state.fragments(),
fragmentainer,
};
let run = &run;
@@ -2495,7 +2493,7 @@ fn lay_out_run_root_and_contents<'pass>(
},
};
if content_alignment_offset.y != CssPixels::default() {
- if let Some(fragments) = run.fragments.as_deref() {
+ if let Some(fragments) = run.fragments {
fragments.translate_root_contents(content_alignment_offset);
}
let shift = |baseline: Option<CssPixels>| baseline.map(|baseline| baseline + content_alignment_offset.y);
@@ -2684,7 +2682,7 @@ fn lay_out_abspos_contained_by_run_root(
root_in_own_frame: used_values::RootInputCells,
own_frame: geometry::Frame,
) -> bool {
- let Some(fragments) = body_run.fragments.as_deref() else {
+ let Some(fragments) = body_run.fragments else {
return false;
};
let mut batch = fragments.take_abspos_contained_by_root(&body_run.callbacks);
@@ -3020,7 +3018,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
percentage_block_insets_of_containing_block_have_definite_basis,
);
run_formatting_context(
- run.fragments.as_deref(),
+ run.fragments,
child_input_cells,
child,
root_containing_block,
@@ -3044,7 +3042,6 @@ pub(crate) fn leave_child_unplaced(
) {
if let Some(arrival) = fragment_arrival {
run.fragments
- .as_deref()
.expect("only a run that builds fragments is handed a child's fragments")
.leave_child_unplaced(arrival, unplaced_child);
}
@@ -3626,78 +3623,88 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
percentage_basis_block_size: Some(viewport_block_size),
..ContainingBlockConstraints::default()
};
- RunState::with_root(callbacks, root, Node::INVALID, None, |entry_run_state, callbacks| {
- let _trace = scratch.layout_trace.pass(None);
- let entry_fragments = std::rc::Rc::new(fragment_tree::RunFragmentBuilder::new_entry_accumulator(root));
- let entry_run = FormattingContextRun {
- state: entry_run_state,
- box_: root,
- callbacks,
- should_collect_devtools_layout_data,
- treat_block_axis_percentage_insets_as_auto_beyond_root: false,
- fragments: Some(entry_fragments.clone()),
- fragmentainer: None,
- };
+ RunState::with_root_building_fragments(
+ callbacks,
+ root,
+ Node::INVALID,
+ None,
+ Some(fragment_tree::RunFragmentBuilder::new_entry_accumulator(root)),
+ |entry_run_state, callbacks| {
+ let _trace = scratch.layout_trace.pass(None);
+ let entry_fragments = entry_run_state
+ .fragments()
+ .expect("an entry pass accumulates fragments");
+ let entry_run = FormattingContextRun {
+ state: entry_run_state,
+ box_: root,
+ callbacks,
+ should_collect_devtools_layout_data,
+ treat_block_axis_percentage_insets_as_auto_beyond_root: false,
+ fragments: Some(entry_fragments),
+ fragmentainer: None,
+ };
- let first_child = callbacks.first_child(root);
- let root_for_layout = if !first_child.is_invalid() && NodeFacts::new(&callbacks, first_child).is_svg_svg_box() {
- let mut viewport_cells = used_values::cells_before_sizing(&callbacks, root, root_constraints);
- viewport_cells.set_content_inline_size(viewport_inline_size);
- viewport_cells.set_content_block_size(viewport_block_size);
+ let first_child = callbacks.first_child(root);
+ let root_for_layout =
+ if !first_child.is_invalid() && NodeFacts::new(&callbacks, first_child).is_svg_svg_box() {
+ let mut viewport_cells = used_values::cells_before_sizing(&callbacks, root, root_constraints);
+ viewport_cells.set_content_inline_size(viewport_inline_size);
+ viewport_cells.set_content_block_size(viewport_block_size);
+ place_child(
+ &entry_run,
+ root,
+ PlacedChild::new(fragment_tree::FragmentGeometry {
+ cells: viewport_cells,
+ line_data: None,
+ }),
+ FfiCssPixelPoint::default(),
+ None,
+ None,
+ );
+ first_child
+ } else {
+ root
+ };
+ let root_cells = used_values::cells_before_sizing(&callbacks, root_for_layout, root_constraints);
+ let input = LayoutInput::new(
+ AvailableSpace {
+ inline_size: AvailableSize::definite(viewport_inline_size),
+ block_size: AvailableSize::definite(viewport_block_size),
+ },
+ ContainingBlockConstraints::default(),
+ ParticipationInParentFormattingContext::Root,
+ )
+ .with_forced_sizes(viewport_inline_size, viewport_block_size);
+ let fc_type = independent_formatting_context_type(root_for_layout, &callbacks);
+ let root_outcome = run_formatting_context(
+ Some(entry_fragments),
+ root_cells,
+ root_for_layout,
+ callbacks.in_flow_containing_block(root_for_layout),
+ None,
+ fc_type,
+ should_collect_devtools_layout_data,
+ callbacks,
+ input,
+ None,
+ );
place_child(
&entry_run,
- root,
- PlacedChild::new(fragment_tree::FragmentGeometry {
- cells: viewport_cells,
- line_data: None,
- }),
+ root_for_layout,
+ root_outcome.placed_child(),
FfiCssPixelPoint::default(),
None,
- None,
+ root_outcome.fragment_arrival,
);
- first_child
- } else {
- root
- };
- let root_cells = used_values::cells_before_sizing(&callbacks, root_for_layout, root_constraints);
- let input = LayoutInput::new(
- AvailableSpace {
- inline_size: AvailableSize::definite(viewport_inline_size),
- block_size: AvailableSize::definite(viewport_block_size),
- },
- ContainingBlockConstraints::default(),
- ParticipationInParentFormattingContext::Root,
- )
- .with_forced_sizes(viewport_inline_size, viewport_block_size);
- let fc_type = independent_formatting_context_type(root_for_layout, &callbacks);
- let root_outcome = run_formatting_context(
- Some(&entry_fragments),
- root_cells,
- root_for_layout,
- callbacks.in_flow_containing_block(root_for_layout),
- None,
- fc_type,
- should_collect_devtools_layout_data,
- callbacks,
- input,
- None,
- );
- place_child(
- &entry_run,
- root_for_layout,
- root_outcome.placed_child(),
- FfiCssPixelPoint::default(),
- None,
- root_outcome.fragment_arrival,
- );
- finish_entry_pass(
- entry_run_state,
- &entry_fragments,
- &callbacks,
- scratch,
- should_collect_devtools_layout_data,
- )
- })
+ finish_entry_pass(
+ entry_run_state,
+ entry_fragments,
+ &callbacks,
+ scratch,
+ should_collect_devtools_layout_data,
+ )
+ },
+ )
}
/// Brings the arena up to date for a stage before the stage borrows it: a root stage covers whatever kept pending
@@ -3714,7 +3721,7 @@ fn prepare_layout_stage(state: &mut super::ArenaHandle, kind: LayoutStageKind) {
fn finish_entry_pass(
entry_run_state: &RunState,
- entry_fragments: &std::rc::Rc<fragment_tree::RunFragmentBuilder>,
+ entry_fragments: &fragment_tree::RunFragmentBuilder,
callbacks: &LayoutPass<'_>,
scratch: &super::run_state::LayoutScratch,
should_collect_devtools_layout_data: bool,
@@ -3766,22 +3773,24 @@ fn compute_subtree_layout_fragments(input: LayoutStageInput<'_>, containing_bloc
} else {
(root, containing_block)
};
- RunState::with_root(
+ RunState::with_root_building_fragments(
callbacks,
entry_root,
entry_root_containing_block,
None,
+ Some(fragment_tree::RunFragmentBuilder::new_entry_accumulator(entry_root)),
|entry_run_state, callbacks| {
let _trace = scratch.layout_trace.pass(Some(root));
- let entry_fragments =
- std::rc::Rc::new(fragment_tree::RunFragmentBuilder::new_entry_accumulator(entry_root));
+ let entry_fragments = entry_run_state
+ .fragments()
+ .expect("an entry pass accumulates fragments");
let entry_run = FormattingContextRun {
state: entry_run_state,
box_: entry_root,
callbacks,
should_collect_devtools_layout_data: false,
treat_block_axis_percentage_insets_as_auto_beyond_root: false,
- fragments: Some(entry_fragments.clone()),
+ fragments: Some(entry_fragments),
fragmentainer: None,
};
if root_is_absolutely_positioned {
@@ -3789,7 +3798,7 @@ fn compute_subtree_layout_fragments(input: LayoutStageInput<'_>, containing_bloc
} else {
layout_subtree_with_frozen_root_geometry(&entry_run);
}
- finish_entry_pass(entry_run_state, &entry_fragments, &callbacks, scratch, false)
+ finish_entry_pass(entry_run_state, entry_fragments, &callbacks, scratch, false)
},
)
}
@@ -3800,7 +3809,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let committed_root = used_values::committed_box_from_fragment_link(callbacks, root)
.expect("partial relayout root must have committed geometry");
let root_cells = committed_root.cells;
- let fragments = run.fragments.as_deref().expect("partial relayout must build fragments");
+ let fragments = run.fragments.expect("partial relayout must build fragments");
let mut input = LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(root_cells.content_inline_size),
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 434b1d42839..b169cb38320 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -5586,7 +5586,7 @@ impl<'pass> GridFormattingContext<'pass> {
.then(|| self.abspos_containing_block_info(child));
formatting_context::register_contained_abspos_child(
&self.run.callbacks,
- self.run.fragments.as_deref(),
+ self.run.fragments,
self.run.box_,
child,
rect,
@@ -5594,7 +5594,7 @@ impl<'pass> GridFormattingContext<'pass> {
);
}
}
- if let Some(fragments) = self.run.fragments.as_deref() {
+ if let Some(fragments) = self.run.fragments {
for child in fragments.pending_abspos_children_awaiting_containing_block_info(self.run.box_) {
// Deeper descendants inside grid items still get the grid area
// as their containing block, but their static position comes
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 73d510232e4..a96d3c3811e 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -492,7 +492,6 @@ pub(crate) fn compute(
let collect_inline_containing_block_rects = context
.run
.fragments
- .as_deref()
.is_some_and(fragment_tree::RunFragmentBuilder::any_pending_abspos_has_inline_containing_block);
let container_inline_axis_is_reverse =
collect_inline_containing_block_rects && context.facts(context.containing_block).inline_axis_is_reverse();
@@ -652,7 +651,6 @@ pub(crate) fn compute(
&& context
.run
.fragments
- .as_deref()
.is_some_and(|fragments| fragments.any_pending_abspos_names_inline_containing_block(node));
let mut corners = FirstAndLastContentLineCorners::default();
@@ -814,7 +812,6 @@ pub(crate) fn compute(
&& context
.run
.fragments
- .as_deref()
.is_some_and(|fragments| fragments.any_pending_abspos_names_inline_containing_block(node))
{
inline_containing_block_rect_candidates.push(InlineContainingBlockRectCandidate {
@@ -1116,7 +1113,7 @@ impl<'context> InlineFormattingContext<'context> {
fn discard_unplaced_atomic_inline(&self, node: Node) {
let fragment_arrival = self.take_atomic_inline_fragment_arrival(node);
- if let Some(fragments) = self.run.fragments.as_deref() {
+ if let Some(fragments) = self.run.fragments {
fragments.discard_unplaced_subtree(node, fragment_arrival);
}
}
@@ -2678,7 +2675,7 @@ impl<'context> InlineFormattingContext<'context> {
}
formatting_context::register_contained_abspos_child(
&self.callbacks,
- self.run.fragments.as_deref(),
+ self.run.fragments,
self.containing_block,
box_,
static_position,
@@ -2778,7 +2775,7 @@ impl<'context> InlineFormattingContext<'context> {
let mut rect = candidate.rect;
rect.x += relative_inset_chain.offset_x;
rect.y += relative_inset_chain.offset_y;
- if let Some(fragments) = self.run.fragments.as_deref() {
+ if let Some(fragments) = self.run.fragments {
fragments.register_inline_containing_block_rect(
candidate.inline_containing_block,
rect,
@@ -2789,7 +2786,7 @@ impl<'context> InlineFormattingContext<'context> {
}
fn register_inline_anchor_candidates(&self) {
- let Some(fragments) = self.run.fragments.as_deref() else {
+ let Some(fragments) = self.run.fragments else {
return;
};
// An inline anchor's border box is the union of its line fragments, including relative positioning.
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index 86e31837e06..4bf88ae3a55 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -2663,7 +2663,7 @@ impl<'pass> MathFormattingContext<'pass> {
};
formatting_context::register_contained_abspos_child(
&self.run.callbacks,
- self.run.fragments.as_deref(),
+ self.run.fragments,
self.run.box_,
child,
static_position_rect,
diff --git a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
index 7900c19b10e..52aa7fdd75d 100644
--- a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
@@ -41,7 +41,7 @@ pub(super) fn layout_replaced_with_children(
wrapper_cells.set_content_inline_size(content_inline_size);
let wrapper_outcome = formatting_context::run_formatting_context(
- run.fragments.as_deref(),
+ run.fragments,
wrapper_cells,
wrapper,
run.callbacks.in_flow_containing_block(wrapper),
diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rs
index 7ab6d7befac..29212e973bb 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs
@@ -177,6 +177,7 @@ pub(crate) struct RunState {
root_anchor_resolved_values: Option<Box<style_values::AnchorResolvedValues>>,
/// What the run found out for the host so far, which the pass the run is handed notes into.
host_findings: RefCell<HostFindings>,
+ fragments: Option<fragment_tree::RunFragmentBuilder>,
}
/// Where a box is placed: the offset of its content box in the containing block it is placed in.
@@ -301,6 +302,26 @@ impl RunState {
root_containing_block,
root_anchor_resolved_values,
ContentSizing::Layout,
+ None,
+ run,
+ )
+ }
+
+ pub(crate) fn with_root_building_fragments<R>(
+ callbacks: LayoutPass<'_>,
+ root: Node,
+ root_containing_block: Node,
+ root_anchor_resolved_values: Option<Box<style_values::AnchorResolvedValues>>,
+ fragments: Option<fragment_tree::RunFragmentBuilder>,
+ run: impl for<'run> FnOnce(&'run Self, LayoutPass<'run>) -> R,
+ ) -> R {
+ Self::enter(
+ callbacks,
+ root,
+ root_containing_block,
+ root_anchor_resolved_values,
+ ContentSizing::Layout,
+ fragments,
run,
)
}
@@ -317,6 +338,7 @@ impl RunState {
root_containing_block,
None,
ContentSizing::RootContributions,
+ None,
run,
)
}
@@ -333,6 +355,7 @@ impl RunState {
root_containing_block,
None,
ContentSizing::RootContentInlineSizes,
+ None,
run,
)
}
@@ -343,6 +366,7 @@ impl RunState {
root_containing_block: Node,
root_anchor_resolved_values: Option<Box<style_values::AnchorResolvedValues>>,
content_sizing: ContentSizing,
+ fragments: Option<fragment_tree::RunFragmentBuilder>,
run: impl for<'run> FnOnce(&'run Self, LayoutPass<'run>) -> R,
) -> R {
let state = Self {
@@ -354,6 +378,7 @@ impl RunState {
)]),
root_anchor_resolved_values,
host_findings: RefCell::new(HostFindings::default()),
+ fragments,
};
run(
&state,
@@ -361,6 +386,10 @@ impl RunState {
)
}
+ pub(crate) fn fragments(&self) -> Option<&fragment_tree::RunFragmentBuilder> {
+ self.fragments.as_ref()
+ }
+
/// What this run found out for the host, which its outputs carry to the run that uses its result.
pub(crate) fn take_host_findings(&self) -> Option<Box<HostFindings>> {
let findings = std::mem::take(&mut *self.host_findings.borrow_mut());