Skip to content

Truly independent web browser

LibWeb: Let item runs ignore their unobserved own block size

Aliaksandr Kalenikfbaf0b6c8c12
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index b2e78777136..fec25c676e1 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3734,6 +3734,12 @@ impl<'pass> AbsposEngine<'pass> {
if style.position() != positioning::RELATIVE {
return;
}
+ formatting_context::propagate_percentage_block_size_dependency_to_containing_block(
+ self.records,
+ &self.callbacks,
+ node,
+ false,
+ );
let resolve_opposing = |first: style_values::InsetValue, second: style_values::InsetValue, basis: CssPixels| {
let resolved_first = first.to_px(basis);
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 85481f3d02f..368f8950fe4 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -326,6 +326,27 @@ impl ColumnEarlyBreaks {
}
}
+pub(crate) fn root_lays_out_content_against_its_own_block_size(
+ sizing: &sizing_context::SizingContext<'_>,
+ root: Node,
+) -> bool {
+ let facts = sizing.facts(root);
+ let outside_marker = facts.list_item_marker();
+ let marker_resolves_against_list_item_block_size = facts.is_list_item_box()
+ && !outside_marker.is_invalid()
+ && !sizing.facts(outside_marker).list_marker_is_inside()
+ && sizing.own_style_depends_on_percentage_block_size(outside_marker);
+ facts.is_fieldset_box()
+ || facts.lays_out_in_columns()
+ || is_line_clamp_container(sizing.callbacks(), root)
+ || facts.uses_button_layout()
+ || facts.is_text_input()
+ || facts.is_anonymous_button_content_wrapper()
+ || facts.is_anonymous_button_content_box()
+ || facts.is_table_wrapper()
+ || marker_resolves_against_list_item_block_size
+}
+
impl<'pass> BlockFormattingContext<'pass> {
pub(crate) fn new(run: &FormattingContextRun<'pass>) -> Self {
let style = StyleValues::for_node(&run.callbacks, run.box_);
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 3759efa45fc..f5ff1070a7d 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -25,6 +25,7 @@ pub(super) struct RunInputsTheStoredRunNeverObserved {
pub(super) percentage_block_basis_and_block_size_definiteness: bool,
pub(super) definite_available_inline_sizes_at_or_above: Option<CssPixels>,
pub(super) percentage_inline_basis: bool,
+ pub(super) own_block_size: formatting_context::OwnBlockSizeObservation,
}
impl RunInputsTheStoredRunNeverObserved {
@@ -36,6 +37,7 @@ impl RunInputsTheStoredRunNeverObserved {
percentage_inline_basis: outputs
.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above
.is_some(),
+ own_block_size: outputs.result.own_block_size_observation,
}
}
@@ -45,6 +47,7 @@ impl RunInputsTheStoredRunNeverObserved {
Self {
definite_available_inline_sizes_at_or_above: None,
percentage_inline_basis: false,
+ own_block_size: formatting_context::OwnBlockSizeObservation::Observed,
..Self::proven_by_stored_run(outputs)
}
}
@@ -54,10 +57,35 @@ impl RunInputsTheStoredRunNeverObserved {
percentage_block_basis_and_block_size_definiteness,
definite_available_inline_sizes_at_or_above,
percentage_inline_basis,
+ own_block_size,
} = self;
percentage_block_basis_and_block_size_definiteness
|| definite_available_inline_sizes_at_or_above.is_some()
|| percentage_inline_basis
+ || own_block_size != formatting_context::OwnBlockSizeObservation::Observed
+ }
+
+ fn available_block_size_definiteness(self) -> bool {
+ self.percentage_block_basis_and_block_size_definiteness
+ || self.own_block_size != formatting_context::OwnBlockSizeObservation::Observed
+ }
+}
+
+fn root_input_cells_match_ignoring_unobserved_own_block_size(
+ stored: used_values::RootInputCells,
+ probe: used_values::RootInputCells,
+ own_block_size: formatting_context::OwnBlockSizeObservation,
+) -> bool {
+ match own_block_size {
+ formatting_context::OwnBlockSizeObservation::Observed => stored == probe,
+ formatting_context::OwnBlockSizeObservation::Unobserved => {
+ let without_own_block_size = |cells| used_values::RootInputCells {
+ content_block_size: CssPixels::default(),
+ has_definite_block_size: false,
+ ..cells
+ };
+ without_own_block_size(stored) == without_own_block_size(probe)
+ }
}
}
@@ -108,7 +136,11 @@ impl FcRunCacheKey {
}
self.fc_type == probe.fc_type
&& self.layout_mode == probe.layout_mode
- && self.root_cells == probe.root_cells
+ && root_input_cells_match_ignoring_unobserved_own_block_size(
+ self.root_cells,
+ probe.root_cells,
+ unobserved.own_block_size,
+ )
&& layout_inputs_match_ignoring_unobserved(&self.input, &probe.input, unobserved)
}
}
@@ -159,14 +191,14 @@ fn layout_inputs_match_ignoring_unobserved(
&& available_block_sizes_match(
available_space.block_size,
b.available_space.block_size,
- unobserved.percentage_block_basis_and_block_size_definiteness,
+ unobserved.available_block_size_definiteness(),
)
&& inline_bases_match
&& block_bases_match
&& sizing_directives_match_ignoring_unobserved(
&sizing,
&b.sizing,
- unobserved.percentage_block_basis_and_block_size_definiteness,
+ unobserved.available_block_size_definiteness(),
)
}
@@ -262,9 +294,9 @@ pub(super) struct FcRunCacheHit {
impl FcRunCacheEntry {
/// Whether the committed fragment of `box_` and every fragment committed in its subtree are the ones the stored run
- /// produced: the root's fragment shows the stored line data at the stored content size, and each fragment the run
- /// placed in its own scope is the box's committed fragment, placed as the run placed it. A fragment that was
- /// committed holds the fragments committed below it.
+ /// produced: the root's fragment shows the stored line data at the stored content size, or at any block size where
+ /// the stored run never observed its own, and each fragment the run placed in its own scope is the box's committed
+ /// fragment, placed as the run placed it. A fragment that was committed holds the fragments committed below it.
pub(super) fn describes_committed_subtree(&self, arena: &LayoutNodeArena, box_: Node) -> bool {
let Some(root) = self.outputs.root.as_ref() else {
return false;
@@ -282,7 +314,9 @@ impl FcRunCacheEntry {
fragment.line_data.as_ref(),
self.outputs.root_outcome.line_data.as_ref(),
) && fragment.content_inline_size == content_inline_size
- && fragment.content_block_size == content_block_size
+ && (fragment.content_block_size == content_block_size
+ || self.outputs.result.own_block_size_observation
+ == formatting_context::OwnBlockSizeObservation::Unobserved)
})
.unwrap_or(false);
root_fragment_is_the_stored_one
@@ -765,6 +799,10 @@ pub(super) enum FcRunCacheAttempt {
}
impl FcRunCacheAttempt {
+ pub(super) fn stores_outputs(&self) -> bool {
+ !matches!(self, Self::Bypass)
+ }
+
pub(super) fn trace_action(&self) -> &'static str {
match self {
Self::Bypass => "RUN (cache=bypass)",
@@ -1006,9 +1044,9 @@ mod tests {
fn inline_inputs_unobserved_at_or_above(threshold: i64) -> RunInputsTheStoredRunNeverObserved {
RunInputsTheStoredRunNeverObserved {
- percentage_block_basis_and_block_size_definiteness: false,
definite_available_inline_sizes_at_or_above: Some(px(threshold)),
percentage_inline_basis: true,
+ ..RunInputsTheStoredRunNeverObserved::default()
}
}
@@ -1355,8 +1393,7 @@ mod tests {
&probe,
RunInputsTheStoredRunNeverObserved {
percentage_block_basis_and_block_size_definiteness: true,
- definite_available_inline_sizes_at_or_above: None,
- percentage_inline_basis: false,
+ ..RunInputsTheStoredRunNeverObserved::default()
}
));
}
@@ -1426,4 +1463,89 @@ mod tests {
assert!(!stored.matches(&probe, inline_inputs_unobserved_at_or_above(0)));
}
}
+
+ fn item_key(content_block_size: i64, has_definite_block_size: bool) -> FcRunCacheKey {
+ let record = UsedValues::default();
+ record.content_block_size.set(px(content_block_size));
+ record.has_definite_block_size.set(has_definite_block_size);
+ record.has_definite_inline_size.set(true);
+ record.content_inline_size.set(px(300));
+ FcRunCacheKey::new(
+ formatting_context::FormattingContextType::Block,
+ LayoutMode::Normal,
+ LayoutInput::new(
+ AvailableSpace {
+ inline_size: AvailableSize::definite(px(300)),
+ block_size: if has_definite_block_size {
+ AvailableSize::definite(px(content_block_size))
+ } else {
+ AvailableSize::Indefinite
+ },
+ },
+ ContainingBlockConstraints::default(),
+ ParticipationInParentFormattingContext::Item,
+ ),
+ used_values::RootInputCells::capture(&record),
+ )
+ }
+
+ fn own_block_size(observation: formatting_context::OwnBlockSizeObservation) -> RunInputsTheStoredRunNeverObserved {
+ RunInputsTheStoredRunNeverObserved {
+ percentage_block_basis_and_block_size_definiteness: true,
+ own_block_size: observation,
+ ..RunInputsTheStoredRunNeverObserved::default()
+ }
+ }
+
+ #[test]
+ fn an_item_run_that_observed_its_own_block_size_matches_only_the_block_size_it_was_assigned() {
+ let observed = own_block_size(formatting_context::OwnBlockSizeObservation::Observed);
+ let stored = item_key(40, false);
+ assert!(stored.matches(&item_key(40, false), observed));
+ assert!(!stored.matches(&item_key(40, true), observed));
+ assert!(!stored.matches(&item_key(60, false), observed));
+ assert!(!stored.matches(&item_key(60, true), observed));
+ }
+
+ #[test]
+ fn an_item_run_that_never_observed_its_own_block_size_matches_any_assigned_block_size_and_definiteness() {
+ let unobserved = own_block_size(formatting_context::OwnBlockSizeObservation::Unobserved);
+ for stored in [item_key(40, false), item_key(40, true)] {
+ for probe in [
+ item_key(40, false),
+ item_key(40, true),
+ item_key(60, true),
+ item_key(0, false),
+ ] {
+ assert!(stored.matches(&probe, unobserved));
+ }
+ }
+ let mut wider = item_key(60, true);
+ wider.root_cells.content_inline_size = px(320);
+ assert!(
+ !item_key(40, false).matches(&wider, unobserved),
+ "only the root's own block size is unobserved"
+ );
+ let mut button_aligned = item_key(60, true);
+ button_aligned
+ .root_cells
+ .has_definite_block_size_only_for_button_content_alignment = true;
+ assert!(!item_key(40, false).matches(&button_aligned, unobserved));
+ }
+
+ #[test]
+ fn stale_line_data_after_structural_inline_damage_is_taken_only_at_the_same_own_block_size() {
+ let mut outputs = entry(item_key(40, false), 1, None, 0).outputs;
+ outputs.result.own_block_size_observation = formatting_context::OwnBlockSizeObservation::Unobserved;
+ assert!(item_key(40, false).matches(
+ &item_key(60, true),
+ RunInputsTheStoredRunNeverObserved::proven_by_stored_run(&outputs)
+ ));
+ assert!(!item_key(40, false).matches(
+ &item_key(60, true),
+ RunInputsTheStoredRunNeverObserved::accepted_when_reusing_stale_line_data_after_structural_inline_damage(
+ &outputs
+ )
+ ));
+ }
}
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index c7e60387aea..ea4a411caa2 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1057,6 +1057,14 @@ pub(crate) struct ChildLayoutResult {
/// For a box with a preferred aspect ratio, the block size of its laid out content.
pub content_block_size_for_aspect_ratio_minimum: Option<CssPixels>,
pub depends_on_percentage_block_size: bool,
+ pub own_block_size_observation: OwnBlockSizeObservation,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub(crate) enum OwnBlockSizeObservation {
+ #[default]
+ Observed,
+ Unobserved,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -2050,6 +2058,33 @@ pub(super) fn run_formatting_context(
if let Some(discarded_outputs) = &discarded_outputs {
run_repeatability::verify_repeated_run(&callbacks, box_, discarded_outputs, &outputs);
}
+ if cache_attempt.stores_outputs() {
+ run_repeatability::verify_run_ignores_its_unobserved_own_block_size(
+ &callbacks,
+ box_,
+ root_cells,
+ input,
+ &outputs,
+ |root_cells_at_other_own_block_size, input_at_other_own_block_size| {
+ execute_formatting_context_run(
+ builds_fragments,
+ root_cells_at_other_own_block_size,
+ box_,
+ root_containing_block,
+ parent_grid,
+ fc_type,
+ layout_mode,
+ should_collect_devtools_layout_data,
+ callbacks,
+ input_at_other_own_block_size,
+ parent_block,
+ None,
+ None,
+ None,
+ )
+ },
+ );
+ }
cache_attempt.conclude(&callbacks, box_, cache_key, &input, &outputs);
absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, &input, outputs, false)
}
@@ -2149,6 +2184,7 @@ fn execute_formatting_context_run(
) -> RunOutputs {
assert!(!box_.is_invalid());
let parent_owns_root_input_cells = parent_owns_root_input_cells(&callbacks, box_, &input);
+ let run_is_handed_table_inline_layout_outside_its_key = table_inline_layout.is_some();
let root_used = root_cells.materialize_record();
let outputs = RunRecords::with_root(
callbacks,
@@ -2389,6 +2425,10 @@ fn execute_formatting_context_run(
);
}
result.depends_on_percentage_block_size = run.sizing().resolve_percentage_block_size_dependency(run.box_);
+ if !run_is_handed_table_inline_layout_outside_its_key {
+ result.own_block_size_observation =
+ own_block_size_observation_of_item_run(run, fc_type, &input, &result);
+ }
// NB: The root's descendants are laid out in the frame the root establishes.
let take_run_fragments = || {
@@ -2867,7 +2907,7 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
let cache_key =
fc_run_cache::FcRunCacheKey::new(FormattingContextType::Block, LayoutMode::Normal, input, root_cells);
let builds_fragments = run_builds_fragments(LayoutMode::Normal, &input, false);
- let execute = |previous_line_data| {
+ let execute_at = |root_cells, input, previous_line_data| {
execute_formatting_context_run(
builds_fragments,
root_cells,
@@ -2895,7 +2935,7 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
) {
return None;
}
- return Some(execute(None).result);
+ return Some(execute_at(root_cells, input, None).result);
}
let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(
cell,
@@ -2924,11 +2964,22 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
|| "RUN AHEAD OF INTRINSIC BLOCK PADDING",
);
let previous_line_data = cache_attempt.previous_line_data();
- let discarded_outputs = run_repeatability::lay_out_discarded_run(&run.callbacks, || execute(None));
- let outputs = execute(previous_line_data);
+ let discarded_outputs =
+ run_repeatability::lay_out_discarded_run(&run.callbacks, || execute_at(root_cells, input, None));
+ let outputs = execute_at(root_cells, input, previous_line_data);
if let Some(discarded_outputs) = &discarded_outputs {
run_repeatability::verify_repeated_run(&run.callbacks, cell, discarded_outputs, &outputs);
}
+ run_repeatability::verify_run_ignores_its_unobserved_own_block_size(
+ &run.callbacks,
+ cell,
+ root_cells,
+ input,
+ &outputs,
+ |root_cells_at_other_own_block_size, input_at_other_own_block_size| {
+ execute_at(root_cells_at_other_own_block_size, input_at_other_own_block_size, None)
+ },
+ );
cache_attempt.conclude(&run.callbacks, cell, cache_key, &input, &outputs);
Some(outputs.result)
}
@@ -2942,6 +2993,50 @@ pub(super) fn parent_owns_root_input_cells(callbacks: &LayoutPass<'_>, box_: Nod
&& !frame_established_by(callbacks, box_).is_orthogonal_to(callbacks.frame)
}
+fn own_block_size_observation_of_item_run(
+ run: &FormattingContextRun,
+ fc_type: FormattingContextType,
+ input: &LayoutInput,
+ result: &ChildLayoutResult,
+) -> OwnBlockSizeObservation {
+ let root_used = run.records.used_values(run.box_);
+ let item_is_plain_block_container_laid_out_without_its_own_block_size = fc_type == FormattingContextType::Block
+ && run.layout_mode == LayoutMode::Normal
+ && !run.callbacks.frame.is_transposed()
+ && parent_owns_root_input_cells(&run.callbacks, run.box_, input)
+ && !result.depends_on_percentage_block_size
+ && !root_used.has_descendant_that_depends_on_percentage_block_size.get()
+ && !block_formatting_context::root_lays_out_content_against_its_own_block_size(&run.sizing(), run.box_)
+ && !root_content_includes_an_orthogonal_flow_sized_by_the_root_block_size(&run.callbacks, run.box_);
+ if item_is_plain_block_container_laid_out_without_its_own_block_size {
+ OwnBlockSizeObservation::Unobserved
+ } else {
+ OwnBlockSizeObservation::Observed
+ }
+}
+
+fn root_content_includes_an_orthogonal_flow_sized_by_the_root_block_size(
+ callbacks: &LayoutPass<'_>,
+ root: Node,
+) -> bool {
+ let mut boxes_whose_children_the_root_contains: smallvec::SmallVec<[Node; 8]> = smallvec::smallvec![root];
+ while let Some(container) = boxes_whose_children_the_root_contains.pop() {
+ for child in callbacks.children(container) {
+ let facts = NodeFacts::new(callbacks, child);
+ if facts.is_text_node() || facts.is_absolutely_positioned() {
+ continue;
+ }
+ if frame_established_by(callbacks, child).is_orthogonal_to(callbacks.frame) {
+ return true;
+ }
+ if facts.is_anonymous() || (facts.is_inline() && !facts.is_atomic_inline()) {
+ boxes_whose_children_the_root_contains.push(child);
+ }
+ }
+ }
+ false
+}
+
pub(super) fn content_block_size_adopted_after_run(
input: &LayoutInput,
automatic_content_block_size: CssPixels,
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index 82f56c080fc..5e545025cb2 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -8,6 +8,9 @@
//! no memoized layout from before it, keeps none after it, and its result is discarded; the second is the run itself.
//! Both have to agree on everything the run hands its parent, which shows that a run depends on nothing but its input
//! and the state of the pass, and that what it reads from memoized layout is what it would have computed.
+//!
+//! With LIBWEB_VERIFY_UNOBSERVED_BLOCK_SIZE, every run that claims it never observed its own block size is laid out
+//! again the same way, at the other definiteness of that size and with extra space, and has to agree with the run too.
use super::*;
@@ -56,77 +59,181 @@ pub(super) fn verify_repeated_run(
discarded: &formatting_context::RunOutputs,
used: &formatting_context::RunOutputs,
) {
- assert_eq!(
- used.result, discarded.result,
- "the run of {box_:?} returned a result its discarded repetition does not"
- );
- assert_eq!(
- used.root_outcome.cells, discarded.root_outcome.cells,
- "the run of {box_:?} left a root record its discarded repetition does not"
- );
- assert_eq!(
- used.root_outcome.own_metrics_sealed, discarded.root_outcome.own_metrics_sealed,
- "the run of {box_:?} seals the root's metrics unlike its discarded repetition"
- );
- assert!(
- used.root_outcome.line_data.as_deref() == discarded.root_outcome.line_data.as_deref(),
- "the run of {box_:?} left line data its discarded repetition does not"
- );
- assert!(
- rare_payloads_match(
- used.root_outcome.rare.as_deref(),
- discarded.root_outcome.rare.as_deref()
- ),
- "the run of {box_:?} left rare payloads its discarded repetition does not"
- );
- assert_eq!(
- used.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
- discarded.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
- "the run of {box_:?} claims an available inline size threshold its discarded repetition does not"
- );
- assert!(
- host_findings_match(used.host_findings.as_deref(), discarded.host_findings.as_deref()),
- "the run of {box_:?} found out for the host what its discarded repetition does not"
- );
- let (used_root, discarded_root) = match (&used.root, &discarded.root) {
- (None, None) => return,
- (Some(used_root), Some(discarded_root)) => (used_root, discarded_root),
- _ => panic!("the run of {box_:?} and its discarded repetition do not both build fragments"),
- };
- assert!(
- discarded_root.reused_subtree_roots.is_empty(),
- "the discarded repetition of the run of {box_:?} reused a subtree"
- );
- assert!(
- same_elements_in_any_order(
- &used_root.propagated_pending_abspos,
- &discarded_root.propagated_pending_abspos
- ) && same_elements_in_any_order(
- &used_root.propagated_anchor_candidates,
- &discarded_root.propagated_anchor_candidates
- ) && same_elements_in_any_order(
- &used_root.propagated_inline_containing_block_rects,
- &discarded_root.propagated_inline_containing_block_rects
- ) && same_elements_in_any_order(
- &used_root.propagated_abspos_containing_block_info,
- &discarded_root.propagated_abspos_containing_block_info
- ),
- "the run of {box_:?} propagates payloads its discarded repetition does not"
- );
- let mut nodes_laid_out_afresh = HashSet::default();
- collect_nodes_of_fragment_subtrees(&discarded_root.scoped_descendants, &mut nodes_laid_out_afresh);
- let comparison = FreshDescendantComparison {
- callbacks,
- reused_subtree_roots: &used_root.reused_subtree_roots,
- nodes_laid_out_afresh,
- };
- if let Err(difference) = comparison.compare_children(
- box_,
- &used_root.scoped_descendants,
- &discarded_root.scoped_descendants,
- false,
+ ComparedLayouts {
+ checked: &format!("the run of {box_:?}"),
+ reference: "its discarded repetition",
+ }
+ .verify(callbacks, box_, used, discarded);
+}
+
+fn unobserved_own_block_size_verification_is_enabled() -> bool {
+ static ENABLED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+ *ENABLED.get_or_init(|| std::env::var_os("LIBWEB_VERIFY_UNOBSERVED_BLOCK_SIZE").is_some())
+}
+
+fn root_inputs_at_other_own_block_sizes(
+ root_cells: used_values::RootInputCells,
+ input: LayoutInput,
+ result: &formatting_context::ChildLayoutResult,
+) -> Vec<(used_values::RootInputCells, LayoutInput)> {
+ if result.own_block_size_observation == formatting_context::OwnBlockSizeObservation::Observed
+ || root_cells.has_content_offset
+ || input.available_space.block_size.is_intrinsic_sizing_constraint()
+ {
+ return Vec::new();
+ }
+ let mut other_definite_own_block_sizes = Vec::new();
+ if root_cells.has_definite_block_size {
+ other_definite_own_block_sizes.push(None);
+ }
+ let definite_block_size_with_extra_space_beyond_assigned_and_automatic_sizes =
+ root_cells.content_block_size.max(result.automatic_content_block_size) + CssPixels::from_integer(50);
+ if definite_block_size_with_extra_space_beyond_assigned_and_automatic_sizes.raw_value() != i32::MAX {
+ other_definite_own_block_sizes.push(Some(
+ definite_block_size_with_extra_space_beyond_assigned_and_automatic_sizes,
+ ));
+ }
+ other_definite_own_block_sizes
+ .into_iter()
+ .map(|definite_own_block_size| {
+ let cells = used_values::RootInputCells {
+ content_block_size: definite_own_block_size.unwrap_or_default(),
+ has_definite_block_size: definite_own_block_size.is_some(),
+ ..root_cells
+ };
+ let mut input = input;
+ input.available_space.block_size =
+ definite_own_block_size.map_or(AvailableSize::Indefinite, AvailableSize::definite);
+ (cells, input)
+ })
+ .collect()
+}
+
+pub(super) fn verify_run_ignores_its_unobserved_own_block_size(
+ callbacks: &LayoutPass<'_>,
+ box_: Node,
+ root_cells: used_values::RootInputCells,
+ input: LayoutInput,
+ outputs: &formatting_context::RunOutputs,
+ lay_out: impl Fn(used_values::RootInputCells, LayoutInput) -> formatting_context::RunOutputs,
+) {
+ if !unobserved_own_block_size_verification_is_enabled() || callbacks.scratch().reads_no_memoized_layout() {
+ return;
+ }
+ let checked = format!("the run of {box_:?}, which never observed its own block size,");
+ for (cells_at_other_own_block_size, input_at_other_own_block_size) in
+ root_inputs_at_other_own_block_sizes(root_cells, input, &outputs.result)
+ {
+ let outputs_at_other_own_block_size = callbacks.arena().layout_trace.without_events(|| {
+ callbacks
+ .scratch()
+ .lay_out_discarded_run(|| lay_out(cells_at_other_own_block_size, input_at_other_own_block_size))
+ });
+ let reference = if cells_at_other_own_block_size.has_definite_block_size {
+ format!(
+ "its layout at the definite block size {:?}",
+ cells_at_other_own_block_size.content_block_size
+ )
+ } else {
+ "its layout at an indefinite block size".to_owned()
+ };
+ ComparedLayouts {
+ checked: &checked,
+ reference: &reference,
+ }
+ .verify(callbacks, box_, outputs, &outputs_at_other_own_block_size);
+ }
+}
+
+struct ComparedLayouts<'a> {
+ checked: &'a str,
+ reference: &'a str,
+}
+
+impl ComparedLayouts<'_> {
+ fn verify(
+ &self,
+ callbacks: &LayoutPass<'_>,
+ box_: Node,
+ checked_outputs: &formatting_context::RunOutputs,
+ reference_outputs: &formatting_context::RunOutputs,
) {
- panic!("the run of {box_:?} lays out descendants unlike its discarded repetition: {difference}");
+ let Self { checked, reference } = self;
+ assert_eq!(
+ checked_outputs.result, reference_outputs.result,
+ "{checked} returned a result {reference} does not"
+ );
+ assert_eq!(
+ checked_outputs.root_outcome.cells, reference_outputs.root_outcome.cells,
+ "{checked} left a root record {reference} does not"
+ );
+ assert_eq!(
+ checked_outputs.root_outcome.own_metrics_sealed, reference_outputs.root_outcome.own_metrics_sealed,
+ "{checked} seals the root's metrics unlike {reference}"
+ );
+ assert!(
+ checked_outputs.root_outcome.line_data.as_deref() == reference_outputs.root_outcome.line_data.as_deref(),
+ "{checked} left line data {reference} does not"
+ );
+ assert!(
+ rare_payloads_match(
+ checked_outputs.root_outcome.rare.as_deref(),
+ reference_outputs.root_outcome.rare.as_deref()
+ ),
+ "{checked} left rare payloads {reference} does not"
+ );
+ assert_eq!(
+ checked_outputs.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ reference_outputs.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ "{checked} claims an available inline size threshold {reference} does not"
+ );
+ assert!(
+ host_findings_match(
+ checked_outputs.host_findings.as_deref(),
+ reference_outputs.host_findings.as_deref()
+ ),
+ "{checked} found out for the host what {reference} does not"
+ );
+ let (checked_root, reference_root) = match (&checked_outputs.root, &reference_outputs.root) {
+ (None, None) => return,
+ (Some(checked_root), Some(reference_root)) => (checked_root, reference_root),
+ _ => panic!("{checked} and {reference} do not both build fragments"),
+ };
+ assert!(
+ reference_root.reused_subtree_roots.is_empty(),
+ "{checked}: {reference} reused a subtree"
+ );
+ assert!(
+ same_elements_in_any_order(
+ &checked_root.propagated_pending_abspos,
+ &reference_root.propagated_pending_abspos
+ ) && same_elements_in_any_order(
+ &checked_root.propagated_anchor_candidates,
+ &reference_root.propagated_anchor_candidates
+ ) && same_elements_in_any_order(
+ &checked_root.propagated_inline_containing_block_rects,
+ &reference_root.propagated_inline_containing_block_rects
+ ) && same_elements_in_any_order(
+ &checked_root.propagated_abspos_containing_block_info,
+ &reference_root.propagated_abspos_containing_block_info
+ ),
+ "{checked} propagates payloads {reference} does not"
+ );
+ let mut nodes_laid_out_afresh = HashSet::default();
+ collect_nodes_of_fragment_subtrees(&reference_root.scoped_descendants, &mut nodes_laid_out_afresh);
+ let comparison = FreshDescendantComparison {
+ callbacks,
+ reused_subtree_roots: &checked_root.reused_subtree_roots,
+ nodes_laid_out_afresh,
+ };
+ if let Err(difference) = comparison.compare_children(
+ box_,
+ &checked_root.scoped_descendants,
+ &reference_root.scoped_descendants,
+ false,
+ ) {
+ panic!("{checked} lays out descendants unlike {reference}: {difference}");
+ }
}
}
@@ -378,3 +485,100 @@ fn describe_placement(link: &fragment_tree::FragmentLink) -> String {
}
)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn px(value: i64) -> CssPixels {
+ CssPixels::from_integer(value)
+ }
+
+ fn item_root_inputs(
+ content_block_size: i64,
+ has_definite_block_size: bool,
+ ) -> (used_values::RootInputCells, LayoutInput) {
+ let record = UsedValues::default();
+ record.content_block_size.set(px(content_block_size));
+ record.has_definite_block_size.set(has_definite_block_size);
+ let input = LayoutInput::new(
+ AvailableSpace {
+ inline_size: AvailableSize::definite(px(300)),
+ block_size: if has_definite_block_size {
+ AvailableSize::definite(px(content_block_size))
+ } else {
+ AvailableSize::Indefinite
+ },
+ },
+ ContainingBlockConstraints::default(),
+ ParticipationInParentFormattingContext::Item,
+ );
+ (used_values::RootInputCells::capture(&record), input)
+ }
+
+ fn result_observing(
+ observation: formatting_context::OwnBlockSizeObservation,
+ automatic_content_block_size: i64,
+ ) -> formatting_context::ChildLayoutResult {
+ formatting_context::ChildLayoutResult {
+ automatic_content_block_size: px(automatic_content_block_size),
+ own_block_size_observation: observation,
+ ..formatting_context::ChildLayoutResult::default()
+ }
+ }
+
+ fn own_block_sizes_verified_from(
+ (root_cells, input): (used_values::RootInputCells, LayoutInput),
+ automatic_content_block_size: i64,
+ ) -> Vec<Option<CssPixels>> {
+ root_inputs_at_other_own_block_sizes(
+ root_cells,
+ input,
+ &result_observing(
+ formatting_context::OwnBlockSizeObservation::Unobserved,
+ automatic_content_block_size,
+ ),
+ )
+ .into_iter()
+ .map(|(cells, input)| {
+ assert_eq!(
+ cells.has_definite_block_size,
+ matches!(input.available_space.block_size, AvailableSize::Definite(_))
+ );
+ cells.has_definite_block_size.then_some(cells.content_block_size)
+ })
+ .collect()
+ }
+
+ #[test]
+ fn an_unobserved_own_block_size_is_verified_at_the_other_definiteness_and_with_extra_space() {
+ let (root_cells, input) = item_root_inputs(40, false);
+ assert!(
+ root_inputs_at_other_own_block_sizes(
+ root_cells,
+ input,
+ &result_observing(formatting_context::OwnBlockSizeObservation::Observed, 40)
+ )
+ .is_empty()
+ );
+ assert_eq!(
+ own_block_sizes_verified_from(item_root_inputs(40, false), 40),
+ [Some(px(90))]
+ );
+ assert_eq!(
+ own_block_sizes_verified_from(item_root_inputs(20, false), 40),
+ [Some(px(90))]
+ );
+ assert_eq!(
+ own_block_sizes_verified_from(item_root_inputs(40, true), 40),
+ [None, Some(px(90))],
+ "a stretched run whose content fills it exactly is also verified where extra space is left"
+ );
+ let (mut saturated_cells, saturated_input) = item_root_inputs(40, true);
+ saturated_cells.content_block_size = CssPixels::from_raw(i32::MAX);
+ assert_eq!(
+ own_block_sizes_verified_from((saturated_cells, saturated_input), 40),
+ [None]
+ );
+ }
+}
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 1241061f5c5..20c3834e0f3 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -172,6 +172,10 @@ impl<'pass> SizingContext<'pass> {
}
}
+ pub(super) fn callbacks(&self) -> &LayoutPass<'pass> {
+ &self.callbacks
+ }
+
#[inline]
pub(super) fn facts(&self, node: Node) -> NodeFacts<'_> {
NodeFacts::new(&self.callbacks, node)
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index d2805e23d2e..732ab821c00 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -251,47 +251,49 @@ impl<'a> PaintableCommit<'a> {
let mut inline_content_unchanged = false;
let mut inline_item_order_unchanged = false;
let mut child_sequence_unchanged = false;
- let (old_identity, old_content_size) = self.arena().with_committed_fragment_link(node, |old_link| {
- old_link.map_or((0, used_values::FfiCssPixelSize::default()), |old_link| {
- let previous = &old_link.fragment;
- if reuses_committed_subtree || previous.identity == fragment.identity {
- root_box_unchanged =
- std::sync::Arc::ptr_eq(fragment, previous) || fragment.has_same_box_properties(previous);
- own_paint_unchanged = root_box_unchanged;
- child_placements_unchanged = true;
- inline_content_unchanged = true;
- inline_item_order_unchanged = true;
- child_sequence_unchanged = true;
- } else {
- inline_content_unchanged = same_inline_content(fragment, previous);
- inline_item_order_unchanged = inline_content_unchanged
- || match (&fragment.line_data, &previous.line_data) {
- (Some(left), Some(right)) => left.has_same_item_order(right),
- _ => false,
- };
- own_paint_unchanged = inline_content_unchanged
- && fragment.has_same_box_properties(previous)
- && !has_descendant_dependent_paint(self.arena(), node);
- child_placements_unchanged = fragment.has_same_child_placements(previous);
- child_sequence_unchanged = fragment.has_same_child_sequence(previous);
- }
- own_paint_unchanged &= old_link.has_same_placement(link);
- (
- old_link.fragment.identity,
- frame.size_to_physical(
- old_link.fragment.content_inline_size,
- old_link.fragment.content_block_size,
- ),
- )
- })
- });
+ let (old_identity, old_content_size, old_content_inline_size) =
+ self.arena().with_committed_fragment_link(node, |old_link| {
+ old_link.map_or((0, used_values::FfiCssPixelSize::default(), None), |old_link| {
+ let previous = &old_link.fragment;
+ if reuses_committed_subtree || previous.identity == fragment.identity {
+ root_box_unchanged =
+ std::sync::Arc::ptr_eq(fragment, previous) || fragment.has_same_box_properties(previous);
+ own_paint_unchanged = root_box_unchanged;
+ child_placements_unchanged = true;
+ inline_content_unchanged = true;
+ inline_item_order_unchanged = true;
+ child_sequence_unchanged = true;
+ } else {
+ inline_content_unchanged = same_inline_content(fragment, previous);
+ inline_item_order_unchanged = inline_content_unchanged
+ || match (&fragment.line_data, &previous.line_data) {
+ (Some(left), Some(right)) => left.has_same_item_order(right),
+ _ => false,
+ };
+ own_paint_unchanged = inline_content_unchanged
+ && fragment.has_same_box_properties(previous)
+ && !has_descendant_dependent_paint(self.arena(), node);
+ child_placements_unchanged = fragment.has_same_child_placements(previous);
+ child_sequence_unchanged = fragment.has_same_child_sequence(previous);
+ }
+ own_paint_unchanged &= old_link.has_same_placement(link);
+ (
+ old_link.fragment.identity,
+ frame.size_to_physical(
+ old_link.fragment.content_inline_size,
+ old_link.fragment.content_block_size,
+ ),
+ Some(old_link.fragment.content_inline_size),
+ )
+ })
+ });
if old_content_size != new_content_size {
if self.arena().data(node).kind.get() == NodeKind::Viewport {
self.arena().set_needs_full_scrollable_overflow_recalculation();
}
assert!(
- !reuses_committed_subtree,
- "a reused committed subtree changed its content size"
+ !reuses_committed_subtree || old_content_inline_size == Some(fragment.content_inline_size),
+ "a reused committed subtree changed its content inline size"
);
content_size_change = Some((old_content_size, new_content_size));
}
diff --git a/Meta/Linters/check_rust_process_wide_state.py b/Meta/Linters/check_rust_process_wide_state.py
index 01f9602d234..1aa6d825cfe 100755
--- a/Meta/Linters/check_rust_process_wide_state.py
+++ b/Meta/Linters/check_rust_process_wide_state.py
@@ -117,6 +117,7 @@ RENDER_STATE_ALLOWED = {
"css/style/mod.rs:SELECTOR_TRUTH_DERIVATION",
"css/style/mod.rs:STYLE_ANSWER_PATCH",
"css/style/mod.rs:STYLE_PLAN_PROVENANCE",
+ "layout/run_repeatability.rs:ENABLED",
"layout/run_repeatability.rs:VERIFICATION",
"render_state/clock/hover.rs:LOGS",
],
diff --git a/Tests/LibWeb/Ref/expected/items-relayout-when-their-automatic-block-size-becomes-definite-ref.html b/Tests/LibWeb/Ref/expected/items-relayout-when-their-automatic-block-size-becomes-definite-ref.html
new file mode 100644
index 00000000000..0582b1fec53
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/items-relayout-when-their-automatic-block-size-becomes-definite-ref.html
@@ -0,0 +1,82 @@
+<!doctype html>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #column {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ width: 200px;
+ height: 300px;
+ }
+
+ .column {
+ display: flex;
+ flex-direction: column;
+ width: 40px;
+ background: lightgray;
+ }
+
+ .row {
+ display: flex;
+ width: 100px;
+ background: lightgray;
+ }
+
+ .percentage-height {
+ height: 100%;
+ background: green;
+ }
+
+ .percentage-basis {
+ flex-basis: 50%;
+ min-height: 0;
+ background: green;
+ }
+
+ .square {
+ aspect-ratio: 1;
+ background: green;
+ }
+
+ .short {
+ width: 20px;
+ height: 10px;
+ }
+
+ .tall {
+ width: 20px;
+ height: 30px;
+ }
+
+ .taller {
+ width: 20px;
+ height: 50px;
+ }
+
+ .blue {
+ background: blue;
+ }
+
+ #grid-row {
+ display: flex;
+ align-items: stretch;
+ }
+
+ .grid {
+ display: grid;
+ grid-template-rows: 50% auto;
+ width: 40px;
+ background: lightgray;
+ }
+</style>
+<div id="column">
+ <div class="column"><div><div class="percentage-height"><div class="short"></div></div><div class="short blue"></div></div></div>
+ <div class="column"><div class="percentage-basis"><div class="tall"></div></div><div class="short blue"></div></div>
+ <div class="row"><div class="square"></div><div class="taller blue"></div></div>
+</div>
+<div id="grid-row">
+ <div class="grid"><div class="short" style="background: green"></div><div class="tall blue"></div></div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/nested-flex-rows-relayout-at-new-block-size-ref.html b/Tests/LibWeb/Ref/expected/nested-flex-rows-relayout-at-new-block-size-ref.html
new file mode 100644
index 00000000000..fa6309cb29b
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/nested-flex-rows-relayout-at-new-block-size-ref.html
@@ -0,0 +1,42 @@
+<!doctype html>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #rows {
+ display: flex;
+ height: 80px;
+ column-gap: 10px;
+ }
+
+ .row {
+ display: flex;
+ column-gap: 10px;
+ }
+
+ .bottom-aligned {
+ align-items: flex-end;
+ }
+
+ .item {
+ width: 40px;
+ background: lightgray;
+ }
+
+ .box {
+ width: 20px;
+ height: 20px;
+ background: green;
+ }
+
+ .half {
+ height: 50%;
+ background: green;
+ }
+</style>
+<div id="rows">
+ <div class="row"><div class="item"><div class="box"></div></div><div class="item"><div class="half"></div></div></div>
+ <div class="row bottom-aligned"><div class="item"><div class="box"></div></div></div>
+ <div class="row"><div class="row"><div class="item"><div class="half"></div></div><div class="item"><div class="box"></div></div></div></div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/stretched-flex-items-relayout-at-new-block-size-ref.html b/Tests/LibWeb/Ref/expected/stretched-flex-items-relayout-at-new-block-size-ref.html
new file mode 100644
index 00000000000..85af101b4fd
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/stretched-flex-items-relayout-at-new-block-size-ref.html
@@ -0,0 +1,133 @@
+<!doctype html>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #items {
+ display: flex;
+ height: 80px;
+ column-gap: 10px;
+ font-size: 0;
+ }
+
+ .item {
+ width: 40px;
+ background: lightgray;
+ }
+
+ .box {
+ width: 20px;
+ height: 20px;
+ background: green;
+ }
+
+ .half {
+ height: 50%;
+ background: green;
+ }
+
+ .stretch-fit {
+ height: stretch;
+ background: green;
+ }
+
+ fieldset.item {
+ display: flex;
+ align-items: flex-end;
+ min-inline-size: 0;
+ margin: 0;
+ border: 0;
+ padding: 0;
+ }
+
+ .multicol {
+ column-count: 2;
+ column-gap: 0;
+ column-fill: auto;
+ }
+
+ .multicol > div {
+ height: 20px;
+ }
+
+ button.item {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ font-size: 0;
+ }
+
+ button.item > span {
+ display: inline-block;
+ }
+
+ .clamped {
+ continue: collapse;
+ }
+
+ .clamped > span {
+ display: inline-block;
+ vertical-align: top;
+ width: 40px;
+ height: 20px;
+ }
+
+ input.item {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ font-size: 10px;
+ }
+
+ .table {
+ display: table;
+ }
+
+ .bottom-cell {
+ display: table-cell;
+ vertical-align: bottom;
+ }
+
+ li.item {
+ font-size: 10px;
+ }
+
+ .positioned {
+ position: relative;
+ }
+
+ .positioned > div {
+ position: absolute;
+ bottom: 0;
+ }
+
+ .green {
+ background: green;
+ }
+
+ .blue {
+ background: blue;
+ }
+
+ .purple {
+ background: purple;
+ }
+
+ .orange {
+ background: orange;
+ }
+</style>
+<div id="items">
+ <div class="item"><div class="box"></div></div>
+ <div class="item"><div class="half"></div></div>
+ <div class="item"><div class="stretch-fit"></div></div>
+ <fieldset class="item"><div class="box"></div></fieldset>
+ <div class="item multicol"><div class="green"></div><div class="blue"></div><div class="purple"></div><div class="orange"></div></div>
+ <button class="item"><span class="box"></span></button>
+ <div class="item clamped"><span class="green"></span><span class="blue"></span><span class="purple"></span><span class="orange"></span></div>
+ <input class="item" value="x">
+ <div class="item table"><div class="bottom-cell"><div class="box"></div></div></div>
+ <li class="item"><div class="box"></div></li>
+ <div class="item positioned"><div class="box"></div></div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/stretched-grid-items-relayout-at-new-block-size-ref.html b/Tests/LibWeb/Ref/expected/stretched-grid-items-relayout-at-new-block-size-ref.html
new file mode 100644
index 00000000000..6843b0405de
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/stretched-grid-items-relayout-at-new-block-size-ref.html
@@ -0,0 +1,103 @@
+<!doctype html>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #items {
+ display: grid;
+ grid-auto-flow: column;
+ grid-auto-columns: 40px;
+ grid-auto-rows: minmax(0, 1fr);
+ height: 80px;
+ column-gap: 10px;
+ font-size: 0;
+ }
+
+ .item {
+ width: 40px;
+ background: lightgray;
+ }
+
+ .box {
+ width: 20px;
+ height: 20px;
+ background: green;
+ }
+
+ .half {
+ height: 50%;
+ background: green;
+ }
+
+ .stretch-fit {
+ height: stretch;
+ background: green;
+ }
+
+ fieldset.item {
+ display: flex;
+ align-items: flex-end;
+ min-inline-size: 0;
+ margin: 0;
+ border: 0;
+ padding: 0;
+ }
+
+ .multicol {
+ column-count: 2;
+ column-gap: 0;
+ column-fill: auto;
+ }
+
+ .multicol > div {
+ height: 20px;
+ }
+
+ button.item {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ font-size: 0;
+ }
+
+ button.item > span {
+ display: inline-block;
+ }
+
+ .clamped {
+ continue: collapse;
+ }
+
+ .clamped > span {
+ display: inline-block;
+ vertical-align: top;
+ width: 40px;
+ height: 20px;
+ }
+
+ .green {
+ background: green;
+ }
+
+ .blue {
+ background: blue;
+ }
+
+ .purple {
+ background: purple;
+ }
+
+ .orange {
+ background: orange;
+ }
+</style>
+<div id="items">
+ <div class="item"><div class="box"></div></div>
+ <div class="item"><div class="half"></div></div>
+ <div class="item"><div class="stretch-fit"></div></div>
+ <fieldset class="item"><div class="box"></div></fieldset>
+ <div class="item multicol"><div class="green"></div><div class="blue"></div><div class="purple"></div><div class="orange"></div></div>
+ <button class="item"><span class="box"></span></button>
+ <div class="item clamped"><span class="green"></span><span class="blue"></span><span class="purple"></span><span class="orange"></span></div>
+</div>
diff --git a/Tests/LibWeb/Ref/input/items-relayout-when-their-automatic-block-size-becomes-definite.html b/Tests/LibWeb/Ref/input/items-relayout-when-their-automatic-block-size-becomes-definite.html
new file mode 100644
index 00000000000..6f28e421eca
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/items-relayout-when-their-automatic-block-size-becomes-definite.html
@@ -0,0 +1,94 @@
+<!doctype html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/items-relayout-when-their-automatic-block-size-becomes-definite-ref.html">
+<style>
+ body {
+ margin: 0;
+ }
+
+ #column {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ width: 200px;
+ }
+
+ .column {
+ display: flex;
+ flex-direction: column;
+ width: 40px;
+ background: lightgray;
+ }
+
+ .row {
+ display: flex;
+ width: 100px;
+ background: lightgray;
+ }
+
+ .percentage-height {
+ height: 100%;
+ background: green;
+ }
+
+ .percentage-basis {
+ flex-basis: 50%;
+ min-height: 0;
+ background: green;
+ }
+
+ .square {
+ aspect-ratio: 1;
+ background: green;
+ }
+
+ .short {
+ width: 20px;
+ height: 10px;
+ }
+
+ .tall {
+ width: 20px;
+ height: 30px;
+ }
+
+ .taller {
+ width: 20px;
+ height: 50px;
+ }
+
+ .blue {
+ background: blue;
+ }
+
+ #grid-row {
+ display: flex;
+ align-items: flex-start;
+ }
+
+ .grid {
+ display: grid;
+ grid-template-rows: 50% auto;
+ width: 40px;
+ background: lightgray;
+ }
+</style>
+<div id="column">
+ <div class="column"><div><div class="percentage-height"><div class="short"></div></div><div class="short blue"></div></div></div>
+ <div class="column"><div class="percentage-basis"><div class="tall"></div></div><div class="short blue"></div></div>
+ <div class="row"><div class="square"></div><div class="taller blue"></div></div>
+</div>
+<div id="grid-row">
+ <div class="grid"><div class="short" style="background: green"></div><div class="tall blue"></div></div>
+</div>
+<script>
+ // The items are first laid out at an indefinite block size equal to their automatic one, then at that same size
+ // made definite.
+ window.addEventListener("load", () => {
+ document.body.offsetWidth;
+ document.getElementById("column").style.height = "300px";
+ document.getElementById("grid-row").style.alignItems = "stretch";
+ document.body.offsetWidth;
+ document.documentElement.classList.remove("reftest-wait");
+ });
+</script>
diff --git a/Tests/LibWeb/Ref/input/nested-flex-rows-relayout-at-new-block-size.html b/Tests/LibWeb/Ref/input/nested-flex-rows-relayout-at-new-block-size.html
new file mode 100644
index 00000000000..256dbde4783
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/nested-flex-rows-relayout-at-new-block-size.html
@@ -0,0 +1,53 @@
+<!doctype html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/nested-flex-rows-relayout-at-new-block-size-ref.html">
+<style>
+ body {
+ margin: 0;
+ }
+
+ #rows {
+ display: flex;
+ height: 40px;
+ column-gap: 10px;
+ }
+
+ .row {
+ display: flex;
+ column-gap: 10px;
+ }
+
+ .bottom-aligned {
+ align-items: flex-end;
+ }
+
+ .item {
+ width: 40px;
+ background: lightgray;
+ }
+
+ .box {
+ width: 20px;
+ height: 20px;
+ background: green;
+ }
+
+ .half {
+ height: 50%;
+ background: green;
+ }
+</style>
+<div id="rows">
+ <div class="row"><div class="item"><div class="box"></div></div><div class="item"><div class="half"></div></div></div>
+ <div class="row bottom-aligned"><div class="item"><div class="box"></div></div></div>
+ <div class="row"><div class="row"><div class="item"><div class="half"></div></div><div class="item"><div class="box"></div></div></div></div>
+</div>
+<script>
+ // The rows are laid out stretched to the first height before the change stretches them again.
+ window.addEventListener("load", () => {
+ document.body.offsetWidth;
+ rows.style.height = "80px";
+ document.body.offsetWidth;
+ document.documentElement.classList.remove("reftest-wait");
+ });
+</script>
diff --git a/Tests/LibWeb/Ref/input/stretched-flex-items-relayout-at-new-block-size.html b/Tests/LibWeb/Ref/input/stretched-flex-items-relayout-at-new-block-size.html
new file mode 100644
index 00000000000..504788ba329
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/stretched-flex-items-relayout-at-new-block-size.html
@@ -0,0 +1,144 @@
+<!doctype html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/stretched-flex-items-relayout-at-new-block-size-ref.html">
+<style>
+ body {
+ margin: 0;
+ }
+
+ #items {
+ display: flex;
+ height: 40px;
+ column-gap: 10px;
+ font-size: 0;
+ }
+
+ .item {
+ width: 40px;
+ background: lightgray;
+ }
+
+ .box {
+ width: 20px;
+ height: 20px;
+ background: green;
+ }
+
+ .half {
+ height: 50%;
+ background: green;
+ }
+
+ .stretch-fit {
+ height: stretch;
+ background: green;
+ }
+
+ fieldset.item {
+ display: flex;
+ align-items: flex-end;
+ min-inline-size: 0;
+ margin: 0;
+ border: 0;
+ padding: 0;
+ }
+
+ .multicol {
+ column-count: 2;
+ column-gap: 0;
+ column-fill: auto;
+ }
+
+ .multicol > div {
+ height: 20px;
+ }
+
+ button.item {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ font-size: 0;
+ }
+
+ button.item > span {
+ display: inline-block;
+ }
+
+ .clamped {
+ continue: collapse;
+ }
+
+ .clamped > span {
+ display: inline-block;
+ vertical-align: top;
+ width: 40px;
+ height: 20px;
+ }
+
+ input.item {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ font-size: 10px;
+ }
+
+ .table {
+ display: table;
+ }
+
+ .bottom-cell {
+ display: table-cell;
+ vertical-align: bottom;
+ }
+
+ li.item {
+ font-size: 10px;
+ }
+
+ .positioned {
+ position: relative;
+ }
+
+ .positioned > div {
+ position: absolute;
+ bottom: 0;
+ }
+
+ .green {
+ background: green;
+ }
+
+ .blue {
+ background: blue;
+ }
+
+ .purple {
+ background: purple;
+ }
+
+ .orange {
+ background: orange;
+ }
+</style>
+<div id="items">
+ <div class="item"><div class="box"></div></div>
+ <div class="item"><div class="half"></div></div>
+ <div class="item"><div class="stretch-fit"></div></div>
+ <fieldset class="item"><div class="box"></div></fieldset>
+ <div class="item multicol"><div class="green"></div><div class="blue"></div><div class="purple"></div><div class="orange"></div></div>
+ <button class="item"><span class="box"></span></button>
+ <div class="item clamped"><span class="green"></span><span class="blue"></span><span class="purple"></span><span class="orange"></span></div>
+ <input class="item" value="x">
+ <div class="item table"><div class="bottom-cell"><div class="box"></div></div></div>
+ <li class="item"><div class="box"></div></li>
+ <div class="item positioned"><div class="box"></div></div>
+</div>
+<script>
+ // The items are laid out stretched to the first height before the change stretches them again.
+ window.addEventListener("load", () => {
+ document.body.offsetWidth;
+ items.style.height = "80px";
+ document.body.offsetWidth;
+ document.documentElement.classList.remove("reftest-wait");
+ });
+</script>
diff --git a/Tests/LibWeb/Ref/input/stretched-grid-items-relayout-at-new-block-size.html b/Tests/LibWeb/Ref/input/stretched-grid-items-relayout-at-new-block-size.html
new file mode 100644
index 00000000000..780503ef019
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/stretched-grid-items-relayout-at-new-block-size.html
@@ -0,0 +1,114 @@
+<!doctype html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/stretched-grid-items-relayout-at-new-block-size-ref.html">
+<style>
+ body {
+ margin: 0;
+ }
+
+ #items {
+ display: grid;
+ grid-auto-flow: column;
+ grid-auto-columns: 40px;
+ grid-auto-rows: minmax(0, 1fr);
+ height: 40px;
+ column-gap: 10px;
+ font-size: 0;
+ }
+
+ .item {
+ width: 40px;
+ background: lightgray;
+ }
+
+ .box {
+ width: 20px;
+ height: 20px;
+ background: green;
+ }
+
+ .half {
+ height: 50%;
+ background: green;
+ }
+
+ .stretch-fit {
+ height: stretch;
+ background: green;
+ }
+
+ fieldset.item {
+ display: flex;
+ align-items: flex-end;
+ min-inline-size: 0;
+ margin: 0;
+ border: 0;
+ padding: 0;
+ }
+
+ .multicol {
+ column-count: 2;
+ column-gap: 0;
+ column-fill: auto;
+ }
+
+ .multicol > div {
+ height: 20px;
+ }
+
+ button.item {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ font-size: 0;
+ }
+
+ button.item > span {
+ display: inline-block;
+ }
+
+ .clamped {
+ continue: collapse;
+ }
+
+ .clamped > span {
+ display: inline-block;
+ vertical-align: top;
+ width: 40px;
+ height: 20px;
+ }
+
+ .green {
+ background: green;
+ }
+
+ .blue {
+ background: blue;
+ }
+
+ .purple {
+ background: purple;
+ }
+
+ .orange {
+ background: orange;
+ }
+</style>
+<div id="items">
+ <div class="item"><div class="box"></div></div>
+ <div class="item"><div class="half"></div></div>
+ <div class="item"><div class="stretch-fit"></div></div>
+ <fieldset class="item"><div class="box"></div></fieldset>
+ <div class="item multicol"><div class="green"></div><div class="blue"></div><div class="purple"></div><div class="orange"></div></div>
+ <button class="item"><span class="box"></span></button>
+ <div class="item clamped"><span class="green"></span><span class="blue"></span><span class="purple"></span><span class="orange"></span></div>
+</div>
+<script>
+ // The items are laid out stretched to the first height before the change stretches them again.
+ window.addEventListener("load", () => {
+ document.body.offsetWidth;
+ items.style.height = "80px";
+ document.body.offsetWidth;
+ document.documentElement.classList.remove("reftest-wait");
+ });
+</script>
diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-stretched-items-ignore-unobserved-block-size.txt b/Tests/LibWeb/Text/expected/layout-run-cache-stretched-items-ignore-unobserved-block-size.txt
new file mode 100644
index 00000000000..1f7c87b3498
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/layout-run-cache-stretched-items-ignore-unobserved-block-size.txt
@@ -0,0 +1,7 @@
+PASS: a taller flex line stretches its items again (work + checks)
+PASS: a flex line that grows again stretches its items once more (work + checks)
+PASS: a taller grid row stretches its items again (work + checks)
+PASS: a grid row that grows again stretches its items once more (work + checks)
+PASS: a wider vertical-lr flex line stretches its item again (work + checks)
+PASS: a wider vertical-rl flex line stretches its item again and keeps its content at the block start (work + checks)
+PASS: a wider vertical-lr grid row stretches its item again (work + checks)
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-stretched-items-ignore-unobserved-block-size.html b/Tests/LibWeb/Text/input/layout-run-cache-stretched-items-ignore-unobserved-block-size.html
new file mode 100644
index 00000000000..9209a5721bc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/layout-run-cache-stretched-items-ignore-unobserved-block-size.html
@@ -0,0 +1,195 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script src="layout-test.js"></script>
+<style>
+ body { margin: 0; }
+ #flex { display: flex; height: 40px; }
+ #grid { display: grid; grid-auto-flow: column; grid-auto-columns: 40px; height: 40px; }
+ .item { width: 40px; }
+ .box { width: 20px; height: 20px; }
+ .half { height: 50%; }
+ .vertical-lr { writing-mode: vertical-lr; }
+ .vertical-rl { writing-mode: vertical-rl; }
+ .vertical-flex { display: flex; width: 40px; height: 40px; }
+ .vertical-grid { display: grid; grid-auto-flow: column; grid-auto-columns: 40px; width: 40px; height: 40px; }
+ .vertical-item { height: 40px; }
+</style>
+<div id="flex"><div class="item" id="flexPlain"><div class="box"></div></div><div class="item" id="flexPercentage"><div class="half" id="flexHalf"></div></div></div>
+<div id="grid"><div class="item" id="gridPlain"><div class="box"></div></div><div class="item" id="gridPercentage"><div class="half" id="gridHalf"></div></div></div>
+<div class="vertical-flex vertical-lr" id="verticalLrFlex"><div class="vertical-item" id="verticalLrFlexItem"><div class="box"></div></div></div>
+<div class="vertical-flex vertical-rl" id="verticalRlFlex"><div class="vertical-item" id="verticalRlFlexItem"><div class="box" id="verticalRlFlexBox"></div></div></div>
+<div class="vertical-grid vertical-lr" id="verticalLrGrid"><div class="vertical-item" id="verticalLrGridItem"><div class="box"></div></div></div>
+<script>
+ layoutTest({
+ steps: [
+ {
+ name: "a taller flex line stretches its items again",
+ mutate: () => {
+ flex.style.height = "80px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex RUN (cache=miss)
+ BlockContainer<DIV>#flexPlain.item/block REUSE SUBTREE
+ BlockContainer<DIV>#flexPercentage.item/block RUN (cache=miss)
+ Box<DIV>#grid/grid REUSE SUBTREE
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex REUSE SUBTREE
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex REUSE SUBTREE
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(flexPlain.getBoundingClientRect().height, 80, "plain item height");
+ equal(flexPercentage.getBoundingClientRect().height, 80, "percentage item height");
+ equal(flexHalf.getBoundingClientRect().height, 40, "percentage child height");
+ },
+ },
+ {
+ name: "a flex line that grows again stretches its items once more",
+ mutate: () => {
+ flex.style.height = "120px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex RUN (cache=miss)
+ BlockContainer<DIV>#flexPlain.item/block REUSE SUBTREE
+ BlockContainer<DIV>#flexPercentage.item/block RUN (cache=miss)
+ Box<DIV>#grid/grid REUSE SUBTREE
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex REUSE SUBTREE
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex REUSE SUBTREE
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(flexPlain.getBoundingClientRect().height, 120, "plain item height");
+ equal(flexPercentage.getBoundingClientRect().height, 120, "percentage item height");
+ equal(flexHalf.getBoundingClientRect().height, 60, "percentage child height");
+ },
+ },
+ {
+ name: "a taller grid row stretches its items again",
+ mutate: () => {
+ grid.style.height = "80px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex REUSE SUBTREE
+ Box<DIV>#grid/grid RUN (cache=miss)
+ BlockContainer<DIV>#gridPlain.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPlain.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPlain.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPercentage.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPercentage.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPercentage.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPlain.item/block REUSE SUBTREE
+ BlockContainer<DIV>#gridPercentage.item/block RUN (cache=miss)
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex REUSE SUBTREE
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex REUSE SUBTREE
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(gridPlain.getBoundingClientRect().height, 80, "plain item height");
+ equal(gridPercentage.getBoundingClientRect().height, 80, "percentage item height");
+ equal(gridHalf.getBoundingClientRect().height, 40, "percentage child height");
+ },
+ },
+ {
+ name: "a grid row that grows again stretches its items once more",
+ mutate: () => {
+ grid.style.height = "120px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex REUSE SUBTREE
+ Box<DIV>#grid/grid RUN (cache=miss)
+ BlockContainer<DIV>#gridPlain.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPlain.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPlain.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPercentage.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPercentage.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPercentage.item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#gridPlain.item/block REUSE SUBTREE
+ BlockContainer<DIV>#gridPercentage.item/block RUN (cache=miss)
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex REUSE SUBTREE
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex REUSE SUBTREE
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(gridPlain.getBoundingClientRect().height, 120, "plain item height");
+ equal(gridPercentage.getBoundingClientRect().height, 120, "percentage item height");
+ equal(gridHalf.getBoundingClientRect().height, 60, "percentage child height");
+ },
+ },
+ {
+ name: "a wider vertical-lr flex line stretches its item again",
+ mutate: () => {
+ verticalLrFlex.style.width = "80px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex REUSE SUBTREE
+ Box<DIV>#grid/grid REUSE SUBTREE
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex RUN (cache=miss)
+ BlockContainer<DIV>#verticalLrFlexItem.vertical-item/block RUN (cache=miss)
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex REUSE SUBTREE
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(verticalLrFlexItem.getBoundingClientRect().width, 80, "vertical-lr flex item width");
+ },
+ },
+ {
+ name: "a wider vertical-rl flex line stretches its item again and keeps its content at the block start",
+ mutate: () => {
+ verticalRlFlex.style.width = "80px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex REUSE SUBTREE
+ Box<DIV>#grid/grid REUSE SUBTREE
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex REUSE SUBTREE
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex RUN (cache=miss)
+ BlockContainer<DIV>#verticalRlFlexItem.vertical-item/block RUN (cache=miss)
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(verticalRlFlexItem.getBoundingClientRect().width, 80, "vertical-rl flex item width");
+ equal(verticalRlFlexBox.getBoundingClientRect().right, verticalRlFlexItem.getBoundingClientRect().right, "vertical-rl content right edge");
+ },
+ },
+ {
+ name: "a wider vertical-lr grid row stretches its item again",
+ mutate: () => {
+ verticalLrGrid.style.width = "80px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#flex/flex REUSE SUBTREE
+ Box<DIV>#grid/grid REUSE SUBTREE
+ Box<DIV>#verticalLrFlex.vertical-flex.vertical-lr/flex REUSE SUBTREE
+ Box<DIV>#verticalRlFlex.vertical-flex.vertical-rl/flex REUSE SUBTREE
+ Box<DIV>#verticalLrGrid.vertical-grid.vertical-lr/grid RUN (cache=miss)
+ BlockContainer<DIV>#verticalLrGridItem.vertical-item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#verticalLrGridItem.vertical-item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#verticalLrGridItem.vertical-item MEASURE max-content block (cache=hit)
+ BlockContainer<DIV>#verticalLrGridItem.vertical-item/block RUN (cache=miss)
+ `,
+ check: equal => {
+ equal(verticalLrGridItem.getBoundingClientRect().width, 80, "vertical-lr grid item width");
+ },
+ },
+ ],
+ });
+</script>