From d1e542999cb0de18cb96d754acf68d7ab3a1edf6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 12 Sep 2023 00:58:51 +0200 Subject: [PATCH] LibWeb: Ensure preceding offset is non-negative in `float_box()` When calculating the edge offset of the next floating item based on the offset of the preceding floating item, we need to ensure that the preceding offset is always > 0. This isn't explicitly written in the spec, but all other popular engines do that. Fixes https://github.com/SerenityOS/serenity/issues/21023 --- ...loats-with-negative-percentage-margins.txt | 28 +++++++++++++++++++ ...oats-with-negative-percentage-margins.html | 22 +++++++++++++++ .../LibWeb/Layout/BlockFormattingContext.cpp | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/floats-with-negative-percentage-margins.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/floats-with-negative-percentage-margins.txt b/Tests/LibWeb/Layout/expected/block-and-inline/floats-with-negative-percentage-margins.txt new file mode 100644 index 0000000000..b699ed9a6d --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/floats-with-negative-percentage-margins.txt @@ -0,0 +1,28 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x208 [BFC] children: not-inline + BlockContainer at (8,8) content-size 600x0 children: not-inline + BlockContainer at (8,8) content-size 100x100 floating [BFC] children: inline + line 0 width: 26.640625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 3, rect: [8,8 26.640625x17.46875] + "top" + TextNode <#text> + BlockContainer at (8,108) content-size 100x100 floating [BFC] children: inline + line 0 width: 26.25, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 4, rect: [8,108 26.25x17.46875] + "left" + TextNode <#text> + BlockContainer at (208,108) content-size 100x100 floating [BFC] children: inline + line 0 width: 37.109375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 5, rect: [208,108 37.109375x17.46875] + "right" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x208] + PaintableWithLines (BlockContainer) [8,8 600x0] overflow: [8,8 300x200] + PaintableWithLines (BlockContainer
#top) [8,8 100x100] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer
#left) [8,108 100x100] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer
#right) [208,108 100x100] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html b/Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html new file mode 100644 index 0000000000..8244ca53d9 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html @@ -0,0 +1,22 @@ +
top
left