Truly independent web browser
LibWeb: Read placements and insets through the run that owns them
Aliaksandr Kalenik1952bff023e0
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 441be3302e8..b28d764220f 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -168,14 +168,10 @@ impl<'pass> AbsposEngine<'pass> {let mut origin = FfiCssPixelPoint::default();loop {origins_by_chain_box.push((chain_box, origin));- let Some(used) = self- .records- .used_values_if_owned(chain_box)- .filter(|used| used.has_content_offset.get())- else {+ let Some(placement) = self.records.placement_of(chain_box) else {break;};- origin = formatting_context::point_add(origin, used.content_offset.get());+ origin = formatting_context::point_add(origin, placement.content_offset_in_containing_block);chain_box = self.placement_containing_block(chain_box);if chain_box.is_invalid() {break;@@ -190,17 +186,13 @@ impl<'pass> AbsposEngine<'pass> {{return formatting_context::point_sub(*origin, space_origin);}- let used = self- .records- .used_values_if_owned(space_box)- .filter(|used| used.has_content_offset.get())- .unwrap_or_else(|| {- panic!(- "an entry's space chain crossed an unplaced or foreign record before meeting its containing block's chain (slot {})",- space_box.slot_index()- )- });- space_origin = formatting_context::point_add(space_origin, used.content_offset.get());+ let placement = self.records.placement_of(space_box).unwrap_or_else(|| {+ panic!(+ "an entry's space chain crossed an unplaced or foreign record before meeting its containing block's chain (slot {})",+ space_box.slot_index()+ )+ });+ space_origin = formatting_context::point_add(space_origin, placement.content_offset_in_containing_block);space_box = self.placement_containing_block(space_box);assert!(!space_box.is_invalid(),@@ -222,13 +214,12 @@ impl<'pass> AbsposEngine<'pass> {let mut offset = FfiCssPixelPoint::default();let mut current = descendant;while current != merge_point {- let used = self.records.used_values_if_owned(current).unwrap_or_else(|| {- panic!(- "a payload resting space's chain crossed a record this run does not own (slot {})",- current.slot_index()- )- });- offset = formatting_context::point_add(offset, used.content_offset.get());+ assert!(+ self.records.used_values_if_owned(current).is_some(),+ "a payload resting space's chain crossed a record this run does not own (slot {})",+ current.slot_index()+ );+ offset = formatting_context::point_add(offset, self.records.content_offset_or_origin(current));current = self.placement_containing_block(current);assert!(!current.is_invalid());}@@ -3134,20 +3125,21 @@ impl<'pass> AbsposEngine<'pass> {let static_offset = self.static_offset(node, inputs.static_position_rect);let used = self.used(node);let collapsed = used.uses_collapsing_borders_model.get();+ let mut used_insets = self.records.used_insets_of(node);let mut used_offset = geometry::LogicalOffset {inline_offset: if inputs.containing_block_info.inline_axis_mode== abspos_inputs::AbsposAxisMode::StaticPosition{static_offset.inline_offset} else {- inputs.containing_block_info.rect.offset.inline_offset + used.inset_left.get()+ inputs.containing_block_info.rect.offset.inline_offset + used_insets.left},block_offset: if inputs.containing_block_info.block_axis_mode== abspos_inputs::AbsposAxisMode::StaticPosition{static_offset.block_offset} else {- inputs.containing_block_info.rect.offset.block_offset + used.inset_top.get()+ inputs.containing_block_info.rect.offset.block_offset + used_insets.top},};used_offset.inline_offset += used.margin_left.get() + used.border_box_left(collapsed);@@ -3165,17 +3157,14 @@ impl<'pass> AbsposEngine<'pass> {.with_resolved_insets(inputs.resolved_anchor_insets.as_ref());let containing_block_size = inputs.containing_block_info.rect.size;if aligns_inline {- used.inset_left- .set(style.inset_left().to_px(containing_block_size.inline_size));- used.inset_right- .set(style.inset_right().to_px(containing_block_size.inline_size));+ used_insets.left = style.inset_left().to_px(containing_block_size.inline_size);+ used_insets.right = style.inset_right().to_px(containing_block_size.inline_size);}if aligns_block {- used.inset_top- .set(style.inset_top().to_px(containing_block_size.block_size));- used.inset_bottom- .set(style.inset_bottom().to_px(containing_block_size.block_size));+ used_insets.top = style.inset_top().to_px(containing_block_size.block_size);+ used_insets.bottom = style.inset_bottom().to_px(containing_block_size.block_size);}+ self.records.set_used_insets(node, used_insets);}if self.fragments.is_some() {self.used(node).rare_data_mut().abspos_layout_inputs = Some(inputs);@@ -3786,11 +3775,15 @@ impl<'pass> AbsposEngine<'pass> {block_axis_inset_value(style.inset_bottom(), treat_block_axis_percentage_insets_as_auto),containing_block_size.block_size,);- let used = self.used(node);- used.inset_left.set(left);- used.inset_right.set(right);- used.inset_top.set(top);- used.inset_bottom.set(bottom);+ self.records.set_used_insets(+ node,+ run_records::UsedInsets {+ left,+ right,+ top,+ bottom,+ },+ );}}diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 920c04530be..6c564cff173 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -2475,7 +2475,7 @@ impl<'pass> BlockFormattingContext<'pass> {drop(margin_state);let used = self.used(node);self.block_offset_of_current_block_container.set(Some(- used.content_offset.get().y+ self.run.records.content_offset_or_origin(node).y+ used.content_block_size.get()+ used.border_box_bottom(used.uses_collapsing_borders_model.get()),));@@ -2490,7 +2490,7 @@ impl<'pass> BlockFormattingContext<'pass> {let used = self.used(node);*bottom_of_lowest_margin_box = (*bottom_of_lowest_margin_box).max(- used.content_offset.get().y+ self.run.records.content_offset_or_origin(node).y+ used.content_block_size.get()+ used.margin_box_bottom(used.uses_collapsing_borders_model.get()),);@@ -2662,7 +2662,7 @@ impl<'pass> BlockFormattingContext<'pass> {let mut cells = used_values::UsedValuesCellState::capture(used);cells.inputs.has_content_offset = false;cells.inputs.content_offset = FfiCssPixelPoint::default();- let content_offset = used.content_offset.get();+ let content_offset = self.run.records.content_offset_or_origin(node);let entry = in_flow_block_cache::InFlowBlockEntry {key,validity,@@ -2856,12 +2856,10 @@ impl<'pass> BlockFormattingContext<'pass> {.borrow_mut().take_if(|token| token.node == child);if let Some(token) = broken_child_token {- if self.allows_unforced_breaks()- && let Some(used) = self.run.records.used_values_if_owned(child)- {+ if self.allows_unforced_breaks() && self.run.records.used_values_if_owned(child).is_some() {let content_block_end = state.container_content_box_block_start_in_root+ self.block_offset_adjustment_from_pending_ancestor_block_start_margins(block_container)- + used.content_offset.get().y+ + self.run.records.content_offset_or_origin(child).y+ self.block_end_of_content(child);if fragmentainer.exceeds(content_block_end) {fragmentainer.note_space_shortage(content_block_end);@@ -2891,7 +2889,7 @@ impl<'pass> BlockFormattingContext<'pass> {if self.allows_unforced_breaks() {let content_block_end = state.container_content_box_block_start_in_root+ self.block_offset_adjustment_from_pending_ancestor_block_start_margins(block_container)- + used.content_offset.get().y+ + self.run.records.content_offset_or_origin(child).y+ used.content_block_size.get();let is_breakable = self.child_is_breakable(child);if !is_breakable {@@ -3201,10 +3199,12 @@ impl<'pass> BlockFormattingContext<'pass> {.map_or(CssPixels::default(), |line| line.physical_vertical_end());}self.laid_out_children(node)- .filter_map(|child| self.run.records.used_values_if_owned(child))- .filter(|used| used.has_content_offset.get())- .map(|used| {- used.content_offset.get().y+ .filter_map(|child| {+ let placement = self.run.records.placement_of(child)?;+ Some((placement, self.run.records.used_values(child)))+ })+ .map(|(placement, used)| {+ placement.content_offset_in_containing_block.y+ used.content_block_size.get()+ used.border_box_bottom(used.uses_collapsing_borders_model.get())})@@ -4443,7 +4443,7 @@ impl<'pass> BlockFormattingContext<'pass> {margin_state.box_last_in_flow_child_margin_bottom_collapsed = true;margin_bottom = CssPixels::default();}- return (child_used.content_offset.get().y+ return (self.run.records.content_offset_or_origin(child).y+ child_used.content_block_size.get()+ child_used.border_box_bottom(child_used.uses_collapsing_borders_model.get())+ margin_bottom)@@ -4759,7 +4759,7 @@ pub(crate) fn automatic_block_size_for_bfc_root(}_ => child_used.margin_bottom.get(),};- let child_bottom = child_used.content_offset.get().y+ let child_bottom = records.content_offset_or_origin(child).y+ child_used.content_block_size.get()+ child_used.border_box_bottom(collapsed)+ margin_bottom;diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 098df56192d..7db158a8080 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -372,7 +372,11 @@ pub(crate) fn place_child_in_containing_block(let records = run.records;let callbacks = &run.callbacks;let used = records.used_values(node);- set_placement(used, containing_block, offset);+ let placement = run_records::BoxPlacement {+ content_offset_in_containing_block: offset,+ containing_block,+ };+ records.place_box(node, placement);let fragments = run.fragments.as_deref()?;if let Some((fragment, reuses_subtree)) = fragments.take_reused_committed_fragment(callbacks, node, used) {fragments.attach_committed_fragment(@@ -381,11 +385,13 @@ pub(crate) fn place_child_in_containing_block(reuses_subtree,(!containing_block.is_invalid()).then_some(containing_block),used,- containing_block_is_sealed(records, containing_block),+ placement,+ records.used_insets_of(node),+ containing_block_is_placed_or_outside_run(records, containing_block),resolve_containing_line_box_index(records, callbacks, node, containing_block, containing_line_box_fragment),point_add(offset,- committed_offset_delta_at_placement(records, callbacks, node, containing_block, used),+ committed_offset_delta_at_placement(records, callbacks, node, containing_block),),callbacks.frame,);@@ -406,8 +412,8 @@ pub(crate) fn place_child_in_containing_block(let own_anchor_candidate_border_box_rect = (node_facts.is_box() && node_facts.has_anchor_names()).then(|| {let collapsed = used.uses_collapsing_borders_model.get();CssPixelRect {- x: used.content_offset.get().x - used.border_box_left(collapsed),- y: used.content_offset.get().y - used.border_box_top(collapsed),+ x: offset.x - used.border_box_left(collapsed),+ y: offset.y - used.border_box_top(collapsed),width: used.border_box_inline_size(collapsed),height: used.border_box_block_size(collapsed),}@@ -417,11 +423,13 @@ pub(crate) fn place_child_in_containing_block(node,(!containing_block.is_invalid()).then_some(containing_block),used,- containing_block_is_sealed(records, containing_block),+ placement,+ records.used_insets_of(node),+ containing_block_is_placed_or_outside_run(records, containing_block),resolve_containing_line_box_index(records, callbacks, node, containing_block, containing_line_box_fragment),point_add(offset,- committed_offset_delta_at_placement(records, callbacks, node, containing_block, used),+ committed_offset_delta_at_placement(records, callbacks, node, containing_block),),own_anchor_candidate_border_box_rect,))@@ -438,8 +446,11 @@ pub(crate) fn place_reused_child(let records = run.records;let callbacks = &run.callbacks;let containing_block = callbacks.in_flow_containing_block(node);- let used = records.used_values(node);- set_placement(used, containing_block, offset);+ let placement = run_records::BoxPlacement {+ content_offset_in_containing_block: offset,+ containing_block,+ };+ records.place_box(node, placement);let fragments = run.fragments.as_deref()@@ -449,30 +460,22 @@ pub(crate) fn place_reused_child(fragment,true,(!containing_block.is_invalid()).then_some(containing_block),- used,- containing_block_is_sealed(records, containing_block),+ records.used_values(node),+ placement,+ records.used_insets_of(node),+ containing_block_is_placed_or_outside_run(records, containing_block),None,point_add(offset,- committed_offset_delta_at_placement(records, callbacks, node, containing_block, used),+ committed_offset_delta_at_placement(records, callbacks, node, containing_block),),callbacks.frame,);}-fn set_placement(used: &UsedValues, containing_block: Node, offset: FfiCssPixelPoint) {- assert!(!used.has_content_offset.get());- used.has_content_offset.set(true);- used.content_offset.set(offset);- used.placed_in.set(containing_block);- used.seal_committed_box_metrics();-}--fn containing_block_is_sealed(records: &RunRecords, containing_block: Node) -> bool {+fn containing_block_is_placed_or_outside_run(records: &RunRecords, containing_block: Node) -> bool {!containing_block.is_invalid()- && records- .used_values_if_owned(containing_block)- .is_none_or(|containing_block_used| containing_block_used.has_content_offset.get())+ && (records.used_values_if_owned(containing_block).is_none() || records.is_placed(containing_block))}/// The line box index to record for atomic inlines whose containing line@@ -509,7 +512,6 @@ fn committed_offset_delta_at_placement(callbacks: &LayoutPass<'_>,node: Node,containing_block: Node,- used: &UsedValues,) -> FfiCssPixelPoint {let mut delta = FfiCssPixelPoint::default();let facts = NodeFacts::new(callbacks, node);@@ -517,8 +519,9 @@ fn committed_offset_delta_at_placement(return delta;}if facts.is_relatively_positioned() {- delta.x += used.inset_left.get();- delta.y += used.inset_top.get();+ let insets = records.used_insets_of(node);+ delta.x += insets.left;+ delta.y += insets.top;}if facts.is_in_flow() && facts.display().is_block_outside() {let chain = inline_formatting_context::accumulated_relative_insets_from_inline_ancestor_chain(@@ -562,9 +565,8 @@ pub(crate) fn register_contained_abspos_child(pub(crate) fn placement_containing_block(records: &RunRecords, callbacks: &LayoutPass<'_>, node: Node) -> Node {let placed_in = records- .used_values_if_owned(node)- .filter(|used| used.has_content_offset.get())- .map_or(NodeSlotId::INVALID, |used| used.placed_in.get());+ .placement_of(node)+ .map_or(NodeSlotId::INVALID, |placement| placement.containing_block);if !placed_in.is_invalid() {return placed_in;}@@ -801,7 +803,7 @@ pub(crate) fn derive_baselines(records: &RunRecords, callbacks: &LayoutPass<'_>,.first_fragment_node.expect("block-level line must have one fragment");let block_child_state = records.used_values(fragment_node);- let child_offset_from_margin_edge = block_child_state.content_offset.get().y+ let child_offset_from_margin_edge = records.content_offset_or_origin(fragment_node).y- block_child_state.margin_box_top(block_child_state.uses_collapsing_borders_model.get());child_offset_from_margin_edge+ box_baseline_for_purpose(@@ -933,12 +935,13 @@ pub(crate) fn baseline_of_child_for_purpose(// https://drafts.csswg.org/css-align-3/#synthesize-baseline// The alphabetic baseline is synthesized from the line-under edge of the border box.return Some(- child_state.content_offset.get().y+ records.content_offset_or_origin(child).y+ child_state.content_block_size.get()+ child_state.border_box_bottom(collapsed),);}- let child_offset_from_margin_edge = child_state.content_offset.get().y - child_state.margin_box_top(collapsed);+ let child_offset_from_margin_edge =+ records.content_offset_or_origin(child).y - child_state.margin_box_top(collapsed);Some(child_offset_from_margin_edge+ box_baseline_for_purpose(@@ -1715,11 +1718,8 @@ fn in_flow_children_margin_box_block_extent(let facts = NodeFacts::new(callbacks, child);if facts.is_box() && !facts.is_absolutely_positioned() {let used = records.used_values_if_owned(child)?;- if !used.has_content_offset.get() {- return None;- }+ let content_block_offset = records.placement_of(child)?.content_offset_in_containing_block.y;let collapsed = used.uses_collapsing_borders_model.get();- let content_block_offset = used.content_offset.get().y;block_start = block_start.min(content_block_offset - used.margin_box_top(collapsed));block_end =block_end.max(content_block_offset + used.content_block_size.get() + used.margin_box_bottom(collapsed));@@ -3495,14 +3495,20 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {// The retained offset already includes relative positioning. Publish it directly instead// of applying placement adjustments a second time.fragments.normalize_arrivals_for_placement(root, callbacks);+ let placement = run+ .records+ .placement_of(root)+ .expect("the root of a partial relayout keeps the placement it committed");fragments.build_fragment_for_placed_box(callbacks,root,None,root_used,+ placement,+ run.records.used_insets_of(root),false,None,- root_used.content_offset.get(),+ placement.content_offset_in_containing_block,None,);}diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex a0631a92b6a..246062303f4 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -394,13 +394,10 @@ fn propagate_payload_toward_run_root_space<Payload: PropagatedPayload>(callbacks: &LayoutPass<'_>,) {while payload.coordinate_space_box() != run_root {- let Some(used) = records- .used_values_if_owned(payload.coordinate_space_box())- .filter(|used| used.has_content_offset.get())- else {+ let Some(placement) = records.placement_of(payload.coordinate_space_box()) else {break;};- payload.translate_by(used.content_offset.get());+ payload.translate_by(placement.content_offset_in_containing_block);let containing_block =formatting_context::placement_containing_block(records, callbacks, payload.coordinate_space_box());if containing_block.is_invalid() {@@ -545,8 +542,10 @@ pub(crate) struct PlacementData {}impl PlacementData {- fn from_record(+ fn of_box(used: &UsedValues,+ containing_block: crate::layout::node_data::NodeSlotId,+ used_insets: run_records::UsedInsets,containing_line_box_index: Option<usize>,committed_offset: FfiCssPixelPoint,frame: geometry::Frame,@@ -555,16 +554,36 @@ impl PlacementData {Self {frame,committed_offset,- inset_left: used.inset_left.get(),- inset_right: used.inset_right.get(),- inset_top: used.inset_top.get(),- inset_bottom: used.inset_bottom.get(),+ inset_left: used_insets.left,+ inset_right: used_insets.right,+ inset_top: used_insets.top,+ inset_bottom: used_insets.bottom,containing_line_box_index,abspos_layout_inputs: rare.as_ref().and_then(|rare| rare.abspos_layout_inputs),default_scroll_shift: rare.as_ref().and_then(|rare| rare.default_scroll_shift),- containing_block: used.placed_in.get(),+ containing_block,}}++ /// The placement data of a box `close()` hands on unplaced or placed as it is.+ fn of_box_as_this_run_left_it(+ records: &RunRecords,+ node: crate::layout::node_data::NodeSlotId,+ frame: geometry::Frame,+ ) -> Self {+ Self::of_box(+ records.used_values(node),+ records+ .placement_of(node)+ .map_or(crate::layout::node_data::NodeSlotId::INVALID, |placement| {+ placement.containing_block+ }),+ records.used_insets_of(node),+ None,+ records.content_offset_or_origin(node),+ frame,+ )+ }}fn link_fragment(fragment: std::sync::Arc<Fragment>, placement: PlacementData) -> FragmentLink {@@ -1051,9 +1070,7 @@ impl RunFragmentBuilder {let containing_block = entry.containing_block();!containing_block.is_invalid()&& (self.is_entry_accumulator || containing_block != self.root_node)- && records- .used_values_if_owned(containing_block)- .is_some_and(|containing_block_used| containing_block_used.has_content_offset.get())+ && records.is_placed(containing_block)};let mut taken: Vec<abspos_inputs::PendingAbsposChild> = inner.pending_abspos_at_root@@ -1237,6 +1254,8 @@ impl RunFragmentBuilder {node: crate::layout::node_data::NodeSlotId,containing_block: Option<crate::layout::node_data::NodeSlotId>,used: &UsedValues,+ placement: run_records::BoxPlacement,+ used_insets: run_records::UsedInsets,containing_block_is_sealed: bool,containing_line_box_index: Option<usize>,committed_offset: FfiCssPixelPoint,@@ -1261,14 +1280,21 @@ impl RunFragmentBuilder {let fragment = snapshot_fragment(callbacks, node, children, used);let link = link_fragment(fragment.clone(),- PlacementData::from_record(used, containing_line_box_index, committed_offset, callbacks.frame),+ PlacementData::of_box(+ used,+ placement.containing_block,+ used_insets,+ containing_line_box_index,+ committed_offset,+ callbacks.frame,+ ),);self.attach(&mut inner, link, containing_block, containing_block_is_sealed);let exports_payloads = !pending_abspos_from_placed_box.is_empty()|| !anchor_candidates_from_placed_box.is_empty()|| !inline_containing_block_rects_from_placed_box.is_empty()|| own_anchor_candidate_border_box_rect.is_some();- let content_offset = used.content_offset.get();+ let content_offset = placement.content_offset_in_containing_block;let frames = exports_payloads.then(|| {let own = formatting_context::frame_established_by(callbacks, node);@@ -1343,6 +1369,8 @@ impl RunFragmentBuilder {reuses_subtree: bool,containing_block: Option<crate::layout::node_data::NodeSlotId>,used: &UsedValues,+ placement: run_records::BoxPlacement,+ used_insets: run_records::UsedInsets,containing_block_is_sealed: bool,containing_line_box_index: Option<usize>,committed_offset: FfiCssPixelPoint,@@ -1356,7 +1384,14 @@ impl RunFragmentBuilder {);let link = link_fragment(fragment,- PlacementData::from_record(used, containing_line_box_index, committed_offset, frame),+ PlacementData::of_box(+ used,+ placement.containing_block,+ used_insets,+ containing_line_box_index,+ committed_offset,+ frame,+ ),);self.attach(&mut inner, link, containing_block, containing_block_is_sealed);if reuses_subtree {@@ -1444,7 +1479,7 @@ impl RunFragmentBuilder {let used = records.used_values(pending_fragment.node);inner.top_scope_links.push(link_fragment(snapshot_fragment(callbacks, pending_fragment.node, pending_fragment.children, used),- PlacementData::from_record(used, None, used.content_offset.get(), callbacks.frame),+ PlacementData::of_box_as_this_run_left_it(records, pending_fragment.node, callbacks.frame),));}// NB: A reused subtree root its run never placed has no children of its own in this run, as an empty held@@ -1462,7 +1497,7 @@ impl RunFragmentBuilder {}inner.top_scope_links.push(link_fragment(snapshot_fragment(callbacks, node, Vec::new(), used),- PlacementData::from_record(used, None, used.content_offset.get(), callbacks.frame),+ PlacementData::of_box_as_this_run_left_it(records, node, callbacks.frame),));}let child_roots_awaiting_placement = std::mem::take(&mut inner.child_roots_awaiting_placement);@@ -1470,7 +1505,7 @@ impl RunFragmentBuilder {let used = records.used_values(root.node);inner.top_scope_links.push(link_fragment(snapshot_fragment(callbacks, root.node, root.scoped_descendants, used),- PlacementData::from_record(used, None, used.content_offset.get(), callbacks.frame),+ PlacementData::of_box_as_this_run_left_it(records, root.node, callbacks.frame),));}for entry in &mut propagated_pending_abspos {@@ -1480,9 +1515,7 @@ impl RunFragmentBuilder {debug_assert!(containing_block.is_invalid()|| containing_block == self.root_node- || records- .used_values_if_owned(containing_block)- .is_none_or(|containing_block_used| !containing_block_used.has_content_offset.get()),+ || !records.is_placed(containing_block),"a drainable abspos registration survived its containing block's run (slot {})",entry.child_box.slot_index());diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex b7b6349f702..47d2a3406e9 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -917,9 +917,9 @@ pub(crate) fn accumulated_relative_insets_from_inline_ancestor_chain(// committed fragment or piece was entered by its inline// formatting context this pass, which created its used values// and resolved its insets.- let used = records.used_values(ancestor);- result.offset_x += used.inset_left.get();- result.offset_y += used.inset_top.get();+ let insets = records.used_insets_of(ancestor);+ result.offset_x += insets.left;+ result.offset_y += insets.top;}ancestor = callbacks.parent(ancestor);}diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rsindex d86bbaf68d4..1f4bc4ac467 100644--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs@@ -527,9 +527,15 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {block_end_margin: CssPixels,) {let used = self.context().used(node);- assert!(used.has_content_offset.get());- let inline_offset = used.content_offset.get().x;- let block_offset = used.content_offset.get().y;+ let content_offset = self+ .context()+ .run+ .records+ .placement_of(node)+ .expect("a block-level box is placed before its line takes it")+ .content_offset_in_containing_block;+ let inline_offset = content_offset.x;+ let block_offset = content_offset.y;let inline_length = used.content_inline_size.get();let block_length = used.content_block_size.get();let border_start = used.border_box_top(false);diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex dc7b197ab42..17f24047ee9 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -305,6 +305,22 @@ pub(crate) struct RunRecords<'arena> {percentage_block_size_dependencies_in_progress: PercentageBlockSizeDependenciesInProgress,}+/// Where a box is placed: the offset of its content box in the containing block it is placed in.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) struct BoxPlacement {+ pub(crate) content_offset_in_containing_block: FfiCssPixelPoint,+ pub(crate) containing_block: Node,+}++/// The used values of a box's inset properties.+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+pub(crate) struct UsedInsets {+ pub(crate) left: CssPixels,+ pub(crate) right: CssPixels,+ pub(crate) top: CssPixels,+ pub(crate) bottom: CssPixels,+}+/// Whether a box depends on the block size its percentages resolve against, and whether a box it contains does.#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub(crate) struct PercentageBlockSizeDependency {@@ -541,6 +557,56 @@ impl<'arena> RunRecords<'arena> {self.root}+ /// Places `node` in `placement`, which is final: the box's metrics are sealed with it.+ pub(crate) fn place_box(&self, node: Node, placement: BoxPlacement) {+ let used = self.used_values(node);+ assert!(!used.has_content_offset.get(), "a box is placed once");+ used.has_content_offset.set(true);+ used.content_offset.set(placement.content_offset_in_containing_block);+ used.placed_in.set(placement.containing_block);+ used.seal_committed_box_metrics();+ }++ /// Where `node` is placed, if this run placed it.+ pub(crate) fn placement_of(&self, node: Node) -> Option<BoxPlacement> {+ let used = self.used_values_if_owned(node)?;+ used.has_content_offset.get().then(|| BoxPlacement {+ content_offset_in_containing_block: used.content_offset.get(),+ containing_block: used.placed_in.get(),+ })+ }++ pub(crate) fn is_placed(&self, node: Node) -> bool {+ self.placement_of(node).is_some()+ }++ /// The offset of the content box of `node` in its containing block, or the origin while the box is not placed.+ #[track_caller]+ pub(crate) fn content_offset_or_origin(&self, node: Node) -> FfiCssPixelPoint {+ self.used_values(node).content_offset.get()+ }++ #[track_caller]+ pub(crate) fn used_insets_of(&self, node: Node) -> UsedInsets {+ let used = self.used_values(node);+ UsedInsets {+ left: used.inset_left.get(),+ right: used.inset_right.get(),+ top: used.inset_top.get(),+ bottom: used.inset_bottom.get(),+ }+ }++ /// Sets the used insets of `node`, which cannot change once the box is placed.+ #[track_caller]+ pub(crate) fn set_used_insets(&self, node: Node, insets: UsedInsets) {+ let used = self.used_values(node);+ used.inset_left.set(insets.left);+ used.inset_right.set(insets.right);+ used.inset_top.set(insets.top);+ used.inset_bottom.set(insets.bottom);+ }+/// Tracks the percentage block size dependency of `node` until the returned tracking is dropped, which the layout/// of `node` holds while it is in progress.pub(crate) fn track_percentage_block_size_dependency_while_laying_out(diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex dc73b2136c6..ff89d926ddb 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2236,7 +2236,7 @@ impl<'pass> SvgFormattingContext<'pass> {if matches!(self.node_kind(child), NodeKind::SVGTextBox | NodeKind::SVGTextPathBox) {self.layout_graphics_element(run, child);let child_used = self.used_values(child);- let offset = child_used.content_offset.get();+ let offset = self.run.records.content_offset_or_origin(child);bounding_box.unite(SvgCssPixelRect {x: offset.x,y: offset.y,@@ -2374,9 +2374,10 @@ impl<'pass> SvgFormattingContext<'pass> {let child_used = child_used_pointer;// The container's bounding box includes descendants' transforms; children lay out// untransformed, so each child rect maps through the child's own transform here.+ let child_content_offset = self.run.records.content_offset_or_origin(child);let mapped_child_rect = self.svg_element_transform(child).map_rect(FfiFloatRect {- x: child_used.content_offset.get().x.raw_value() as f32 / 64.0,- y: child_used.content_offset.get().y.raw_value() as f32 / 64.0,+ x: child_content_offset.x.raw_value() as f32 / 64.0,+ y: child_content_offset.y.raw_value() as f32 / 64.0,width: child_used.content_inline_size.get().raw_value() as f32 / 64.0,height: child_used.content_block_size.get().raw_value() as f32 / 64.0,});diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex bd20dcf27e3..f24ff73ff8c 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -3049,11 +3049,12 @@ impl<'pass> TableFormattingContext<'pass> {continue;}let used = self.used_values(row.box_);+ let row_block_offset = self.run.records.content_offset_or_origin(row.box_).y;if !has_rows {- block_start = used.content_offset.get().y;+ block_start = row_block_offset;has_rows = true;}- block_end = used.content_offset.get().y + used.border_box_block_size(false);+ block_end = row_block_offset + used.border_box_block_size(false);inline_size = inline_size.max(used.border_box_inline_size(false));}let used = self.used_values(group);@@ -3221,16 +3222,18 @@ impl<'pass> TableFormattingContext<'pass> {for cell_index in 0..self.cells.len() {let cell = self.cells[cell_index];let used = self.used_values(cell.box_);- let row_used = self.used_values(self.rows[cell.row_index].box_);+ let row_content_offset = self+ .run+ .records+ .content_offset_or_origin(self.rows[cell.row_index].box_);// Compute cell position as specified by https://www.w3.org/TR/css-tables-3/#bounding-box-assignment:// left/top location is the sum of:// - for top: the height reserved for top captions (including margins), if any// - the padding-left/padding-top and border-left-width/border-top-width of the table// - the border spacing after each visible column before the cell (in its column's inline_offset)- let x = row_used.content_offset.get().x- + used.border_box_left(collapsed)- + self.columns[cell.column_index].inline_offset;- let y = row_used.content_offset.get().y + used.border_box_top(collapsed);+ let x =+ row_content_offset.x + used.border_box_left(collapsed) + self.columns[cell.column_index].inline_offset;+ let y = row_content_offset.y + used.border_box_top(collapsed);self.place_child(cell.box_, x, y);}}@@ -3253,7 +3256,7 @@ impl<'pass> TableFormattingContext<'pass> {.rows.first().map_or(self.table_box_content_block_offset_in_wrapper + block_spacing, |row| {- self.used_values(row.box_).content_offset.get().y+ self.run.records.content_offset_or_origin(row.box_).y});let mut block_end = block_start;for row in &self.rows {@@ -3261,7 +3264,8 @@ impl<'pass> TableFormattingContext<'pass> {continue;}let used = self.used_values(row.box_);- block_end = block_end.max(used.content_offset.get().y + used.border_box_block_size(false));+ block_end = block_end+ .max(self.run.records.content_offset_or_origin(row.box_).y + used.border_box_block_size(false));}let block_size = block_end - block_start;@@ -3314,7 +3318,7 @@ impl<'pass> TableFormattingContext<'pass> {if let Some(group) = group&& self.run.callbacks.in_flow_containing_block(node) == group{- let group_offset = self.used_values(group).content_offset.get();+ let group_offset = self.run.records.content_offset_or_origin(group);x -= group_offset.x;y -= group_offset.y;}@@ -3346,7 +3350,7 @@ impl<'pass> TableFormattingContext<'pass> {/// wrapper (see position_row_boxes), so each baseline is made relative to the content box it is stored on here.fn store_table_part_baselines(&self) {let baseline_in_wrapper = |row_index: usize| {- self.used_values(self.rows[row_index].box_).content_offset.get().y + self.row_baseline(row_index)+ self.run.records.content_offset_or_origin(self.rows[row_index].box_).y + self.row_baseline(row_index)};let baselines_of_rows = |rows: &[usize], content_block_offset: CssPixels| DerivedBaselines {inline_alignment: None,@@ -3381,7 +3385,7 @@ impl<'pass> TableFormattingContext<'pass> {let used = self.used_values(group);formatting_context::store_derived_baselines(used,- baselines_of_rows(&rows_in_group, used.content_offset.get().y),+ baselines_of_rows(&rows_in_group, self.run.records.content_offset_or_origin(group).y),);}self.derived_baselines_of_root_box.set(baselines_of_rows(