Truly independent web browser
LibWeb: Stop sealing the metrics of layout records
Aliaksandr Kalenikc804fb902f2b
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 6b07b7b6a47..1e86453fe96 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -3045,20 +3045,14 @@ impl<'pass> BlockFormattingContext<'pass> {);let mut deferred_legend = None;let mut placed = match pending_position {- Some(position) => {- let placed = formatting_context::place_child(- &self.run,- node,- placed_child,- position,- containing_line_box_fragment,- fragment_arrival_of_child_with_own_formatting_context,- );- if let Some(record) = sized_child.record() {- record.seal_own_metrics();- }- placed- }+ Some(position) => formatting_context::place_child(+ &self.run,+ node,+ placed_child,+ position,+ containing_line_box_fragment,+ fragment_arrival_of_child_with_own_formatting_context,+ ),None => {deferred_legend = Some(Box::new(DeferredLegend {flow_position: legend_flow_position.expect("only a rendered legend waits for its position"),@@ -3276,7 +3270,6 @@ impl<'pass> BlockFormattingContext<'pass> {reuses_subtree: true,}),);- used.seal_own_metrics();self.block_offset_of_current_block_container.set(Some(flow_position + entry.flow_position_advance));(diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex cd07cedb03e..71bf8607890 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -2275,6 +2275,15 @@ fn execute_formatting_context_run(fragmentainer,parent_owns_root_input_cells,);+ if input.sizing.root_keeps_its_committed_geometry {+ assert_eq!(+ sizes_and_box_sides(+ used_values::RecordInFrame::new(records.used_values(box_), callbacks.frame).cells()+ ),+ sizes_and_box_sides(root_cells),+ "the run of {box_:?} changed the committed geometry of its root"+ );+ }let root_cells_left_by_run = checks_root_input_cells_its_parent_owns.then(|| used_values::RecordInFrame::new(records.used_values(box_), callbacks.frame).cells());(outputs, root_cells_left_by_run)@@ -2299,6 +2308,18 @@ fn execute_formatting_context_run(outputs}+/// The sizes and box sides of `cells`, with every flag cleared.+fn sizes_and_box_sides(cells: used_values::RootInputCells) -> used_values::RootInputCells {+ used_values::RootInputCells {+ has_definite_inline_size: false,+ has_definite_block_size: false,+ has_definite_block_size_only_for_button_content_alignment: false,+ uses_collapsing_borders_model: false,+ is_collapsed_borders_table_box: false,+ ..cells+ }+}+#[expect(clippy::too_many_arguments)]fn lay_out_run_root_and_contents<'pass>(records: &'pass RunRecords<'pass>,@@ -2316,9 +2337,6 @@ fn lay_out_run_root_and_contents<'pass>(parent_owns_root_input_cells: bool,) -> RunOutputs {let run_is_handed_table_inline_layout_outside_its_key = table_inline_layout.is_some();- if input.sizing.root_keeps_its_committed_geometry {- records.used_values(box_).seal_own_metrics();- }let run = FormattingContextRun {records,box_,@@ -2615,7 +2633,6 @@ fn lay_out_run_root_and_contents<'pass>(}}}- run.records.used_values(run.box_).seal_own_metrics();run.outputs(result,take_run_fragments(),diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 81e35b951a2..e26d9b48da2 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4508,8 +4508,6 @@ impl<'pass> GridFormattingContext<'pass> {x: area.offset.inline_offset + self.item_margin_box_start(item, Axis::Column),y: area.offset.block_offset + self.item_margin_box_start(item, Axis::Row),};- // Resolve relative-position insets before placement seals the- // item's committed metrics.let insets = abspos_engine::compute_inset_native(run,item.box_,diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 3edf607cc12..560f3adee2a 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -1881,7 +1881,6 @@ impl<'pass> SvgFormattingContext<'pass> {fn place_child(&self, node: Node, record: &UsedValues, x: CssPixels, y: CssPixels) -> LaidOutSvgElement {let placed_child = formatting_context::PlacedChild::of_record(record, None, &self.run);self.place_laid_out_child(node, placed_child, x, y, None);- record.seal_own_metrics();LaidOutSvgElement {cells: used_values::RootInputCells::capture(record),content_offset: FfiCssPixelPoint { x, y },@@ -2253,7 +2252,6 @@ impl<'pass> SvgFormattingContext<'pass> {reuses_subtree: false,}),);- used.seal_own_metrics();Some(LaidOutSvgElement {cells: used_values::RootInputCells::capture(used),content_offset: committed_offset,diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 715a7593a23..7d9a0b7a1c7 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1276,7 +1276,6 @@ impl<'pass> TableFormattingContext<'pass> {None,None,);- record.seal_own_metrics();participant_box.content_offset.set(content_offset);}diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rsindex a91f0951aa8..9a6982d7b01 100644--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs@@ -62,42 +62,6 @@ pub(crate) struct LineBoxFragmentCoordinate {pub line_box_index: usize,}-pub(crate) struct SealableCell<T> {- value: Cell<T>,- sealed: Cell<bool>,-}--impl<T: Copy + std::fmt::Debug> std::fmt::Debug for SealableCell<T> {- fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {- self.value.get().fmt(formatter)- }-}--impl<T: Copy> SealableCell<T> {- pub(crate) fn new(value: T) -> Self {- Self {- value: Cell::new(value),- sealed: Cell::new(false),- }- }-- #[inline]- pub(crate) fn get(&self) -> T {- self.value.get()- }-- #[track_caller]- #[inline]- pub(crate) fn set(&self, value: T) {- assert!(!self.sealed.get(), "write to a sealed committed box metric");- self.value.set(value);- }-- pub(crate) fn seal(&self) {- self.sealed.set(true);- }-}-#[derive(Clone, Default, PartialEq)]pub(crate) struct LineData {pub(crate) line_boxes: Vec<line_box::LineBoxData>,@@ -168,23 +132,23 @@ pub(crate) struct CommittedSvgFacts {/// The per-box geometry stored in a Rust-owned layout pass.#[derive(Debug)]pub(crate) struct UsedValues {- pub content_inline_size: SealableCell<CssPixels>,- pub content_block_size: SealableCell<CssPixels>,+ pub content_inline_size: Cell<CssPixels>,+ pub content_block_size: Cell<CssPixels>,- pub margin_left: SealableCell<CssPixels>,- pub margin_right: SealableCell<CssPixels>,- pub margin_top: SealableCell<CssPixels>,- pub margin_bottom: SealableCell<CssPixels>,+ pub margin_left: Cell<CssPixels>,+ pub margin_right: Cell<CssPixels>,+ pub margin_top: Cell<CssPixels>,+ pub margin_bottom: Cell<CssPixels>,- pub border_left: SealableCell<CssPixels>,- pub border_right: SealableCell<CssPixels>,- pub border_top: SealableCell<CssPixels>,- pub border_bottom: SealableCell<CssPixels>,+ pub border_left: Cell<CssPixels>,+ pub border_right: Cell<CssPixels>,+ pub border_top: Cell<CssPixels>,+ pub border_bottom: Cell<CssPixels>,- pub padding_left: SealableCell<CssPixels>,- pub padding_right: SealableCell<CssPixels>,- pub padding_top: SealableCell<CssPixels>,- pub padding_bottom: SealableCell<CssPixels>,+ pub padding_left: Cell<CssPixels>,+ pub padding_right: Cell<CssPixels>,+ pub padding_top: Cell<CssPixels>,+ pub padding_bottom: Cell<CssPixels>,pub has_definite_inline_size: Cell<bool>,pub has_definite_block_size: Cell<bool>,@@ -206,20 +170,20 @@ impl Default for UsedValues {fn default() -> Self {let zero = CssPixels::from_raw(0);Self {- content_inline_size: SealableCell::new(zero),- content_block_size: SealableCell::new(zero),- margin_left: SealableCell::new(zero),- margin_right: SealableCell::new(zero),- margin_top: SealableCell::new(zero),- margin_bottom: SealableCell::new(zero),- border_left: SealableCell::new(zero),- border_right: SealableCell::new(zero),- border_top: SealableCell::new(zero),- border_bottom: SealableCell::new(zero),- padding_left: SealableCell::new(zero),- padding_right: SealableCell::new(zero),- padding_top: SealableCell::new(zero),- padding_bottom: SealableCell::new(zero),+ content_inline_size: Cell::new(zero),+ content_block_size: Cell::new(zero),+ margin_left: Cell::new(zero),+ margin_right: Cell::new(zero),+ margin_top: Cell::new(zero),+ margin_bottom: Cell::new(zero),+ border_left: Cell::new(zero),+ border_right: Cell::new(zero),+ border_top: Cell::new(zero),+ border_bottom: Cell::new(zero),+ padding_left: Cell::new(zero),+ padding_right: Cell::new(zero),+ padding_top: Cell::new(zero),+ padding_bottom: Cell::new(zero),has_definite_inline_size: Cell::new(false),has_definite_block_size: Cell::new(false),has_definite_block_size_only_for_button_content_alignment: Cell::new(false),@@ -230,25 +194,6 @@ impl Default for UsedValues {}}-impl UsedValues {- pub(crate) fn seal_own_metrics(&self) {- self.content_inline_size.seal();- self.content_block_size.seal();- self.margin_left.seal();- self.margin_right.seal();- self.margin_top.seal();- self.margin_bottom.seal();- self.border_left.seal();- self.border_right.seal();- self.border_top.seal();- self.border_bottom.seal();- self.padding_left.seal();- self.padding_right.seal();- self.padding_top.seal();- self.padding_bottom.seal();- }-}-macro_rules! used_values_cells {($name:ident { $($field:ident: $type:ty,)+ }) => {#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]