Truly independent web browser
LibWeb: Stop carrying a frame in the values placement takes
Aliaksandr Kalenik1ee95e0cba7b
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 36b98a4ce46..84afa8ff1d1 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3250,8 +3250,7 @@ impl<'pass> AbsposEngine<'pass> {}}self.records.set_used_insets(node, used_insets);- let mut placed_child =- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, run.callbacks.frame);+ let mut placed_child = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);placed_child.facts_decided_by_parent.used_insets = used_insets;placed_child.facts_decided_by_parent.default_scroll_shift = default_scroll_shift;formatting_context::place_child_in_containing_block(diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex c6f42c90a12..8002a3acb3b 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -2210,7 +2210,7 @@ impl<'pass> BlockFormattingContext<'pass> {self.place_laid_out_child(marker,- formatting_context::PlacedChild::of_laid_out_box(&marker_box, marker_line_data, self.run.callbacks.frame),+ formatting_context::PlacedChild::of_laid_out_box(&marker_box, marker_line_data),FfiCssPixelPoint {x: round_css_pixels(marker_inline_offset),y: marker_block_offset,@@ -2795,7 +2795,6 @@ impl<'pass> BlockFormattingContext<'pass> {child_handed_back_by_its_run = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out_box,line_data,- self.run.callbacks.frame,));laid_out_box_handed_back_by_its_run = Some(laid_out_box);}@@ -4853,9 +4852,9 @@ impl<'pass> BlockFormattingContext<'pass> {let (float_layout, fragment_arrival, float_box, float_line_data) =self.layout_inside(run, node, block_container, float_input, false);// NB: A float its own run laid out is placed as that run handed it back, and any other with its record here.- let float_handed_back_by_its_run = float_layout.is_some().then(|| {- formatting_context::PlacedChild::of_laid_out_box(&float_box, float_line_data, self.run.callbacks.frame)- });+ let float_handed_back_by_its_run = float_layout+ .is_some()+ .then(|| formatting_context::PlacedChild::of_laid_out_box(&float_box, float_line_data));let laid_out_float_handed_back_by_its_run = float_layout.is_some().then_some(float_box);let containing_block_rect = self.containing_block_rect(block_container, containing_block_position_in_root);let containing_block_rect_now = containing_block_rect.translated(diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 009588dd4c1..bb50504e523 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3120,9 +3120,7 @@ impl<'pass> FlexFormattingContext<'pass> {ChildLayoutOutcome::Skipped { .. } => laid_out_box.expect("a skipped item leaves its box").baselines,};let placed_item = match laid_out_box {- Some(laid_out_box) => {- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, run.callbacks.frame)- }+ Some(laid_out_box) => formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),// NB: The item was laid out by this flex container's run, in the record it keeps.None => formatting_context::PlacedChild::of_record(run.records.used_values(node), run),};diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 2b0d83f68a0..2cc148b23e9 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -345,11 +345,10 @@ pub(crate) fn lay_out_pending_abspos_children(}/// What placing a child takes from its layout and from its parent: what the child's fragment shows of the box's own-/// layout, in the frame its sizes are in, and what the parent decided about the child besides where it goes.+/// layout, in the frame of the run placing it, and what the parent decided about the child besides where it goes.#[derive(Clone)]pub(crate) struct PlacedChild {pub(crate) geometry: fragment_tree::FragmentGeometry,- pub(crate) frame: geometry::Frame,/// What the parent decided about the child before placing it, which placing it adds the placement to.pub(crate) facts_decided_by_parent: run_records::FactsDecidedByParent,/// The offset the relative positioning of the fragmented inline boxes a block-level child interrupts gives the@@ -358,47 +357,39 @@ pub(crate) struct PlacedChild {}impl PlacedChild {- /// A child whose fragment shows `geometry`, in `frame`, before its parent decided anything about it.- pub(crate) fn new(geometry: fragment_tree::FragmentGeometry, frame: geometry::Frame) -> Self {+ /// A child whose fragment shows `geometry` before its parent decided anything about it.+ pub(crate) fn new(geometry: fragment_tree::FragmentGeometry) -> Self {Self {geometry,- frame,facts_decided_by_parent: run_records::FactsDecidedByParent::default(),offset_from_relatively_positioned_inline_ancestors: FfiCssPixelPoint::default(),}}- /// A child whose run handed back the box `laid_out` with the lines `line_data`, in `frame`, before its parent- /// decided anything about it.+ /// A child whose run handed back the box `laid_out` with the lines `line_data`, before its parent decided anything+ /// about it.pub(crate) fn of_laid_out_box(laid_out: &run_records::LaidOutChildBox,line_data: Option<std::sync::Arc<inline_content::InlineContent>>,- frame: geometry::Frame,) -> Self {- Self::new(- fragment_tree::FragmentGeometry {- cells: laid_out.cells,- line_data,- },- frame,- )+ Self::new(fragment_tree::FragmentGeometry {+ cells: laid_out.cells,+ line_data,+ })}/// A box that `run` lays out in `record`, before its parent decided anything about it.pub(crate) fn of_record(record: &UsedValues, run: &FormattingContextRun) -> Self {let callbacks = &run.callbacks;- Self::new(- fragment_tree::FragmentGeometry {- cells: used_values::RecordInFrame::new(record, callbacks.frame).cells(),- // NB: Only a run that builds fragments shows the lines it laid out in the boxes it places.- line_data: run- .fragments- .is_some()- .then(|| record.finish_line_data(callbacks))- .flatten(),- },- callbacks.frame,- )+ Self::new(fragment_tree::FragmentGeometry {+ cells: used_values::RecordInFrame::new(record, callbacks.frame).cells(),+ // NB: Only a run that builds fragments shows the lines it laid out in the boxes it places.+ line_data: run+ .fragments+ .is_some()+ .then(|| record.finish_line_data(callbacks))+ .flatten(),+ })}/// The child with the insets its parent resolved for it as an in-flow box.@@ -484,29 +475,16 @@ pub(crate) fn place_child_in_containing_block();return None;};- let placed_child_cells_in_run_frame = || {- placed_child- .geometry- .cells- .in_frame(placed_child.frame, callbacks.frame)- };fragments.note_placed_box(node,placement,- cells_kept_for_contained_abspos(run, node, placed_child_cells_in_run_frame),+ cells_kept_for_contained_abspos(run, node, || placed_child.geometry.cells),);let PlacedChild {geometry,- frame,facts_decided_by_parent,offset_from_relatively_positioned_inline_ancestors,} = placed_child;- if cfg!(debug_assertions) || run_repeatability::verification_is_enabled() {- assert_eq!(- frame, callbacks.frame,- "{node:?} is placed in another frame than the one its box is kept in"- );- }debug_assert!(facts_decided_by_parent.placement.is_none(),"a child is handed to placement before it is placed"@@ -2150,26 +2128,15 @@ pub(crate) struct ChildRunOutcome {impl ChildRunOutcome {/// Hands the laid out box back to the formatting context of `run`, the run that holds `child`, which keeps what it- /// reads of the box: returns the run's result, the box, and the fragments its placement takes.- pub(crate) fn hand_box_back_to(- self,- run: &FormattingContextRun,- child: Node,- ) -> (- ChildLayoutResult,- run_records::ChildLaidOutByItsOwnRun,- Option<fragment_tree::ChildFragmentArrival>,- ) {+ /// reads of the box.+ pub(crate) fn hand_box_back_to(self, run: &FormattingContextRun, child: Node) -> Self {run.records.note_child_handed_back(child);- (- self.result,- run_records::ChildLaidOutByItsOwnRun {- laid_out: self.laid_out_box,- line_data: self.line_data,- frame: run.callbacks.frame,- },- self.fragment_arrival,- )+ self+ }++ /// What placing the child takes of the box its run handed back.+ pub(crate) fn placed_child(&self) -> PlacedChild {+ PlacedChild::of_laid_out_box(&self.laid_out_box, self.line_data.clone())}}@@ -3132,12 +3099,17 @@ pub(crate) fn layout_inside_child_with_input_cells(input,run.records.take_table_inline_layout(child),);- let (result, handed_back, fragment_arrival) = child_run_outcome.hand_box_back_to(run, child);+ let ChildRunOutcome {+ result,+ laid_out_box,+ line_data,+ fragment_arrival,+ } = child_run_outcome.hand_box_back_to(run, child);ChildLayout {outcome: ChildLayoutOutcome::Created(result),fragment_arrival,- laid_out_box: Some(handed_back.laid_out),- line_data: handed_back.line_data,+ laid_out_box: Some(laid_out_box),+ line_data,}}@@ -3748,14 +3720,14 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layoinput,None,);- let (_, handed_back_root, fragment_arrival) = root_outcome.hand_box_back_to(&entry_run, root_for_layout);+ let root_outcome = root_outcome.hand_box_back_to(&entry_run, root_for_layout);place_laid_out_child(&entry_run,root_for_layout,- handed_back_root.placed_child(),+ root_outcome.placed_child(),FfiCssPixelPoint::default(),None,- fragment_arrival,+ root_outcome.fragment_arrival,);finish_entry_pass(entry_records,@@ -3903,10 +3875,15 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {input,None,);- let (_, handed_back_root, fragment_arrival) = root_outcome.hand_box_back_to(run, root);+ let ChildRunOutcome {+ laid_out_box: root_box,+ line_data: root_line_data,+ fragment_arrival,+ ..+ } = root_outcome.hand_box_back_to(run, root);let root_geometry = fragment_tree::FragmentGeometry {- cells: handed_back_root.laid_out.cells,- line_data: handed_back_root.line_data,+ cells: root_box.cells,+ line_data: root_line_data,};let facts_decided_by_parent = committed_root.facts_decided_by_parent;let placement = facts_decided_by_parentdiff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex 3aa2a9d7b9c..69471cd79c4 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -676,19 +676,11 @@ impl PlacementData {}}- /// The placement data of `node`, a child the run left unplaced, which `close()` hands on as `unplaced_child`- /// shows it.+ /// The placement data of a child the run left unplaced, which `close()` hands on as `unplaced_child` shows it.fn of_unplaced_child(unplaced_child: &crate::layout::formatting_context::PlacedChild,- node: crate::layout::node_data::NodeSlotId,frame: geometry::Frame,) -> Self {- if cfg!(debug_assertions) || crate::layout::run_repeatability::verification_is_enabled() {- assert_eq!(- unplaced_child.frame, frame,- "{node:?} is left unplaced in another frame than the one its box is kept in"- );- }Self::of_box(&unplaced_child.facts_decided_by_parent,None,@@ -1766,7 +1758,7 @@ impl RunFragmentBuilder {} => {let node = fragment.node;inner.reused_subtree_roots.insert(node.slot_index());- let placement = PlacementData::of_unplaced_child(&unplaced_child, node, callbacks.frame);+ let placement = PlacementData::of_unplaced_child(&unplaced_child, callbacks.frame);inner.top_scope_links.push(link_fragment(snapshot_fragment(callbacks,@@ -1795,7 +1787,7 @@ impl RunFragmentBuilder {if reuses_committed_subtree {inner.reused_subtree_roots.insert(root.node.slot_index());}- let placement = PlacementData::of_unplaced_child(&unplaced_child, root.node, callbacks.frame);+ let placement = PlacementData::of_unplaced_child(&unplaced_child, callbacks.frame);inner.top_scope_links.push(link_fragment(snapshot_fragment(callbacks,diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex d21928e9fac..5539e3346c1 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4500,9 +4500,7 @@ impl<'pass> GridFormattingContext<'pass> {};self.laid_out_items.borrow_mut().insert(item.box_, laid_out_item);let placed_item = match laid_out_box {- Some(laid_out_box) => {- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, run.callbacks.frame)- }+ Some(laid_out_box) => formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),// NB: The item was laid out by this grid container's run, in the record it keeps.None => formatting_context::PlacedChild::of_record(run.records.used_values(item.box_), run),};diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 067578cfeed..61dcc371246 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1284,13 +1284,10 @@ impl<'context> InlineFormattingContext<'context> {.borrow().get(&node).expect("the inline formatting context entered the inline box");- formatting_context::PlacedChild::new(- fragment_tree::FragmentGeometry {- cells: entered.sides,- line_data: None,- },- self.callbacks.frame,- )+ formatting_context::PlacedChild::new(fragment_tree::FragmentGeometry {+ cells: entered.sides,+ line_data: None,+ }).with_in_flow_box_insets(entered.insets)}@@ -1518,7 +1515,7 @@ impl<'context> InlineFormattingContext<'context> {};let (placed_child, laid_out_cells) = match laid_out_box {Some(laid_out_box) => (- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, self.callbacks.frame),+ formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),laid_out_box.cells,),// NB: The box was laid out by this context's parent flow, in the record it keeps here.diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex fcc346830c5..8ac08a15077 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2178,7 +2178,7 @@ impl<'pass> MathFormattingContext<'pass> {let laid_out_box = laid_out_box.expect("the layout of a math child leaves its box");self.placed_children.borrow_mut().insert(child,- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, run.callbacks.frame),+ formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),);outcome.report_percentage_block_size_dependency_of(run, child);let metrics = laid_out_box.cells;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.rsindex ddb9cfbdae2..09f20cbb87b 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@@ -68,7 +68,8 @@ pub(super) fn layout_replaced_with_children(},None,);- let (wrapper_result, handed_back_wrapper, fragment_arrival) = wrapper_outcome.hand_box_back_to(run, wrapper);+ let wrapper_outcome = wrapper_outcome.hand_box_back_to(run, wrapper);+ let wrapper_result = wrapper_outcome.result;formatting_context::propagate_percentage_block_size_dependency_to_containing_block(run.records,&run.callbacks,@@ -78,10 +79,10 @@ pub(super) fn layout_replaced_with_children(formatting_context::place_laid_out_child(run,wrapper,- handed_back_wrapper.placed_child(),+ wrapper_outcome.placed_child(),used_values::FfiCssPixelPoint::default(),None,- fragment_arrival,+ wrapper_outcome.fragment_arrival,);formatting_context::ChildLayoutResult {diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex cd1a4867106..0ab0e45a15c 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -343,22 +343,6 @@ impl LaidOutChildBox {}}-/// What the parent of a box laid out by a run of its own keeps of it once that run returns: the box, the lines the run-/// laid out in it, and the frame the box's metrics are in.-#[derive(Clone)]-pub(crate) struct ChildLaidOutByItsOwnRun {- pub(crate) laid_out: LaidOutChildBox,- pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,- pub(crate) frame: geometry::Frame,-}--impl ChildLaidOutByItsOwnRun {- /// What placing the child takes of the box its run handed back.- pub(crate) fn placed_child(&self) -> formatting_context::PlacedChild {- formatting_context::PlacedChild::of_laid_out_box(&self.laid_out, self.line_data.clone(), self.frame)- }-}-/// The sizes, size constraints, box sides and baselines of a box as a run sees them: kept as a value for a child/// awaiting the run of its own, or read from the record of a box the run lays out itself.#[derive(Clone, Copy)]diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex a5588d81e6f..d04cfaafb4f 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2109,7 +2109,7 @@ impl<'pass> SvgFormattingContext<'pass> {// Masks and clips may use this offset for objectBoundingBox units.self.place_laid_out_child(child,- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, run.callbacks.frame),+ formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),rect.x,rect.y,fragment_arrival,diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex d70084dde35..fa495d76800 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2743,9 +2743,7 @@ impl<'pass> TableFormattingContext<'pass> {}};self.placed_cells[cell_index] = Some(match laid_out_box {- Some(laid_out_box) => {- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, run.callbacks.frame)- }+ Some(laid_out_box) => formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),// NB: The cell was laid out by this table's run, in the record it keeps.None => formatting_context::PlacedChild::of_record(run.records.used_values(cell.box_), run),});@@ -3316,11 +3314,7 @@ impl<'pass> TableFormattingContext<'pass> {baselines: measurement.baselines,orthogonal_flow_baselines: None,};- self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(- &laid_out,- None,- run.callbacks.frame,- ));+ self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out, None));self.content_baselines_of_handed_back_cells[cell_index] = Some(laid_out.baselines);run.records.note_child_handed_back(cell.box_);formatting_context::propagate_percentage_block_size_dependency_to_containing_block(