From bf3144fcff96ec3e655a3588c7b4e979f1fbea1f Mon Sep 17 00:00:00 2001 From: Emil Militzer Date: Tue, 11 Jul 2023 16:22:25 +0200 Subject: [PATCH] LibWeb: Prevent max-width expanding the width --- .../max-width-must-not-expand-element.txt | 5 +++++ .../max-width-must-not-expand-element.html | 8 ++++++++ .../Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/max-width-must-not-expand-element.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/max-width-must-not-expand-element.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/max-width-must-not-expand-element.txt b/Tests/LibWeb/Layout/expected/block-and-inline/max-width-must-not-expand-element.txt new file mode 100644 index 0000000000..b74b1ed309 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/max-width-must-not-expand-element.txt @@ -0,0 +1,5 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x0 [BFC] children: not-inline + BlockContainer at (10,10) content-size 4x54 positioned [BFC] children: not-inline + BlockContainer at (11,11) content-size 2x52 children: not-inline + BlockContainer at (12,12) content-size 0x50 children: not-inline \ No newline at end of file diff --git a/Tests/LibWeb/Layout/input/block-and-inline/max-width-must-not-expand-element.html b/Tests/LibWeb/Layout/input/block-and-inline/max-width-must-not-expand-element.html new file mode 100644 index 0000000000..a4a2b48a72 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/max-width-must-not-expand-element.html @@ -0,0 +1,8 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 91e18f6b8e..9d8d3f559f 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -255,7 +255,7 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& // but this time using the computed value of 'max-width' as the computed value for 'width'. if (!should_treat_max_width_as_none(box, available_space.width)) { auto max_width = calculate_inner_width(box, remaining_available_space.width, computed_values.max_width()); - auto used_width_px = used_width.is_auto() ? remaining_available_space.width.to_px() : used_width.to_px(box); + auto used_width_px = used_width.is_auto() ? CSSPixels { 0 } : used_width.to_px(box); if (used_width_px > max_width.to_px(box)) { used_width = try_compute_width(max_width); }