From 3f6f3966b91c364c3bd39f6c7271a20b9ef92de1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 25 Mar 2023 16:00:54 +0100 Subject: [PATCH] LibWeb: Don't allow resolved width of abspos elements to become negative We have to clamp the resulting width to 0 when solving for it. --- ...n-replaced-abspos-element-must-not-be-negative.txt | 4 ++++ ...-replaced-abspos-element-must-not-be-negative.html | 11 +++++++++++ .../Libraries/LibWeb/Layout/FormattingContext.cpp | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt create mode 100644 Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html diff --git a/Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt b/Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt new file mode 100644 index 0000000000..b60df89a3e --- /dev/null +++ b/Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt @@ -0,0 +1,4 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x0 children: not-inline + BlockContainer at (8,8) content-size 0x0 positioned children: not-inline + BlockContainer at (9,9) content-size 0x0 positioned children: not-inline diff --git a/Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html b/Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html new file mode 100644 index 0000000000..a8decc04b0 --- /dev/null +++ b/Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html @@ -0,0 +1,11 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 727973afd2..f3126525a3 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -515,7 +515,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele }; auto solve_for_width = [&] { - return CSS::Length::make_px(width_of_containing_block - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left - padding_right - border_right - margin_right.to_px(box) - right.to_px(box)); + return CSS::Length::make_px(max(CSSPixels(0), width_of_containing_block - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left - padding_right - border_right - margin_right.to_px(box) - right.to_px(box))); }; auto solve_for_right = [&] {