From c3745417112e33c09cb6371a714d3fa33e702035 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Jun 2023 20:06:41 +0200 Subject: [PATCH] LibWeb: Use correct reference for abspos elements with % height sizes Absolutely positioned elements should have their percentage sizes resolved against the padding box of the containing block, not the content box. From CSS-POSITION-3 "..the containing block is formed by the padding edge of the ancestor.." --- ...ved-against-padding-box-of-containing-block.txt | 4 ++++ ...ed-against-padding-box-of-containing-block.html | 14 ++++++++++++++ .../Libraries/LibWeb/Layout/FormattingContext.cpp | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.txt b/Tests/LibWeb/Layout/expected/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.txt new file mode 100644 index 0000000000..ca6919072c --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.txt @@ -0,0 +1,4 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x256 [BFC] children: not-inline + BlockContainer at (8,248) content-size 784x0 positioned children: not-inline + BlockContainer at (8,8) content-size 784x240 positioned [BFC] children: not-inline diff --git a/Tests/LibWeb/Layout/input/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.html b/Tests/LibWeb/Layout/input/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.html new file mode 100644 index 0000000000..6ae632143d --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/abspos-with-percentage-height-resolved-against-padding-box-of-containing-block.html @@ -0,0 +1,14 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 45efa15fd9..b78238d22d 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1390,9 +1390,9 @@ CSS::Length FormattingContext::calculate_inner_width(Layout::Box const& box, Ava return width.resolved(box, width_of_containing_block_as_length_for_resolve); } -CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const&, CSS::Size const& height) const +CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const& available_height, CSS::Size const& height) const { - auto height_of_containing_block = m_state.get(*box.non_anonymous_containing_block()).content_height(); + auto height_of_containing_block = available_height.to_px(); auto height_of_containing_block_as_length_for_resolve = CSS::Length::make_px(height_of_containing_block); if (height.is_auto()) { return height.resolved(box, height_of_containing_block_as_length_for_resolve);