aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorOriol Brufau <obrufau@igalia.com>2024-12-20 06:04:56 -0800
committerGitHub <noreply@github.com>2024-12-20 14:04:56 +0000
commit65c65c9a6aafbae16e694814e198c8744cc0e567 (patch)
tree530d153320813c94078d9574935583aab839a142 /components
parent915901bdec4b15e2f9023db3e62c9020bc7479a7 (diff)
downloadservo-65c65c9a6aafbae16e694814e198c8744cc0e567.tar.gz
servo-65c65c9a6aafbae16e694814e198c8744cc0e567.zip
layout: Fix intrinsic contributions of tables (#34696)
If a table element had e.g. `width: 0px`, we were assuming that this was its intrinsic min-content and max-content contributions. However, tables are always at least as big as its min-content size, so this patch floors the intrinsic contributions by that amount. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components')
-rw-r--r--components/layout_2020/flow/mod.rs1
-rw-r--r--components/layout_2020/formatting_contexts.rs7
-rw-r--r--components/layout_2020/sizing.rs20
3 files changed, 24 insertions, 4 deletions
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index e94301391e2..745f7b57e73 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -411,6 +411,7 @@ fn compute_inline_content_sizes_for_block_level_boxes(
containing_block,
&LogicalVec2::zero(),
false, /* auto_block_size_stretches_to_containing_block */
+ false, /* is_table */
|_| None, /* TODO: support preferred aspect ratios on non-replaced boxes */
|constraint_space| {
base.inline_content_sizes(layout_context, constraint_space, contents)
diff --git a/components/layout_2020/formatting_contexts.rs b/components/layout_2020/formatting_contexts.rs
index 0fb34b422cd..886328fb304 100644
--- a/components/layout_2020/formatting_contexts.rs
+++ b/components/layout_2020/formatting_contexts.rs
@@ -204,11 +204,18 @@ impl IndependentFormattingContext {
auto_minimum: &LogicalVec2<Au>,
auto_block_size_stretches_to_containing_block: bool,
) -> InlineContentSizesResult {
+ let is_table = matches!(
+ self.contents,
+ IndependentFormattingContextContents::NonReplaced(
+ IndependentNonReplacedContents::Table(_)
+ )
+ );
sizing::outer_inline(
self.style(),
containing_block,
auto_minimum,
auto_block_size_stretches_to_containing_block,
+ is_table,
|padding_border_sums| self.preferred_aspect_ratio(padding_border_sums),
|constraint_space| self.inline_content_sizes(layout_context, constraint_space),
)
diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs
index 1e8fe74d6e6..49c9c6aedee 100644
--- a/components/layout_2020/sizing.rs
+++ b/components/layout_2020/sizing.rs
@@ -114,6 +114,7 @@ pub(crate) fn outer_inline(
containing_block: &IndefiniteContainingBlock,
auto_minimum: &LogicalVec2<Au>,
auto_block_size_stretches_to_containing_block: bool,
+ is_table: bool,
get_preferred_aspect_ratio: impl FnOnce(&LogicalVec2<Au>) -> Option<AspectRatio>,
get_content_size: impl FnOnce(&ConstraintSpace) -> InlineContentSizesResult,
) -> InlineContentSizesResult {
@@ -175,10 +176,12 @@ pub(crate) fn outer_inline(
let (preferred_min_content, preferred_max_content, preferred_depends_on_block_constraints) =
resolve_non_initial(content_box_sizes.inline.preferred)
.unwrap_or_else(|| resolve_non_initial(Size::FitContent).unwrap());
- let (min_min_content, min_max_content, min_depends_on_block_constraints) = resolve_non_initial(
- content_box_sizes.inline.min,
- )
- .unwrap_or((auto_minimum.inline, auto_minimum.inline, false));
+ let (mut min_min_content, mut min_max_content, mut min_depends_on_block_constraints) =
+ resolve_non_initial(content_box_sizes.inline.min).unwrap_or((
+ auto_minimum.inline,
+ auto_minimum.inline,
+ false,
+ ));
let (max_min_content, max_max_content, max_depends_on_block_constraints) =
resolve_non_initial(content_box_sizes.inline.max)
.map(|(min_content, max_content, depends_on_block_constraints)| {
@@ -189,6 +192,15 @@ pub(crate) fn outer_inline(
)
})
.unwrap_or_default();
+
+ // Regardless of their sizing properties, tables are always forced to be at least
+ // as big as their min-content size, so floor the minimums.
+ if is_table {
+ min_min_content.max_assign(content_size.sizes.min_content);
+ min_max_content.max_assign(content_size.sizes.min_content);
+ min_depends_on_block_constraints |= content_size.depends_on_block_constraints;
+ }
+
InlineContentSizesResult {
sizes: ContentSizes {
min_content: preferred_min_content