Truly independent web browser
LibWeb: Ask whether a run holds a box, not whether it has its record
Aliaksandr Kalenike0ef9516d41e
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex cab0f1a1cc1..e669ee66765 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -215,8 +215,8 @@ impl<'pass> AbsposEngine<'pass> {let mut current = descendant;while current != merge_point {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 {})",+ self.records.holds_box(current),+ "a payload resting space's chain crossed a box this run does not hold (slot {})",current.slot_index());offset = formatting_context::point_add(offset, self.records.content_offset_or_origin(current));diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex ad627155406..697a06c830d 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -1596,7 +1596,7 @@ impl<'pass> BlockFormattingContext<'pass> {}fn margins_collapse_through(&self, node: Node) -> bool {- if self.run.records.used_values_if_owned(node).is_none() {+ if !self.run.records.holds_box(node) {return true;}let facts = self.facts(node);@@ -2976,13 +2976,13 @@ impl<'pass> BlockFormattingContext<'pass> {}self.discard_block_start_margin_of_next_child.set(false);state.truncate_next_block_start_margin &=- self.run.records.used_values_if_owned(child).is_some() && self.margins_collapse_through(child);+ self.run.records.holds_box(child) && self.margins_collapse_through(child);let broken_child_token = self.broken_child_token.borrow_mut().take_if(|token| token.node == child);if let Some(token) = broken_child_token {- if self.allows_unforced_breaks() && self.run.records.used_values_if_owned(child).is_some() {+ if self.allows_unforced_breaks() && self.run.records.holds_box(child) {let content_block_end = state.container_content_box_block_start_in_root+ self.block_offset_adjustment_from_pending_ancestor_block_start_margins(block_container)+ self.run.records.content_offset_or_origin(child).y@@ -3307,7 +3307,7 @@ impl<'pass> BlockFormattingContext<'pass> {!child_facts.is_absolutely_positioned()&& !child_facts.is_floating()&& !child_facts.is_list_item_marker_box()- && self.run.records.used_values_if_owned(child).is_some()+ && self.run.records.holds_box(child)&& !self.run.records.is_invisible_for_line_clamp(child)&& !self.margins_collapse_through(child)})diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex ee20c2335be..143eb3524c1 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -544,8 +544,7 @@ pub(crate) fn place_reused_child(}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() || records.is_placed(containing_block))+ !containing_block.is_invalid() && (!records.holds_box(containing_block) || records.is_placed(containing_block))}/// The line box index to record for atomic inlines whose containing line@@ -2820,7 +2819,7 @@ pub(crate) fn propagate_percentage_block_size_dependency_to_containing_block(}let containing_block = callbacks.in_flow_containing_block(child);let containing_block_or_run_root_that_forwarded_the_basis =- if !containing_block.is_invalid() && records.used_values_if_owned(containing_block).is_some() {+ if !containing_block.is_invalid() && records.holds_box(containing_block) {containing_block} else {records.root()diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 11b85ee884f..83a0bfe58ff 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1797,7 +1797,7 @@ impl<'context> InlineFormattingContext<'context> {}inline_level_iterator::ItemType::Element => {line_builder.prepare_to_append_inline_content();- if shares_items && self.run.records.used_values_if_owned(item.node).is_none() {+ if shares_items && !self.run.records.holds_box(item.node) {self.create_used_values(item.node, self.input.containing_block_constraints);self.dimension_box_on_line(item.node);}diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 003bd8b4cb3..9f33e80ebba 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -712,6 +712,21 @@ impl<'arena> RunRecords<'arena> {}}+ /// Whether this run holds `node`: lays it out itself, or keeps a child laid out by a run of its own.+ pub(crate) fn holds_box(&self, node: Node) -> bool {+ self.held_box(node).is_some()+ }++ #[track_caller]+ fn panic_for_box_not_held(&self, node: Node) -> ! {+ panic!(+ "the run rooted at slot {} does not hold slot {} (read at {})",+ self.root.slot_index(),+ node.slot_index(),+ std::panic::Location::caller(),+ )+ }+fn held_box(&self, node: Node) -> Option<HeldBox> {if node == self.root && self.root_used.is_some() {return Some(HeldBox::RootWithRecord);@@ -742,11 +757,7 @@ impl<'arena> RunRecords<'arena> {Some(HeldBox::Kept(index)) => {self.scratch.kept_boxes.borrow_mut()[index as usize].facts_decided_by_parent = facts;}- None => panic!(- "the run rooted at slot {} does not own the record for slot {}",- self.root.slot_index(),- node.slot_index()- ),+ None => self.panic_for_box_not_held(node),}}@@ -757,8 +768,7 @@ impl<'arena> RunRecords<'arena> {/// Places `node` in `placement`, which is final: the box's metrics are sealed with it.#[track_caller]pub(crate) fn place_box(&self, node: Node, placement: BoxPlacement) {- let used = self.used_values(node);- let facts = self.kept_facts_decided_by_parent_of(node).unwrap_or_default();+ let facts = self.facts_decided_by_parent_of(node);assert!(facts.placement.is_none(), "a box is placed once");self.keep_facts_decided_by_parent_of(node,@@ -767,19 +777,22 @@ impl<'arena> RunRecords<'arena> {..facts},);- used.seal_own_metrics();+ if let Some(used) = self.used_values_if_owned(node) {+ used.seal_own_metrics();+ }}/// Adopts for `node` what its parent decided about it in the layout that committed `facts`, placing the box there.#[track_caller]pub(crate) fn adopt_committed_facts_decided_by_parent(&self, node: Node, facts: FactsDecidedByParent) {- let used = self.used_values(node);assert!(- facts.placement.is_some() && self.placement_of(node).is_none(),+ facts.placement.is_some() && self.facts_decided_by_parent_of(node).placement.is_none(),"a box adopts the placement it committed once");self.keep_facts_decided_by_parent_of(node, facts);- used.seal_own_metrics();+ if let Some(used) = self.used_values_if_owned(node) {+ used.seal_own_metrics();+ }}#[track_caller]@@ -797,8 +810,10 @@ impl<'arena> RunRecords<'arena> {/// What the parent of `node` has decided about it so far.#[track_caller]pub(crate) fn facts_decided_by_parent_of(&self, node: Node) -> FactsDecidedByParent {- self.used_values(node);- self.kept_facts_decided_by_parent_of(node).unwrap_or_default()+ match self.kept_facts_decided_by_parent_of(node) {+ Some(facts) => facts,+ None => self.panic_for_box_not_held(node),+ }}#[track_caller]@@ -871,8 +886,8 @@ impl<'arena> RunRecords<'arena> {/// 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);- self.placement_of(node)+ self.facts_decided_by_parent_of(node)+ .placement.map_or(FfiCssPixelPoint::default(), |placement| {placement.content_offset_in_containing_block})@@ -880,10 +895,7 @@ impl<'arena> RunRecords<'arena> {#[track_caller]pub(crate) fn used_insets_of(&self, node: Node) -> UsedInsets {- self.used_values(node);- self.kept_facts_decided_by_parent_of(node)- .unwrap_or_default()- .used_insets+ self.facts_decided_by_parent_of(node).used_insets}/// Sets the used insets of `node`, which cannot change once the box is placed.@@ -963,13 +975,8 @@ impl<'arena> RunRecords<'arena> {/// Keeps what the run of `child`, a box this run holds the record of, handed back once it returned.#[track_caller]pub(crate) fn receive_laid_out_child_box(&self, child: Node, laid_out: LaidOutChildBox) {- let caller = std::panic::Location::caller();let Some(HeldBox::Kept(index)) = self.held_box(child) else {- panic!(- "the run rooted at slot {} does not hold a child box for slot {} (received at {caller})",- self.root.slot_index(),- child.slot_index(),- )+ self.panic_for_box_not_held(child)};let KeptBoxHolding::Record {handed_back_by_its_run, ..@@ -981,14 +988,10 @@ impl<'arena> RunRecords<'arena> {/// out by a run of its own.#[track_caller]pub(crate) fn box_metrics_of(&self, node: Node) -> BoxMetrics<'_> {- let caller = std::panic::Location::caller();- self.box_metrics_of_if_owned(node).unwrap_or_else(|| {- panic!(- "the run rooted at slot {} does not hold slot {} (read at {caller})",- self.root.slot_index(),- node.slot_index(),- )- })+ match self.box_metrics_of_if_owned(node) {+ Some(metrics) => metrics,+ None => self.panic_for_box_not_held(node),+ }}/// The sizes, size constraints, box sides and baselines of `node`, if this run lays it out or holds a child it laiddiff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 3e8e295a002..0b551f6e32e 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1269,7 +1269,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {let in_quirks_mode = facts.document_in_quirks_mode();let svg_root_forwards_quirks_basis = facts.is_svg_svg_box() && in_quirks_mode;let forwards_block_basis_as_anonymous_box =- self.records.used_values_if_owned(node).is_some() && self.forwards_percentage_bases_as_anonymous_box(node);+ self.records.holds_box(node) && self.forwards_percentage_bases_as_anonymous_box(node);let forwards_quirks_basis_as_auto_height_block_container = in_quirks_mode&& !facts.is_viewport()&& !facts.is_table_cell()