Skip to content

Truly independent web browser

LibWeb: Hand root runs their sizes in their input cells

Aliaksandr Kalenik09057b3da072
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 1e646a44f4f..b1599c17f46 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -4108,11 +4108,7 @@ impl<'pass> BlockFormattingContext<'pass> {
block_size: definite_block_size.map_or(AvailableSize::Indefinite, AvailableSize::definite),
},
containing_block_constraints: input.containing_block_constraints,
- sizing: RootSizingDirectives {
- forced_content_inline_size: geometry::PackedOptionalCssPixels::from(Some(geometry.inline_size)),
- forced_content_block_size: geometry::PackedOptionalCssPixels::from(definite_block_size),
- ..RootSizingDirectives::default()
- },
+ sizing: RootSizingDirectives::default(),
participation: ParticipationInParentFormattingContext::Root,
};
let spanner_input = self.child_layout_input(self.root_block_container(), input.clone(), input.available_space);
@@ -4496,6 +4492,11 @@ impl<'pass> BlockFormattingContext<'pass> {
ColumnLayoutUse::BalancingProbe => false,
ColumnLayoutUse::ContainerContent => self.run.fragments.is_some(),
};
+ let AvailableSize::Definite(column_inline_size) = input.available_space.inline_size else {
+ unreachable!("a column's available inline size is the inline size of the columns");
+ };
+ let mut column_root_cells = self.root_cells;
+ column_root_cells.set_content_inline_size(column_inline_size);
loop {
let fragmentainer = std::rc::Rc::new(fragmentation::FragmentainerContext::new(
block_size,
@@ -4507,7 +4508,7 @@ impl<'pass> BlockFormattingContext<'pass> {
));
let outputs = formatting_context::run_fragmentainer(
&self.run,
- self.root_cells,
+ column_root_cells,
builds_fragments,
input.clone(),
fragmentainer.clone(),
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 0bcfdb37925..65c0aca6714 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -285,7 +285,6 @@ fn sizing_directives_match_ignoring_unobserved(
content_block_size_adopted_after_run_unobserved: bool,
) -> bool {
let RootSizingDirectives {
- forced_content_inline_size,
forced_content_block_size,
forced_min_border_box_block_size,
block_parent_resolved_content_inline_size,
@@ -300,8 +299,7 @@ fn sizing_directives_match_ignoring_unobserved(
root_is_measured_for_its_content_block_size,
root_keeps_its_committed_geometry,
} = *a;
- forced_content_inline_size == b.forced_content_inline_size
- && forced_content_block_size == b.forced_content_block_size
+ forced_content_block_size == b.forced_content_block_size
&& forced_min_border_box_block_size == b.forced_min_border_box_block_size
&& block_parent_resolved_content_inline_size == b.block_parent_resolved_content_inline_size
&& table_cell_intrinsic_block_padding == b.table_cell_intrinsic_block_padding
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index dd4ace0cdd1..e4433898da4 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1712,20 +1712,7 @@ fn apply_root_sizing_directives(
}
input.clone()
}
- ParticipationInParentFormattingContext::Root => {
- let directives = input.sizing;
- if directives.forced_content_inline_size.is_some() || directives.forced_content_block_size.is_some() {
- let used = sized_root.cells;
- if let Some(inline_size) = directives.forced_content_inline_size.get() {
- used.set_content_inline_size(inline_size);
- }
- if let Some(block_size) = directives.forced_content_block_size.get() {
- used.set_content_block_size(block_size);
- used.update_cells(|cells| cells.has_definite_block_size = true);
- }
- }
- input.clone()
- }
+ ParticipationInParentFormattingContext::Root => input.clone(),
};
RootSizingOutcome {
body_input,
@@ -2783,12 +2770,10 @@ fn body_input_in_own_frame(
}
let mut constraints = input.containing_block_constraints;
let mut available_space = input.available_space;
- let mut sizing = RootSizingDirectives {
+ let sizing = RootSizingDirectives {
treat_block_axis_percentage_insets_as_auto_beyond_root: input
.sizing
.treat_block_axis_percentage_insets_as_auto_beyond_root,
- forced_content_inline_size: body_input.sizing.forced_content_inline_size,
- forced_content_block_size: body_input.sizing.forced_content_block_size,
root_keeps_its_committed_geometry: input.sizing.root_keeps_its_committed_geometry,
..RootSizingDirectives::default()
};
@@ -2798,10 +2783,6 @@ fn body_input_in_own_frame(
);
constraints.quirks_mode_percentage_basis_block_size = None;
std::mem::swap(&mut available_space.inline_size, &mut available_space.block_size);
- std::mem::swap(
- &mut sizing.forced_content_inline_size,
- &mut sizing.forced_content_block_size,
- );
// https://drafts.csswg.org/css-writing-modes-4/#orthogonal-flows
// In the sizing phase [...] the dimensions of the box and the containing block are mapped to the inline
// size and block size and calculations are performed accordingly using the writing mode of the box
@@ -3735,7 +3716,10 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
} else {
root
};
- let root_cells = used_values::cells_before_sizing(&callbacks, root_for_layout, root_constraints);
+ let mut root_cells = used_values::cells_before_sizing(&callbacks, root_for_layout, root_constraints);
+ root_cells.set_content_inline_size(viewport_inline_size);
+ root_cells.set_content_block_size(viewport_block_size);
+ root_cells.has_definite_block_size = true;
let input = LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(viewport_inline_size),
@@ -3743,8 +3727,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
},
ContainingBlockConstraints::default(),
ParticipationInParentFormattingContext::Root,
- )
- .with_forced_sizes(viewport_inline_size, viewport_block_size);
+ );
let fc_type = independent_formatting_context_type(root_for_layout, &callbacks);
let root_outcome = run_formatting_context(
true,
diff --git a/Libraries/LibWeb/Rust/src/layout/geometry.rs b/Libraries/LibWeb/Rust/src/layout/geometry.rs
index ce1e1d0a771..9a5e226fe15 100644
--- a/Libraries/LibWeb/Rust/src/layout/geometry.rs
+++ b/Libraries/LibWeb/Rust/src/layout/geometry.rs
@@ -354,7 +354,7 @@ impl From<Option<CssPixels>> for PackedOptionalCssPixels {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct RootSizingDirectives {
- pub(crate) forced_content_inline_size: PackedOptionalCssPixels,
+ // Input-only: a fieldset's content wrapper fills the fieldset's definite content block size.
pub(crate) forced_content_block_size: PackedOptionalCssPixels,
pub(crate) forced_min_border_box_block_size: PackedOptionalCssPixels,
// Input-only: the parent block formatting context supplies the inline size it resolved while
@@ -435,14 +435,4 @@ impl LayoutInput {
participation,
}
}
-
- pub(crate) fn with_forced_sizes(
- mut self,
- forced_content_inline_size: CssPixels,
- forced_content_block_size: CssPixels,
- ) -> Self {
- self.sizing.forced_content_inline_size = PackedOptionalCssPixels::from(Some(forced_content_inline_size));
- self.sizing.forced_content_block_size = PackedOptionalCssPixels::from(Some(forced_content_block_size));
- self
- }
}