Skip to content

Truly independent web browser

LibWeb: Read and write record metrics only through methods

Aliaksandr Kalenik3b30c8010a89
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 7f9138acdc2..5004ff3af85 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -2227,7 +2227,7 @@ impl AbsposEngine<'_> {
let used = sized.record;
used.set_content_inline_size(auto_px_value(used_inline_size));
Self::set_used_inline_insets(sized, left, right);
- used.update(|cells| {
+ used.update_cells(|cells| {
cells.margin_left = auto_px_value(margin_left);
cells.margin_right = auto_px_value(margin_right);
});
@@ -2279,7 +2279,7 @@ impl AbsposEngine<'_> {
let used = sized.record;
Self::set_used_inline_insets(sized, solution.start, solution.end);
- used.update(|cells| {
+ used.update_cells(|cells| {
cells.margin_left = solution.margin_start;
cells.margin_right = solution.margin_end;
});
@@ -2718,17 +2718,17 @@ impl AbsposEngine<'_> {
// NB: A box that establishes an orthogonal flow is sized in this axis before its contents are laid out,
// which they are at that size.
if solution.block_size.is_some() && self.sizing().establishes_orthogonal_flow(node) {
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
return;
}
if !style.height().is_intrinsic_sizing_constraint() {
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
Self::set_used_block_insets(sized, auto_px_value(solution.top), auto_px_value(solution.bottom));
// NOTE: solve_non_replaced_block_once() already resolved these against the bases the C++ layout code used:
// the insets against the containing block's block size, but the margins against its inline size.
- used.update(|cells| {
+ used.update_cells(|cells| {
cells.margin_top = auto_px_value(solution.margin_top);
cells.margin_bottom = auto_px_value(solution.margin_bottom);
});
@@ -2812,15 +2812,15 @@ impl AbsposEngine<'_> {
.sizing()
.should_treat_block_size_as_auto(sized.sized_box(), available_space, constraints)
{
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
return;
}
if !style.height().is_intrinsic_sizing_constraint() {
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
Self::set_used_block_insets(sized, solution.start, solution.end);
- used.update(|cells| {
+ used.update_cells(|cells| {
cells.margin_top = solution.margin_start;
cells.margin_bottom = solution.margin_end;
});
@@ -2886,7 +2886,7 @@ impl<'pass> AbsposEngine<'pass> {
"an out-of-flow root with anchor() insets must arrive with their resolutions"
);
let style = self.style_of(sized).with_resolved_insets(resolved);
- sized.record.update(|cells| {
+ sized.record.update_cells(|cells| {
cells.border_left = style.border_left_width();
cells.border_right = style.border_right_width();
cells.border_top = style.border_top_width();
@@ -2918,13 +2918,13 @@ impl<'pass> AbsposEngine<'pass> {
{
let used = sized.record;
if !style.inset_left().is_auto() && !style.inset_right().is_auto() {
- used.update(|cells| cells.has_definite_inline_size = true);
+ used.update_cells(|cells| cells.has_definite_inline_size = true);
}
if !style.inset_top().is_auto()
&& !style.inset_bottom().is_auto()
&& (style.height().is_auto() || !style.height().is_intrinsic_sizing_constraint())
{
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
}
if !self.facts(node).creates_block_formatting_context() {
@@ -2932,11 +2932,11 @@ impl<'pass> AbsposEngine<'pass> {
&& self.facts(node).has_preferred_aspect_ratio()
&& sized.record.has_definite_inline_size();
let used = sized.record;
- used.update(|cells| cells.has_definite_inline_size = true);
+ used.update_cells(|cells| cells.has_definite_inline_size = true);
if (!style.height().is_auto() && !style.height().is_intrinsic_sizing_constraint())
|| block_size_resolved_from_aspect_ratio
{
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 3efabcd74b7..d8934d94241 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -1645,7 +1645,7 @@ impl<'pass> BlockFormattingContext<'pass> {
) -> inline_formatting_context::SpaceUsedByFloats {
// Deliberately read the root inline size at query time. It can be stale while
// intrinsic sizing of this context's own root is in progress.
- let root_content_inline_size = self.used(self.run.box_).content_inline_size.get();
+ let root_content_inline_size = self.used(self.run.box_).content_inline_size();
inline_formatting_context::SpaceUsedByFloats {
left: band.left_intrusion.map_or(CssPixels::default(), |intrusion| {
(intrusion - rect_in_root.x).max(CssPixels::default())
@@ -1737,7 +1737,7 @@ impl<'pass> BlockFormattingContext<'pass> {
let pending_adjustment =
self.block_offset_adjustment_from_pending_ancestor_block_start_margins(floating_box.box_);
containing_block_rect_in_root.y += pending_adjustment;
- let root_content_inline_size = self.used(self.run.box_).content_inline_size.get();
+ let root_content_inline_size = self.used(self.run.box_).content_inline_size();
let margin_box_rect = floating_box
.margin_box_rect_in_root_coordinate_space
.translated(CssPixels::default(), pending_adjustment);
@@ -2554,8 +2554,8 @@ impl<'pass> BlockFormattingContext<'pass> {
let box_opens_top_margin_group = !has_independent_formatting_context
&& continuation.is_none()
- && self.record_of(sized_child).border_top.get() == CssPixels::default()
- && self.record_of(sized_child).padding_top.get() == CssPixels::default()
+ && self.record_of(sized_child).border_top() == CssPixels::default()
+ && self.record_of(sized_child).padding_top() == CssPixels::default()
&& !self.margin_state.borrow().has_open_top_margin_group();
let container_facts = self.facts(block_container.node);
@@ -2673,7 +2673,7 @@ impl<'pass> BlockFormattingContext<'pass> {
if continuation.is_some() && self.record_of(sized_child).has_definite_block_size() {
let used = self.record_of(sized_child);
used.set_content_block_size(
- (used.content_block_size.get() - continuation_inner_size_excess).max(CssPixels::default()),
+ (used.content_block_size() - continuation_inner_size_excess).max(CssPixels::default()),
);
}
@@ -2788,8 +2788,8 @@ impl<'pass> BlockFormattingContext<'pass> {
self.record_of(sized_child)
.available_inner_space_or_constraints_from(available_space)
};
- if self.record_of(sized_child).border_top.get() > CssPixels::default()
- || self.record_of(sized_child).padding_top.get() > CssPixels::default()
+ if self.record_of(sized_child).border_top() > CssPixels::default()
+ || self.record_of(sized_child).padding_top() > CssPixels::default()
{
// margin-top of block container can't collapse with its children if it has non-zero border or padding.
self.margin_state.borrow_mut().reset();
@@ -2802,8 +2802,8 @@ impl<'pass> BlockFormattingContext<'pass> {
self.discard_block_start_margin_of_next_child.set(
discards_block_start_margin
&& !facts.children_are_inline()
- && self.record_of(sized_child).border_top.get() == CssPixels::default()
- && self.record_of(sized_child).padding_top.get() == CssPixels::default(),
+ && self.record_of(sized_child).border_top() == CssPixels::default()
+ && self.record_of(sized_child).padding_top() == CssPixels::default(),
);
}
let content_box_position_in_root = FfiCssPixelPoint {
@@ -2935,7 +2935,7 @@ impl<'pass> BlockFormattingContext<'pass> {
}
let breaks_inside = can_break_after_block_start_edges
&& content_block_start_in_root <= block_size
- && content_block_start_in_root + self.record_of(sized_child).content_block_size.get() > block_size
+ && content_block_start_in_root + self.record_of(sized_child).content_block_size() > block_size
&& content_block_start_in_root
+ children
.map_or(CssPixels::default(), ChildrenSummary::block_end_of_content)
@@ -2954,7 +2954,7 @@ impl<'pass> BlockFormattingContext<'pass> {
if let (Some(block_size), Some(content_block_start_in_root)) =
(fragmentainer.block_size, content_block_start_in_root)
{
- let content_block_size = used.content_block_size.get();
+ let content_block_size = used.content_block_size();
let remaining_block_size = (block_size - content_block_start_in_root).max(CssPixels::default());
fragmentainer.note_space_shortage(content_block_start_in_root + content_block_size);
used.set_content_block_size(if used.has_definite_block_size() {
@@ -2963,14 +2963,16 @@ impl<'pass> BlockFormattingContext<'pass> {
remaining_block_size
});
}
- used.padding_bottom.set(CssPixels::default());
- used.border_bottom.set(CssPixels::default());
- used.margin_bottom.set(CssPixels::default());
+ used.update_cells(|cells| {
+ cells.padding_bottom = CssPixels::default();
+ cells.border_bottom = CssPixels::default();
+ cells.margin_bottom = CssPixels::default();
+ });
fragment_facts.continues_in_next_fragment = true;
std::rc::Rc::make_mut(&mut token).consumed_block_size = continuation
.as_ref()
.map_or(CssPixels::default(), |continuation| continuation.consumed_block_size)
- + used.content_block_size.get();
+ + used.content_block_size();
broken_token_of_box = Some(token);
}
}
@@ -3313,8 +3315,8 @@ impl<'pass> BlockFormattingContext<'pass> {
flow_position_advance: self.flow_position() - flow_position,
outgoing_margins: self.margin_state.borrow().clone(),
margin_box_bottom_from_flow_position: content_offset.y
- + used.content_block_size.get()
- + used.margin_box_bottom(used.uses_collapsing_borders_model.get())
+ + used.content_block_size()
+ + used.margin_box_bottom(used.uses_collapsing_borders_model())
- flow_position,
depends_on_percentage_block_size,
fragment_identity: placed.fragment.identity,
@@ -3673,9 +3675,7 @@ impl<'pass> BlockFormattingContext<'pass> {
let node = sized_child.node;
let used = self.record_of(sized_child);
if used.has_definite_block_size() {
- used.set_content_block_size(
- (used.content_block_size.get() - consumed_block_size).max(CssPixels::default()),
- );
+ used.set_content_block_size((used.content_block_size() - consumed_block_size).max(CssPixels::default()));
return;
}
let content_block_size = self.automatic_block_size_for_block_level_element_disregarding_marker(
@@ -3686,7 +3686,7 @@ impl<'pass> BlockFormattingContext<'pass> {
false,
children,
);
- let sized_for_whole_box = used.content_block_size.get();
+ let sized_for_whole_box = used.content_block_size();
let consumed = consumed_block_size + inner_size_excess;
let unconsumed_part_of_whole_box = (sized_for_whole_box - consumed).max(CssPixels::default());
let block_size = sized_for_whole_box.min(content_block_size.max(unconsumed_part_of_whole_box));
@@ -3867,11 +3867,11 @@ impl<'pass> BlockFormattingContext<'pass> {
let root = self.run.box_;
let root_used = self.used(root);
let style = self.style(root);
- let content_inline_size = root_used.content_inline_size.get();
+ let content_inline_size = root_used.content_inline_size();
let geometry = fragmentation::resolve_column_geometry(style, content_inline_size);
let definite_block_size = root_used
.has_definite_block_size()
- .then(|| root_used.content_block_size.get());
+ .then(|| root_used.content_block_size());
let column_input = LayoutInput {
available_space: AvailableSpace {
inline_size: AvailableSize::definite(geometry.inline_size),
@@ -5053,7 +5053,7 @@ impl<'pass> BlockFormattingContext<'pass> {
margin_state.current_collapsed_margin()
};
let used = self.record_of(sized_child);
- if used.padding_bottom.get() == CssPixels::default() && used.border_bottom.get() == CssPixels::default() {
+ if used.padding_bottom() == CssPixels::default() && used.border_bottom() == CssPixels::default() {
margin_state.box_last_in_flow_child_margin_bottom_collapsed = true;
margin_bottom = CssPixels::default();
}
@@ -5077,7 +5077,7 @@ impl<'pass> BlockFormattingContext<'pass> {
fn resolve_automatic_line_clamp_block_size(&self, input: LayoutInput) -> Option<CssPixels> {
let used = self.used(self.run.box_);
if used.has_definite_block_size() {
- return Some(used.content_block_size.get());
+ return Some(used.content_block_size());
}
let style = self.style(self.run.box_);
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 17929d69fad..cc06bca9a69 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3025,7 +3025,7 @@ impl<'pass> FlexFormattingContext<'pass> {
main_size: Option<CssPixels>,
cross_size: Option<CssPixels>,
) {
- let reference = self.container_used().content_inline_size.get();
+ let reference = self.container_used().content_inline_size();
let style = self.style(self.flex_items[index].box_);
cells.margin_left = style.margin_left().to_px(reference);
cells.margin_right = style.margin_right().to_px(reference);
@@ -3219,8 +3219,8 @@ impl<'pass> FlexFormattingContext<'pass> {
node,
container_used,
geometry::LogicalSize {
- inline_size: container_used.content_inline_size.get(),
- block_size: container_used.content_block_size.get(),
+ inline_size: container_used.content_inline_size(),
+ block_size: container_used.content_block_size(),
},
run.percentage_block_insets_of_root_children_have_definite_basis(run.records.used_values(run.box_)),
);
@@ -4248,7 +4248,7 @@ impl<'pass> FlexFormattingContext<'pass> {
}
pub(super) fn automatic_content_block_size(&self) -> CssPixels {
- self.container_used().content_block_size.get()
+ self.container_used().content_block_size()
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index cf47e9f091e..70bf7d7565c 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -396,7 +396,7 @@ impl PlacedChild {
std::sync::Arc::new(inline_content::InlineContent::finish(
lines,
callbacks.arena(),
- record.content_inline_size.get(),
+ record.content_inline_size(),
record.frame.get().writing_mode(),
))
})
@@ -1723,7 +1723,7 @@ fn apply_root_sizing_directives(
}
if let Some(block_size) = directives.forced_content_block_size {
used.set_content_block_size(block_size);
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
}
*input
@@ -1752,7 +1752,7 @@ fn dimension_block_level_root(
if let Some(block_size) = input.sizing.forced_content_block_size {
let used = run.root_record();
used.set_content_block_size(block_size);
- used.update(|cells| cells.has_definite_block_size = true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
body_input.available_space.block_size = AvailableSize::definite(block_size);
return body_input;
}
@@ -2510,7 +2510,7 @@ fn lay_out_run_root_and_contents<'pass>(
let record = records.used_values(box_);
root_lines.finish(
callbacks.arena(),
- record.content_inline_size.get(),
+ record.content_inline_size(),
record.frame.get().writing_mode(),
);
result = result_in_parent_frame(run, result, parent_frame, own_frame);
@@ -2577,7 +2577,7 @@ fn lay_out_run_root_and_contents<'pass>(
let record = records.used_values(box_);
let root_line_data = root_lines.finish(
callbacks.arena(),
- record.content_inline_size.get(),
+ record.content_inline_size(),
record.frame.get().writing_mode(),
);
result.depends_on_percentage_block_size = run.sizing().resolve_percentage_block_size_dependency(run.box_);
@@ -2730,13 +2730,13 @@ fn result_in_parent_frame(
// orthogonal flow, the used block size of the child is calculated to fit its content; and this resulting
// content-based size is used as input to the inline-axis min-content size and max-content size of the
// parent.
- let content_inline_size = used.content_inline_size.get();
+ let content_inline_size = used.content_inline_size();
// NB: The root's baselines lie across its own block axis, which is the horizontal axis of its parent's frame.
let block_start_is_left = matches!(
own_frame.side_in(geometry::Side::Top, parent_frame),
geometry::Side::Left
);
- let content_block_size = used.content_block_size.get();
+ let content_block_size = used.content_block_size();
let along_parent_horizontal_axis = |baseline: Option<CssPixels>| {
baseline.map(|baseline| {
if block_start_is_left {
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 61ea086f0ff..9a343e3c07e 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -2249,8 +2249,8 @@ impl<'pass> GridFormattingContext<'pass> {
fn container_padding_start(&self, axis: Axis) -> CssPixels {
let used = self.container_used();
let (left_or_top, right_or_bottom) = axis.select(
- (used.padding_left.get(), used.padding_right.get()),
- (used.padding_top.get(), used.padding_bottom.get()),
+ (used.padding_left(), used.padding_right()),
+ (used.padding_top(), used.padding_bottom()),
);
if self.tracks_are_reversed(axis) {
right_or_bottom
@@ -2262,8 +2262,8 @@ impl<'pass> GridFormattingContext<'pass> {
fn container_padding_end(&self, axis: Axis) -> CssPixels {
let used = self.container_used();
let (left_or_top, right_or_bottom) = axis.select(
- (used.padding_left.get(), used.padding_right.get()),
- (used.padding_top.get(), used.padding_bottom.get()),
+ (used.padding_left(), used.padding_right()),
+ (used.padding_top(), used.padding_bottom()),
);
if self.tracks_are_reversed(axis) {
left_or_top
@@ -3095,13 +3095,13 @@ impl<'pass> GridFormattingContext<'pass> {
let used = self.container_used();
let (left_or_top, right_or_bottom) = if axis.is_column() {
(
- used.margin_left.get() + used.border_left.get() + used.padding_left.get(),
- used.padding_right.get() + used.border_right.get() + used.margin_right.get(),
+ used.margin_left() + used.border_left() + used.padding_left(),
+ used.padding_right() + used.border_right() + used.margin_right(),
)
} else {
(
- used.margin_top.get() + used.border_top.get() + used.padding_top.get(),
- used.padding_bottom.get() + used.border_bottom.get() + used.margin_bottom.get(),
+ used.margin_top() + used.border_top() + used.padding_top(),
+ used.padding_bottom() + used.border_bottom() + used.margin_bottom(),
)
};
let parent = container_as_parent_grid_item;
@@ -4116,19 +4116,19 @@ impl<'pass> GridFormattingContext<'pass> {
fn grid_container_alignment_size(&self, axis: Axis) -> CssPixels {
if axis.is_column() {
- return self.container_used().content_inline_size.get();
+ return self.container_used().content_inline_size();
}
if self.use_row_alignment_container_size {
let style = self.style(self.run.box_);
if !crate::layout::sizing_context::is_plain_auto(style.min_height()) {
return self
.row_alignment_container_size
- .max(self.container_used().content_block_size.get());
+ .max(self.container_used().content_block_size());
}
return self.row_alignment_container_size;
}
if self.container_used().has_definite_block_size() {
- self.container_used().content_block_size.get()
+ self.container_used().content_block_size()
} else {
self.row_alignment_container_size
}
@@ -5158,8 +5158,8 @@ impl<'pass> GridFormattingContext<'pass> {
rect: geometry::LogicalRect {
offset: Default::default(),
size: geometry::LogicalSize {
- inline_size: self.container_used().content_inline_size.get(),
- block_size: self.container_used().content_block_size.get(),
+ inline_size: self.container_used().content_inline_size(),
+ block_size: self.container_used().content_block_size(),
},
},
inline_alignment: static_position_alignment(child, horizontal_axis),
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index 052239434db..7d443d53f57 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -1422,7 +1422,7 @@ pub(super) fn layout_operator(run: &FormattingContextRun<'_>, input: &LayoutInpu
let used = run.records.used_values(operator);
// NB: The math content box sizes the content box, unless the width property gives it a size.
if sizing_context::is_plain_auto(context.style(operator).width()) {
- used.content_inline_size.set(inline_size);
+ used.update_cells(|cells| cells.content_inline_size = inline_size);
}
result.automatic_content_block_size = ascent + descent;
result.baselines = DerivedBaselines {
@@ -2276,7 +2276,7 @@ impl<'pass> MathFormattingContext<'pass> {
// block-start edges of the math content box are aligned with the ones of the content box, unless otherwise
// specified in a specific layout algorithm.
let root_used = run.records.used_values(root);
- let content_box_inline_size = root_used.content_inline_size.get();
+ let content_box_inline_size = root_used.content_inline_size();
let centers_math_content = match kind {
// If the computed display property is equal to block math then that math content box is rendered
// horizontally centered within the content box.
@@ -2642,8 +2642,8 @@ impl<'pass> MathFormattingContext<'pass> {
rect: geometry::LogicalRect {
offset: Default::default(),
size: geometry::LogicalSize {
- inline_size: root_used.content_inline_size.get(),
- block_size: root_used.content_block_size.get(),
+ inline_size: root_used.content_inline_size(),
+ block_size: root_used.content_block_size(),
},
},
inline_alignment: abspos_inputs::StaticPositionAlignment::Start,
diff --git a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
index 5974bcf8d36..f5ecff4df0a 100644
--- a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
@@ -15,12 +15,11 @@ pub(super) fn layout_replaced_with_children(
// (e.g. width/height: 100%) resolves against them.
let (content_inline_size, root_content_block_size) = {
let root_state = run.records.used_values(run.box_);
- root_state.has_definite_inline_size.set(true);
- root_state.has_definite_block_size.set(true);
- (
- root_state.content_inline_size.get(),
- root_state.content_block_size.get(),
- )
+ root_state.update_cells(|cells| {
+ cells.has_definite_inline_size = true;
+ cells.has_definite_block_size = true;
+ });
+ (root_state.content_inline_size(), root_state.content_block_size())
};
let child_available_space = geometry::AvailableSpace {
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 60fb8b040b0..8f4f27b43bc 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -21,7 +21,7 @@ pub(crate) struct ResolvedBlockSize {
impl ResolvedBlockSize {
pub(crate) fn apply_to_record(self, used: used_values::RecordInFrame<'_>) {
- used.update(|cells| self.apply_to_cells(cells));
+ used.update_cells(|cells| self.apply_to_cells(cells));
}
pub(crate) fn apply_to_cells(self, cells: &mut used_values::RootInputCells) {
@@ -2227,7 +2227,9 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
&& block_size_is_automatic;
if native_control_block_size_constraint_is_active || block_size_is_definite_from_aspect_ratio {
- sized_record.record.update(|cells| cells.has_definite_block_size = true);
+ sized_record
+ .record
+ .update_cells(|cells| cells.has_definite_block_size = true);
}
return None;
}
@@ -3543,7 +3545,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
if !content_box_needs_to_be_definite {
return;
}
- sized_record.record.update(|cells| {
+ sized_record.record.update_cells(|cells| {
cells.set_content_block_size(used_block_size);
cells.has_definite_block_size = true;
cells.has_definite_block_size_only_for_button_content_alignment =
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index 560f3adee2a..a0a01d0c9af 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -1909,7 +1909,7 @@ impl<'pass> SvgFormattingContext<'pass> {
fn set_definite_content_size(used: &UsedValues, width: CssPixels, height: CssPixels) {
used.set_content_inline_size(width);
used.set_content_block_size(height);
- used.has_definite_block_size.set(true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
}
fn set_content_rect(&self, node: Node, used: &UsedValues, rect: SvgCssPixelRect) -> LaidOutSvgElement {
@@ -1957,8 +1957,10 @@ impl<'pass> SvgFormattingContext<'pass> {
// NOTE: We consider all SVG root elements to have definite size in both axes.
// I'm not sure if this is good or bad, but our viewport transform logic depends on it.
- used.has_definite_inline_size.set(true);
- used.has_definite_block_size.set(true);
+ used.update_cells(|cells| {
+ cells.has_definite_inline_size = true;
+ cells.has_definite_block_size = true;
+ });
// An embedded SVG viewport's outer size does not depend on its descendants. Measuring it
// only needs the root sizing above; shapes, text, and foreignObject content wait for layout.
@@ -1970,8 +1972,8 @@ impl<'pass> SvgFormattingContext<'pass> {
self.set_svg_viewport_size(
self.run.box_,
FfiCssPixelSize {
- width: used.content_inline_size.get(),
- height: used.content_block_size.get(),
+ width: used.content_inline_size(),
+ height: used.content_block_size(),
},
);
}
@@ -2009,16 +2011,16 @@ impl<'pass> SvgFormattingContext<'pass> {
attributes.preserve_aspect_ratio_align,
attributes.preserve_aspect_ratio_meet_or_slice,
view_box,
- (used.content_inline_size.get(), used.content_block_size.get()),
+ (used.content_inline_size(), used.content_block_size()),
)
});
self.set_svg_viewport_transform(self.run.box_, viewport_transform);
}
- self.viewport_width = active_view_box.map_or(used.content_inline_size.get(), |view_box| {
+ self.viewport_width = active_view_box.map_or(used.content_inline_size(), |view_box| {
CssPixels::nearest_value_for(view_box.width)
});
- self.viewport_height = active_view_box.map_or(used.content_block_size.get(), |view_box| {
+ self.viewport_height = active_view_box.map_or(used.content_block_size(), |view_box| {
CssPixels::nearest_value_for(view_box.height)
});
self.viewport_is_committed_viewport = kind == NodeKind::SVGSVGBox
@@ -2032,8 +2034,8 @@ impl<'pass> SvgFormattingContext<'pass> {
committed.view_box == attributes.has_active_view_box.then_some(attributes.active_view_box)
&& committed.viewport_size
== Some(FfiCssPixelSize {
- width: used.content_inline_size.get(),
- height: used.content_block_size.get(),
+ width: used.content_inline_size(),
+ height: used.content_block_size(),
})
})
},
@@ -2241,7 +2243,7 @@ impl<'pass> SvgFormattingContext<'pass> {
return None;
}
used.set_box_metrics_from_fragment(&fragment);
- used.has_definite_block_size.set(true);
+ used.update_cells(|cells| cells.has_definite_block_size = true);
self.place_laid_out_child(
shape,
formatting_context::PlacedChild::of_record(used, None, &self.run),
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 7d9a0b7a1c7..85f99dcd9c2 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -1050,7 +1050,7 @@ impl TableFormattingContext<'_> {
}
if removed > CssPixels::default() {
let table_used = self.used_values(self.run.box_);
- table_used.set_content_inline_size(table_used.content_inline_size.get() - removed);
+ table_used.set_content_inline_size(table_used.content_inline_size() - removed);
}
}
}
@@ -1425,18 +1425,20 @@ impl<'pass> TableFormattingContext<'pass> {
let table_used = self.used_values(self.run.box_);
let old_border_box_top = table_used.border_box_top(false);
let old_inline_borders = table_used.border_box_left(false) + table_used.border_box_right(false);
- table_used.border_top.set(outer.top);
- table_used.border_right.set(outer.right);
- table_used.border_bottom.set(outer.bottom);
- table_used.border_left.set(outer.left);
- // https://www.w3.org/TR/CSS22/tables.html#collapsing-borders
- // "In this model, a table does not have padding (but does have margins)."
- table_used.padding_top.set(CssPixels::default());
- table_used.padding_right.set(CssPixels::default());
- table_used.padding_bottom.set(CssPixels::default());
- table_used.padding_left.set(CssPixels::default());
- table_used.uses_collapsing_borders_model.set(true);
- table_used.is_collapsed_borders_table_box.set(true);
+ table_used.update_cells(|cells| {
+ cells.border_top = outer.top;
+ cells.border_right = outer.right;
+ cells.border_bottom = outer.bottom;
+ cells.border_left = outer.left;
+ // https://www.w3.org/TR/CSS22/tables.html#collapsing-borders
+ // "In this model, a table does not have padding (but does have margins)."
+ cells.padding_top = CssPixels::default();
+ cells.padding_right = CssPixels::default();
+ cells.padding_bottom = CssPixels::default();
+ cells.padding_left = CssPixels::default();
+ cells.uses_collapsing_borders_model = true;
+ cells.is_collapsed_borders_table_box = true;
+ });
self.table_box_content_block_offset_in_wrapper += table_used.border_box_top(true) - old_border_box_top;
let freed_inline = old_inline_borders - (table_used.border_box_left(true) + table_used.border_box_right(true));
if let AvailableSize::Definite(available) = self.available_space.inline_size {
@@ -2304,7 +2306,7 @@ impl<'pass> TableFormattingContext<'pass> {
};
let edges = if self.style(self.run.box_).box_sizing() == box_sizing::BORDER_BOX {
let used = self.used_values(self.run.box_);
- let collapsed = used.uses_collapsing_borders_model.get();
+ let collapsed = used.uses_collapsing_borders_model();
used.border_box_left(collapsed) + used.border_box_right(collapsed)
} else {
CssPixels::default()
@@ -2342,7 +2344,7 @@ impl<'pass> TableFormattingContext<'pass> {
// NB: The table wrapper box carries the margins, so a stretch size fills the basis with the table's border box.
if constraint.is_stretch() {
let used = self.used_values(self.run.box_);
- let collapsed = used.uses_collapsing_borders_model.get();
+ let collapsed = used.uses_collapsing_borders_model();
let stretch_fit_size =
(basis - used.border_box_left(collapsed) - used.border_box_right(collapsed)).max(CssPixels::default());
return self.resolve_calc_size_of_keyword(constraint, stretch_fit_size, basis);
@@ -2352,7 +2354,7 @@ impl<'pass> TableFormattingContext<'pass> {
let mut resolved = constraint.to_px(basis);
if self.style(self.run.box_).box_sizing() == box_sizing::BORDER_BOX {
let used = self.used_values(self.run.box_);
- let collapsed = used.uses_collapsing_borders_model.get();
+ let collapsed = used.uses_collapsing_borders_model();
resolved -= used.border_box_left(collapsed) + used.border_box_right(collapsed);
}
resolved.max(CssPixels::default())
@@ -2565,7 +2567,7 @@ impl<'pass> TableFormattingContext<'pass> {
.used_table_inline_size_when_laid_out_at_intrinsic_inline_size(AvailableSize::MaxContent, measures),
};
let table_used = self.used_values(self.run.box_);
- let collapsed = table_used.uses_collapsing_borders_model.get();
+ let collapsed = table_used.uses_collapsing_borders_model();
let border_box_inline_size = |content_inline_size: CssPixels| {
table_used.border_box_left(collapsed) + content_inline_size + table_used.border_box_right(collapsed)
};
@@ -2952,7 +2954,7 @@ impl<'pass> TableFormattingContext<'pass> {
};
if let Some(minimum) = self.min_border_box_block_size_from_flex_item {
let used = self.used_values(self.run.box_);
- let collapsed = used.uses_collapsing_borders_model.get();
+ let collapsed = used.uses_collapsing_borders_model();
let content_min =
minimum - used.border_box_top(collapsed) - used.border_box_bottom(collapsed) - row_spacing;
self.table_block_size = self.table_block_size.max(content_min);
@@ -2964,7 +2966,7 @@ impl<'pass> TableFormattingContext<'pass> {
let mut specified = table_style.height().to_px(self.table_constraints.block_basis());
if table_style.box_sizing() == box_sizing::BORDER_BOX {
let used = self.used_values(self.run.box_);
- let collapsed = used.uses_collapsing_borders_model.get();
+ let collapsed = used.uses_collapsing_borders_model();
specified -= used.border_box_top(collapsed) + used.border_box_bottom(collapsed);
}
self.table_block_size = self.table_block_size.max(specified - row_spacing);
@@ -3173,7 +3175,7 @@ impl<'pass> TableFormattingContext<'pass> {
let table_used = self.used_values(self.run.box_);
let block_spacing = self.border_spacing_block();
let inline_spacing = self.border_spacing_inline();
- let inline_offset = table_used.border_box_left(table_used.uses_collapsing_borders_model.get()) + inline_spacing;
+ let inline_offset = table_used.border_box_left(table_used.uses_collapsing_borders_model()) + inline_spacing;
let mut row_block_offset = self.table_box_content_block_offset_in_wrapper + block_spacing;
let row_inline_size = self
.columns
@@ -3232,7 +3234,7 @@ impl<'pass> TableFormattingContext<'pass> {
);
group_block_offset = block_end + if has_rows { block_spacing } else { CssPixels::default() };
}
- let padding_top = table_used.padding_top.get();
+ let padding_top = table_used.padding_top();
let total =
row_block_offset.max(group_block_offset) - self.table_box_content_block_offset_in_wrapper - padding_top;
self.table_block_size = self.table_block_size.max(total);
@@ -3349,7 +3351,7 @@ impl<'pass> TableFormattingContext<'pass> {
// https://www.w3.org/TR/css-tables-3/#bounding-box-assignment
let first = &self.row_boxes[cell.row_index].record;
if cell.row_span == 1 {
- return first.content_block_size.get();
+ return first.content_block_size();
}
// When the row span is greater than 1, the borders of inner rows within the span have to be
// included in the content block size of the spanning cell. First top and final bottom borders are
@@ -3359,9 +3361,9 @@ impl<'pass> TableFormattingContext<'pass> {
for index in 0..cell.row_span {
let used = &self.row_boxes[cell.row_index + index].record;
if index == 0 {
- span += used.content_block_size.get() + used.border_box_bottom(false);
+ span += used.content_block_size() + used.border_box_bottom(false);
} else if index == cell.row_span - 1 {
- span += used.border_box_top(false) + used.content_block_size.get();
+ span += used.border_box_top(false) + used.content_block_size();
} else {
span += used.border_box_block_size(false);
}
@@ -3435,7 +3437,7 @@ impl<'pass> TableFormattingContext<'pass> {
let table_used = self.used_values(self.run.box_);
let inline_spacing = self.border_spacing_inline();
let block_spacing = self.border_spacing_block();
- let inline_offset = table_used.border_box_left(table_used.uses_collapsing_borders_model.get()) + inline_spacing;
+ let inline_offset = table_used.border_box_left(table_used.uses_collapsing_borders_model()) + inline_spacing;
// The rows were positioned by position_row_boxes(): the columns extend from the first row to the end of
// the last one.
@@ -3590,7 +3592,7 @@ impl<'pass> TableFormattingContext<'pass> {
(self.columns.len() + 1) * self.border_spacing_inline()
};
// The assignable table inline size is its used inline size minus the inline-axis border spacing.
- let assignable = table_used.content_inline_size.get() - total_spacing;
+ let assignable = table_used.content_inline_size() - total_spacing;
let fixed = self.use_fixed_mode_layout();
// Distribute the inline size of the table among columns.
distribute_inline_size(&mut self.columns, assignable, fixed);
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index b7abfbf1de1..a4f5ceb9b36 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -353,6 +353,13 @@ impl RootInputCells {
}
impl UsedValues {
+ /// Writes the record's metrics, which `write` sees and changes as the record holds them.
+ pub(crate) fn update_cells(&self, write: impl FnOnce(&mut RootInputCells)) {
+ let mut cells = RootInputCells::capture(self);
+ write(&mut cells);
+ cells.apply_to_record(self);
+ }
+
pub(crate) fn set_content_inline_size(&self, value: CssPixels) {
// Negative inline sizes are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
self.content_inline_size
@@ -565,7 +572,7 @@ impl<'record> RecordInFrame<'record> {
}
/// 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)) {
+ pub(crate) fn update_cells(self, write: impl FnOnce(&mut RootInputCells)) {
let mut cells = self.cells();
write(&mut cells);
cells
@@ -574,20 +581,20 @@ impl<'record> RecordInFrame<'record> {
}
pub(crate) fn set_content_inline_size(self, value: CssPixels) {
- self.update(|cells| cells.set_content_inline_size(value));
+ self.update_cells(|cells| cells.set_content_inline_size(value));
}
pub(crate) fn set_content_block_size(self, value: CssPixels) {
- self.update(|cells| cells.set_content_block_size(value));
+ self.update_cells(|cells| cells.set_content_block_size(value));
}
/// Resolves every margin, border and padding of `style`, with percentages against `basis`.
pub(crate) fn resolve_box_model(self, style: &StyleValues<'_>, basis: CssPixels) {
- self.update(|cells| cells.resolve_box_model(style, basis));
+ self.update_cells(|cells| cells.resolve_box_model(style, basis));
}
pub(crate) fn set_box_metrics_from_fragment(self, fragment: &fragment_tree::Fragment) {
- self.update(|cells| cells.take_box_metrics_of_fragment(fragment));
+ self.update_cells(|cells| cells.take_box_metrics_of_fragment(fragment));
}
}