Truly independent web browser
LibWeb: Read box metrics through one method of BoxMetricCells
Aliaksandr Kalenik51cfb14e910d
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 3af1156259c..4801091487a 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -782,7 +782,7 @@ impl<'pass> BlockFormattingContext<'pass> {fn child_metrics(&self, node: Node) -> used_values::RootInputCells {match self.cells_of_child_sized_ahead_of_its_run(node) {Some(cells) => cells,- None => self.run.records.box_metrics_of(node).input_cells(),+ None => self.run.records.box_metrics_of(node).cells(),}}@@ -844,7 +844,7 @@ impl<'pass> BlockFormattingContext<'pass> {.cells_of_children_sized_ahead_of_their_runs.borrow_mut().remove(&node);- handed_over.unwrap_or_else(|| self.run.records.box_metrics_of(node).input_cells())+ handed_over.unwrap_or_else(|| self.run.records.box_metrics_of(node).cells())}fn register_contained_abspos_child(&self, node: Node, block_offset: CssPixels, coordinate_space_box: Node) {@@ -2317,7 +2317,7 @@ impl<'pass> BlockFormattingContext<'pass> {None => {let metrics = self.run.records.box_metrics_of(node);(- metrics.input_cells(),+ metrics.cells(),metrics.content_baselines(),formatting_context::baselines_child_gives_container(self.run.records, &self.run.callbacks, node),)diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 711ce56f01e..026c85c07e3 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -267,7 +267,7 @@ impl<'pass> FlexFormattingContext<'pass> {{return self.flex_items[index].cells;}- self.run.records.box_metrics_of(node).input_cells()+ self.run.records.box_metrics_of(node).cells()}fn container_used(&self) -> &'pass UsedValues {@@ -3106,7 +3106,7 @@ impl<'pass> FlexFormattingContext<'pass> {self.flex_items[index].cells = match &laid_out_box {Some(laid_out_box) => laid_out_box.cells,// NB: The item was laid out by this flex container's run, in the record it keeps.- None => run.records.box_metrics_of(node).input_cells(),+ None => run.records.box_metrics_of(node).cells(),};self.flex_items[index].orthogonal_flow_baselines =laid_out_box.and_then(|laid_out_box| laid_out_box.orthogonal_flow_baselines);diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 114a8410973..1b58044f8ad 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4475,7 +4475,7 @@ impl<'pass> GridFormattingContext<'pass> {let laid_out_cells = match &laid_out_box {Some(laid_out_box) => laid_out_box.cells,// NB: The item was laid out by this grid container's run, in the record it keeps.- None => run.records.box_metrics_of(item.box_).input_cells(),+ None => run.records.box_metrics_of(item.box_).cells(),};self.update_cells_of(item, |item_cells| *item_cells = laid_out_cells);outcome.report_percentage_block_size_dependency_of(run, item.box_);diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex e533a3d79bd..d5545839093 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -986,7 +986,7 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {let cells = if self.box_model_node_stack.last().copied() != Some(node) {self.context().hold_atomic_inline(node)} else {- self.context().box_metrics(node).input_cells()+ self.context().box_metrics(node).cells()};let (content_baselines, box_cells) = self.context_mut().dimension_box_on_line(node, cells);item.content_baselines = content_baselines;diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 0ab0e45a15c..7cbc578c079 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -354,13 +354,6 @@ pub(crate) enum BoxMetrics<'records> {}impl BoxMetrics<'_> {- pub(crate) fn input_cells(&self) -> used_values::RootInputCells {- match self {- Self::LaidOutByThisRun(record) => record.cells(),- Self::NotYetLaidOut(cells) => *cells,- }- }-pub(crate) fn content_baselines(&self) -> DerivedBaselines {match self {Self::LaidOutByThisRun(record) => record.record().content_baselines_from_cells(),@@ -369,49 +362,21 @@ impl BoxMetrics<'_> {}}-macro_rules! box_metrics_getters {- ($($name:ident: $value:ty,)+) => {- impl BoxMetricCells for BoxMetrics<'_> {- $(- #[inline]- fn $name(&self) -> $value {- match self {- Self::LaidOutByThisRun(record) => record.$name(),- Self::NotYetLaidOut(cells) => cells.$name(),- }- }- )+-- fn record_viewed(&self) -> Option<&UsedValues> {- match self {- Self::LaidOutByThisRun(record) => Some(record.record()),- _ => None,- }- }+impl BoxMetricCells for BoxMetrics<'_> {+ #[inline]+ fn cells(&self) -> used_values::RootInputCells {+ match self {+ Self::LaidOutByThisRun(record) => record.cells(),+ Self::NotYetLaidOut(cells) => *cells,}- };-}+ }-box_metrics_getters! {- content_inline_size: CssPixels,- content_block_size: CssPixels,- margin_left: CssPixels,- margin_right: CssPixels,- margin_top: CssPixels,- margin_bottom: CssPixels,- border_left: CssPixels,- border_right: CssPixels,- border_top: CssPixels,- border_bottom: CssPixels,- padding_left: CssPixels,- padding_right: CssPixels,- padding_top: CssPixels,- padding_bottom: CssPixels,- has_definite_inline_size: bool,- has_definite_block_size: bool,- has_definite_block_size_only_for_button_content_alignment: bool,- uses_collapsing_borders_model: bool,- is_collapsed_borders_table_box: bool,+ fn record_viewed(&self) -> Option<&UsedValues> {+ match self {+ Self::LaidOutByThisRun(record) => Some(record.record()),+ Self::NotYetLaidOut(_) => None,+ }+ }}/// The used values of a box's inset properties.diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 7de3de13971..839730b1bb8 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2727,7 +2727,7 @@ impl<'pass> TableFormattingContext<'pass> {self.cell_box_cells[cell_index] = match &laid_out_box {Some(laid_out_box) => laid_out_box.cells,// NB: The cell was laid out by this table's run, in the record it keeps.- None => run.records.box_metrics_of(cell.box_).input_cells(),+ None => run.records.box_metrics_of(cell.box_).cells(),};// NB: A cell this table lays out in the record it keeps hands nothing back.self.content_baselines_of_handed_back_cells[cell_index] =diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rsindex 695219b3356..75e60dab8fc 100644--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs@@ -330,6 +330,7 @@ macro_rules! used_values_cells {}impl $name {+ #[inline]pub(crate) fn capture(used: &UsedValues) -> Self {Self {$($field: used.$field.get(),)+@@ -419,6 +420,7 @@ impl RootInputCells {}/// The cells, with the sizes, size constraints and box sides they hold in frame `from` read in frame `to` instead.+ #[inline]pub(crate) fn in_frame(mut self, from: geometry::Frame, to: geometry::Frame) -> Self {if from == to {return self;@@ -574,26 +576,42 @@ impl UsedValues {/// The sizes, size constraints and box sides of a box, with what derives from them, whether a run holds them in the box's/// record or its parent holds them as a value.+macro_rules! box_metric_getters {+ ($($name:ident: $value:ty,)+) => {+ $(+ #[inline]+ fn $name(&self) -> $value {+ self.cells().$name+ }+ )++ };+}+pub(crate) trait BoxMetricCells {- fn content_inline_size(&self) -> CssPixels;- fn content_block_size(&self) -> CssPixels;- fn margin_left(&self) -> CssPixels;- fn margin_right(&self) -> CssPixels;- fn margin_top(&self) -> CssPixels;- fn margin_bottom(&self) -> CssPixels;- fn border_left(&self) -> CssPixels;- fn border_right(&self) -> CssPixels;- fn border_top(&self) -> CssPixels;- fn border_bottom(&self) -> CssPixels;- fn padding_left(&self) -> CssPixels;- fn padding_right(&self) -> CssPixels;- fn padding_top(&self) -> CssPixels;- fn padding_bottom(&self) -> CssPixels;- fn has_definite_inline_size(&self) -> bool;- fn has_definite_block_size(&self) -> bool;- fn has_definite_block_size_only_for_button_content_alignment(&self) -> bool;- fn uses_collapsing_borders_model(&self) -> bool;- fn is_collapsed_borders_table_box(&self) -> bool;+ /// The sizes, size constraints and box sides these metrics hold.+ fn cells(&self) -> RootInputCells;++ box_metric_getters! {+ content_inline_size: CssPixels,+ content_block_size: CssPixels,+ margin_left: CssPixels,+ margin_right: CssPixels,+ margin_top: CssPixels,+ margin_bottom: CssPixels,+ border_left: CssPixels,+ border_right: CssPixels,+ border_top: CssPixels,+ border_bottom: CssPixels,+ padding_left: CssPixels,+ padding_right: CssPixels,+ padding_top: CssPixels,+ padding_bottom: CssPixels,+ has_definite_inline_size: bool,+ has_definite_block_size: bool,+ has_definite_block_size_only_for_button_content_alignment: bool,+ uses_collapsing_borders_model: bool,+ is_collapsed_borders_table_box: bool,+ }/// The record these metrics view, if they view one, which a reader in another frame views in its own.fn record_viewed(&self) -> Option<&UsedValues> {@@ -711,52 +729,19 @@ pub(crate) trait BoxMetricCells {}}-macro_rules! impl_box_metric_cells {- ($type:ty, $read:ident) => {- impl BoxMetricCells for $type {- impl_box_metric_cells!(@getters $read;- content_inline_size: CssPixels,- content_block_size: CssPixels,- margin_left: CssPixels,- margin_right: CssPixels,- margin_top: CssPixels,- margin_bottom: CssPixels,- border_left: CssPixels,- border_right: CssPixels,- border_top: CssPixels,- border_bottom: CssPixels,- padding_left: CssPixels,- padding_right: CssPixels,- padding_top: CssPixels,- padding_bottom: CssPixels,- has_definite_inline_size: bool,- has_definite_block_size: bool,- has_definite_block_size_only_for_button_content_alignment: bool,- uses_collapsing_borders_model: bool,- is_collapsed_borders_table_box: bool,- );- }- };- (@getters cell; $($name:ident: $value:ty,)+) => {- $(- #[inline]- fn $name(&self) -> $value {- self.$name.get()- }- )+- };- (@getters value; $($name:ident: $value:ty,)+) => {- $(- #[inline]- fn $name(&self) -> $value {- self.$name- }- )+- };+impl BoxMetricCells for UsedValues {+ #[inline]+ fn cells(&self) -> RootInputCells {+ RootInputCells::capture(self)+ }}-impl_box_metric_cells!(UsedValues, cell);-impl_box_metric_cells!(RootInputCells, value);+impl BoxMetricCells for RootInputCells {+ #[inline]+ fn cells(&self) -> RootInputCells {+ *self+ }+}/// A record as a reader in frame `reader` sees it: the sizes, size constraints and box sides the record holds in its own/// frame, read and written in the reader's frame.@@ -803,11 +788,6 @@ impl<'record> RecordInFrame<'record> {self.reader.side_in(side, record_frame)}- /// The record's input cells, read in the reader's frame.- pub(crate) fn cells(self) -> RootInputCells {- RootInputCells::capture(self.record).in_frame(self.record.frame.get(), self.reader)- }-pub(crate) fn set_content_inline_size(self, value: CssPixels) {if self.sizes_swap_axes() {self.record.set_content_block_size(value);@@ -899,116 +879,8 @@ impl<'record> RecordInFrame<'record> {impl BoxMetricCells for RecordInFrame<'_> {#[inline]- fn content_inline_size(&self) -> CssPixels {- if self.sizes_swap_axes() {- self.record.content_block_size.get()- } else {- self.record.content_inline_size.get()- }- }-- #[inline]- fn content_block_size(&self) -> CssPixels {- if self.sizes_swap_axes() {- self.record.content_inline_size.get()- } else {- self.record.content_block_size.get()- }- }-- #[inline]- fn margin_left(&self) -> CssPixels {- self.record.margin_cell(self.stored_side(geometry::Side::Left)).get()- }-- #[inline]- fn margin_right(&self) -> CssPixels {- self.record.margin_cell(self.stored_side(geometry::Side::Right)).get()- }-- #[inline]- fn margin_top(&self) -> CssPixels {- self.record.margin_cell(self.stored_side(geometry::Side::Top)).get()- }-- #[inline]- fn margin_bottom(&self) -> CssPixels {- self.record.margin_cell(self.stored_side(geometry::Side::Bottom)).get()- }-- #[inline]- fn border_left(&self) -> CssPixels {- self.record.border_cell(self.stored_side(geometry::Side::Left)).get()- }-- #[inline]- fn border_right(&self) -> CssPixels {- self.record.border_cell(self.stored_side(geometry::Side::Right)).get()- }-- #[inline]- fn border_top(&self) -> CssPixels {- self.record.border_cell(self.stored_side(geometry::Side::Top)).get()- }-- #[inline]- fn border_bottom(&self) -> CssPixels {- self.record.border_cell(self.stored_side(geometry::Side::Bottom)).get()- }-- #[inline]- fn padding_left(&self) -> CssPixels {- self.record.padding_cell(self.stored_side(geometry::Side::Left)).get()- }-- #[inline]- fn padding_right(&self) -> CssPixels {- self.record.padding_cell(self.stored_side(geometry::Side::Right)).get()- }-- #[inline]- fn padding_top(&self) -> CssPixels {- self.record.padding_cell(self.stored_side(geometry::Side::Top)).get()- }-- #[inline]- fn padding_bottom(&self) -> CssPixels {- self.record.padding_cell(self.stored_side(geometry::Side::Bottom)).get()- }-- #[inline]- fn has_definite_inline_size(&self) -> bool {- if self.sizes_swap_axes() {- self.record.has_definite_block_size.get()- } else {- self.record.has_definite_inline_size.get()- }- }-- #[inline]- fn has_definite_block_size(&self) -> bool {- if self.sizes_swap_axes() {- self.record.has_definite_inline_size.get()- } else {- self.record.has_definite_block_size.get()- }- }-- #[inline]- fn has_definite_block_size_only_for_button_content_alignment(&self) -> bool {- self.record- .has_definite_block_size_only_for_button_content_alignment- .get()- }-- #[inline]- fn uses_collapsing_borders_model(&self) -> bool {- self.record.uses_collapsing_borders_model.get()- }-- #[inline]- fn is_collapsed_borders_table_box(&self) -> bool {- self.record.is_collapsed_borders_table_box.get()+ fn cells(&self) -> RootInputCells {+ RootInputCells::capture(self.record).in_frame(self.record.frame.get(), self.reader)}fn record_viewed(&self) -> Option<&UsedValues> {