Skip to content

Truly independent web browser

LibWeb: Improve table layout compatibility with other engines

Andreas Kling06b3d010f783
diff --git a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs b/Libraries/LibWeb/Rust/src/css/computed_value_views.rs
index 83340b5c74a..80b8207c30a 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_value_views.rs
@@ -118,6 +118,24 @@ impl LengthPercentageRef<'_> {
}
}
+ /// The percentage the value is, as a fraction, when it is a percentage or a calculation that simplified to one,
+ /// as `calc(10% + 15%)` does.
+ pub(crate) fn percentage_fraction(self) -> Option<f64> {
+ match self.value {
+ StyleValueData::Percentage { .. } => Some(self.as_fraction()),
+ StyleValueData::Calculated(calculated_payload) => {
+ let CalculatedPayload { rust_calculation, .. } = &**calculated_payload;
+ match rust_calculation.node() {
+ crate::css::calc::CalcNode::Numeric(crate::css::calc::CalcNumericValue::Percentage(value)) => {
+ Some(value * 0.01)
+ }
+ _ => None,
+ }
+ }
+ _ => None,
+ }
+ }
+
pub(crate) fn contains_anchor_function(self) -> bool {
matches!(self.value, StyleValueData::Calculated(calculated) if calculated.rust_calculation.node().contains_anchor_function())
}
@@ -291,6 +309,16 @@ impl ComputedSize {
.expect("computed length-percentage size lost its style value")
}
+ /// The percentage the size is, as a fraction, when it is a percentage or a calculation that simplified to one.
+ pub(crate) fn percentage_fraction(&self) -> Option<f64> {
+ match self.kind {
+ ComputedSizeKind::Percentage | ComputedSizeKind::Calculated => {
+ self.length_percentage().percentage_fraction()
+ }
+ _ => None,
+ }
+ }
+
/// The fit-content argument; None for the keyword-only form.
pub(crate) fn fit_content_available_space(&self) -> Option<LengthPercentageRef<'_>> {
debug_assert!(self.is_fit_content());
diff --git a/Libraries/LibWeb/Rust/src/css/style/layout_style.rs b/Libraries/LibWeb/Rust/src/css/style/layout_style.rs
index c5696bb35df..ea6f47ab854 100644
--- a/Libraries/LibWeb/Rust/src/css/style/layout_style.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/layout_style.rs
@@ -387,7 +387,7 @@ impl LayoutStyle {
});
}
- // CSS table wrappers carry positioning and margins, and act as the table's grid item.
+ // CSS table wrappers carry positioning and margins, and act as the table's flex or grid item.
// z-index and vertical-align also follow the wrapper for interoperable painting and
// inline alignment; clip only applies on the wrapper that receives position.
fn transfer_table_properties(&mut self, source: &Self) {
@@ -458,6 +458,12 @@ impl LayoutStyle {
target.align_self_overflow = alignment.align_self_overflow;
target.justify_self_overflow = alignment.justify_self_overflow;
target.order = alignment.order;
+ // https://drafts.csswg.org/css-flexbox-1/#flex-items
+ // "In the case of flex items with display: table, the table wrapper box becomes the flex item"
+ // NB: The flex longhands follow the wrapper, which the flex container sizes as the flex item.
+ target.flex_basis = alignment.flex_basis.clone();
+ target.flex_grow = alignment.flex_grow;
+ target.flex_shrink = alignment.flex_shrink;
});
self.edit::<GridValues>(|target| {
crate::css::computed_values::copy_grid_placements(source.group::<GridValues>(), target);
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index f3bed8b4e9d..d60f0f9f988 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -685,6 +685,10 @@ impl BlockMarginState {
}
/// What the probe for a stored in-flow layout found, and what storing the fresh layout needs.
+#[expect(
+ clippy::large_enum_variant,
+ reason = "a probe result lives on the stack for one child's layout, which boxing would give an allocation"
+)]
enum InFlowReuse {
Ineligible,
Hit {
@@ -3625,6 +3629,16 @@ impl<'pass> BlockFormattingContext<'pass> {
containing_block_rect_in_root_now,
&mut probe,
);
+ if let Some(forced) = input.sizing.forced_table_box_border_box_inline_size.get()
+ && container_facts.is_table_wrapper()
+ && style.display().is_table_inside()
+ {
+ // NB: A flex container sized the wrapper of this table box along its inline axis, and the table box takes
+ // that size (see TableFormattingContext::used_table_inline_size).
+ let metrics = self.metrics_of(sized_child);
+ let offsets = metrics.border_box_left(false) + metrics.border_box_right(false);
+ probe.content_inline_size = Some((forced - offsets).max(CssPixels::default()));
+ }
if let Some(content_inline_size) = probe.content_inline_size {
self.update_cells_of(sized_child, |cells| cells.set_content_inline_size(content_inline_size));
} else {
@@ -3766,6 +3780,11 @@ impl<'pass> BlockFormattingContext<'pass> {
} else {
geometry::PackedOptionalCssPixels::from(None)
},
+ forced_table_box_border_box_inline_size: if is_table_formatting_context {
+ input.sizing.forced_table_box_border_box_inline_size
+ } else {
+ geometry::PackedOptionalCssPixels::from(None)
+ },
table_box_content_block_offset_in_wrapper: geometry::PackedOptionalCssPixels::from(
is_table_formatting_context.then_some(content_block_offset),
),
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 6fd3624669a..d8c0698f125 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -407,6 +407,7 @@ fn sizing_directives_match_ignoring_unobserved(
let RootSizingDirectives {
forced_content_block_size,
forced_min_border_box_block_size,
+ forced_table_box_border_box_inline_size,
table_box_content_block_offset_in_wrapper,
content_block_size_after_run,
table_cell_contents_block_offset,
@@ -417,6 +418,7 @@ fn sizing_directives_match_ignoring_unobserved(
} = *a;
forced_content_block_size == b.forced_content_block_size
&& forced_min_border_box_block_size == b.forced_min_border_box_block_size
+ && forced_table_box_border_box_inline_size == b.forced_table_box_border_box_inline_size
&& table_box_content_block_offset_in_wrapper == b.table_box_content_block_offset_in_wrapper
&& (content_block_size_after_run == b.content_block_size_after_run
|| content_block_size_adopted_after_run_unobserved)
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 6fe0203ac9b..93323ae5f25 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -1617,6 +1617,19 @@ impl<'pass> FlexFormattingContext<'pass> {
let max_cross = self.computed_cross_max_size(index);
flex_base_size = self.adjust_main_size_through_aspect_ratio(index, flex_base_size, min_cross, max_cross);
}
+ // https://drafts.csswg.org/css-flexbox-1/#flex-items
+ // "[...] the flex longhands apply to the table box as follows: the flex item's final size is calculated by
+ // performing layout as if the distance between the table wrapper box's edges and the table box's content edges
+ // were all part of the table box's border+padding area, and the table box were the flex item."
+ // NB: So a definite flex basis along the block axis of a table leaves out its captions.
+ if inputs.is_table_wrapper
+ && basis_is_definite
+ && matches!(basis, UsedFlexBasis::Size { .. })
+ && !self.main_axis_is_parallel_to_inline_axis_of_item(index)
+ {
+ let sizes = self.measure_table_wrapper_block_sizes(index);
+ flex_base_size += sizes.wrapper_content_block_size - sizes.table_box_border_box_block_size;
+ }
// NOTE: We don't clamp the main size until we have them for all items.
self.flex_items[index].flex_base_size = flex_base_size;
self.flex_items[index].automatic_minimum_size_before_flexing = None;
@@ -2628,7 +2641,9 @@ impl<'pass> FlexFormattingContext<'pass> {
// Once the cross size of a flex line has been determined, the cross sizes of items in auto-sized flex
// containers are also considered definite for the purpose of layout.
let (mut cross_min, cross_max) = self.cross_size_limits(index);
- if self.flex_item_details[index].inputs.is_table_wrapper && !self.cross_axis_is_horizontal() {
+ if self.flex_item_details[index].inputs.is_table_wrapper
+ && self.main_axis_is_parallel_to_inline_axis_of_item(index)
+ {
// A table is never smaller than its content, so neither is its stretched wrapper.
let sizes = self.measure_table_wrapper_block_sizes(index);
self.flex_item_details[index].stretched_table_wrapper_block_sizes = Some(sizes);
@@ -3208,8 +3223,9 @@ impl<'pass> FlexFormattingContext<'pass> {
// the table wrapper box's edges and the table box's content edges
// were all part of the table box's border+padding area,
// and the table box were the flex item.
+ // NB: The main and cross axes map onto the inline and block axes of the table, whatever its writing mode.
if self.flex_item_details[index].inputs.is_table_wrapper
- && !self.cross_axis_is_horizontal()
+ && self.main_axis_is_parallel_to_inline_axis_of_item(index)
&& self.flex_item_is_stretched(index)
{
let sizes = self.flex_item_details[index]
@@ -3223,6 +3239,51 @@ impl<'pass> FlexFormattingContext<'pass> {
stretched_table_box_block_size.max(sizes.table_box_border_box_block_size),
));
}
+ // NB: The cells of the item run along the axes of this container, which are not those of an orthogonal table.
+ let (main_size, cross_size) = if self.main_axis_is_horizontal() {
+ (
+ cells.has_definite_inline_size.then(|| cells.content_inline_size()),
+ cells.has_definite_block_size.then(|| cells.content_block_size()),
+ )
+ } else {
+ (
+ cells.has_definite_block_size.then(|| cells.content_block_size()),
+ cells.has_definite_inline_size.then(|| cells.content_inline_size()),
+ )
+ };
+ if self.flex_item_details[index].inputs.is_table_wrapper
+ && self.main_axis_is_parallel_to_inline_axis_of_item(index)
+ && let Some(main_size) = main_size
+ {
+ // NB: The table box takes the main size the wrapper is flexed to, whatever its own inline size.
+ input.sizing.forced_table_box_border_box_inline_size =
+ geometry::PackedOptionalCssPixels::from(Some(main_size));
+ }
+ if self.flex_item_details[index].inputs.is_table_wrapper
+ && !self.main_axis_is_parallel_to_inline_axis_of_item(index)
+ && self.flex_item_details[index].inputs.establishes_orthogonal_flow
+ && self.flex_item_is_stretched(index)
+ && let Some(cross_size) = cross_size
+ {
+ // NB: The cross axis of an orthogonal table is its inline axis, which a stretched wrapper fills.
+ input.sizing.forced_table_box_border_box_inline_size =
+ geometry::PackedOptionalCssPixels::from(Some(cross_size));
+ }
+ if self.flex_item_details[index].inputs.is_table_wrapper
+ && !self.main_axis_is_parallel_to_inline_axis_of_item(index)
+ && let Some(main_size) = main_size
+ && (main_size > self.flex_items[index].hypothetical_main_size
+ || self.flex_item_details[index].inputs.flex_basis.is_length_percentage())
+ {
+ // NB: Likewise, the table box fills the main size the wrapper is flexed to, less its captions.
+ let sizes = self.measure_table_wrapper_block_sizes(index);
+ let captions_block_size = sizes.wrapper_content_block_size - sizes.table_box_border_box_block_size;
+ let flexed_table_box_block_size = main_size - captions_block_size;
+ if flexed_table_box_block_size > sizes.table_box_border_box_block_size {
+ input.sizing.forced_min_border_box_block_size =
+ geometry::PackedOptionalCssPixels::from(Some(flexed_table_box_block_size));
+ }
+ }
if self.flex_items[index].cross_size_was_resolved_from_aspect_ratio
&& !self.cross_axis_is_horizontal()
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index d78adefcdb1..51b81fcc09c 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1091,6 +1091,9 @@ pub(crate) struct ChildLayoutResult {
/// children once they are placed, unless one of them is not an item.
pub in_flow_children_margin_box_block_extent: Option<CssPixels>,
pub depends_on_percentage_block_size: bool,
+ /// Whether a descendant of the root resolves percentages against the block size of the root, or of a box that
+ /// passes it through to its children.
+ pub contents_depend_on_percentage_block_size: bool,
/// For an absolutely positioned box, the used insets its run gave it.
pub out_of_flow_root_used_insets: Option<run_state::UsedInsets>,
/// For a box that establishes an orthogonal flow, its baselines along the horizontal axis of its parent's frame,
@@ -2704,6 +2707,10 @@ fn lay_out_run_root_and_contents<'pass>(
}
});
result.depends_on_percentage_block_size = run.sizing().resolve_percentage_block_size_dependency(run.box_);
+ result.contents_depend_on_percentage_block_size = run
+ .state
+ .percentage_block_size_dependency_of(run.box_)
+ .has_descendant_that_depends_on_percentage_block_size;
// NB: A run that builds no fragments could never lay out the absolutely positioned boxes it registers. Those whose
// containing block is the root are laid out against its final sizes and box sides, in the frame its contents
// are laid out in, so that the root's fragment holds them. The columns of a fragmentainer run leave them to the
@@ -2871,10 +2878,13 @@ fn body_input_in_own_frame(
}
let mut constraints = input.containing_block_constraints;
let mut available_space = input.available_space;
+ // NB: A flex container hands the wrapper of an orthogonal table its sizes in the table's own axes already.
let sizing = RootSizingDirectives {
treat_block_axis_percentage_insets_as_auto_beyond_root: input
.sizing
.treat_block_axis_percentage_insets_as_auto_beyond_root,
+ forced_min_border_box_block_size: input.sizing.forced_min_border_box_block_size,
+ forced_table_box_border_box_inline_size: input.sizing.forced_table_box_border_box_inline_size,
..RootSizingDirectives::default()
};
std::mem::swap(
@@ -3110,6 +3120,15 @@ impl ChildLayout {
}
}
+ /// Whether the contents of the child resolve percentages against its block size (see
+ /// ChildLayoutResult::contents_depend_on_percentage_block_size).
+ pub(crate) fn contents_depend_on_percentage_block_size(&self) -> bool {
+ match self {
+ Self::SizedInParentRun { .. } => false,
+ Self::Laid(layout) => layout.outcome.contents_depend_on_percentage_block_size,
+ }
+ }
+
/// Whether the child depends on the block size its percentages resolve against, which the box containing it hears
/// of.
pub(crate) fn child_depends_on_percentage_block_size(&self) -> bool {
diff --git a/Libraries/LibWeb/Rust/src/layout/geometry.rs b/Libraries/LibWeb/Rust/src/layout/geometry.rs
index 5a24c8c8b90..fd653746828 100644
--- a/Libraries/LibWeb/Rust/src/layout/geometry.rs
+++ b/Libraries/LibWeb/Rust/src/layout/geometry.rs
@@ -422,6 +422,9 @@ pub(crate) struct RootSizingDirectives {
// Input-only: a fieldset's content wrapper fills the fieldset's definite content block size.
pub(crate) forced_content_block_size: PackedOptionalCssPixels,
pub(crate) forced_min_border_box_block_size: PackedOptionalCssPixels,
+ // Input-only: a flex container that sizes a table wrapper along the table's inline axis tells the table box the
+ // border box inline size it takes.
+ pub(crate) forced_table_box_border_box_inline_size: PackedOptionalCssPixels,
// Input-only: the wrapper's BFC tells the table formatting context where the table box's
// content box sits in the wrapper, so rows and row groups (whose containing block is the
// wrapper) can be placed in wrapper coordinates.
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 8c9841680b4..3b4862b969e 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1381,7 +1381,8 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
//
// 2. If element has a computed value of the display property that is table-cell, then return a
// UA-defined value.
- // FIXME: Likely UA-defined value should not be 0.
+ // INTEROP: Like other engines, the UA-defined value is the block size of the cell when it is definite (see
+ // TableFormattingContext::cell_block_size_is_definite_after_row_sizing), and 0 otherwise.
//
// 3. If element has a computed value of the height property that is not auto, then return element.
//
@@ -1396,7 +1397,11 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
} else if facts.is_viewport() {
Some(metrics.content_block_size())
} else if facts.is_table_cell() {
- Some(CssPixels::default())
+ Some(if metrics.has_definite_block_size() {
+ metrics.content_block_size()
+ } else {
+ CssPixels::default()
+ })
} else if quirks_body_block.is_some() {
quirks_body_block
} else if !style.height().is_auto()
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 51203465cc6..001c06e150f 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -623,6 +623,8 @@ struct CellLayoutState {
content_baselines: DerivedBaselines,
/// Whether the cell's run laid out the absolutely positioned boxes the cell contains against its final size.
run_laid_out_abspos_contained_by_cell: bool,
+ /// Whether the cell's contents resolve percentages against the block size of the cell.
+ contents_depend_on_percentage_block_size: bool,
/// How far the table moves the contents of the cell along the block axis to align them in the rows it spans.
contents_block_offset: CssPixels,
}
@@ -1061,6 +1063,10 @@ pub(super) struct TableFormattingContext<'pass> {
participant_constraints: ContainingBlockConstraints,
available_space: AvailableSpace,
table_block_size: CssPixels,
+ /// The block size that percentage block sizes of rows and cells resolve against (see compute_table_block_size).
+ table_percentage_basis: CssPixels,
+ /// The border box inline size a flex container sizes the table box to, if it does.
+ forced_border_box_inline_size: Option<CssPixels>,
pub(super) automatic_content_block_size: CssPixels,
/// The collapsed borders the table box's fragment paints, once they are materialized.
collapsed_table_borders: Option<std::sync::Arc<OwnedCollapsedTableBorders>>,
@@ -1223,6 +1229,8 @@ impl<'pass> TableFormattingContext<'pass> {
participant_constraints: ContainingBlockConstraints::default(),
available_space: AvailableSpace::default(),
table_block_size: CssPixels::default(),
+ table_percentage_basis: CssPixels::default(),
+ forced_border_box_inline_size: None,
automatic_content_block_size: CssPixels::default(),
collapsed_table_borders: None,
table_box_content_block_offset_in_wrapper: CssPixels::default(),
@@ -1748,11 +1756,18 @@ impl<'pass> TableFormattingContext<'pass> {
/// of table cells and table rows is calculated when their height is specified using percentage values.")
/// https://www.w3.org/TR/CSS21/tables.html#height-layout
fn cell_has_resolvable_percentage_block_size(&self, cell_box: Node) -> bool {
- self.style(cell_box).height().is_percentage() && !self.table_block_size_is_auto()
+ self.style(cell_box).height().percentage_fraction().is_some() && !self.table_block_size_is_auto()
}
+ /// Whether the table's block size is auto, or a percentage that has nothing to resolve against, which acts as
+ /// auto (see compute_table_block_size).
fn table_block_size_is_auto(&self) -> bool {
- self.style(self.run.box_).height().is_auto()
+ let height = self.style(self.run.box_).height();
+ height.is_auto()
+ || (height.contains_percentage()
+ && self.table_constraints.percentage_basis_block_size.is_none()
+ && !(self.node_facts(self.run.box_).document_in_quirks_mode()
+ && self.table_constraints.quirks_mode_percentage_basis_block_size.is_some()))
}
fn use_fixed_mode_layout(&self) -> bool {
@@ -1782,6 +1797,7 @@ impl<'pass> TableFormattingContext<'pass> {
fn compute_constrainedness(&mut self) {
// Definition of constrainedness: https://www.w3.org/TR/css-tables-3/#constrainedness
+ let fixed = self.use_fixed_mode_layout();
// NB: The definition uses https://www.w3.org/TR/CSS21/visudet.html#propdef-width for width, which doesn't include
// keyword values. The remaining checks can be simplified to checking whether the size is a length.
for &range in &self.column_track_ranges {
@@ -1804,6 +1820,14 @@ impl<'pass> TableFormattingContext<'pass> {
if cell.column_span == 1 && style.width().is_length() {
self.columns[cell.column_index].is_constrained = true;
}
+ // INTEROP: In fixed mode, a cell of the first row with a length inline size constrains every column it
+ // spans, which share that inline size, as in other engines: "the width of the cell is divided
+ // over the columns" (CSS 2.1 §17.5.2.1).
+ if fixed && cell.row_index == 0 && cell.column_span > 1 && style.width().is_length() {
+ for index in cell.column_index..cell.column_index + cell.column_span {
+ self.columns[index].is_constrained = true;
+ }
+ }
if style.height().is_length() {
self.rows[cell.row_index].is_constrained = true;
}
@@ -1900,7 +1924,7 @@ impl<'pass> TableFormattingContext<'pass> {
// add the cell intrinsic offsets of a content-box percentage cell to its resolved percentage
// (CSS 2.1's fixed-table-layout-025..031 expect that). The offsets are kept as the outer sizes
// of such a cell and become the column's percentage_offsets in initialize_intrinsic_percentages.
- let outer = if width.is_percentage() && style.box_sizing() != box_sizing::BORDER_BOX {
+ let outer = if width.percentage_fraction().is_some() && style.box_sizing() != box_sizing::BORDER_BOX {
inline_offsets
} else {
CssPixels::default()
@@ -1958,12 +1982,10 @@ impl<'pass> TableFormattingContext<'pass> {
let height = style.height();
let max_height = style.max_height();
// The specified block size takes part in the row measures as an outer size (see
- // initialize_table_measures); a percentage resolves against the basis the table forwards from its
- // containing block, and a block size that contains a percentage takes no part at all when the table's
- // own block size is auto (see cell_has_resolvable_percentage_block_size).
- let specified_outer = if height.is_auto()
- || (height.contains_percentage() && self.table_block_size_is_auto())
- {
+ // initialize_table_measures). A block size that contains a percentage takes no part, "percentages
+ // being treated as 0px" (https://www.w3.org/TR/css-tables-3/#computing-the-table-height); it is
+ // applied when the table block size is distributed to the rows (see distribute_block_size_to_rows).
+ let specified_outer = if height.is_auto() || height.contains_percentage() {
CssPixels::default()
} else {
self.cell_specified_outer_block_size(cell.box_, &style, height.to_px(block_basis), block_offsets)
@@ -2032,7 +2054,13 @@ impl<'pass> TableFormattingContext<'pass> {
} else {
CssPixels::from_raw(i32::MAX)
};
- let size = style.height().to_px(basis);
+ // NB: A percentage block size counts as 0px here, as the specification says above, and is applied when
+ // the table block size is distributed to the rows (see distribute_block_size_to_rows).
+ let size = if style.height().contains_percentage() {
+ CssPixels::default()
+ } else {
+ style.height().to_px(basis)
+ };
// The outer min-content block size of a table row or row group is max(min-block-size, block-size).
self.rows[row_index].min_size = min_size.max(size);
// The outer max-content block size is max(min-block-size, min(max-block-size, block-size)).
@@ -2167,16 +2195,11 @@ impl<'pass> TableFormattingContext<'pass> {
TrackAxis::Row => (style.height(), style.max_height()),
TrackAxis::Column => (style.width(), style.max_width()),
};
- let maximum = if max_size.is_percentage() {
- max_size.length_percentage().as_fraction() * 100.0
- } else {
- f64::INFINITY
- };
- let preferred = if size.is_percentage() {
- size.length_percentage().as_fraction() * 100.0
- } else {
- 0.0
- };
+ // NB: A calculation that simplified to a percentage, like calc(10% + 15%), is that percentage.
+ let maximum = max_size
+ .percentage_fraction()
+ .map_or(f64::INFINITY, |fraction| fraction * 100.0);
+ let preferred = size.percentage_fraction().map_or(0.0, |fraction| fraction * 100.0);
preferred.min(maximum)
}
@@ -2185,15 +2208,16 @@ impl<'pass> TableFormattingContext<'pass> {
for index in 0..self.rows.len() {
let style = self.style(self.rows[index].box_);
// Definition of percentage contribution: https://www.w3.org/TR/css-tables-3/#percentage-contribution
- self.rows[index].has_intrinsic_percentage =
- style.max_height().is_percentage() || style.height().is_percentage();
+ self.rows[index].has_intrinsic_percentage = style.max_height().percentage_fraction().is_some()
+ || style.height().percentage_fraction().is_some();
self.rows[index].intrinsic_percentage = Self::cell_percentage(style, axis);
}
} else {
for &range in &self.column_track_ranges {
let style = self.style(self.column_sizing_box(range));
// Definition of percentage contribution: https://www.w3.org/TR/css-tables-3/#percentage-contribution
- let has_intrinsic_percentage = style.max_width().is_percentage() || style.width().is_percentage();
+ let has_intrinsic_percentage =
+ style.max_width().percentage_fraction().is_some() || style.width().percentage_fraction().is_some();
let intrinsic_percentage = Self::cell_percentage(style, axis);
for index in range.start..range.end {
self.columns[index].has_intrinsic_percentage = has_intrinsic_percentage;
@@ -2213,7 +2237,7 @@ impl<'pass> TableFormattingContext<'pass> {
TrackAxis::Row => style.height(),
TrackAxis::Column => style.width(),
};
- if !size.is_percentage() {
+ if size.percentage_fraction().is_none() {
continue;
}
let start = Self::cell_index(cell, axis);
@@ -2636,7 +2660,18 @@ impl<'pass> TableFormattingContext<'pass> {
if !crate::layout::sizing_context::is_plain_auto(table_style.min_width()) {
used_min = used_min.max(self.resolve_inline_constraint(table_style.min_width(), grid_min, grid_max, basis));
}
- let width_is_auto_or_indefinite_percentage = table_style.width().is_auto()
+ // https://drafts.csswg.org/css-flexbox-1/#flex-items
+ // "[...] like width and height, the flex longhands apply to the table box as follows: the flex item's final
+ // size is calculated by performing layout as if the distance between the table wrapper box's edges and the
+ // table box's content edges were all part of the table box's border+padding area, and the table box were the
+ // flex item."
+ // NB: So once the flex container sizes the wrapper along the table's inline axis, the table fills that size,
+ // and its specified inline size only takes part in the flex base size, through the max-content inline size.
+ // The min-content inline size, which the automatic minimum size of the item comes from, ignores it.
+ let width_is_flexed = self.forced_border_box_inline_size.is_some()
+ || (available_inline == AvailableSize::MinContent && self.wrapper_is_flex_item_along_inline_axis());
+ let width_is_auto_or_indefinite_percentage = width_is_flexed
+ || table_style.width().is_auto()
|| (table_style.width().contains_percentage()
&& self.table_constraints.percentage_basis_inline_size.is_none());
let mut used = if width_is_auto_or_indefinite_percentage {
@@ -2663,9 +2698,9 @@ impl<'pass> TableFormattingContext<'pass> {
for cell_index in 0..self.cells.len() {
let cell = self.cells[cell_index];
let cell_width = self.style(cell.box_).width();
- if cell_width.is_percentage() {
+ if let Some(fraction) = cell_width.percentage_fraction() {
let mut adjusted = spacing;
- let percentage = cell_width.length_percentage().as_fraction() * 100.0;
+ let percentage = fraction * 100.0;
if percentage != 0.0 {
adjusted += CssPixels::nearest_value_for(
(100.0 / percentage * cell.outer_max_inline_size.to_double()).ceil(),
@@ -2728,9 +2763,46 @@ impl<'pass> TableFormattingContext<'pass> {
used.max(used_min)
}
+ /// Whether the table wrapper is a flex item whose main axis is the inline axis of the table.
+ fn wrapper_is_flex_item_along_inline_axis(&self) -> bool {
+ let wrapper = self.parent(self.run.box_);
+ if wrapper.is_invalid()
+ || !self.node_facts(wrapper).is_table_wrapper()
+ || self.node_facts(wrapper).is_absolutely_positioned()
+ {
+ return false;
+ }
+ let container = self.parent(wrapper);
+ if container.is_invalid() {
+ return false;
+ }
+ let container_style = self.style(container);
+ if !container_style.display().is_flex_inside()
+ && container_style.display().inside != display_inside::_WEBKIT_BOX
+ {
+ return false;
+ }
+ let is_row_layout = matches!(
+ container_style.effective_flex_direction(),
+ flex_direction::ROW | flex_direction::ROW_REVERSE
+ );
+ let table_is_orthogonal = geometry::Frame::of(self.style(self.run.box_).writing_mode())
+ .is_orthogonal_to(geometry::Frame::of(container_style.writing_mode()));
+ is_row_layout != table_is_orthogonal
+ }
+
fn compute_table_inline_size(&mut self) {
let measures = self.table_inline_size_measures();
- let used = self.used_table_inline_size(self.available_space.inline_size, measures);
+ let available = if let Some(forced) = self.forced_border_box_inline_size {
+ let used = &self.table_box_cells;
+ let collapsed = used.uses_collapsing_borders_model();
+ AvailableSize::definite(
+ (forced - used.border_box_left(collapsed) - used.border_box_right(collapsed)).max(CssPixels::default()),
+ )
+ } else {
+ self.available_space.inline_size
+ };
+ let used = self.used_table_inline_size(available, measures);
self.table_box_cells.set_content_inline_size(used);
}
@@ -2804,7 +2876,13 @@ impl<'pass> TableFormattingContext<'pass> {
measures: TableInlineSizeMeasures,
) -> CssPixels {
let intrinsic_inline_size = self.used_table_inline_size(intrinsic_sizing_constraint, measures);
- if self.max_inline_size_fits_content_to_unknown_containing_block_inline_size() {
+ // NB: The specified inline size of a flexed table takes no part in its min-content inline size (see
+ // used_table_inline_size).
+ let min_content_ignores_specified_inline_size =
+ intrinsic_sizing_constraint == AvailableSize::MinContent && self.wrapper_is_flex_item_along_inline_axis();
+ if min_content_ignores_specified_inline_size
+ || self.max_inline_size_fits_content_to_unknown_containing_block_inline_size()
+ {
return intrinsic_inline_size;
}
self.used_table_inline_size(AvailableSize::Definite(intrinsic_inline_size), measures)
@@ -2939,6 +3017,7 @@ impl<'pass> TableFormattingContext<'pass> {
layout.box_cells = laid_out.cells();
layout.content_baselines = laid_out.baselines();
layout.run_laid_out_abspos_contained_by_cell = laid_out.laid_out_abspos_contained_by_root();
+ layout.contents_depend_on_percentage_block_size = laid_out.contents_depend_on_percentage_block_size();
layout.placed = Some(laid_out.placed_child());
layout.fragment_arrival = laid_out.into_fragment_arrival(run);
}
@@ -3008,6 +3087,11 @@ impl<'pass> TableFormattingContext<'pass> {
sum + self.columns[cell.column_index + index].used_inline_size
});
let mut cell_box = self.cell_box_with_resolved_sides(cell_index, collapsed, cell_padding_basis);
+ // NB: A percentage block size of the cell counts as 0px until the rows are sized (see
+ // initialize_row_content_sizes), so it gives the contents no basis yet.
+ if style.height().contains_percentage() {
+ cell_box.has_definite_block_size = false;
+ }
// A cell whose columns all have 'visibility: collapse' is removed from the display along with them, as in
// other engines: "This value causes the entire row or column to be removed from the display". It is laid
// out like any other cell (with no inline size, see remove_collapsed_columns), and painting skips it.
@@ -3120,7 +3204,18 @@ impl<'pass> TableFormattingContext<'pass> {
self.table_block_size = self.table_block_size.max(content_min);
}
let table_style = self.style(self.run.box_);
- let block_basis = self.table_constraints.block_basis();
+ // https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk
+ // NB: In quirks mode, a percentage block size of the table resolves against the nearest ancestor with a
+ // block size when its containing block has none.
+ let block_basis = self.table_constraints.percentage_basis_block_size.unwrap_or_else(|| {
+ if self.node_facts(self.run.box_).document_in_quirks_mode() {
+ self.table_constraints
+ .quirks_mode_percentage_basis_block_size
+ .unwrap_or_default()
+ } else {
+ CssPixels::default()
+ }
+ });
let border_box_offsets = if table_style.box_sizing() == box_sizing::BORDER_BOX {
let used = &self.table_box_cells;
let collapsed = used.uses_collapsing_borders_model();
@@ -3133,6 +3228,21 @@ impl<'pass> TableFormattingContext<'pass> {
// The table's `max-height` lowers that size, and its `min-height` raises it, as for the block size of any box.
let mut specified =
(!table_style.height().is_auto()).then(|| table_style.height().to_px(block_basis) - border_box_offsets);
+ // https://drafts.csswg.org/css-sizing-4/#aspect-ratio
+ // NB: An auto block size follows from the inline size through the preferred aspect ratio. Like a specified
+ // block size, it only gives the table grid a minimum block size.
+ if specified.is_none()
+ && let Some(ratio) = self.node_facts(self.run.box_).preferred_aspect_ratio()
+ {
+ let used = &self.table_box_cells;
+ let collapsed = used.uses_collapsing_borders_model();
+ let inline_size = if table_style.box_sizing() == box_sizing::BORDER_BOX {
+ used.border_box_inline_size(collapsed)
+ } else {
+ used.content_inline_size()
+ };
+ specified = Some(ratio.divide(inline_size) - border_box_offsets);
+ }
if let Some(size) = specified.as_mut()
&& table_style.max_height().is_length()
{
@@ -3157,22 +3267,15 @@ impl<'pass> TableFormattingContext<'pass> {
// the second pass of rows layout.
row.reference_block_size = row.base_block_size;
}
- // Second pass of row block-size calculation:
- // At this point, percentage row block sizes can be resolved because the final table block size is calculated.
- for row_index in 0..self.rows.len() {
- if self.rows[row_index].is_collapsed {
- self.rows[row_index].reference_block_size = CssPixels::default();
- continue;
- }
- let style = self.style(self.rows[row_index].box_);
- // NB: A percentage block size resolves against the table's, which an auto-height table doesn't have before
- // its rows are sized. So in such a table, a row with a percentage block size is sized as an auto row
- // is, as a cell with one is (see cell_has_resolvable_percentage_block_size()).
- if style.height().is_percentage() && !self.table_block_size_is_auto() {
- let used = style.height().to_px(table_percentage_basis);
- self.rows[row_index].reference_block_size = self.rows[row_index].reference_block_size.max(used);
+ // NB: Percentage block sizes of rows and cells don't raise the reference sizes here. They are applied when the
+ // table block size is distributed to the rows (see distribute_block_size_to_rows), where a row grows to its
+ // percentage block size only as far as the table block size allows.
+ for row in &mut self.rows {
+ if row.is_collapsed {
+ row.reference_block_size = CssPixels::default();
}
}
+ self.table_percentage_basis = table_percentage_basis;
// Second pass cells layout:
// At this point, percentage cell block sizes can be resolved because the final table block size is calculated.
for cell_index in 0..self.cells.len() {
@@ -3191,10 +3294,6 @@ impl<'pass> TableFormattingContext<'pass> {
);
cell_box.set_content_block_size(cell_size - offsets);
self.cell_layouts[cell_index].pre_layout_content_block_size = cell_box.content_block_size;
- if !self.rows[cell.row_index].is_collapsed {
- self.rows[cell.row_index].reference_block_size =
- self.rows[cell.row_index].reference_block_size.max(cell_size);
- }
let span_inline = (0..cell.column_span).fold(CssPixels::default(), |sum, index| {
sum + self.columns[cell.column_index + index].used_inline_size
});
@@ -3217,7 +3316,7 @@ impl<'pass> TableFormattingContext<'pass> {
);
self.cells[cell_index].baseline = self.cell_baseline(cell_index);
if !self.rows[cell.row_index].is_collapsed {
- let border_size = cell_box.border_box_block_size(collapsed);
+ let border_size = self.cell_layouts[cell_index].box_cells.border_box_block_size(collapsed);
self.rows[cell.row_index].reference_block_size =
self.rows[cell.row_index].reference_block_size.max(border_size);
self.note_cell_in_row_baseline(cell_index, &style);
@@ -3313,57 +3412,165 @@ impl<'pass> TableFormattingContext<'pass> {
}
}
- fn distribute_block_size_to_rows(&mut self) {
- let sum = self
- .rows
+ /// The block size a row takes from its own percentage block size and those of the cells that span only that
+ /// row, resolved against `basis`, if any of them has one. `cells_of_row` holds the indices of the cells that
+ /// originate in the row.
+ fn row_percentage_block_size(
+ &self,
+ row_index: usize,
+ cells_of_row: &[usize],
+ basis: CssPixels,
+ ) -> Option<CssPixels> {
+ let row_height = self.style(self.rows[row_index].box_).height();
+ let mut size = row_height
+ .percentage_fraction()
+ .is_some()
+ .then(|| row_height.to_px(basis));
+ let collapsed = self.style(self.run.box_).border_collapse() != BORDER_COLLAPSE_SEPARATE;
+ for &cell_index in cells_of_row {
+ let cell = self.cells[cell_index];
+ if cell.row_span != 1 {
+ continue;
+ }
+ let style = self.style(cell.box_);
+ if style.height().percentage_fraction().is_none() {
+ continue;
+ }
+ let cell_box = &self.cell_layouts[cell_index].box_cells;
+ let offsets = cell_box.border_box_top(collapsed) + cell_box.border_box_bottom(collapsed);
+ let cell_size =
+ self.cell_specified_outer_block_size(cell.box_, &style, style.height().to_px(basis), offsets);
+ size = Some(size.map_or(cell_size, |size: CssPixels| size.max(cell_size)));
+ }
+ size
+ }
+
+ /// Whether neither a row nor any of its cells has a specified block size, so that its block size depends only on
+ /// its contents. `cells_of_row` holds the indices of the cells that originate in the row.
+ fn row_is_auto(&self, row_index: usize, cells_of_row: &[usize]) -> bool {
+ // INTEROP: A calculation that mixes a percentage with a length, like calc(25% + 10px), counts as auto here, as
+ // in other engines.
+ let acts_as_auto = |size: &ComputedSize| {
+ size.is_auto() || (size.contains_percentage() && size.percentage_fraction().is_none())
+ };
+ acts_as_auto(self.style(self.rows[row_index].box_).height())
+ && cells_of_row
+ .iter()
+ .all(|&cell_index| acts_as_auto(self.style(self.cells[cell_index].box_).height()))
+ }
+
+ /// Adds `amount` to the final block sizes of `rows`, in proportion to their current final block sizes, or in
+ /// equal shares if they are all empty.
+ fn grow_rows_proportionally(&mut self, rows: &[usize], amount: CssPixels) {
+ let total = rows.iter().fold(CssPixels::default(), |sum, &index| {
+ sum + self.rows[index].final_block_size
+ });
+ let weights = rows
.iter()
- .fold(CssPixels::default(), |sum, row| sum + row.reference_block_size);
+ .map(|&index| {
+ if total > CssPixels::default() {
+ self.rows[index].final_block_size.to_double()
+ } else {
+ 1.0
+ }
+ })
+ .collect::<Vec<_>>();
+ let total_weight: f64 = weights.iter().sum();
+ // Hand out cumulative shares so that the rounded increments add up to exactly `amount`.
+ let mut accumulated_weight = 0.0;
+ let mut distributed = CssPixels::default();
+ for (&index, weight) in rows.iter().zip(weights) {
+ accumulated_weight += weight;
+ let target = CssPixels::nearest_value_for(amount.to_double() * accumulated_weight / total_weight);
+ self.rows[index].final_block_size += target - distributed;
+ distributed = target;
+ }
+ }
+
+ // NB: The specification's distribution of the table block size to the rows
+ // (https://drafts.csswg.org/css-tables-3/#distributing-height-to-rows) is not what browsers do, and is
+ // unresolved (https://github.com/w3c/csswg-drafts/issues/4418).
+ // INTEROP: Rows keep their reference sizes, and the rest of the table block size goes first to rows with a
+ // percentage block size, in row order, each growing to at most that size. What remains then goes to the
+ // rows whose block size depends only on their contents, in proportion to their block sizes, or else to
+ // all rows in proportion to their block sizes. When the table has rows outside of header and footer
+ // groups, only those rows grow, and their percentages resolve against their share of the table.
+ fn distribute_block_size_to_rows(&mut self) {
let visible = self.rows.iter().filter(|row| !row.is_collapsed).count();
if visible == 0 {
return;
}
- let auto_rows = (0..self.rows.len())
- .filter(|index| {
- // NB: A row with a percentage block size counts as an auto row in an auto-height table.
- let height = self.style(self.rows[*index].box_).height();
- !self.rows[*index].is_collapsed
- && (height.is_auto() || (height.is_percentage() && self.table_block_size_is_auto()))
- })
- .collect::<Vec<_>>();
- if self.table_block_size <= sum && sum != CssPixels::default() {
- // If the table block size is no larger than the sum of reference sizes, each final row block size is the
- // weighted mean of the base and reference sizes that yields the correct total block size.
-
- for row in &mut self.rows {
- if row.is_collapsed {
- row.final_block_size = CssPixels::default();
- } else {
- row.final_block_size = CssPixels::nearest_value_for(
- self.table_block_size.to_double() * row.reference_block_size.to_double() / sum.to_double(),
- );
+ for row in &mut self.rows {
+ row.final_block_size = if row.is_collapsed {
+ CssPixels::default()
+ } else {
+ row.reference_block_size
+ };
+ }
+ let sum = self
+ .rows
+ .iter()
+ .fold(CssPixels::default(), |sum, row| sum + row.final_block_size);
+ if self.table_block_size <= sum {
+ self.table_block_size = sum;
+ } else {
+ let mut excess = self.table_block_size - sum;
+ let mut cells_by_row = vec![Vec::new(); self.rows.len()];
+ for (cell_index, cell) in self.cells.iter().enumerate() {
+ cells_by_row[cell.row_index].push(cell_index);
+ }
+ // NB: Only the first header group and the first footer group are rendered as such, and the rows are in
+ // layout order, which puts them first and last (see row_containers_in_layout_order). Any other header
+ // or footer group acts as an ordinary row group.
+ let row_group_if = |row: Option<&Row>, is_group: fn(&NodeFacts) -> bool| {
+ row.map(|row| self.parent(row.box_))
+ .filter(|&parent| is_group(&self.node_facts(parent)))
+ };
+ let header_group = row_group_if(self.rows.first(), |facts| facts.is_table_header_group());
+ let footer_group = row_group_if(self.rows.last(), |facts| facts.is_table_footer_group());
+ let body_rows = (0..self.rows.len())
+ .filter(|&index| {
+ if self.rows[index].is_collapsed {
+ return false;
+ }
+ let parent = Some(self.parent(self.rows[index].box_));
+ parent != header_group && parent != footer_group
+ })
+ .collect::<Vec<_>>();
+ let (growing_rows, percentage_basis) = if body_rows.is_empty() || body_rows.len() == visible {
+ let rows = (0..self.rows.len())
+ .filter(|&index| !self.rows[index].is_collapsed)
+ .collect::<Vec<_>>();
+ (rows, self.table_percentage_basis)
+ } else {
+ let body_sum = body_rows.iter().fold(CssPixels::default(), |sum, &index| {
+ sum + self.rows[index].final_block_size
+ });
+ (body_rows, body_sum + excess)
+ };
+ for &index in &growing_rows {
+ if excess <= CssPixels::default() {
+ break;
+ }
+ if let Some(size) = self.row_percentage_block_size(index, &cells_by_row[index], percentage_basis) {
+ let growth = (size - self.rows[index].final_block_size)
+ .max(CssPixels::default())
+ .min(excess);
+ self.rows[index].final_block_size += growth;
+ excess -= growth;
}
}
- } else if !auto_rows.is_empty() {
- // Else, if the table owns any auto-block-size row, each non-auto row receives its reference block size and
- // auto rows receive their reference size plus an equal share of the missing table block size.
-
- for row in &mut self.rows {
- row.final_block_size = row.reference_block_size;
- }
- let increment = (self.table_block_size - sum) / auto_rows.len();
- for index in auto_rows {
- self.rows[index].final_block_size += increment;
- }
- } else {
- // Else, all rows receive their reference size plus an equal share of the missing table block size.
-
- let increment = (self.table_block_size - sum) / visible;
- for row in &mut self.rows {
- row.final_block_size = if row.is_collapsed {
- CssPixels::default()
+ if excess > CssPixels::default() {
+ let auto_rows = growing_rows
+ .iter()
+ .copied()
+ .filter(|&index| self.row_is_auto(index, &cells_by_row[index]))
+ .collect::<Vec<_>>();
+ if auto_rows.is_empty() {
+ self.grow_rows_proportionally(&growing_rows, excess);
} else {
- row.reference_block_size + increment
- };
+ self.grow_rows_proportionally(&auto_rows, excess);
+ }
}
}
// Add undistributable space due to border spacing: https://www.w3.org/TR/css-tables-3/#computing-undistributable-space.
@@ -3445,6 +3652,22 @@ impl<'pass> TableFormattingContext<'pass> {
self.table_block_size = self.table_block_size.max(total);
}
+ /// Whether the block size of a cell is definite once the rows are sized, so that its contents resolve percentage
+ /// block sizes against it.
+ // INTEROP: CSS 2.1 leaves this undefined. Like other engines, the cell's block size is definite when the cell has a
+ // length block size, or when the table has a computed block size other than auto (even a percentage
+ // that acts as auto) and the rows gave the cell a block size other than the one its contents gave it. A
+ // block size the row specifies alone doesn't make it definite.
+ fn cell_block_size_is_definite_after_row_sizing(&self, cell_index: usize, collapsed: bool) -> bool {
+ let cell = self.cells[cell_index];
+ if self.style(cell.box_).height().is_length() {
+ return true;
+ }
+ !self.style(self.run.box_).height().is_auto()
+ && self.compute_row_content_block_size(cell)
+ != self.cell_layouts[cell_index].box_cells.border_box_block_size(collapsed)
+ }
+
/// Stretches each cell to the rows it spans and aligns its contents in them: the table moves the contents as it
/// places the cell, or, where the cell's run laid out the absolutely positioned boxes the cell contains, lays the
/// cell out again at its stretched size with its contents moved, for those boxes to be laid out against it.
@@ -3452,6 +3675,27 @@ impl<'pass> TableFormattingContext<'pass> {
let collapsed = self.style(self.run.box_).border_collapse() != BORDER_COLLAPSE_SEPARATE;
for cell_index in 0..self.cells.len() {
let cell = self.cells[cell_index];
+ if self.cell_layouts[cell_index].contents_depend_on_percentage_block_size
+ && self.cell_block_size_is_definite_after_row_sizing(cell_index, collapsed)
+ {
+ // Lay the contents out again with the final block size of the cell as their percentage basis.
+ let mut cell_box = self.cell_layouts[cell_index].box_cells;
+ let offsets = cell_box.border_box_top(collapsed) + cell_box.border_box_bottom(collapsed);
+ cell_box.set_content_block_size(self.compute_row_content_block_size(cell) - offsets);
+ cell_box.has_definite_block_size = true;
+ let layout = &mut self.cell_layouts[cell_index];
+ layout.inside_layout_input = cell_box.available_inner_space_or_constraints_from(self.available_space);
+ layout.pre_layout_content_block_size = cell_box.content_block_size;
+ layout.box_cells = cell_box;
+ self.layout_inside_cell(
+ run,
+ cell_index,
+ RootSizingDirectives {
+ content_block_size_after_run: geometry::ContentBlockSizeAfterRun::Automatic,
+ ..RootSizingDirectives::default()
+ },
+ );
+ }
let laid_out = self.cell_layouts[cell_index].box_cells;
let free_space = self.compute_row_content_block_size(cell) - laid_out.border_box_block_size(collapsed);
let contents_block_offset = self.cell_contents_block_offset(cell_index, free_space);
@@ -3725,6 +3969,7 @@ impl<'pass> TableFormattingContext<'pass> {
fn run(&mut self, run: &FormattingContextRun<'pass>, input: LayoutInput, inline_layout: Option<TableInlineLayout>) {
self.available_space = input.available_space;
self.min_border_box_block_size_from_flex_item = input.sizing.forced_min_border_box_block_size.get();
+ self.forced_border_box_inline_size = input.sizing.forced_table_box_border_box_inline_size.get();
self.table_box_content_block_offset_in_wrapper = input
.sizing
.table_box_content_block_offset_in_wrapper
diff --git a/Tests/LibWeb/Layout/expected/table/percentage-row-height-does-not-shrink-other-rows.txt b/Tests/LibWeb/Layout/expected/table/percentage-row-height-does-not-shrink-other-rows.txt
new file mode 100644
index 00000000000..0b21352bafe
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/table/percentage-row-height-does-not-shrink-other-rows.txt
@@ -0,0 +1,16 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 416 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 400 0+0+8] children: not-inline
+ TableWrapper <(anonymous)> at [8,8] [0+0+0 300 0+0+484] [0+0+0 400 0+0+0] [BFC] children: not-inline
+ Box <div.table> at [8,8] table-box [0+0+0 300 0+0+0] [0+0+0 400 0+0+0] [TFC] children: not-inline
+ Box <(anonymous)> at [8,8] table-row [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] children: not-inline
+ BlockContainer <(anonymous)> at [8,8] table-cell [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] [BFC] children: not-inline
+ BlockContainer <div.first> at [8,8] [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] children: not-inline
+ Box <div.row> at [8,208] table-row [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] children: not-inline
+ BlockContainer <(anonymous)> at [8,208] table-cell [0+0+0 300 0+0+0] [0+0+0 200 0+0+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 4, rect: [8,210 46.984375x20] baseline: 16
+ "Text"
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x416] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/table/rows-height-distribution-4.txt b/Tests/LibWeb/Layout/expected/table/rows-height-distribution-4.txt
index 72e03a2fa11..18f9a2b1eda 100644
--- a/Tests/LibWeb/Layout/expected/table/rows-height-distribution-4.txt
+++ b/Tests/LibWeb/Layout/expected/table/rows-height-distribution-4.txt
@@ -3,14 +3,14 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 300 0+0+8] children: not-inline
TableWrapper <(anonymous)> at [8,8] [0+0+0 200 0+0+584] [0+0+0 300 0+0+0] [BFC] children: not-inline
Box <div.table> at [8,8] table-box [0+0+0 200 0+0+0] [0+0+0 300 0+0+0] [TFC] children: not-inline
- Box <div.row.a> at [8,8] table-row [0+0+0 200 0+0+0] [0+0+0 100 0+0+0] children: not-inline
- BlockContainer <div.cell> at [8,8] table-cell [0+0+0 200 0+0+0] [0+0+0 100 0+0+0] [BFC] children: inline
+ Box <div.row.a> at [8,8] table-row [0+0+0 200 0+0+0] [0+0+0 75 0+0+0] children: not-inline
+ BlockContainer <div.cell> at [8,8] table-cell [0+0+0 200 0+0+0] [0+0+0 75 0+0+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 1, rect: [8,8 9.34375x16] baseline: 13
"a"
TextNode <#text> (not painted)
- Box <div.row.b> at [8,108] table-row [0+0+0 200 0+0+0] [0+0+0 200 0+0+0] children: not-inline
- BlockContainer <div.cell> at [8,108] table-cell [0+0+0 200 0+0+0] [0+0+0 200 0+0+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 1, rect: [8,108 9.46875x16] baseline: 13
+ Box <div.row.b> at [8,83] table-row [0+0+0 200 0+0+0] [0+0+0 225 0+0+0] children: not-inline
+ BlockContainer <div.cell> at [8,83] table-cell [0+0+0 200 0+0+0] [0+0+0 225 0+0+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,83 9.46875x16] baseline: 13
"b"
TextNode <#text> (not painted)
diff --git a/Tests/LibWeb/Layout/input/table/percentage-row-height-does-not-shrink-other-rows.html b/Tests/LibWeb/Layout/input/table/percentage-row-height-does-not-shrink-other-rows.html
new file mode 100644
index 00000000000..756237ad2fe
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/table/percentage-row-height-does-not-shrink-other-rows.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<style>
+ .table {
+ display: table;
+ width: 300px;
+ height: 400px;
+ font: 20px/25px SerenitySans;
+ }
+ .first {
+ height: 200px;
+ background: orange;
+ }
+ .row {
+ display: table-row;
+ height: 100%;
+ background: lightblue;
+ }
+</style>
+<div class="table">
+ <div class="first"></div>
+ <div class="row">Text</div>
+</div>
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/table-with-percent-intrinsic-width.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/table-with-percent-intrinsic-width.txt
index 1de1e63e3fe..37c627c14b3 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/table-with-percent-intrinsic-width.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/table-with-percent-intrinsic-width.txt
@@ -2,6 +2,6 @@ Harness status: OK
Found 2 tests
-2 Fail
-Fail table 1
-Fail table 2
\ No newline at end of file
+2 Pass
+Pass table 1
+Pass table 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-item-aspect-ratio-justify-self-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-item-aspect-ratio-justify-self-002.txt
index 0dcb7506809..536d0b6d86d 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-item-aspect-ratio-justify-self-002.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-item-aspect-ratio-justify-self-002.txt
@@ -2,7 +2,8 @@ Harness status: OK
Found 20 tests
-20 Fail
+9 Pass
+11 Fail
Fail .item 1
Fail .item 2
Fail .item 3
@@ -14,12 +15,12 @@ Fail .item 8
Fail .item 9
Fail .item 10
Fail .item 11
-Fail .item 12
-Fail .item 13
-Fail .item 14
-Fail .item 15
-Fail .item 16
-Fail .item 17
-Fail .item 18
-Fail .item 19
-Fail .item 20
\ No newline at end of file
+Pass .item 12
+Pass .item 13
+Pass .item 14
+Pass .item 15
+Pass .item 16
+Pass .item 17
+Pass .item 18
+Pass .item 19
+Pass .item 20
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/tentative/table-width-redistribution-fixed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/tentative/table-width-redistribution-fixed.txt
index 038bc1ea195..2cd62e4b0b2 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/tentative/table-width-redistribution-fixed.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/tentative/table-width-redistribution-fixed.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 26 tests
-24 Pass
-2 Fail
+25 Pass
+1 Fail
Pass table 1
Pass table 2
Pass table 3
@@ -15,7 +15,7 @@ Pass table 8
Pass table 9
Pass table 10
Pass table 11
-Fail table 12
+Pass table 12
Pass table 13
Pass table 14
Pass table 15