Truly independent web browser
LibWeb: Place a child from a value instead of its record
Aliaksandr Kalenik2892966199c8
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 9bab26bbff1..6a05fdef158 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3187,6 +3187,7 @@ impl<'pass> AbsposEngine<'pass> {formatting_context::place_child_in_containing_block(run,node,+ formatting_context::PlacedChild::read_from_records(run, node),inputs.containing_block,FfiCssPixelPoint {x: used_offset.inline_offset,diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex a535074ecfd..47e903ae07c 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -764,6 +764,7 @@ impl<'pass> BlockFormattingContext<'pass> {formatting_context::place_laid_out_child(&self.run,node,+ formatting_context::PlacedChild::read_from_records(&self.run, node),offset,containing_line_box_fragment,fragment_arrival,@@ -2979,6 +2980,7 @@ impl<'pass> BlockFormattingContext<'pass> {formatting_context::place_reused_child(&self.run,node,+ self.run.records.facts_decided_by_parent_of(node),FfiCssPixelPoint {x: entry.offset_from_flow_position.x,y: entry.offset_from_flow_position.y + flow_position,diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex be0395724be..d9b34bae61d 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3932,7 +3932,14 @@ impl<'pass> FlexFormattingContext<'pass> {y: item.main_offset,}};- formatting_context::place_laid_out_child(&self.run, item.box_, offset, None, fragment_arrival);+ formatting_context::place_laid_out_child(+ &self.run,+ item.box_,+ formatting_context::PlacedChild::read_from_records(&self.run, item.box_),+ offset,+ None,+ fragment_arrival,+ );}self.derived_baselines_of_root_box = DerivedBaselines {inline_alignment: self.flex_lines.len().checked_sub(1).and_then(|line_index| {diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex fa70f5f776c..51757f0ad60 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -347,19 +347,52 @@ pub(crate) fn lay_out_pending_abspos_children(placed}+/// 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.+#[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,+}++impl PlacedChild {+ // FIXME: Remove this adapter once every caller hands placement the values it holds.+ pub(crate) fn read_from_records(run: &FormattingContextRun, node: Node) -> Self {+ let records = run.records;+ // NB: A run that builds no fragments reads no geometry of the boxes it places.+ let geometry = if run.fragments.is_some() {+ records.fragment_geometry_of(node, &run.callbacks)+ } else {+ fragment_tree::FragmentGeometry {+ cells: records.box_metrics_of(node).input_cells(),+ line_data: None,+ }+ };+ Self {+ geometry,+ frame: run.callbacks.frame,+ facts_decided_by_parent: records.facts_decided_by_parent_of(node),+ }+ }+}+pub(crate) fn place_child(run: &FormattingContextRun,node: Node,+ placed_child: PlacedChild,offset: FfiCssPixelPoint,containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,) -> Option<fragment_tree::PlacedFragment> {- place_laid_out_child(run, node, offset, containing_line_box_fragment, None)+ place_laid_out_child(run, node, placed_child, offset, containing_line_box_fragment, None)}/// Places `node`, taking in what the layout of the box handed its placement.pub(crate) fn place_laid_out_child(run: &FormattingContextRun,node: Node,+ placed_child: PlacedChild,offset: FfiCssPixelPoint,containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,@@ -368,6 +401,7 @@ pub(crate) fn place_laid_out_child(place_child_in_containing_block(run,node,+ placed_child,containing_block,offset,containing_line_box_fragment,@@ -377,9 +411,11 @@ pub(crate) fn place_laid_out_child(}/// Places `node` in `containing_block`. An absolutely positioned box hands its link the inputs it was laid out with.+#[expect(clippy::too_many_arguments)]pub(crate) fn place_child_in_containing_block(run: &FormattingContextRun,node: Node,+ placed_child: PlacedChild,containing_block: Node,offset: FfiCssPixelPoint,containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,@@ -401,7 +437,25 @@ pub(crate) fn place_child_in_containing_block(return None;};fragments.note_placed_box(node, placement, cells_kept_for_contained_abspos(run, node));- let facts_decided_by_parent = records.facts_decided_by_parent_of(node);+ let PlacedChild {+ geometry,+ frame,+ facts_decided_by_parent,+ } = 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"+ );+ let facts_decided_by_parent = run_records::FactsDecidedByParent {+ placement: Some(placement),+ ..facts_decided_by_parent+ };debug_assert!(fragment_arrival.as_ref()@@ -417,7 +471,7 @@ pub(crate) fn place_child_in_containing_block(fragment_tree::committed_fragment_showing_box(callbacks,node,- || records.fragment_geometry_of(node, callbacks),+ || geometry.clone(),facts_decided_by_parent.fragment_facts,fragment,),@@ -443,7 +497,13 @@ pub(crate) fn place_child_in_containing_block(resolve_containing_line_box_index(callbacks, node, containing_line_box_fragment),point_add(offset,- committed_offset_delta_at_placement(records, callbacks, node, containing_block),+ committed_offset_delta_at_placement(+ records,+ callbacks,+ node,+ facts_decided_by_parent.used_insets,+ containing_block,+ ),),callbacks.frame,);@@ -469,7 +529,7 @@ pub(crate) fn place_child_in_containing_block(}let node_facts = NodeFacts::new(callbacks, node);let own_anchor_candidate_border_box_rect = (node_facts.is_box() && node_facts.has_anchor_names()).then(|| {- let metrics = records.box_metrics_of(node);+ let metrics = &geometry.cells;let collapsed = metrics.uses_collapsing_borders_model();CssPixelRect {x: offset.x - metrics.border_box_left(collapsed),@@ -482,13 +542,19 @@ pub(crate) fn place_child_in_containing_block(callbacks,node,(!containing_block.is_invalid()).then_some(containing_block),- records.fragment_geometry_of(node, callbacks),- records.facts_decided_by_parent_of(node),+ geometry,+ facts_decided_by_parent,abspos_layout_inputs,resolve_containing_line_box_index(callbacks, node, containing_line_box_fragment),point_add(offset,- committed_offset_delta_at_placement(records, callbacks, node, containing_block),+ committed_offset_delta_at_placement(+ records,+ callbacks,+ node,+ facts_decided_by_parent.used_insets,+ containing_block,+ ),),own_anchor_candidate_border_box_rect,);@@ -519,6 +585,7 @@ fn cells_kept_for_contained_abspos(run: &FormattingContextRun, node: Node) -> Oppub(crate) fn place_reused_child(run: &FormattingContextRun,node: Node,+ facts_decided_by_parent: run_records::FactsDecidedByParent,offset: FfiCssPixelPoint,fragment: std::sync::Arc<fragment_tree::Fragment>,) {@@ -535,17 +602,31 @@ pub(crate) fn place_reused_child(.as_deref().expect("a reused subtree is placed by a run that builds fragments");fragments.note_placed_box(node, placement, cells_kept_for_contained_abspos(run, node));+ debug_assert!(+ facts_decided_by_parent.placement.is_none(),+ "a child is handed to placement before it is placed"+ );+ let facts_decided_by_parent = run_records::FactsDecidedByParent {+ placement: Some(placement),+ ..facts_decided_by_parent+ };fragments.attach_committed_fragment(node,fragment,true,(!containing_block.is_invalid()).then_some(containing_block),- records.facts_decided_by_parent_of(node),+ facts_decided_by_parent,None,None,point_add(offset,- committed_offset_delta_at_placement(records, callbacks, node, containing_block),+ committed_offset_delta_at_placement(+ records,+ callbacks,+ node,+ facts_decided_by_parent.used_insets,+ containing_block,+ ),),callbacks.frame,);@@ -569,6 +650,7 @@ fn committed_offset_delta_at_placement(records: &RunRecords,callbacks: &LayoutPass<'_>,node: Node,+ used_insets: run_records::UsedInsets,containing_block: Node,) -> FfiCssPixelPoint {let mut delta = FfiCssPixelPoint::default();@@ -577,7 +659,7 @@ fn committed_offset_delta_at_placement(return delta;}if facts.is_relatively_positioned() {- let insets = records.used_insets_of(node);+ let insets = used_insets;delta.x += insets.left;delta.y += insets.top;}@@ -3524,7 +3606,13 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layolet viewport_used = entry_records.create_used_values(&callbacks, root, root_constraints);viewport_used.set_content_inline_size(viewport_inline_size);viewport_used.set_content_block_size(viewport_block_size);- place_child(&entry_run, root, FfiCssPixelPoint::default(), None);+ place_child(+ &entry_run,+ root,+ PlacedChild::read_from_records(&entry_run, root),+ FfiCssPixelPoint::default(),+ None,+ );first_child} else {root@@ -3556,6 +3644,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layoplace_laid_out_child(&entry_run,root_for_layout,+ PlacedChild::read_from_records(&entry_run, root_for_layout),FfiCssPixelPoint::default(),None,fragment_arrival,diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 7cca6404dc7..7b3412d2af3 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4456,7 +4456,14 @@ impl<'pass> GridFormattingContext<'pass> {baseline_aligned_items.push((item_index, offset, fragment_arrival));continue;}- formatting_context::place_laid_out_child(&self.run, item.box_, offset, None, fragment_arrival);+ formatting_context::place_laid_out_child(+ &self.run,+ item.box_,+ formatting_context::PlacedChild::read_from_records(&self.run, item.box_),+ offset,+ None,+ fragment_arrival,+ );}self.place_baseline_aligned_items(baseline_aligned_items);self.derived_baselines_of_root_box = DerivedBaselines {@@ -4617,7 +4624,14 @@ impl<'pass> GridFormattingContext<'pass> {if self.item_participates_in_column_baseline_alignment(item) {offset.x += shared_column_baselines[&item.column] - self.item_column_baseline(item);}- formatting_context::place_laid_out_child(&self.run, item.box_, offset, None, fragment_arrival);+ formatting_context::place_laid_out_child(+ &self.run,+ item.box_,+ formatting_context::PlacedChild::read_from_records(&self.run, item.box_),+ offset,+ None,+ fragment_arrival,+ );}}diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex ce069cb707f..603f1e9ef51 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -2111,7 +2111,14 @@ impl<'context> InlineFormattingContext<'context> {for (node, position) in atomic_inlines_after_clamp_point {self.run.records.hide_for_line_clamp(node);let fragment_arrival = self.take_atomic_inline_fragment_arrival(node);- formatting_context::place_laid_out_child(self.run, node, position, None, fragment_arrival);+ formatting_context::place_laid_out_child(+ self.run,+ node,+ formatting_context::PlacedChild::read_from_records(self.run, node),+ position,+ None,+ fragment_arrival,+ );}}if self.parent.line_clamp_reached() {@@ -2235,7 +2242,13 @@ impl<'context> InlineFormattingContext<'context> {.as_ref().is_none_or(|present| present.contains(&node)){- formatting_context::place_child(self.run, node, FfiCssPixelPoint::default(), None);+ formatting_context::place_child(+ self.run,+ node,+ formatting_context::PlacedChild::read_from_records(self.run, node),+ FfiCssPixelPoint::default(),+ None,+ );}}}@@ -2259,6 +2272,7 @@ impl<'context> InlineFormattingContext<'context> {formatting_context::place_laid_out_child(self.run,fragment.layout_node,+ formatting_context::PlacedChild::read_from_records(self.run, fragment.layout_node),FfiCssPixelPoint {x: x + relative_insets.offset_x,y: y + relative_insets.offset_y,diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex ca835fb7f7b..ab78f9bdb50 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -1017,7 +1017,13 @@ fn record_entered_inline_box(let sides = used_values::RootInputCells::capture(used);context.keep_entered_inline_box(node, sides, insets);if context.run.fragments.is_some() && context.run.fragmentainer.is_none() {- formatting_context::place_child(context.run, node, FfiCssPixelPoint::default(), None);+ formatting_context::place_child(+ context.run,+ node,+ formatting_context::PlacedChild::read_from_records(context.run, node),+ FfiCssPixelPoint::default(),+ None,+ );}sides}diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex 238c29f2cac..3a7fa8e637e 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2292,7 +2292,14 @@ impl<'pass> MathFormattingContext<'pass> {y: margin_box_top + metrics.margin_box_top(collapsed),};let fragment_arrival = self.take_fragment_arrival_of_child(child.node);- formatting_context::place_laid_out_child(run, child.node, offset, None, fragment_arrival);+ formatting_context::place_laid_out_child(+ run,+ child.node,+ formatting_context::PlacedChild::read_from_records(run, child.node),+ offset,+ None,+ fragment_arrival,+ );}for fragment_arrival in self.fragment_arrivals_of_children.take() {formatting_context::leave_child_unplaced(run, Some(fragment_arrival));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 d5c397cb18d..57d3ef07299 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@@ -76,6 +76,7 @@ pub(super) fn layout_replaced_with_children(formatting_context::place_laid_out_child(run,wrapper,+ formatting_context::PlacedChild::read_from_records(run, wrapper),used_values::FfiCssPixelPoint::default(),None,fragment_arrival,diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 2d83860cb45..7177081ea7d 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -1880,7 +1880,14 @@ impl<'pass> SvgFormattingContext<'pass> {y: CssPixels,fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,) {- formatting_context::place_laid_out_child(&self.run, node, FfiCssPixelPoint { x, y }, None, fragment_arrival);+ formatting_context::place_laid_out_child(+ &self.run,+ node,+ formatting_context::PlacedChild::read_from_records(&self.run, node),+ FfiCssPixelPoint { x, y },+ None,+ fragment_arrival,+ );}/// Gives `node` a content size that is definite in both axes.diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex be4711b5b86..2c36007b903 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1225,7 +1225,13 @@ impl<'pass> TableFormattingContext<'pass> {}fn place_child(&self, node: Node, x: CssPixels, y: CssPixels) {- formatting_context::place_child(&self.run, node, FfiCssPixelPoint { x, y }, None);+ formatting_context::place_child(+ &self.run,+ node,+ formatting_context::PlacedChild::read_from_records(&self.run, node),+ FfiCssPixelPoint { x, y },+ None,+ );}fn border_spacing_inline(&mut self) -> CssPixels {@@ -3331,6 +3337,7 @@ impl<'pass> TableFormattingContext<'pass> {formatting_context::place_laid_out_child(&self.run,cell.box_,+ formatting_context::PlacedChild::read_from_records(&self.run, cell.box_),FfiCssPixelPoint { x, y },None,fragment_arrival,