Skip to content

Truly independent web browser

LibWeb: Build the cells of a box sized outside a run as a value

Aliaksandr Kalenik816d28239d82
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 4f7158204db..15269e40ef0 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3529,11 +3529,7 @@ impl<'pass> AbsposEngine<'pass> {
let laid_out = formatting_context::run_root_without_parent_fragments(
self.callbacks,
node,
- used_values::RootInputCells::of_box_before_sizing(
- &self.callbacks,
- node,
- ContainingBlockConstraints::default(),
- ),
+ used_values::cells_before_sizing(&self.callbacks, node, ContainingBlockConstraints::default()),
LayoutInput::new(
available_space,
constraints,
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 4801091487a..d069553e48b 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -789,7 +789,7 @@ impl<'pass> BlockFormattingContext<'pass> {
/// The sizes, size constraints and box sides of `child`, a box this block formatting context sizes.
fn metrics_of(&self, child: ChildSizedHere<'_>) -> used_values::RootInputCells {
match child.record_its_layout_owns {
- Some(record) => used_values::RecordInFrame::in_its_own_frame(record).cells(),
+ Some(record) => used_values::RootInputCells::capture(record),
None => self.child_metrics(child.node),
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index bb1257eeff8..3cd95b66d5b 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -1023,7 +1023,7 @@ mod tests {
},
ParticipationInParentFormattingContext::AtomicInline,
),
- root_cells: used_values::RootInputCells::capture(&UsedValues::default()),
+ root_cells: used_values::RootInputCells::default(),
}
}
@@ -1072,7 +1072,7 @@ mod tests {
result: formatting_context::ChildLayoutResult::default(),
root,
root_outcome: formatting_context::RunRootOutcome {
- input_cells_left_by_run: Some(used_values::RootInputCells::capture(&UsedValues::default())),
+ input_cells_left_by_run: Some(used_values::RootInputCells::default()),
line_data: None,
},
// NB: As a run whose result depends on no percentage block size proves.
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index fb77ad76ada..f71bb48cd49 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -3763,7 +3763,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let callbacks = &run.callbacks;
let committed_root = used_values::committed_box_from_fragment_link(callbacks, root)
.expect("partial relayout root must have committed geometry");
- let root_cells = used_values::RootInputCells::capture(&committed_root.record);
+ let root_cells = committed_root.cells;
run.records.keep_child_for_its_run_with_cells(root, root_cells);
// Adopting the committed geometry is the root's placement, final from the moment it is adopted.
run.records
@@ -3916,7 +3916,7 @@ mod baseline_tests {
document_in_quirks_mode: false,
},
);
- let parent_cells = used_values::RootInputCells::capture(&UsedValues::default());
+ let parent_cells = used_values::RootInputCells::default();
RunRecords::with_root(
callbacks,
parent,
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index d027dac85e7..ab8e41978f8 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1323,7 +1323,7 @@ impl<'context> InlineFormattingContext<'context> {
.records
.keep_child_for_its_run(&self.callbacks, node, constraints)
} else {
- used_values::RecordInFrame::in_its_own_frame(self.create_used_values(node, constraints)).cells()
+ used_values::RootInputCells::capture(self.create_used_values(node, constraints))
}
}
@@ -1523,7 +1523,7 @@ impl<'context> InlineFormattingContext<'context> {
let record = self.run.records.used_values(node);
(
formatting_context::PlacedChild::of_record(record, self.run),
- used_values::RecordInFrame::in_its_own_frame(record).cells(),
+ used_values::RootInputCells::capture(record),
)
}
};
diff --git a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs
index 1858e1a3b29..cd6db7de7b9 100644
--- a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs
+++ b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs
@@ -18,19 +18,16 @@ impl ContentSizingScope {
constraints: ContainingBlockConstraints,
block_size: Option<CssPixels>,
) -> Self {
- let root = used_values::create_used_values(callbacks, node, constraints);
+ let mut root_cells = used_values::cells_before_sizing(callbacks, node, constraints);
// NB: A parent layout can assign a definite block size that is not present in computed style,
// such as the stretched cross size of a flex item. Preserve it so descendant percentages
// resolve against the same size during intrinsic measurement.
if let Some(block_size) = block_size {
- root.set_content_block_size(block_size);
- root.has_definite_block_size.set(true);
- }
- root.has_definite_inline_size.set(false);
- Self {
- node,
- root_cells: used_values::RootInputCells::capture(&root),
+ root_cells.set_content_block_size(block_size);
+ root_cells.has_definite_block_size = true;
}
+ root_cells.has_definite_inline_size = false;
+ Self { node, root_cells }
}
pub(super) fn root_cells(&self) -> used_values::RootInputCells {
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 7cbc578c079..41ec9c8d2c2 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -335,7 +335,7 @@ impl LaidOutChildBox {
/// it to a run of its own.
pub(crate) fn sized_in_parent_run(record: &UsedValues) -> Self {
Self {
- cells: used_values::RecordInFrame::in_its_own_frame(record).cells(),
+ cells: used_values::RootInputCells::capture(record),
baselines: record.content_baselines_from_cells(),
// NB: A box that establishes an orthogonal flow is laid out by a run of its own.
orthogonal_flow_baselines: None,
@@ -564,7 +564,7 @@ impl<'arena> RunRecords<'arena> {
child: Node,
constraints: ContainingBlockConstraints,
) -> used_values::RootInputCells {
- let cells = used_values::RootInputCells::of_box_before_sizing(callbacks, child, constraints);
+ let cells = used_values::cells_before_sizing(callbacks, child, constraints);
self.keep_child_for_its_run_with_cells(child, cells);
cells
}
@@ -1124,7 +1124,7 @@ mod tests {
use super::*;
fn default_root_cells() -> used_values::RootInputCells {
- used_values::RootInputCells::capture(&UsedValues::default())
+ used_values::RootInputCells::default()
}
#[test]
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 3b8ff789384..fa0547543ff 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1865,14 +1865,14 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
}
return self.measure_intrinsic_block_size(content_box, other_axis_size, content_constraints);
}
- let root = used_values::create_used_values(&self.callbacks, node, constraints);
+ let mut root = used_values::cells_before_sizing(&self.callbacks, node, constraints);
root.set_content_inline_size(other_axis_size);
root.set_content_block_size(transferred_size);
- root.set_has_definite_block_size(true);
+ root.has_definite_block_size = true;
let result = formatting_context::lay_out_measurement_root_for_its_result(
self.callbacks,
node,
- used_values::RootInputCells::capture(&root),
+ root,
LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(other_axis_size),
@@ -2375,7 +2375,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
available_block_size: AvailableSize,
constraints: ContainingBlockConstraints,
) -> OuterInlineContributions {
- let root = used_values::create_used_values(&self.callbacks, node, constraints);
+ let mut root = used_values::cells_before_sizing(&self.callbacks, node, constraints);
let indefinite_inline_basis = CssPixels::default();
root.resolve_box_model(&self.style(node), indefinite_inline_basis);
let (contributions, percentage_block_size_dependency_its_layout_would_report) =
@@ -2383,7 +2383,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
self.callbacks,
node,
self.callbacks.in_flow_containing_block(node),
- used_values::RootInputCells::capture(&root),
+ root,
|records, callbacks| {
let sizing = SizingContext::new(records, callbacks);
let root_record = used_values::RecordInFrame::new(records.used_values(node), callbacks.frame);
@@ -3260,8 +3260,8 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
inline_size: CssPixels,
constraints: ContainingBlockConstraints,
) -> formatting_context::ChildLayoutResult {
- let root = used_values::create_used_values(&self.callbacks, node, constraints);
- root.set_has_definite_block_size(false);
+ let mut root = used_values::cells_before_sizing(&self.callbacks, node, constraints);
+ root.has_definite_block_size = false;
root.set_content_inline_size(inline_size);
let mut input = LayoutInput::new(
AvailableSpace {
@@ -3275,12 +3275,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
formatting_context::independent_formatting_context_type(node, &self.callbacks),
formatting_context::FormattingContextType::Flex | formatting_context::FormattingContextType::Grid
);
- formatting_context::lay_out_measurement_root_for_its_result(
- self.callbacks,
- node,
- used_values::RootInputCells::capture(&root),
- input,
- )
+ formatting_context::lay_out_measurement_root_for_its_result(self.callbacks, node, root, input)
}
/// The min-content or max-content block size of a box that establishes an orthogonal flow: its block axis here is
@@ -3441,7 +3436,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
formatting_context::lay_out_measurement_root_for_its_result(
self.callbacks,
node,
- used_values::RootInputCells::of_box_before_sizing(&self.callbacks, node, constraints),
+ used_values::cells_before_sizing(&self.callbacks, node, constraints),
LayoutInput::new(
inner_available_space,
constraints,
@@ -3568,24 +3563,18 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
size_table: impl FnOnce(&FormattingContextRun<'_>) -> R,
) -> R {
let table_box = self.table_box_inside_wrapper(wrapper);
- let table_used = used_values::create_used_values(&self.callbacks, table_box, table_constraints);
+ let mut table_cells = used_values::cells_before_sizing(&self.callbacks, table_box, table_constraints);
let table_style = self.style(table_box);
- table_used.set_border(geometry::Side::Left, table_style.border_left_width());
- table_used.set_border(geometry::Side::Right, table_style.border_right_width());
- table_used.set_padding(
- geometry::Side::Left,
- table_style.padding_left().to_px(containing_block_inline_size),
- );
- table_used.set_padding(
- geometry::Side::Right,
- table_style.padding_right().to_px(containing_block_inline_size),
- );
+ table_cells.border_left = table_style.border_left_width();
+ table_cells.border_right = table_style.border_right_width();
+ table_cells.padding_left = table_style.padding_left().to_px(containing_block_inline_size);
+ table_cells.padding_right = table_style.padding_right().to_px(containing_block_inline_size);
RunRecords::with_content_sizing_root(
self.callbacks,
table_box,
self.callbacks.in_flow_containing_block(table_box),
- used_values::RootInputCells::capture(&table_used),
+ table_cells,
|records, callbacks| {
let table_run = FormattingContextRun {
records,
@@ -3739,19 +3728,19 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
let wrapper_inner_space = sized
.metrics()
.available_inner_space_or_constraints_from(available_space);
- let wrapper_used = used_values::create_used_values(&self.callbacks, wrapper, table_wrapper_constraints);
+ let mut wrapper_cells = used_values::cells_before_sizing(&self.callbacks, wrapper, table_wrapper_constraints);
if let AvailableSize::Definite(inline_size) = wrapper_inner_space.inline_size {
- wrapper_used.set_content_inline_size(inline_size);
+ wrapper_cells.set_content_inline_size(inline_size);
}
if let AvailableSize::Definite(block_size) = wrapper_inner_space.block_size {
- wrapper_used.set_content_block_size(block_size);
+ wrapper_cells.set_content_block_size(block_size);
} else {
- wrapper_used.set_has_definite_block_size(false);
+ wrapper_cells.has_definite_block_size = false;
}
let wrapper_outputs = formatting_context::lay_out_measurement_root_for_its_result(
self.callbacks,
wrapper,
- used_values::RootInputCells::capture(&wrapper_used),
+ wrapper_cells,
LayoutInput::new(
wrapper_inner_space,
table_wrapper_constraints,
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index 75e60dab8fc..3027fe7bcdc 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -324,7 +324,7 @@ impl UsedValues {
macro_rules! used_values_cells {
($name:ident { $($field:ident: $type:ty,)+ }) => {
- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
+ #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct $name {
$(pub(crate) $field: $type,)+
}
@@ -373,15 +373,6 @@ used_values_cells! {
}
impl RootInputCells {
- /// The input cells of `node` as its record starts out, before anything sizes the box.
- pub(crate) fn of_box_before_sizing(
- callbacks: &LayoutPass<'_>,
- node: Node,
- constraints: ContainingBlockConstraints,
- ) -> Self {
- Self::capture(&create_used_values(callbacks, node, constraints))
- }
-
/// Resolves the left and right margins, borders and padding of `style`, with percentages against `basis`.
pub(crate) fn resolve_horizontal_box_model(&mut self, style: &StyleValues<'_>, basis: CssPixels) {
self.margin_left = style.margin_left().to_px(basis);
@@ -411,6 +402,35 @@ impl RootInputCells {
self.content_block_size = clamp_to_max_dimension_value(value.max(CssPixels::default()));
}
+ /// Resolves every margin, border and padding of `style`, with percentages against `basis`.
+ pub(crate) fn resolve_box_model(&mut self, style: &StyleValues<'_>, basis: CssPixels) {
+ self.resolve_horizontal_box_model(style, basis);
+ self.resolve_vertical_box_model(style, basis);
+ }
+
+ /// The sizes and box sides `fragment` shows, with both sizes definite.
+ pub(crate) fn of_committed_fragment(fragment: &fragment_tree::Fragment) -> Self {
+ let mut cells = Self {
+ margin_left: fragment.margin_left,
+ margin_right: fragment.margin_right,
+ margin_top: fragment.margin_top,
+ margin_bottom: fragment.margin_bottom,
+ border_left: fragment.border_left,
+ border_right: fragment.border_right,
+ border_top: fragment.border_top,
+ border_bottom: fragment.border_bottom,
+ padding_left: fragment.padding_left,
+ padding_right: fragment.padding_right,
+ padding_top: fragment.padding_top,
+ padding_bottom: fragment.padding_bottom,
+ has_definite_block_size: true,
+ ..Self::default()
+ };
+ cells.set_content_inline_size(fragment.content_inline_size);
+ cells.set_content_block_size(fragment.content_block_size);
+ cells
+ }
+
/// A record holding the cells, which hold the box's metrics in `frame`.
pub(crate) fn materialize_record(&self, frame: geometry::Frame) -> UsedValues {
let record = UsedValues::default();
@@ -921,11 +941,21 @@ pub(crate) fn collapsed_border_share(width: CssPixels, start_edge: bool, is_tabl
}
}
+/// A record of `node` holding the cells it starts out with in the pass's frame, before anything sizes the box.
pub(crate) fn create_used_values(
callbacks: &LayoutPass<'_>,
node: Node,
constraints: ContainingBlockConstraints,
) -> UsedValues {
+ cells_before_sizing(callbacks, node, constraints).materialize_record(callbacks.frame)
+}
+
+/// The input cells of `node` before anything sizes the box: the sizes its style makes definite without layout.
+pub(crate) fn cells_before_sizing(
+ callbacks: &LayoutPass<'_>,
+ node: Node,
+ constraints: ContainingBlockConstraints,
+) -> RootInputCells {
assert!(!node.is_invalid());
let facts = NodeFacts::new(callbacks, node);
@@ -943,8 +973,7 @@ pub(crate) fn create_used_values(
// definite. We model all of those by considering sizes definite once
// they are assigned through set_content_inline_size() or
// set_content_block_size().
- let used = UsedValues::default();
- used.frame.set(callbacks.frame);
+ let mut cells = RootInputCells::default();
#[derive(Clone, Copy)]
enum Axis {
@@ -1009,7 +1038,7 @@ pub(crate) fn create_used_values(
{
let available = containing_block_size_for_axis(Axis::Inline);
return Some(clamp_to_max_dimension_value(
- available - used.horizontal_margin_border_padding(),
+ available - cells.horizontal_margin_border_padding(),
));
}
return None;
@@ -1073,8 +1102,8 @@ pub(crate) fn create_used_values(
let mut content_inline_size = is_definite_size(style.width(), Axis::Inline);
let mut content_block_size = is_definite_size(style.height(), Axis::Block);
- used.has_definite_inline_size.set(content_inline_size.is_some());
- used.has_definite_block_size.set(content_block_size.is_some());
+ cells.has_definite_inline_size = content_inline_size.is_some();
+ cells.has_definite_block_size = content_block_size.is_some();
if let Some(size) = content_inline_size.as_mut() {
if let Some(minimum) = min_inline_size {
*size = clamp_to_max_dimension_value((*size).max(minimum));
@@ -1091,16 +1120,16 @@ pub(crate) fn create_used_values(
*size = clamp_to_max_dimension_value((*size).min(maximum));
}
}
- used.content_inline_size.set(content_inline_size.unwrap_or_default());
- used.content_block_size.set(content_block_size.unwrap_or_default());
+ cells.content_inline_size = content_inline_size.unwrap_or_default();
+ cells.content_block_size = content_block_size.unwrap_or_default();
- used
+ cells
}
-/// The record of a box and what its parent decided about it, as its committed fragment link has them, which a run
-/// adopts as they are.
+/// The input cells of a box and what its parent decided about it, as its committed fragment link has them in the frame
+/// of the link, which a run adopts as they are.
pub(crate) struct CommittedBox {
- pub(crate) record: UsedValues,
+ pub(crate) cells: RootInputCells,
pub(crate) facts_decided_by_parent: super::run_records::FactsDecidedByParent,
}
@@ -1108,17 +1137,8 @@ pub(crate) fn committed_box_from_fragment_link(callbacks: &LayoutPass<'_>, node:
let link = callbacks.committed_fragment_link(node)?;
let fragment = &link.fragment;
- // Skip normal node initialization: resolving computed sizes requires
- // percentage bases, and every resulting geometry field is replaced by
- // the previously committed value immediately.
- let used = UsedValues::default();
- used.frame.set(link.frame);
- used.set_box_metrics_from_fragment(fragment);
- used.has_definite_inline_size.set(true);
- used.has_definite_block_size.set(true);
-
Some(CommittedBox {
- record: used,
+ cells: RootInputCells::of_committed_fragment(fragment),
facts_decided_by_parent: super::run_records::FactsDecidedByParent {
placement: Some(super::run_records::BoxPlacement {
content_offset_in_containing_block: link.committed_offset,