From 405c5ffa60a393f04ebf019281e693d5cc903c90 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Tue, 19 Aug 2025 15:56:02 +1200 Subject: [PATCH] LibWeb: Propagate border-box dimensions when getting max content width This means that we now calculate the inner width correctly for `display: inline-block` nodes when we have `box-sizing: border-box` and `min-width`, as we would previously assume these dimensions were all `0` --- Libraries/LibWeb/Layout/FormattingContext.cpp | 8 ++++++++ .../Layout/expected/min-width-border-box.txt | 17 +++++++++++++++++ .../Layout/input/min-width-border-box.html | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/min-width-border-box.txt create mode 100644 Tests/LibWeb/Layout/input/min-width-border-box.html diff --git a/Libraries/LibWeb/Layout/FormattingContext.cpp b/Libraries/LibWeb/Layout/FormattingContext.cpp index 204aee1882b..a5f3af0574b 100644 --- a/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1484,10 +1484,18 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box) LayoutState throwaway_state; + auto const& actual_box_state = m_state.get(box); + auto& box_state = throwaway_state.get_mutable(box); box_state.width_constraint = SizeConstraint::MaxContent; box_state.set_indefinite_content_width(); + box_state.border_left = actual_box_state.border_left; + box_state.padding_left = actual_box_state.padding_left; + + box_state.border_right = actual_box_state.border_right; + box_state.padding_right = actual_box_state.padding_right; + auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, LayoutMode::IntrinsicSizing, box); if (!context) { context = make(throwaway_state, LayoutMode::IntrinsicSizing, as(box), nullptr); diff --git a/Tests/LibWeb/Layout/expected/min-width-border-box.txt b/Tests/LibWeb/Layout/expected/min-width-border-box.txt new file mode 100644 index 00000000000..d58f6a256f3 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/min-width-border-box.txt @@ -0,0 +1,17 @@ +Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline + BlockContainer at [0,0] [0+0+0 800 0+0+0] [0+0+0 66 0+0+0] [BFC] children: not-inline + BlockContainer at [8,8] [8+0+0 784 0+0+8] [8+0+0 50 0+0+8] children: inline + frag 0 from BlockContainer start: 0, length: 0, rect: [18,18 30x30] baseline: 23.796875 + BlockContainer at [18,18] inline-block [0+0+10 30 10+0+0] [0+0+10 30 10+0+0] [BFC] children: inline + frag 0 from TextNode start: 0, length: 1, rect: [18,18 6.34375x18] baseline: 13.796875 + "1" + TextNode <#text> (not painted) + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x66] + PaintableWithLines (BlockContainer) [8,8 784x50] + PaintableWithLines (BlockContainer
.min-width) [8,8 50x50] + TextPaintable (TextNode<#text>) + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x66] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/input/min-width-border-box.html b/Tests/LibWeb/Layout/input/min-width-border-box.html new file mode 100644 index 00000000000..19891c720e8 --- /dev/null +++ b/Tests/LibWeb/Layout/input/min-width-border-box.html @@ -0,0 +1,14 @@ + + + + +
1
\ No newline at end of file