Skip to content

Truly independent web browser

LibWeb: Run deferred table cells ahead of their intrinsic padding

Aliaksandr Kalenikc84bb3233acf
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index f5ff1070a7d..57ca05fe221 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -272,8 +272,8 @@ pub(super) struct FcRunCacheEntry {
key: FcRunCacheKey,
validity: FcRunCacheValidity,
pub(super) outputs: formatting_context::RunOutputs,
- /// Whether the run is a table cell's that cannot observe the intrinsic block padding its table hands it (see
- /// table_cell_contents_never_observe_intrinsic_block_padding), so that it stands for runs with any such padding.
+ /// Whether the run is a table cell's that did not observe the intrinsic block padding its table hands it (see
+ /// run_observes_root_block_padding), so that it stands for runs with any such padding.
table_cell_intrinsic_block_padding_unobserved: bool,
root_content_block_size_adopted_after_run: Option<CssPixels>,
/// How many layouts the arena had committed when the run was stored. The subtrees the run took from the cache as
@@ -941,7 +941,7 @@ impl FcRunCacheAttempt {
.table_cell_intrinsic_block_padding
.is_some()
&& outputs.root_outcome.cells.parent_owns_root_input_cells()
- && table_cell_contents_never_observe_intrinsic_block_padding(callbacks, box_),
+ && !run_observes_root_block_padding(callbacks, box_, outputs),
root_content_block_size_adopted_after_run,
layout_commits_when_stored: callbacks.arena().layout_commit_count(),
committed_subtree_token_when_descendants_dropped: None,
@@ -995,24 +995,21 @@ pub(super) fn can_describe_run(
)
}
-/// Whether a table cell's run cannot observe the intrinsic block padding its table hands it (the vertical-alignment
-/// stretch): the padding only moves the cell's content box, and content that is only text lays out relative to that.
-/// Nothing in it resolves against the padding box, as out-of-flow descendants would, and it holds no scroll container.
-pub(super) fn table_cell_contents_never_observe_intrinsic_block_padding(
+/// Whether a run's outputs may depend on its root's block paddings. They hold the content in content box coordinates,
+/// so they stand for the same run at other block paddings unless the root is a scroll container, whose scrollable
+/// overflow area is bounded by its padding box, places a rendered legend on its border box, or passes payloads on to
+/// its ancestors (out-of-flow descendants, their containing block rects, anchors), which are placed against its
+/// padding box. Outputs without a root fragment cannot show those payloads.
+pub(super) fn run_observes_root_block_padding(
callbacks: &LayoutPass<'_>,
box_: Node,
+ outputs: &formatting_context::RunOutputs,
) -> bool {
let facts = NodeFacts::new(callbacks, box_);
- if !facts.is_table_cell() || facts.is_scroll_container() {
- return false;
- }
- for child in callbacks.children(box_) {
- let child_facts = NodeFacts::new(callbacks, child);
- if !child_facts.is_text_node() && !child_facts.is_break_node() {
- return false;
- }
- }
- true
+ let places_rendered_legend_on_its_border_box = facts.is_fieldset_box() && !facts.rendered_legend().is_invalid();
+ facts.is_scroll_container()
+ || places_rendered_legend_on_its_border_box
+ || outputs.root.as_ref().is_none_or(|root| !root.propagates_nothing())
}
#[cfg(test)]
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index ea4a411caa2..16ee05e29b9 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -112,12 +112,6 @@ pub(crate) enum TableWrapperInlineSizeMode {
UseTableUsedInlineSizeIfNotAuto,
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub(crate) enum RootFragments {
- WhereTheRunInputAllows,
- LeftOut,
-}
-
pub(crate) fn run_builds_fragments(
layout_mode: LayoutMode,
input: &LayoutInput,
@@ -151,40 +145,12 @@ impl<'pass> MeasurementState<'pass> {
node_used: &UsedValues,
layout_mode: LayoutMode,
input: LayoutInput,
- ) -> ChildLayoutResult {
- self.launch(
- RootFragments::WhereTheRunInputAllows,
- node,
- node_used,
- layout_mode,
- input,
- )
- }
-
- pub(crate) fn run_without_root_fragments(
- &self,
- node: Node,
- node_used: &UsedValues,
- layout_mode: LayoutMode,
- input: LayoutInput,
- ) -> ChildLayoutResult {
- self.launch(RootFragments::LeftOut, node, node_used, layout_mode, input)
- }
-
- fn launch(
- &self,
- root_fragments: RootFragments,
- node: Node,
- node_used: &UsedValues,
- layout_mode: LayoutMode,
- input: LayoutInput,
) -> ChildLayoutResult {
let fc_type = independent_formatting_context_type(node, &self.callbacks);
let root_containing_block = self
.callbacks
.containing_block_for_child_run(node, &input.participation);
run_formatting_context(
- root_fragments,
None,
node_used,
node,
@@ -1922,7 +1888,6 @@ fn body_input_with_inner_available_space(run: &FormattingContextRun, input: &Lay
#[expect(clippy::too_many_arguments)]
pub(super) fn run_formatting_context(
- root_fragments: RootFragments,
parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,
parent_used: &UsedValues,
box_: Node,
@@ -1941,8 +1906,7 @@ pub(super) fn run_formatting_context(
parent_fragments.clear_reused_subtree_root(box_, parent_used);
}
let root_cells = used_values::RootInputCells::capture(parent_used);
- let builds_fragments = root_fragments == RootFragments::WhereTheRunInputAllows
- && run_builds_fragments(layout_mode, &input, parent_fragments.is_some());
+ let builds_fragments = run_builds_fragments(layout_mode, &input, parent_fragments.is_some());
assert!(
parent_fragments.is_none() || builds_fragments,
"the run of {box_:?} builds no fragments for its parent to commit"
@@ -2739,7 +2703,7 @@ pub(crate) fn layout_inside_child(
parent_grid: Option<&grid_formatting_context::GridFormattingContext>,
child: Node,
layout_mode: LayoutMode,
- mut input: LayoutInput,
+ input: LayoutInput,
force_independent_context_run: bool,
) -> ChildLayoutOutcome {
let facts = NodeFacts::new(&run.callbacks, child);
@@ -2817,37 +2781,21 @@ pub(crate) fn layout_inside_child(
return ChildLayoutOutcome::Skipped;
}
- let fc_type = formatting_context_type_created_by_box(facts)
- .or_else(|| force_independent_context_run.then(|| independent_formatting_context_type(child, &run.callbacks)));
- let Some(fc_type) = fc_type else {
+ let Some(ChildRunPlan {
+ fc_type,
+ root_containing_block,
+ mut input,
+ }) = child_run_plan(run, child, input, force_independent_context_run)
+ else {
if force_independent_context_run {
note_skipped_child_dependency();
return ChildLayoutOutcome::Skipped;
}
return ChildLayoutOutcome::ReenterCurrent;
};
- let root_containing_block = run
- .callbacks
- .containing_block_for_child_run(child, &input.participation);
- // https://drafts.csswg.org/css-sizing-3/#definite
- // "Additionally, the size of the containing block of an absolutely positioned element is always definite with
- // respect to that element."
- // NB: That containing block may also have been laid out by a run other than this one, which holds no record of it.
- input.sizing.treat_block_axis_percentage_insets_as_auto_beyond_root = match input.participation {
- ParticipationInParentFormattingContext::AbsolutelyPositioned(_) => false,
- _ => treat_block_axis_percentage_insets_as_auto_beyond_anonymous_child_root(
- run.records,
- &run.callbacks,
- child,
- root_containing_block,
- run.box_,
- run.treat_block_axis_percentage_insets_as_auto_beyond_root,
- ),
- };
input.sizing.flex_self_block_size_resolution_space =
dimension_root_in_parent_scope(parent_block, child, &input, child_run_builds_fragments);
let result = run_formatting_context(
- RootFragments::WhereTheRunInputAllows,
run.fragments.as_deref(),
used,
child,
@@ -2870,54 +2818,103 @@ pub(crate) fn layout_inside_child(
ChildLayoutOutcome::Created(result)
}
-/// Runs a table cell's committing layout while its table still sizes rows, beside the cell's record, and keeps the
-/// outputs in the run cache. The cell's committing run, once the rows are sized, replays them: its input differs only
-/// in the intrinsic block padding, which the contents of an eligible cell never observe (see
-/// fc_run_cache::table_cell_contents_never_observe_intrinsic_block_padding). Returns None for any other cell.
-pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
+/// The run a table cell's committing run will be (see layout_inside_child), but for the intrinsic block padding that
+/// its table hands it once rows are sized. Laid out ahead of that padding, its outputs stay in the run cache, and the
+/// committing run replays them unless they show that the run observed the root's block padding (see
+/// fc_run_cache::run_observes_root_block_padding).
+pub(crate) fn table_cell_run_shape_ahead_of_its_intrinsic_block_padding(
run: &FormattingContextRun,
cell: Node,
mut input: LayoutInput,
-) -> Option<ChildLayoutResult> {
+) -> Option<ChildRunShape> {
debug_assert!(matches!(
input.participation,
ParticipationInParentFormattingContext::Item
));
- if run.fragments.is_none()
- || formatting_context_type_created_by_box(NodeFacts::new(&run.callbacks, cell))
- != Some(FormattingContextType::Block)
- || !fc_run_cache::table_cell_contents_never_observe_intrinsic_block_padding(&run.callbacks, cell)
- {
- return None;
- }
- // Everything layout_inside_child() hands the committing run, but the intrinsic block padding.
input.sizing.table_cell_intrinsic_block_padding = Some((CssPixels::default(), CssPixels::default()));
- let root_containing_block = run.callbacks.containing_block_for_child_run(cell, &input.participation);
- input.sizing.treat_block_axis_percentage_insets_as_auto_beyond_root =
- treat_block_axis_percentage_insets_as_auto_beyond_anonymous_child_root(
+ let plan = child_run_plan(run, cell, input, false)?;
+ Some(ChildRunShape {
+ node: cell,
+ fc_type: plan.fc_type,
+ input: plan.input,
+ root_cells: used_values::RootInputCells::capture(run.records.used_values(cell)),
+ root_containing_block: plan.root_containing_block,
+ })
+}
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub(crate) struct ChildRunShape {
+ pub(crate) node: Node,
+ pub(crate) fc_type: FormattingContextType,
+ pub(crate) input: LayoutInput,
+ pub(crate) root_cells: used_values::RootInputCells,
+ pub(crate) root_containing_block: Node,
+}
+
+pub(crate) struct ChildRunPlan {
+ pub(crate) fc_type: FormattingContextType,
+ pub(crate) root_containing_block: Node,
+ pub(crate) input: LayoutInput,
+}
+
+pub(crate) fn child_run_plan(
+ run: &FormattingContextRun,
+ child: Node,
+ mut input: LayoutInput,
+ force_independent_context_run: bool,
+) -> Option<ChildRunPlan> {
+ let fc_type = formatting_context_type_created_by_box(NodeFacts::new(&run.callbacks, child)).or_else(|| {
+ force_independent_context_run.then(|| independent_formatting_context_type(child, &run.callbacks))
+ })?;
+ let root_containing_block = run
+ .callbacks
+ .containing_block_for_child_run(child, &input.participation);
+ // https://drafts.csswg.org/css-sizing-3/#definite
+ // "Additionally, the size of the containing block of an absolutely positioned element is always definite with
+ // respect to that element."
+ // NB: That containing block may also have been laid out by a run other than this one, which holds no record of it.
+ input.sizing.treat_block_axis_percentage_insets_as_auto_beyond_root = match input.participation {
+ ParticipationInParentFormattingContext::AbsolutelyPositioned(_) => false,
+ _ => treat_block_axis_percentage_insets_as_auto_beyond_anonymous_child_root(
run.records,
&run.callbacks,
- cell,
+ child,
root_containing_block,
run.box_,
run.treat_block_axis_percentage_insets_as_auto_beyond_root,
- );
- input.sizing.flex_self_block_size_resolution_space = None;
- let root_cells = used_values::RootInputCells::capture(run.records.used_values(cell));
- 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_at = |root_cells, input, previous_line_data| {
+ ),
+ };
+ Some(ChildRunPlan {
+ fc_type,
+ root_containing_block,
+ input,
+ })
+}
+
+pub(crate) fn lay_out_shape_for_its_result(
+ callbacks: LayoutPass<'_>,
+ shape: ChildRunShape,
+ layout_mode: LayoutMode,
+) -> ChildLayoutResult {
+ let ChildRunShape {
+ node,
+ fc_type,
+ input,
+ root_cells,
+ root_containing_block,
+ } = shape;
+ let builds_fragments = run_builds_fragments(layout_mode, &input, false);
+ let lay_out = |root_cells, input, previous_line_data| {
execute_formatting_context_run(
builds_fragments,
root_cells,
- cell,
+ node,
root_containing_block,
None,
- FormattingContextType::Block,
- LayoutMode::Normal,
- run.should_collect_devtools_layout_data,
- run.callbacks,
+ fc_type,
+ layout_mode,
+ false,
+ callbacks,
input,
None,
previous_line_data,
@@ -2925,63 +2922,61 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
None,
)
};
- if run.callbacks.scratch().reads_no_memoized_layout() {
- if !fc_run_cache::can_describe_run(
- cell,
- false,
- run.should_collect_devtools_layout_data,
- &run.callbacks,
- &cache_key,
- ) {
- return None;
- }
- return Some(execute_at(root_cells, input, None).result);
+ let result_with_host_findings = |outputs: &RunOutputs| {
+ callbacks.scratch().receive_host_findings(outputs.host_findings.clone());
+ outputs.result
+ };
+ if callbacks.scratch().reads_no_memoized_layout() {
+ return result_with_host_findings(&lay_out(root_cells, input, None));
}
- let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(
- cell,
- false,
- builds_fragments,
- run.should_collect_devtools_layout_data,
- &run.callbacks,
- &cache_key,
- ) {
- Ok(fc_run_cache::FcRunCacheAttempt::Bypass) => return None,
- Ok(attempt) => attempt,
- Err(hit) => {
- let _trace = run.callbacks.arena().layout_trace.run(
- cell,
- FormattingContextType::Block,
- LayoutMode::Normal,
- || "READ RESULT AHEAD OF INTRINSIC BLOCK PADDING",
- );
- return Some(hit.entry.outputs.result);
- }
+ let runs_ahead_of_intrinsic_block_padding =
+ builds_fragments && input.sizing.table_cell_intrinsic_block_padding.is_some();
+ let cache_key = fc_run_cache::FcRunCacheKey::new(fc_type, layout_mode, input, root_cells);
+ let cache_attempt =
+ match fc_run_cache::FcRunCacheAttempt::probe(node, false, builds_fragments, false, &callbacks, &cache_key) {
+ Ok(attempt) => attempt,
+ Err(hit) => {
+ let action = if runs_ahead_of_intrinsic_block_padding {
+ "READ RESULT AHEAD OF INTRINSIC BLOCK PADDING"
+ } else {
+ "READ RESULT"
+ };
+ let _trace = callbacks
+ .arena()
+ .layout_trace
+ .run(node, fc_type, layout_mode, || action);
+ return result_with_host_findings(&hit.entry.outputs);
+ }
+ };
+ let action = if runs_ahead_of_intrinsic_block_padding {
+ "RUN AHEAD OF INTRINSIC BLOCK PADDING"
+ } else {
+ cache_attempt.trace_action()
};
- let _trace = run.callbacks.arena().layout_trace.run(
- cell,
- FormattingContextType::Block,
- LayoutMode::Normal,
- || "RUN AHEAD OF INTRINSIC BLOCK PADDING",
- );
+ let _trace = callbacks
+ .arena()
+ .layout_trace
+ .run(node, fc_type, layout_mode, || action);
let previous_line_data = cache_attempt.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);
+ let discarded_outputs = run_repeatability::lay_out_discarded_run(&callbacks, || lay_out(root_cells, input, None));
+ let outputs = lay_out(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_repeated_run(&callbacks, node, 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)
+ if cache_attempt.stores_outputs() {
+ run_repeatability::verify_run_ignores_its_unobserved_own_block_size(
+ &callbacks,
+ node,
+ root_cells,
+ input,
+ &outputs,
+ |root_cells_at_other_own_block_size, input_at_other_own_block_size| {
+ lay_out(root_cells_at_other_own_block_size, input_at_other_own_block_size, None)
+ },
+ );
+ }
+ cache_attempt.conclude(&callbacks, node, cache_key, &input, &outputs);
+ result_with_host_findings(&outputs)
}
// NB: An item that establishes an orthogonal flow sizes itself along its container's block axis, so its run owns its
@@ -3375,7 +3370,6 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
.with_forced_sizes(viewport_inline_size, viewport_block_size);
let fc_type = independent_formatting_context_type(root_for_layout, &callbacks);
run_formatting_context(
- RootFragments::WhereTheRunInputAllows,
Some(&entry_fragments),
root_for_layout_used,
root_for_layout,
@@ -3534,7 +3528,6 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let fc_type = formatting_context_type_created_by_box(facts)
.expect("partial relayout root must establish an independent formatting context");
run_formatting_context(
- RootFragments::WhereTheRunInputAllows,
Some(fragments),
root_used,
root,
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 11fd0ea9bac..54010ae1485 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -5,17 +5,12 @@
*/
use super::abspos_inputs::AbsposLayoutInputs;
-use super::formatting_context::DerivedBaselines;
-use super::formatting_context::LayoutMode;
-use super::geometry::AvailableSize;
-use super::geometry::AvailableSpace;
use super::layout_changes::{LayoutChange, queue};
use super::rendered_text::{FfiTextSourceRange, PublishedTextSlot, RenderedTextBoundary, TextContent, TextFragments};
use super::shell_reads::read_arena;
use super::tree_builder::FfiLayoutTreeBuildOutcome;
use super::tree_shape::{Chunk, PUBLISHED_ROWS_PER_CHUNK, ShapeWriter, ShapeWrites, TreeShape};
use super::update_layout::FfiLayoutTreeBuildStats;
-use super::used_values::SizeConstraint;
use crate::cow_column::{ColumnSnapshot, CowColumn};
use crate::css::css_pixels::{CssPixelPoint, FfiCssPixelPoint};
use crate::css::style::bridge::ElementBoxKind;
@@ -42,7 +37,7 @@ use crate::stage::MainThread;
use std::cell::Cell;
use std::cell::RefCell;
use std::ffi::c_void;
-use std::hash::{Hash, Hasher};
+use std::hash::Hash;
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
@@ -227,53 +222,6 @@ fn intrinsic_cache_store<V: IntrinsicMeasurement>(
map.insert(key.masked_for(value.dependencies()), value);
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub(crate) struct TableCellMeasurementKey {
- pub(crate) layout_mode: LayoutMode,
- pub(crate) available_space: AvailableSpace,
- pub(crate) content_inline_size: CssPixels,
- pub(crate) content_block_size: CssPixels,
- pub(crate) has_definite_inline_size: bool,
- pub(crate) has_definite_block_size: bool,
- pub(crate) block_size_constraint: SizeConstraint,
- pub(crate) uses_collapsing_borders_model: bool,
- pub(crate) adopt_automatic_content_block_size: bool,
-}
-
-impl Hash for TableCellMeasurementKey {
- fn hash<H: Hasher>(&self, state: &mut H) {
- fn hash_available_size<H: Hasher>(size: AvailableSize, state: &mut H) {
- match size {
- AvailableSize::Definite(value) => {
- 0u8.hash(state);
- value.raw_value().hash(state);
- }
- AvailableSize::Indefinite => 1u8.hash(state),
- AvailableSize::MinContent => 2u8.hash(state),
- AvailableSize::MaxContent => 3u8.hash(state),
- }
- }
-
- (self.layout_mode as u8).hash(state);
- hash_available_size(self.available_space.inline_size, state);
- hash_available_size(self.available_space.block_size, state);
- self.content_inline_size.raw_value().hash(state);
- self.content_block_size.raw_value().hash(state);
- self.has_definite_inline_size.hash(state);
- self.has_definite_block_size.hash(state);
- (self.block_size_constraint as u8).hash(state);
- self.uses_collapsing_borders_model.hash(state);
- self.adopt_automatic_content_block_size.hash(state);
- }
-}
-
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub(crate) struct TableCellMeasurement {
- pub(crate) automatic_content_block_size: CssPixels,
- pub(crate) baselines: DerivedBaselines,
- pub(crate) depends_on_percentage_block_size: bool,
-}
-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum IntrinsicSizeCacheKind {
MinContentInline,
@@ -342,7 +290,6 @@ struct IntrinsicSizeMaps {
content_inline_sizes: IntrinsicMeasurements<IntrinsicInlineSizeMeasurement>,
min_content_block_size: IntrinsicMeasurements<IntrinsicBlockSizeMeasurement>,
max_content_block_size: IntrinsicMeasurements<IntrinsicBlockSizeMeasurement>,
- table_cell_measurements: HashMap<TableCellMeasurementKey, TableCellMeasurement>,
}
impl IntrinsicSizeMaps {
@@ -509,25 +456,6 @@ impl IntrinsicSizeCaches {
intrinsic_cache_store(&mut maps.content_inline_sizes, key, value);
});
}
-
- pub(crate) fn table_cell_measurement_cache_get(
- &self,
- stamp: IntrinsicSizeCacheStamp,
- key: TableCellMeasurementKey,
- ) -> Option<TableCellMeasurement> {
- self.with_maps(stamp, |maps| maps.table_cell_measurements.get(&key).copied())
- }
-
- pub(crate) fn table_cell_measurement_cache_put(
- &self,
- stamp: IntrinsicSizeCacheStamp,
- key: TableCellMeasurementKey,
- value: TableCellMeasurement,
- ) {
- self.with_maps_mut(stamp, |maps| {
- maps.table_cell_measurements.insert(key, value);
- });
- }
}
#[derive(Clone, Copy, Default)]
@@ -6403,10 +6331,10 @@ mod tests {
use crate::layout::layout_node_arena::{
Chunk, DerivedStyleRecord, IntrinsicBlockSizeMeasurement, IntrinsicInlineSizeMeasurement,
IntrinsicMeasurementDependencies, IntrinsicSizeCacheKey, IntrinsicSizeCacheKind, LayoutNodeArena,
- SLOTS_PER_CHUNK, TableCellMeasurement, TableCellMeasurementKey,
+ SLOTS_PER_CHUNK,
};
use crate::layout::node_data::{NodeConstructionFacts, NodeFlag, NodeKind, NodeSlotId};
- use crate::layout::{CssPixels, fragment_tree, used_values};
+ use crate::layout::{CssPixels, fragment_tree};
use crate::painting::paint_read::{GeometryRead, PaintRead};
use std::ffi::c_void;
@@ -7918,79 +7846,4 @@ mod tests {
.destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());
}
}
-
- #[test]
- fn table_cell_measurements_follow_the_intrinsic_cache_epoch() {
- let mut arena = LayoutNodeArena::new();
- let caches = super::IntrinsicSizeCaches::default();
- let first = arena.allocate_for_test();
- let key = TableCellMeasurementKey {
- layout_mode: crate::layout::layout_node_arena::LayoutMode::Normal,
- available_space: crate::layout::layout_node_arena::AvailableSpace {
- inline_size: crate::layout::layout_node_arena::AvailableSize::definite(CssPixels::from_raw(640)),
- block_size: crate::layout::layout_node_arena::AvailableSize::Indefinite,
- },
- content_inline_size: CssPixels::from_raw(640),
- content_block_size: CssPixels::default(),
- has_definite_inline_size: true,
- has_definite_block_size: false,
- block_size_constraint: used_values::SizeConstraint::None,
- uses_collapsing_borders_model: true,
- adopt_automatic_content_block_size: true,
- };
- let value = TableCellMeasurement {
- automatic_content_block_size: CssPixels::from_raw(320),
- baselines: crate::layout::layout_node_arena::DerivedBaselines {
- inline_alignment: None,
- first: Some(CssPixels::from_raw(64)),
- last: None,
- },
- depends_on_percentage_block_size: true,
- };
-
- let first_data = arena.data(first.slot);
- assert_eq!(
- caches.table_cell_measurement_cache_get(arena.intrinsic_size_cache_stamp(first.slot), key),
- None
- );
- caches.table_cell_measurement_cache_put(arena.intrinsic_size_cache_stamp(first.slot), key, value);
- assert_eq!(
- caches.table_cell_measurement_cache_get(arena.intrinsic_size_cache_stamp(first.slot), key),
- Some(value)
- );
- let percentage_resolved_key = TableCellMeasurementKey {
- content_block_size: CssPixels::from_raw(512),
- has_definite_block_size: true,
- adopt_automatic_content_block_size: false,
- ..key
- };
- assert_eq!(
- caches.table_cell_measurement_cache_get(
- arena.intrinsic_size_cache_stamp(first.slot),
- percentage_resolved_key
- ),
- None
- );
-
- first_data
- .intrinsic_cache_epoch
- .set(first_data.intrinsic_cache_epoch.get() + 1);
- assert_eq!(
- caches.table_cell_measurement_cache_get(arena.intrinsic_size_cache_stamp(first.slot), key),
- None
- );
- arena
- .free_subtree(first.slot)
- .destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());
-
- let second = arena.allocate_for_test();
- assert_eq!(second.slot.slot_index(), first.slot.slot_index());
- assert_eq!(
- caches.table_cell_measurement_cache_get(arena.intrinsic_size_cache_stamp(second.slot), key),
- None
- );
- arena
- .free_subtree(second.slot)
- .destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());
- }
}
diff --git a/Libraries/LibWeb/Rust/src/layout/mod.rs b/Libraries/LibWeb/Rust/src/layout/mod.rs
index 67362f171b1..644452e4f37 100644
--- a/Libraries/LibWeb/Rust/src/layout/mod.rs
+++ b/Libraries/LibWeb/Rust/src/layout/mod.rs
@@ -78,7 +78,6 @@ pub(crate) use crate::layout::layout_node_arena::MainThreadFfiEntry as ArenaMain
pub(crate) use crate::layout::layout_node_arena::{
HostStyle, LayoutNodeArena, LiveRow, PublishedBoundRows, RowsVersion, SLOTS_PER_CHUNK, SampleKind, StyleRelayout,
};
-use crate::layout::layout_node_arena::{TableCellMeasurement, TableCellMeasurementKey};
use crate::layout::node_data::AncestorFact;
pub use crate::layout::node_data::FfiReplacedContentFacts;
pub use crate::layout::node_data::FfiStylePayloads;
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 d9b21651445..757ad72d862 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
@@ -47,7 +47,6 @@ pub(super) fn layout_replaced_with_children(
wrapper_state.set_content_inline_size(content_inline_size);
let wrapper_result = formatting_context::run_formatting_context(
- formatting_context::RootFragments::WhereTheRunInputAllows,
run.fragments.as_deref(),
wrapper_state,
wrapper,
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 20c3834e0f3..33b2dfd8515 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -3464,7 +3464,6 @@ impl<'pass> SizingContext<'pass> {
// table-wrapper can't have borders or paddings but it might have margin taken from table-root.
let available_inline_size = containing_block_inline_size - margin_left - margin_right;
-
// The table wrapper is invisible to percentage resolution, so the table box gets the
// wrapper's constraints unchanged. Callers measuring a table wrapper for grid alignment
// pass the grid-area inline size as the wrapper's percentage basis.
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 5fe64e429fb..e19eac5e265 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -605,6 +605,13 @@ pub(crate) fn distribute_inline_size(columns: &mut [Column], available: CssPixel
distribute_excess(columns, available, fixed);
}
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+struct TableCellMeasurement {
+ automatic_content_block_size: CssPixels,
+ baselines: DerivedBaselines,
+ depends_on_percentage_block_size: bool,
+}
+
#[derive(Clone, Copy)]
pub(crate) struct TableCell {
pub(crate) box_: Node,
@@ -2635,12 +2642,12 @@ impl<'pass> TableFormattingContext<'pass> {
);
}
- /// Measures a cell's content ahead of its committing layout. With the table's committing `run`, a cell whose
- /// committing run can replay the measuring one runs ahead of its intrinsic block padding instead of being
- /// measured in a throwaway layout (see run_table_cell_ahead_of_its_intrinsic_block_padding).
+ /// Measures a cell's content ahead of its committing layout, with everything that layout will be handed but the
+ /// intrinsic block padding, so that the committing run of a cell in a normal-mode table can replay the measuring
+ /// one (see table_cell_run_shape_ahead_of_its_intrinsic_block_padding).
fn measure_cell(
&self,
- run: Option<&FormattingContextRun<'pass>>,
+ run: &FormattingContextRun<'pass>,
cell: TableCell,
used: &UsedValues,
inner: AvailableSpace,
@@ -2658,119 +2665,9 @@ impl<'pass> TableFormattingContext<'pass> {
if !facts.can_have_children() {
return None;
}
-
- // OPTIMIZATION: A cell whose content repeats its measurement at every inline size at or above its max-content
- // inline size shares one entry for all of them, so that a table whose columns grow and shrink
- // measures such a cell again only when its content wraps differently.
- let mut content_inline_size = used.content_inline_size.get();
- let mut available_space = inner;
- if let Some(threshold) = self.cell_measurement_repeats_at_or_above(cell)
- && content_inline_size >= threshold
- && let AvailableSize::Definite(available_inline_size) = inner.inline_size
- && available_inline_size >= threshold
- {
- content_inline_size = threshold;
- available_space.inline_size = AvailableSize::Definite(threshold);
- }
- let key = TableCellMeasurementKey {
- layout_mode: self.run.layout_mode,
- available_space,
- content_inline_size,
- content_block_size: used.content_block_size.get(),
- has_definite_inline_size: used.has_definite_inline_size(),
- has_definite_block_size: used.has_definite_block_size(),
- block_size_constraint: used.block_size_constraint.get(),
- uses_collapsing_borders_model: used.uses_collapsing_borders_model.get(),
- adopt_automatic_content_block_size,
- };
- let caches = self.run.callbacks.intrinsic_size_caches();
- let stamp = self.run.callbacks.intrinsic_size_cache_stamp(cell.box_);
- let layout_trace = &self.run.callbacks.arena().layout_trace;
- if let Some(cached) = caches.table_cell_measurement_cache_get(stamp, key) {
- layout_trace.table_cell_measurement_hit(cell.box_);
- return Some(cached);
- }
- let _trace = layout_trace.table_cell_measurement_miss(cell.box_);
-
- let measured = run
- .filter(|_| {
- adopt_automatic_content_block_size
- && self.style(cell.box_).height().is_auto()
- && !self.anonymous_cell_wraps_flex_or_grid(cell)
- })
- .and_then(|run| {
- formatting_context::run_table_cell_ahead_of_its_intrinsic_block_padding(
- run,
- cell.box_,
- LayoutInput {
- available_space: inner,
- containing_block_constraints: ContainingBlockConstraints::default(),
- content_box_position_in_bfc_root: None,
- sizing: RootSizingDirectives {
- adopt_automatic_content_block_size,
- ..RootSizingDirectives::default()
- },
- participation: ParticipationInParentFormattingContext::Item,
- },
- )
- })
- .map(|result| TableCellMeasurement {
- automatic_content_block_size: result.automatic_content_block_size,
- baselines: result.baselines,
- depends_on_percentage_block_size: result.depends_on_percentage_block_size,
- })
- .unwrap_or_else(|| self.measure_cell_content(cell, used, inner, adopt_automatic_content_block_size));
- caches.table_cell_measurement_cache_put(
- self.run.callbacks.intrinsic_size_cache_stamp(cell.box_),
- key,
- measured,
- );
- Some(measured)
- }
-
- /// The inline size at or above which measuring the cell's content always gives the same result, if there is one.
- /// That is its max-content inline size when the content is only text, which reads the inline size only to break
- /// lines and breaks none at or above it, unless a percentage text-indent reads it too.
- fn cell_measurement_repeats_at_or_above(&self, cell: TableCell) -> Option<CssPixels> {
- let threshold = cell.max_content_inline_size?;
- if self.style(cell.box_).text_indent().contains_percentage() {
- return None;
- }
- for child in self.run.callbacks.children(cell.box_) {
- let facts = NodeFacts::new(&self.run.callbacks, child);
- if !facts.is_text_node() && !facts.is_break_node() {
- return None;
- }
- }
- Some(threshold)
- }
-
- fn measure_cell_content(
- &self,
- cell: TableCell,
- used: &UsedValues,
- inner: AvailableSpace,
- adopt_automatic_content_block_size: bool,
- ) -> TableCellMeasurement {
- // The table formatting context owns the cell's outer geometry. Seed the inputs
- // needed to lay out its contents without copying placement or layout outputs.
- let measurement = formatting_context::MeasurementState::create(self.run.callbacks);
- let measured_root = measurement.create_used_values(cell.box_, ContainingBlockConstraints::default());
- used.mirror_box_metrics_and_size_constraints_into(&measured_root);
- measured_root
- .has_definite_inline_size
- .set(used.has_definite_inline_size());
- measured_root
- .has_definite_block_size
- .set(used.has_definite_block_size());
- measured_root
- .uses_collapsing_borders_model
- .set(used.uses_collapsing_borders_model.get());
-
- let result = measurement.run_without_root_fragments(
+ let shape = formatting_context::table_cell_run_shape_ahead_of_its_intrinsic_block_padding(
+ run,
cell.box_,
- &measured_root,
- self.run.layout_mode,
LayoutInput {
available_space: inner,
containing_block_constraints: ContainingBlockConstraints::default(),
@@ -2781,12 +2678,13 @@ impl<'pass> TableFormattingContext<'pass> {
},
participation: ParticipationInParentFormattingContext::Item,
},
- );
- TableCellMeasurement {
+ )?;
+ let result = formatting_context::lay_out_shape_for_its_result(run.callbacks, shape, self.run.layout_mode);
+ Some(TableCellMeasurement {
automatic_content_block_size: result.automatic_content_block_size,
baselines: result.baselines,
depends_on_percentage_block_size: result.depends_on_percentage_block_size,
- }
+ })
}
fn compute_table_block_size(&mut self, run: &FormattingContextRun<'pass>) {
@@ -2871,8 +2769,8 @@ impl<'pass> TableFormattingContext<'pass> {
let mut content_baselines = None;
if defer_inside_layout {
// This cell's final inside layout happens once row heights are final; measure its
- // content in a throwaway state instead of laying out the committing state twice.
- if let Some(measured) = self.measure_cell(Some(run), cell, used, inner, true) {
+ // content ahead of its intrinsic padding instead of laying out the committing state twice.
+ if let Some(measured) = self.measure_cell(run, cell, used, inner, true) {
self.cell_measurements[cell_index] = Some(measured);
used.set_content_block_size(measured.automatic_content_block_size);
content_baselines = Some(measured.baselines);
@@ -3000,7 +2898,7 @@ impl<'pass> TableFormattingContext<'pass> {
// The first pass measured this cell at its automatic block size; measure it again at
// the percentage-resolved size to preserve the baseline its final inside layout will use.
let content_baselines = self
- .measure_cell(None, cell, used, inner, false)
+ .measure_cell(run, cell, used, inner, false)
.map(|measured| measured.baselines);
let baseline = self.cell_baseline(cell.box_, content_baselines);
self.cells[cell_index].baseline = baseline;
diff --git a/Libraries/LibWeb/Rust/src/layout/trace.rs b/Libraries/LibWeb/Rust/src/layout/trace.rs
index 3fafe2a8344..b31bfa749b3 100644
--- a/Libraries/LibWeb/Rust/src/layout/trace.rs
+++ b/Libraries/LibWeb/Rust/src/layout/trace.rs
@@ -180,17 +180,6 @@ impl LayoutTrace {
})
}
- /// A measurement of the content of the table cell `cell` that the table cell measurement cache holds.
- pub(super) fn table_cell_measurement_hit(&self, cell: NodeSlotId) {
- drop(self.scope("", Some(cell), || " MEASURE CELL (cache=hit)".into()));
- }
-
- /// A measurement of the content of the table cell `cell` that the table cell measurement cache does not hold. The
- /// work that measures it nests under it.
- pub(super) fn table_cell_measurement_miss(&self, cell: NodeSlotId) -> Option<Scope<'_>> {
- self.scope("", Some(cell), || " MEASURE CELL (cache=miss)".into())
- }
-
pub(super) fn run(
&self,
root: NodeSlotId,
@@ -373,8 +362,6 @@ mod tests {
miss.append(" FROM ITEMS");
}
trace.intrinsic_size_hit(NodeSlotId::new(1, 1), IntrinsicSizeCacheKind::MinContentInline);
- drop(trace.table_cell_measurement_miss(NodeSlotId::new(3, 1)));
- trace.table_cell_measurement_hit(NodeSlotId::new(3, 1));
}
// The owners are not named, so each line starts with the indentation and the space before the event.
assert_eq!(
@@ -384,8 +371,6 @@ mod tests {
" MEASURE max-content inline (cache=miss) FROM ITEMS\n",
" MEASURE max-content inline (cache=miss)\n",
" MEASURE min-content inline (cache=hit)\n",
- " MEASURE CELL (cache=miss)\n",
- " MEASURE CELL (cache=hit)\n",
)
);
}
diff --git a/Tests/LibWeb/Ref/expected/table-cell-vertical-align-abspos-children-ref.html b/Tests/LibWeb/Ref/expected/table-cell-vertical-align-abspos-children-ref.html
new file mode 100644
index 00000000000..80c19fa59cf
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/table-cell-vertical-align-abspos-children-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; }
+ div { position: absolute; }
+ .content { width: 100px; height: 20px; background: green; }
+ .bar { width: 100px; height: 10px; background: blue; }
+ .static { width: 50px; height: 10px; background: orange; }
+</style>
+<div class="content" style="left: 0; top: 60px"></div>
+<div class="bar" style="left: 0; top: 0"></div>
+<div class="bar" style="left: 0; top: 130px"></div>
+<div class="content" style="left: 100px; top: 120px"></div>
+<div class="static" style="left: 100px; top: 140px"></div>
+<div class="content" style="left: 200px; top: 60px"></div>
+<div class="static" style="left: 200px; top: 80px"></div>
diff --git a/Tests/LibWeb/Ref/expected/table-cell-vertical-align-scroll-container-ref.html b/Tests/LibWeb/Ref/expected/table-cell-vertical-align-scroll-container-ref.html
new file mode 100644
index 00000000000..e0d2bd94fb7
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/table-cell-vertical-align-scroll-container-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; }
+ div { position: absolute; }
+ .content { width: 100px; height: 20px; background: green; }
+ .bar { width: 100px; height: 5px; background: blue; }
+</style>
+<div class="content" style="left: 0; top: 60px"></div>
+<div class="content" style="left: 100px; top: 120px"></div>
+<div class="bar" style="left: 100px; top: 0"></div>
+<div class="content" style="left: 200px; top: 60px"></div>
diff --git a/Tests/LibWeb/Ref/input/table-cell-vertical-align-abspos-children.html b/Tests/LibWeb/Ref/input/table-cell-vertical-align-abspos-children.html
new file mode 100644
index 00000000000..48764b76013
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/table-cell-vertical-align-abspos-children.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/table-cell-vertical-align-abspos-children-ref.html">
+<style>
+ body { margin: 0; }
+ table { border-spacing: 0; table-layout: fixed; width: 300px; }
+ td { padding: 0; width: 100px; }
+ tr { height: 100px; }
+ .middle { vertical-align: middle; }
+ .bottom { vertical-align: bottom; }
+ .positioned { position: relative; }
+ .content { height: 20px; background: green; }
+ .bar { position: absolute; left: 0; width: 100px; height: 10px; background: blue; }
+ .at-top { top: 0; }
+ .at-bottom { bottom: 0; }
+ .static { position: absolute; width: 50px; height: 10px; background: orange; }
+</style>
+<table><tr id="row">
+ <td class="middle positioned"><div class="content"></div><div class="bar at-top"></div><div class="bar at-bottom"></div></td>
+ <td class="bottom positioned"><div class="content"></div><div class="static"></div></td>
+ <td class="middle"><div class="content"></div><div class="static"></div></td>
+</tr></table>
+<script>
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ document.getElementById("row").style.height = "140px";
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ document.documentElement.classList.remove("reftest-wait");
+ });
+ });
+ });
+ });
+</script>
+</html>
diff --git a/Tests/LibWeb/Ref/input/table-cell-vertical-align-scroll-container.html b/Tests/LibWeb/Ref/input/table-cell-vertical-align-scroll-container.html
new file mode 100644
index 00000000000..4c523a45803
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/table-cell-vertical-align-scroll-container.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/table-cell-vertical-align-scroll-container-ref.html">
+<style>
+ body { margin: 0; }
+ table { border-spacing: 0; table-layout: fixed; width: 300px; }
+ td { padding: 0; width: 100px; overflow: hidden; }
+ tr { height: 100px; }
+ .middle { vertical-align: middle; }
+ .bottom { vertical-align: bottom; }
+ .positioned { position: relative; }
+ .content { height: 20px; background: green; }
+ .bar { position: absolute; left: 0; top: -5px; width: 100px; height: 10px; background: blue; }
+ .wide { width: 150px; height: 20px; background: green; }
+</style>
+<table><tr id="row">
+ <td class="middle"><div class="content"></div></td>
+ <td class="bottom positioned"><div class="content"></div><div class="bar"></div></td>
+ <td class="middle"><div class="wide"></div></td>
+</tr></table>
+<script>
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ document.getElementById("row").style.height = "140px";
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ document.documentElement.classList.remove("reftest-wait");
+ });
+ });
+ });
+ });
+</script>
+</html>
diff --git a/Tests/LibWeb/Text/expected/table-cell-content-placement-across-row-height-changes.txt b/Tests/LibWeb/Text/expected/table-cell-content-placement-across-row-height-changes.txt
new file mode 100644
index 00000000000..729df9da495
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/table-cell-content-placement-across-row-height-changes.txt
@@ -0,0 +1,20 @@
+row 100px middle-fieldset: legend 0, block 54
+row 100px bottom-fieldset: legend 0, block 84
+row 100px baseline-fieldset: legend 0, block 24
+row 100px middle-markup: block 30, float 40, inline-block 46, table 60, block 60
+row 100px bottom-markup: block 60, float 70, inline-block 76, table 90, block 90
+row 140px middle-fieldset: legend 0, block 74
+row 140px bottom-fieldset: legend 0, block 124
+row 140px baseline-fieldset: legend 0, block 24
+row 140px middle-markup: block 50, float 60, inline-block 66, table 80, block 80
+row 140px bottom-markup: block 100, float 110, inline-block 116, table 130, block 130
+row 60px middle-fieldset: legend 0, block 34
+row 60px bottom-fieldset: legend 0, block 44
+row 60px baseline-fieldset: legend 0, block 24
+row 60px middle-markup: block 10, float 20, inline-block 26, table 40, block 40
+row 60px bottom-markup: block 20, float 30, inline-block 36, table 50, block 50
+row 100px middle-fieldset: legend 0, block 54
+row 100px bottom-fieldset: legend 0, block 84
+row 100px baseline-fieldset: legend 0, block 24
+row 100px middle-markup: block 30, float 40, inline-block 46, table 60, block 60
+row 100px bottom-markup: block 60, float 70, inline-block 76, table 90, block 90
diff --git a/Tests/LibWeb/Text/expected/table-cell-measurement-cache-width-changes.txt b/Tests/LibWeb/Text/expected/table-cell-measurement-cache-width-changes.txt
index efbb8e93dd1..7e9fbf14aff 100644
--- a/Tests/LibWeb/Text/expected/table-cell-measurement-cache-width-changes.txt
+++ b/Tests/LibWeb/Text/expected/table-cell-measurement-cache-width-changes.txt
@@ -1,5 +1,5 @@
-900px: 20 misses in BlockContainer<TD>.markup, height 240
-950px: 20 misses in BlockContainer<TD>.markup, height 240
-400px: 40 misses in BlockContainer<TD>.words, BlockContainer<TD>.markup, height 480
-350px: 40 misses in BlockContainer<TD>.words, BlockContainer<TD>.markup, height 480
-1000px: 0 misses, height 240
+900px: 60 laid out ahead, 60 replayed, 0 laid out again, height 240
+950px: 60 laid out ahead, 60 replayed, 0 laid out again, height 240
+400px: 60 laid out ahead, 60 replayed, 0 laid out again, height 480
+350px: 40 laid out ahead, 40 replayed, 0 laid out again, height 480
+1000px: 60 laid out ahead, 60 replayed, 0 laid out again, height 240
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.html b/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.html
index e9dda51600c..46c89699fbe 100644
--- a/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.html
+++ b/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.html
@@ -31,11 +31,9 @@
BlockContainer<TD>#cell/block (intrinsic) RUN (cache=bypass)
BlockContainer<DIV>#nested/block (intrinsic) RUN (cache=miss)
BlockContainer<TD>#cell MEASURE max-content block (cache=hit)
- BlockContainer<TD>#cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#cell/block RUN (cache=miss)
- BlockContainer<DIV>#nested/block RUN (cache=miss)
- BlockContainer<TD>#cell/block RUN (cache=miss)
- BlockContainer<DIV>#nested/block REPLAY FRAGMENTS
+ BlockContainer<TD>#cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<DIV>#nested/block RUN (cache=miss)
+ BlockContainer<TD>#cell/block REPLAY FRAGMENTS
`,
check: equal => {
equal(nested.getBoundingClientRect().width, 80, "nested width");
@@ -60,11 +58,9 @@
BlockContainer<TD>#cell/block (intrinsic) RUN (cache=bypass)
BlockContainer<DIV>#nested/block (intrinsic) READ RESULT
BlockContainer<TD>#cell MEASURE max-content block (cache=hit)
- BlockContainer<TD>#cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#cell/block RUN (cache=miss)
- BlockContainer<DIV>#nested/block REUSE SUBTREE
- BlockContainer<TD>#cell/block RUN (cache=miss)
+ BlockContainer<TD>#cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
BlockContainer<DIV>#nested/block REUSE SUBTREE
+ BlockContainer<TD>#cell/block REPLAY FRAGMENTS
`,
check: equal => {
const rect = nested.getBoundingClientRect();
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-table-cell-ahead-of-intrinsic-padding.html b/Tests/LibWeb/Text/input/layout-run-cache-table-cell-ahead-of-intrinsic-padding.html
index 977377ffab4..a375ca180b0 100644
--- a/Tests/LibWeb/Text/input/layout-run-cache-table-cell-ahead-of-intrinsic-padding.html
+++ b/Tests/LibWeb/Text/input/layout-run-cache-table-cell-ahead-of-intrinsic-padding.html
@@ -70,12 +70,10 @@
BlockContainer<TD>#markup-cell MEASURE max-content inline (cache=hit)
BlockContainer<TD>#markup-cell MEASURE max-content block (cache=hit)
BlockContainer<TD>#markup-cell MEASURE max-content block (cache=hit)
- BlockContainer<TD>#text-cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#text-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
- BlockContainer<TD>#markup-cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#markup-cell/block RUN (cache=miss)
+ BlockContainer<TD>#text-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<TD>#markup-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
BlockContainer<TD>#text-cell/block REPLAY FRAGMENTS
- BlockContainer<TD>#markup-cell/block RUN (cache=miss)
+ BlockContainer<TD>#markup-cell/block REPLAY FRAGMENTS
`,
check: equal => {
const text = document.getElementById("text-cell").getBoundingClientRect();
@@ -108,11 +106,10 @@
BlockContainer<TD>#markup-cell/block (intrinsic) RUN (cache=bypass)
BlockContainer<TD>#markup-cell MEASURE max-content block (cache=miss)
BlockContainer<TD>#markup-cell/block (intrinsic) RUN (cache=bypass)
- BlockContainer<TD>#text-cell MEASURE CELL (cache=hit)
- BlockContainer<TD>#markup-cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#markup-cell/block RUN (cache=miss)
+ BlockContainer<TD>#text-cell/block READ RESULT AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<TD>#markup-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
BlockContainer<TD>#text-cell/block REUSE SUBTREE
- BlockContainer<TD>#markup-cell/block RUN (cache=miss)
+ BlockContainer<TD>#markup-cell/block REPLAY FRAGMENTS
`,
check: equal => {
const top = checkPlacement(equal, 0.5);
@@ -147,12 +144,10 @@
BlockContainer<TD>#markup-cell/block (intrinsic) RUN (cache=bypass)
BlockContainer<TD>#markup-cell MEASURE max-content block (cache=miss)
BlockContainer<TD>#markup-cell/block (intrinsic) RUN (cache=bypass)
- BlockContainer<TD>#text-cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#text-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
- BlockContainer<TD>#markup-cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#markup-cell/block RUN (cache=miss)
+ BlockContainer<TD>#text-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<TD>#markup-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
BlockContainer<TD>#text-cell/block REPLAY FRAGMENTS
- BlockContainer<TD>#markup-cell/block RUN (cache=miss)
+ BlockContainer<TD>#markup-cell/block REPLAY FRAGMENTS
`,
check: equal => { checkPlacement(equal, 1); },
},
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-table-percentage-cell-height-misses.html b/Tests/LibWeb/Text/input/layout-run-cache-table-percentage-cell-height-misses.html
index 13d2eb9efad..9c73ad20aa3 100644
--- a/Tests/LibWeb/Text/input/layout-run-cache-table-percentage-cell-height-misses.html
+++ b/Tests/LibWeb/Text/input/layout-run-cache-table-percentage-cell-height-misses.html
@@ -36,10 +36,9 @@
BlockContainer<TD>#percentage-cell MEASURE max-content inline (cache=hit)
BlockContainer<TD>#percentage-cell MEASURE max-content block (cache=hit)
BlockContainer<TD>#percentage-cell MEASURE max-content block (cache=hit)
- BlockContainer<TD>#percentage-cell MEASURE CELL (cache=hit)
- BlockContainer<TD>#percentage-cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#percentage-cell/block RUN (cache=miss)
- BlockContainer<TD>#percentage-cell/block RUN (cache=miss)
+ BlockContainer<TD>#percentage-cell/block READ RESULT AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<TD>#percentage-cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<TD>#percentage-cell/block REPLAY FRAGMENTS
BlockContainer<TD>#fixed-cell MEASURE min-content inline (cache=hit)
BlockContainer<TD>#fixed-cell MEASURE max-content inline (cache=hit)
TableWrapper(anonymous)/block REUSE SUBTREE
diff --git a/Tests/LibWeb/Text/input/layout-test-harness.html b/Tests/LibWeb/Text/input/layout-test-harness.html
index 6f385c91400..08213aa1c02 100644
--- a/Tests/LibWeb/Text/input/layout-test-harness.html
+++ b/Tests/LibWeb/Text/input/layout-test-harness.html
@@ -74,9 +74,8 @@ test(() => {
" Box<DIV>#item MEASURE max-content block (cache=miss)",
" Box<DIV>#item/flex (intrinsic) RUN (cache=bypass)",
" Box<TABLE>#table/table (intrinsic) RUN (cache=bypass)",
- " BlockContainer<TD>.cell MEASURE CELL (cache=miss)",
- " BlockContainer<TD>.cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING",
- " BlockContainer<TD>.cell MEASURE CELL (cache=hit)",
+ " BlockContainer<TD>.cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING",
+ " BlockContainer<TD>.cell/block READ RESULT AHEAD OF INTRINSIC BLOCK PADDING",
" BlockContainer<DIV> REUSE IN-FLOW SUBTREE",
"layout PARTIAL Box<DIV>#flex",
" Box<DIV>#flex/flex REPLAY FRAGMENTS",
@@ -92,9 +91,8 @@ test(() => {
{ depth: 3, event: "measure", box: "Box<DIV>#item", size: "max-content block", cache: "miss" },
{ depth: 4, event: "run", box: "Box<DIV>#item", formattingContext: "flex", intrinsic: true, action: "RUN", cache: "bypass" },
{ depth: 3, event: "run", box: "Box<TABLE>#table", formattingContext: "table", intrinsic: true, action: "RUN", cache: "bypass" },
- { depth: 4, event: "measure cell", box: "BlockContainer<TD>.cell", cache: "miss" },
- { depth: 5, event: "run", box: "BlockContainer<TD>.cell", formattingContext: "block", intrinsic: false, action: "RUN AHEAD OF INTRINSIC BLOCK PADDING" },
- { depth: 4, event: "measure cell", box: "BlockContainer<TD>.cell", cache: "hit" },
+ { depth: 4, event: "run", box: "BlockContainer<TD>.cell", formattingContext: "block", intrinsic: false, action: "RUN AHEAD OF INTRINSIC BLOCK PADDING" },
+ { depth: 4, event: "run", box: "BlockContainer<TD>.cell", formattingContext: "block", intrinsic: false, action: "READ RESULT AHEAD OF INTRINSIC BLOCK PADDING" },
{ depth: 4, event: "reuse in-flow subtree", box: "BlockContainer<DIV>" },
{ depth: 0, event: "layout", partial: true, box: "Box<DIV>#flex" },
{ depth: 1, event: "run", box: "Box<DIV>#flex", formattingContext: "flex", intrinsic: false, action: "REPLAY FRAGMENTS" },
@@ -135,7 +133,7 @@ test(() => {
exerciseWork("work rejects asynchronous mutations", () => Promise.resolve(),
"flush,begin,take", "mutate must be synchronous");
exerciseWork("work counts the events a filter object matches", () => {}, "flush,begin,flush,take", null,
- work => work.count({ event: "measure", cache: "miss" }) === 3 && work.count({ event: "measure cell" }) === 2);
+ work => work.count({ event: "measure", cache: "miss" }) === 3 && work.count({ event: "run", box: "BlockContainer<TD>.cell" }) === 2);
exerciseWork("work counts the events a filter function matches", () => {}, "flush,begin,flush,take", null,
work => work.count(event => event.depth === 0) === 2);
exerciseWork("work names each matching box once, in trace order", () => {}, "flush,begin,flush,take", null,
diff --git a/Tests/LibWeb/Text/input/layout-test.js b/Tests/LibWeb/Text/input/layout-test.js
index 3b24e24ef78..13a57da3e26 100644
--- a/Tests/LibWeb/Text/input/layout-test.js
+++ b/Tests/LibWeb/Text/input/layout-test.js
@@ -27,7 +27,6 @@ const layoutTraceLines = (() => {
return [
["layout FULL", () => ({ event: "layout", partial: false })],
[`layout PARTIAL ${box}`, box => ({ event: "layout", partial: true, box })],
- [`${box} MEASURE CELL ${cache}`, (box, cache) => ({ event: "measure cell", box, cache })],
[
`${box} MEASURE ((?:min|max)-content (?:inline|block)) ${cache}(?: FROM (ITEMS|FLEX ITEMS|GRID TRACKS|CHILDREN|COLUMNS|REPLACED CONTENT))?`,
(box, size, cache, from) => ({ event: "measure", box, size, cache, from: from?.toLowerCase() }),
@@ -54,7 +53,6 @@ const layoutTraceLines = (() => {
// reuse in-flow subtree
// measure `size` ("min-content inline", ...), `cache`, `from` ("items", "flex items",
// "grid tracks", "children", "columns", "replaced content")
-// measure cell `cache`
function parseLayoutTrace(text) {
const events = [];
for (const line of text.replace(/\r/g, "").split("\n")) {
diff --git a/Tests/LibWeb/Text/input/table-cell-content-placement-across-row-height-changes.html b/Tests/LibWeb/Text/input/table-cell-content-placement-across-row-height-changes.html
new file mode 100644
index 00000000000..fcfbca86edf
--- /dev/null
+++ b/Tests/LibWeb/Text/input/table-cell-content-placement-across-row-height-changes.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; font: 20px/20px SerenitySans; }
+ .table { display: table; border-spacing: 0; }
+ .row { display: table-row; height: 100px; }
+ .cell { display: table-cell; width: 60px; padding: 0; }
+ fieldset.cell { margin: 0; padding: 4px; border: 2px solid black; }
+ legend { padding: 0; }
+ .block { height: 10px; }
+ .float { float: left; width: 10px; height: 10px; }
+ .inline-block { display: inline-block; width: 10px; height: 10px; }
+ table { border-spacing: 0; }
+ td { padding: 0; }
+</style>
+<div class="table"><div class="row" id="row">
+ <fieldset class="cell" id="middle-fieldset" style="vertical-align: middle"><legend>L</legend><div class="block"></div></fieldset>
+ <fieldset class="cell" id="bottom-fieldset" style="vertical-align: bottom"><legend>L</legend><div class="block"></div></fieldset>
+ <fieldset class="cell" id="baseline-fieldset" style="vertical-align: baseline"><legend>L</legend><div class="block"></div></fieldset>
+ <div class="cell" id="middle-markup" style="vertical-align: middle"><div class="block"></div><div class="float"></div><span class="inline-block"></span><table><tr><td><div class="block"></div></td></tr></table></div>
+ <div class="cell" id="bottom-markup" style="vertical-align: bottom"><div class="block"></div><div class="float"></div><span class="inline-block"></span><table><tr><td><div class="block"></div></td></tr></table></div>
+</div></div>
+<script>
+ test(() => {
+ const row = document.getElementById("row");
+ const describeCells = rowHeight => {
+ for (const cell of row.children) {
+ const cellTop = cell.getBoundingClientRect().top;
+ const offsets = [...cell.querySelectorAll("legend, .block, .float, .inline-block, table")].map(
+ element => `${element.className || element.localName} ${element.getBoundingClientRect().top - cellTop}`
+ );
+ println(`row ${rowHeight} ${cell.id}: ${offsets.join(", ")}`);
+ }
+ };
+ describeCells("100px");
+ for (const rowHeight of ["140px", "60px", "100px"]) {
+ row.style.height = rowHeight;
+ describeCells(rowHeight);
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/table-cell-measurement-cache-misses.html b/Tests/LibWeb/Text/input/table-cell-measurement-cache-misses.html
index 805e0bade07..31be3427944 100644
--- a/Tests/LibWeb/Text/input/table-cell-measurement-cache-misses.html
+++ b/Tests/LibWeb/Text/input/table-cell-measurement-cache-misses.html
@@ -15,7 +15,7 @@
const parts = [];
for (let i = 0; i < ROWS; ++i)
parts.push(`<tr><td class="num" id="r${i}c0">${i}</td><td class="num" id="r${i}c1">${i}</td><td id="r${i}c2">line ${i} with <span>some</span> <b>markup</b></td></tr>`);
- const missedCells = work => work.events.filter(event => event.event === "measure cell" && event.cache === "miss");
+ const missedCells = work => work.events.filter(event => event.event === "run" && event.action === "RUN AHEAD OF INTRINSIC BLOCK PADDING");
const lines = [];
let work = layoutWork(() => document.getElementById("rows").innerHTML = parts.join(""));
diff --git a/Tests/LibWeb/Text/input/table-cell-measurement-cache-width-changes.html b/Tests/LibWeb/Text/input/table-cell-measurement-cache-width-changes.html
index c1ff3439cae..475778b4d7d 100644
--- a/Tests/LibWeb/Text/input/table-cell-measurement-cache-width-changes.html
+++ b/Tests/LibWeb/Text/input/table-cell-measurement-cache-width-changes.html
@@ -16,22 +16,18 @@
document.getElementById("rows").innerHTML = parts.join("");
const table = document.getElementById("table");
- // The cells of a column share a box name, so the names of the missed cells name their columns.
+ // Each cell is laid out once ahead of its intrinsic padding, and its committing run replays that layout.
const measure = width => {
const work = layoutWork(() => table.style.width = `${width}px`);
- const misses = { event: "measure cell", cache: "miss" };
- const columns = work.boxes(misses);
- println(`${width}px: ${work.count(misses)} misses${columns.length ? ` in ${columns.join(", ")}` : ""}, height ${table.offsetHeight}`);
+ const cellRuns = action => work.count(event => event.event === "run" && event.box.startsWith("BlockContainer<TD>") && event.action === action);
+ println(`${width}px: ${cellRuns("RUN AHEAD OF INTRINSIC BLOCK PADDING")} laid out ahead, ${cellRuns("REPLAY FRAGMENTS")} replayed, ${cellRuns("RUN")} laid out again, height ${table.offsetHeight}`);
};
layoutWork(() => table.style.width = "1000px");
- // Wide enough for every cell to fit on one line: only cells with markup are measured again.
measure(900);
measure(950);
- // The middle column wraps: its cells are measured again, the text-only first column is not.
measure(400);
measure(350);
- // Back above the max-content widths of the text-only cells.
measure(1000);
});
</script>
diff --git a/Tests/LibWeb/Text/input/table-measurement-reuse-work.html b/Tests/LibWeb/Text/input/table-measurement-reuse-work.html
index c395600c2f3..96042619cb5 100644
--- a/Tests/LibWeb/Text/input/table-measurement-reuse-work.html
+++ b/Tests/LibWeb/Text/input/table-measurement-reuse-work.html
@@ -37,9 +37,8 @@
TableWrapper(anonymous) MEASURE max-content block (cache=miss)
TableWrapper(anonymous)/block (intrinsic) RUN (cache=bypass)
Box<TABLE>#table/table (intrinsic) RUN (cache=miss)
- BlockContainer<TD>#cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#cell/block (intrinsic) RUN (cache=miss)
- BlockContainer<TD> MEASURE CELL (cache=hit)
+ BlockContainer<TD>#cell/block (intrinsic) RUN (cache=miss)
+ BlockContainer<TD>/block (intrinsic) READ RESULT
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
Box<DIV>#item/flex RUN (cache=miss)
@@ -47,9 +46,9 @@
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
TableWrapper(anonymous)/block RUN (cache=miss)
Box<TABLE>#table/table RUN (cache=miss)
- BlockContainer<TD>#cell MEASURE CELL (cache=miss)
- BlockContainer<TD>#cell/block RUN (cache=miss)
- BlockContainer<TD> MEASURE CELL (cache=hit)
+ BlockContainer<TD>#cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<DIV> REUSE IN-FLOW SUBTREE
+ BlockContainer<TD>/block READ RESULT AHEAD OF INTRINSIC BLOCK PADDING
BlockContainer<TD>#cell/block RUN (cache=miss)
BlockContainer<DIV> REUSE IN-FLOW SUBTREE
BlockContainer<TD>/block REUSE SUBTREE
diff --git a/Tests/LibWeb/Text/input/table-missing-cells-incremental-fixup.html b/Tests/LibWeb/Text/input/table-missing-cells-incremental-fixup.html
index 1f6682da47e..c433d589314 100644
--- a/Tests/LibWeb/Text/input/table-missing-cells-incremental-fixup.html
+++ b/Tests/LibWeb/Text/input/table-missing-cells-incremental-fixup.html
@@ -25,7 +25,7 @@
document.body.offsetHeight;
const work = layoutWork(() => rows.rows[2].cells[0].append(control));
- results.push(`Measured cells: ${work.boxes({ event: "measure cell", cache: "miss" }).join(", ") || "none"}`);
+ results.push(`Measured cells: ${work.boxes({ event: "run", action: "RUN AHEAD OF INTRINSIC BLOCK PADDING" }).join(", ") || "none"}`);
results.push(`Control position: ${control.getBoundingClientRect().x},${control.getBoundingClientRect().y}`);
function checkTree(label, mutate) {