From f97754942c57117c07b3d369fa23d12c38828583 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 10 Mar 2023 22:06:20 +0100 Subject: [PATCH] LibWeb: Collapse margin-left with space used by left-side floats We had an issue where boxes with margin-left were shifted right by left-side floats twice instead of just once. --- ...c-float-left-and-sibling-with-margin-left.txt | 9 +++++++++ ...-float-left-and-sibling-with-margin-left.html | 16 ++++++++++++++++ Userland/Libraries/LibWeb/Layout/LineBuilder.cpp | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/ifc-float-left-and-sibling-with-margin-left.txt create mode 100644 Tests/LibWeb/Layout/input/ifc-float-left-and-sibling-with-margin-left.html diff --git a/Tests/LibWeb/Layout/expected/ifc-float-left-and-sibling-with-margin-left.txt b/Tests/LibWeb/Layout/expected/ifc-float-left-and-sibling-with-margin-left.txt new file mode 100644 index 00000000000..efc8ed23b49 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/ifc-float-left-and-sibling-with-margin-left.txt @@ -0,0 +1,9 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x61 children: not-inline + BlockContainer at (10,10) content-size 780x19.46875 children: not-inline + BlockContainer at (11,11) content-size 50x50 floating children: not-inline + BlockContainer at (91,11) content-size 698x17.46875 children: inline + line 0 width: 125.125, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 14, rect: [91,11 125.125x17.46875] + "Chrono Trigger" + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/ifc-float-left-and-sibling-with-margin-left.html b/Tests/LibWeb/Layout/input/ifc-float-left-and-sibling-with-margin-left.html new file mode 100644 index 00000000000..d44e5f5ce40 --- /dev/null +++ b/Tests/LibWeb/Layout/input/ifc-float-left-and-sibling-with-margin-left.html @@ -0,0 +1,16 @@ +
Chrono Trigger \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index 572fa0dba0a..89b735d2083 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -158,6 +158,10 @@ void LineBuilder::update_last_line() CSSPixels x_offset_bottom = m_context.leftmost_x_offset_at(m_current_y + current_line_height - 1); CSSPixels x_offset = max(x_offset_top, x_offset_bottom); + // If the IFC's containing block has left-side margin, it has already been shifted to the right by that amount. + // We subtract the margin-left here to ensure that the left-side "space used by floats" doesn't get applied twice. + x_offset = max(CSSPixels(0), x_offset - m_containing_block_state.margin_left); + CSSPixels excess_horizontal_space = m_available_width_for_current_line - line_box.width(); switch (text_align) {