Truly independent web browser
LibWeb: Mark where a sizing step reads the metrics of a box's own
Aliaksandr Kalenik5a4beba13533
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 386161c2fd0..7f9138acdc2 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -159,7 +159,7 @@ impl<'a> OutOfFlowBox<'a> {}fn sized_box(&self) -> sizing_context::SizedBox<'_> {- sizing_context::SizedBox::new(self.node, &self.record)+ sizing_context::SizedBox::of_own_metrics(self.node, &self.record, self.record.reader())}}diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex b37192478d6..3efabcd74b7 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -5091,15 +5091,16 @@ impl<'pass> BlockFormattingContext<'pass> {{return None;}+ let root_record = self.run.root_record();let mut block_size = sizing.calculate_inner_block_size(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(self.run.box_, &root_record, root_record.reader()),input.available_space,style.max_height(),input.containing_block_constraints,);if !crate::layout::sizing_context::is_plain_auto(style.min_height()) {block_size = block_size.max(sizing.calculate_inner_block_size(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(self.run.box_, &root_record, root_record.reader()),input.available_space,style.min_height(),input.containing_block_constraints,diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 71bf8607890..cf47e9f091e 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -2700,7 +2700,7 @@ fn body_input_in_own_frame(used.content_inline_size()} else {body_run.sizing().orthogonal_flow_inline_size(- sizing_context::SizedBox::new(node, &used),+ sizing_context::SizedBox::of_own_metrics(node, &used, used.reader()),available_space,constraints,)diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex e26d9b48da2..61ea086f0ff 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -1662,8 +1662,9 @@ impl<'pass> GridFormattingContext<'pass> {if crate::layout::sizing_context::is_plain_auto(minimum) || minimum.is_intrinsic_sizing_constraint() {return None;}+ let root_record = self.run.root_record();Some(self.sizing().calculate_inner_size_for_property(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(self.run.box_, &root_record, root_record.reader()),axis.sizing_axis(),axis.select(SizingProperty::MinWidth, SizingProperty::MinHeight),self.container_available_space(),@@ -2908,8 +2909,9 @@ impl<'pass> GridFormattingContext<'pass> {}let available = self.container_available_space();let constraints = self.layout_input.unwrap().containing_block_constraints;+ let root_record = self.run.root_record();self.sizing().calculate_inner_size_for_property(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(self.run.box_, &root_record, root_record.reader()),axis.sizing_axis(),axis.select(SizingProperty::MaxWidth, SizingProperty::MaxHeight),available,@@ -4161,8 +4163,9 @@ impl<'pass> GridFormattingContext<'pass> {&& !self.maximum_size_is_unresolvable_during_measurement(Axis::Row)&& !sizing.should_treat_max_block_size_as_none(self.run.box_, available.block_size, constraints){+ let root_record = self.run.root_record();block_size = block_size.min(sizing.calculate_inner_size_for_property(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(self.run.box_, &root_record, root_record.reader()),SizingAxis::Block,SizingProperty::MaxHeight,available,@@ -4172,8 +4175,9 @@ impl<'pass> GridFormattingContext<'pass> {if !crate::layout::sizing_context::is_plain_auto(style.min_height())&& !(self.own_block_size_is_being_measured() && style.min_height().is_intrinsic_sizing_constraint()){+ let root_record = self.run.root_record();block_size = block_size.max(sizing.calculate_inner_size_for_property(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(self.run.box_, &root_record, root_record.reader()),SizingAxis::Block,SizingProperty::MinHeight,available,@@ -5081,7 +5085,11 @@ impl<'pass> GridFormattingContext<'pass> {self.automatic_content_block_size = intrinsic_block_size;} else if let AvailableSize::Definite(block_size) = available.block_size&& self.sizing().should_treat_block_size_as_auto(- sizing_context::SizedBox::new(self.run.box_, &self.run.root_record()),+ sizing_context::SizedBox::of_own_metrics(+ self.run.box_,+ &self.run.root_record(),+ self.run.callbacks.frame,+ ),available,self.layout_input.unwrap().containing_block_constraints,)diff --git a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rsindex 219efc81211..3c9c58c4849 100644--- a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs+++ b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs@@ -551,8 +551,9 @@ fn content_sizes_of_container_under_each_inline_size_constraint();input.sizing.maximum_inline_size_resolved_by_caller =content_size_named_by_maximum.map(|content_size| {+ let root_record = run.root_record();sizing.apply_transferred_limits_to_intrinsic_inline_size(- sizing_context::SizedBox::new(node, &run.root_record()),+ sizing_context::SizedBox::of_own_metrics(node, &root_record, root_record.reader()),clamp_to_max_dimension_value(content_size),available_inline_size_under_content_size_named_by_maximum(content_size_named_by_maximum_inline_size,@@ -647,8 +648,9 @@ pub(super) fn content_sizes_of_orthogonal_flow(} else {let scope_in_own_frame = ContentSizingScope { node, root_cells };scope_in_own_frame.enter(callbacks_in_own_frame, |run| {+ let root_record = run.root_record();run.sizing().orthogonal_flow_inline_size(- sizing_context::SizedBox::new(node, &run.root_record()),+ sizing_context::SizedBox::of_own_metrics(node, &root_record, root_record.reader()),AvailableSpace {inline_size: available_inline_size_in_own_frame,block_size: AvailableSize::Indefinite,diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex cefe16d60d5..c2be740243b 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -137,6 +137,10 @@ pub(crate) struct SizedBox<'metrics> {pub(crate) node: Node,/// What the caller holds of the box, which is nothing for a box its run does not hold yet.metrics: Option<&'metrics dyn BoxMetricCells>,+ /// Where the metrics are the box's own (held by the run or call that sizes the box, not by a parent sizing it ahead+ /// of its run), the frame they are held in. content_block_size_of_orthogonal_flow() reads such metrics in the box's+ /// own frame.+ own_metrics_frame: Option<geometry::Frame>,}impl<'metrics> SizedBox<'metrics> {@@ -144,19 +148,25 @@ impl<'metrics> SizedBox<'metrics> {Self {node,metrics: Some(metrics),+ own_metrics_frame: None,}}- /// `node`, of which its caller holds no metrics.- pub(crate) fn unheld(node: Node) -> Self {- Self { node, metrics: None }+ /// `node`, with metrics of its own that are held in frame `held_in`.+ pub(crate) fn of_own_metrics(node: Node, metrics: &'metrics dyn BoxMetricCells, held_in: geometry::Frame) -> Self {+ Self {+ node,+ metrics: Some(metrics),+ own_metrics_frame: Some(held_in),+ }}- /// `node`, with the metrics its caller holds of it, if any.- pub(crate) fn held_if_any(node: Node, metrics: Option<&'metrics impl BoxMetricCells>) -> Self {+ /// `node`, of which its caller holds no metrics.+ pub(crate) fn unheld(node: Node) -> Self {Self {node,- metrics: metrics.map(|metrics| metrics as &dyn BoxMetricCells),+ metrics: None,+ own_metrics_frame: None,}}@@ -187,7 +197,7 @@ impl<'record> SizedRecord<'record> {}pub(crate) fn sized_box(&self) -> SizedBox<'_> {- SizedBox::new(self.node, &self.record)+ SizedBox::of_own_metrics(self.node, &self.record, self.record.reader())}}@@ -1873,13 +1883,9 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {content_constraints.percentage_basis_inline_size = Some(other_axis_size);content_constraints.percentage_basis_block_size = Some(transferred_size);if self.establishes_orthogonal_flow(content_box) {- // NB: The run measuring the button may not hold its content box, whose sizing reads no metrics of it.- let content_box_record = self- .records- .used_values_if_owned(content_box)- .map(|record| used_values::RecordInFrame::new(record, self.callbacks.frame));+ // NB: A run that sizes the button never holds its content box, whose sizing reads no metrics of it.return self.content_block_size_of_orthogonal_flow(- SizedBox::held_if_any(content_box, content_box_record.as_ref()),+ SizedBox::unheld(content_box),other_axis_size,content_constraints,IntrinsicSizeCacheKind::MaxContentInline,@@ -2411,7 +2417,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {let root_record = used_values::RecordInFrame::new(records.used_values(node), callbacks.frame);let inline_size_under = |inline_size| {sizing.atomic_root_content_inline_size(- SizedBox::new(node, &root_record),+ SizedBox::of_own_metrics(node, &root_record, root_record.reader()),AvailableSpace {inline_size,block_size: available_block_size,@@ -3303,13 +3309,12 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {percentage_basis_block_size: constraints.percentage_basis_inline_size,quirks_mode_percentage_basis_block_size: None,};- // NB: A record of the box is read in the box's own frame. Cells its parent sizes it in are read as they are.- let record_in_own_frame = sized- .metrics_if_held()- .and_then(|metrics| metrics.record_viewed())- .map(|record| used_values::RecordInFrame::new(record, sizing.callbacks.frame));- let sized_in_own_frame = match &record_in_own_frame {- Some(record) => SizedBox::new(node, record),+ // NB: The box's own metrics are read in the box's own frame. Cells its parent sizes it in are read as they are.+ let own_metrics_in_own_frame = sized+ .own_metrics_frame+ .map(|held_in| sized.metrics().cells().in_frame(held_in, sizing.callbacks.frame));+ let sized_in_own_frame = match &own_metrics_in_own_frame {+ Some(cells) => SizedBox::of_own_metrics(node, cells, sizing.callbacks.frame),None => sized,};let answer = sizing.content_inline_size(sized_in_own_frame, constraints_in_own_frame, Some(inline_size), kind);diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rsindex 9a6982d7b01..b7abfbf1de1 100644--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs@@ -410,11 +410,6 @@ pub(crate) trait BoxMetricCells {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> {- None- }-fn border_left_collapsed(&self, collapsed: bool) -> CssPixels {if collapsed {collapsed_border_share(self.border_left(), true, self.is_collapsed_borders_table_box())@@ -564,6 +559,11 @@ impl<'record> RecordInFrame<'record> {}}+ /// The frame the record is read in.+ pub(crate) fn reader(&self) -> geometry::Frame {+ self.reader+ }+/// Writes the record's metrics, which `write` sees and changes as the reader's frame has them.pub(crate) fn update(self, write: impl FnOnce(&mut RootInputCells)) {let mut cells = self.cells();@@ -596,10 +596,6 @@ impl BoxMetricCells for RecordInFrame<'_> {fn cells(&self) -> RootInputCells {RootInputCells::capture(self.record).in_frame(self.record.frame.get(), self.reader)}-- fn record_viewed(&self) -> Option<&UsedValues> {- Some(self.record)- }}/// The part of a collapsed border that lies after its grid line (below or right of it), the rest lying before it.