From b97229c9b5927fa7b43777aefae769fc4d2a0834 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 6 Apr 2023 14:37:54 +0200 Subject: [PATCH] LibWeb: Ignore preferred width when calculating intrinsic width of block When calculating the intrinsic width of a block-level box, we now ignore the preferred width entirely, and not just when the preferred width should be treated as auto. The condition for this was both confused and wrong, as it looked at the available width around the box, but didn't check for a width constraint on the box itself. Just because the available width has an intrinsic sizing constraint doesn't mean that the box is undergoing intrinsic sizing. It could also be the box's containing block! --- ...contributes-to-intrinsic-size-of-parent.txt | 9 +++++++++ ...ontributes-to-intrinsic-size-of-parent.html | 18 ++++++++++++++++++ .../LibWeb/Layout/BlockFormattingContext.cpp | 5 ++++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.txt b/Tests/LibWeb/Layout/expected/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.txt new file mode 100644 index 0000000000..39151e8cab --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.txt @@ -0,0 +1,9 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x39.46875 children: not-inline + Box at (10,10) content-size 764x21.46875 flex-container(row) children: not-inline + BlockContainer at (11,11) content-size 202x19.46875 flex-item children: not-inline + BlockContainer at (12,12) content-size 200x17.46875 children: inline + line 0 width: 45.15625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 4, rect: [12,12 45.15625x17.46875] + "OPEN" + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.html b/Tests/LibWeb/Layout/input/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.html new file mode 100644 index 0000000000..6a2d8ff373 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/max-width-on-child-block-with-width-auto-contributes-to-intrinsic-size-of-parent.html @@ -0,0 +1,18 @@ +
OPEN \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 5bb8dba717..4013194d45 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -136,7 +136,10 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& box_state.padding_left = padding_left.to_px(box); box_state.padding_right = padding_right.to_px(box); - if (should_treat_width_as_auto(box, available_space) && available_space.width.is_intrinsic_sizing_constraint()) + // NOTE: If we are calculating the min-content or max-content width of this box, + // and the width should be treated as auto, then we can simply return here, + // as the preferred width and min/max constraints are irrelevant for intrinsic sizing. + if (box_state.width_constraint != SizeConstraint::None) return; auto try_compute_width = [&](auto const& a_width) {