From ad9d9bb684e3cfb43566c517f0f918efc52b2690 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 30 Jan 2025 16:24:27 +0100 Subject: [PATCH] LibWeb: Ensure size constraints apply to non-BFC-root abspos boxes BFC roots behave differently in that their height is computed twice, before and after inside layout, since automatic height depends on the results of inside layout. Other formatting contexts only require the "before" pass, and so we can treat their content sizes as definite before proceeding with inside layout. This makes https://play.tailwind.com/ look beautiful. :^) --- Libraries/LibWeb/Layout/FormattingContext.cpp | 9 +++++++++ ...spos-non-bfc-root-with-min-height-constraint.txt | 13 +++++++++++++ ...pos-non-bfc-root-with-min-height-constraint.html | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/abspos-non-bfc-root-with-min-height-constraint.txt create mode 100644 Tests/LibWeb/Layout/input/abspos-non-bfc-root-with-min-height-constraint.html diff --git a/Libraries/LibWeb/Layout/FormattingContext.cpp b/Libraries/LibWeb/Layout/FormattingContext.cpp index 66ba7c450dc..c678bf09b71 100644 --- a/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1245,6 +1245,15 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box, Ava box_state.set_has_definite_height(true); } + // NOTE: BFC is special, as their abspos auto height depends on performing inside layout. + // For other formatting contexts, the height we've resolved early is good. + // See FormattingContext::compute_auto_height_for_absolutely_positioned_element() + // for the special-casing of BFC roots. + if (!creates_block_formatting_context(box)) { + box_state.set_has_definite_width(true); + box_state.set_has_definite_height(true); + } + auto independent_formatting_context = layout_inside(box, LayoutMode::Normal, box_state.available_inner_space_or_constraints_from(available_space)); compute_height_for_absolutely_positioned_element(box, available_space, BeforeOrAfterInsideLayout::After); diff --git a/Tests/LibWeb/Layout/expected/abspos-non-bfc-root-with-min-height-constraint.txt b/Tests/LibWeb/Layout/expected/abspos-non-bfc-root-with-min-height-constraint.txt new file mode 100644 index 00000000000..8c8e57c4e22 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/abspos-non-bfc-root-with-min-height-constraint.txt @@ -0,0 +1,13 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x0 [BFC] children: not-inline + Box at (8,8) content-size 31.15625x300 positioned flex-container(row) [FFC] children: not-inline + BlockContainer
at (8,8) content-size 31.15625x300 flex-item [BFC] children: inline + frag 0 from TextNode start: 0, length: 3, rect: [8,8 31.15625x17] baseline: 13.296875 + "Sup" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x0] + PaintableBox (Box) [8,8 31.15625x300] + PaintableWithLines (BlockContainer
) [8,8 31.15625x300] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/abspos-non-bfc-root-with-min-height-constraint.html b/Tests/LibWeb/Layout/input/abspos-non-bfc-root-with-min-height-constraint.html new file mode 100644 index 00000000000..6e9954bdc8d --- /dev/null +++ b/Tests/LibWeb/Layout/input/abspos-non-bfc-root-with-min-height-constraint.html @@ -0,0 +1,8 @@ +
Sup