From 37bd216c52a10079d4c6895318bf434d8c287107 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 18 Aug 2023 02:06:22 +0200 Subject: [PATCH] LibWeb: Ignore % max-width if box is sized under max-content constraint When a box is sized under max-content constraint, any percentage value set for max-width should be considered as if it were infinite. In other words, it should have no effect on restricting the box's width. --- .../inline-block-percentage-max-width.txt | 16 ++++++++++++++++ .../inline-block-percentage-max-width.html | 11 +++++++++++ .../LibWeb/Layout/FormattingContext.cpp | 2 ++ 3 files changed, 29 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/inline-block-percentage-max-width.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/inline-block-percentage-max-width.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-percentage-max-width.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-percentage-max-width.txt new file mode 100644 index 00000000000..72361aff8a6 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-percentage-max-width.txt @@ -0,0 +1,16 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x113.46875 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x97.46875 children: inline + line 0 width: 134.109375, height: 97.46875, bottom: 97.46875, baseline: 53.53125 + frag 0 from BlockContainer start: 0, length: 0, rect: [48,48 54.109375x17.46875] + BlockContainer
at (48,48) content-size 54.109375x17.46875 inline-block [BFC] children: inline + line 0 width: 54.109375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 6, rect: [48,48 54.109375x17.46875] + "New UI" + TextNode <#text> + +PaintableWithLines (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x113.46875] + PaintableWithLines (BlockContainer) [8,8 784x97.46875] + PaintableWithLines (BlockContainer
) [8,8 134.109375x97.46875] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/block-and-inline/inline-block-percentage-max-width.html b/Tests/LibWeb/Layout/input/block-and-inline/inline-block-percentage-max-width.html new file mode 100644 index 00000000000..01929ad3636 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/inline-block-percentage-max-width.html @@ -0,0 +1,11 @@ +
New UI \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 50c3d577d91..6aaaff89bd7 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1810,6 +1810,8 @@ bool FormattingContext::should_treat_max_width_as_none(Box const& box, Available if (box.is_absolutely_positioned()) return false; if (max_width.contains_percentage()) { + if (available_width.is_max_content()) + return true; if (available_width.is_min_content()) return false; if (!m_state.get(*box.non_anonymous_containing_block()).has_definite_width())