From 2b8c7faee487bb61a4077893f959f6f2c63cdf1c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Dec 2020 19:58:23 +0100 Subject: [PATCH] LibWeb: Use the margin box of floating elements for flowing around Inline content flows around the entire margin box of floating elements, not just the content box. --- Base/res/html/misc/float-2.html | 17 +++++++++++++++++ Libraries/LibWeb/Layout/Box.h | 16 ++++++++++++++++ .../LibWeb/Layout/InlineFormattingContext.cpp | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 Base/res/html/misc/float-2.html diff --git a/Base/res/html/misc/float-2.html b/Base/res/html/misc/float-2.html new file mode 100644 index 0000000000..595c121b6e --- /dev/null +++ b/Base/res/html/misc/float-2.html @@ -0,0 +1,17 @@ + + + + + + +
+
Text
+ + diff --git a/Libraries/LibWeb/Layout/Box.h b/Libraries/LibWeb/Layout/Box.h index 0e53216beb..a601a970b5 100644 --- a/Libraries/LibWeb/Layout/Box.h +++ b/Libraries/LibWeb/Layout/Box.h @@ -58,6 +58,22 @@ public: return width() + border_box.left + border_box.right; } + Gfx::FloatRect content_box_as_relative_rect() const + { + return { m_offset, m_size }; + } + + Gfx::FloatRect margin_box_as_relative_rect() const + { + auto rect = content_box_as_relative_rect(); + auto margin_box = box_model().margin_box(*this); + rect.set_x(rect.x() - margin_box.left); + rect.set_width(rect.width() + margin_box.left + margin_box.right); + rect.set_y(rect.y() - margin_box.top); + rect.set_height(rect.height() + margin_box.top + margin_box.bottom); + return rect; + } + float absolute_x() const { return absolute_rect().x(); } float absolute_y() const { return absolute_rect().y(); } Gfx::FloatPoint absolute_position() const { return absolute_rect().location(); } diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 602ba31be3..295e0fd987 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -62,7 +62,7 @@ static AvailableSpaceForLineInfo available_space_for_line(const InlineFormatting for (ssize_t i = bfc.left_floating_boxes().size() - 1; i >= 0; --i) { auto& floating_box = *bfc.left_floating_boxes().at(i); - Gfx::FloatRect rect { floating_box.effective_offset(), floating_box.size() }; + auto rect = floating_box.margin_box_as_relative_rect(); if (rect.contains_vertically(y)) { info.left = rect.right() + 1; break; @@ -73,7 +73,7 @@ static AvailableSpaceForLineInfo available_space_for_line(const InlineFormatting for (ssize_t i = bfc.right_floating_boxes().size() - 1; i >= 0; --i) { auto& floating_box = *bfc.right_floating_boxes().at(i); - Gfx::FloatRect rect { floating_box.effective_offset(), floating_box.size() }; + auto rect = floating_box.margin_box_as_relative_rect(); if (rect.contains_vertically(y)) { info.right = rect.left() - 1; break;