From af73a5d921210cefc54d0fb43100715d360886db Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 8 Sep 2022 13:21:57 +0200 Subject: [PATCH] LibWeb: Use correct box edge when looking for space between floats --- .../LibWeb/Layout/BlockFormattingContext.cpp | 2 +- .../LibWeb/Layout/InlineFormattingContext.cpp | 4 ++-- .../Libraries/LibWeb/Layout/LayoutState.cpp | 20 +++++++++++++++++++ .../Libraries/LibWeb/Layout/LayoutState.h | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 0513c42f80e..113d30d0567 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -626,7 +626,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer offset_from_edge = box_state.content_width() + box_state.margin_box_right(); }; - auto box_in_root_rect = border_box_rect_in_ancestor_coordinate_space(box, root(), m_state); + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(box, root(), m_state); float y_in_root = box_in_root_rect.y(); float y = box_state.offset.y(); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 379425c3e90..812039770e7 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -52,7 +52,7 @@ BlockFormattingContext const& InlineFormattingContext::parent() const float InlineFormattingContext::leftmost_x_offset_at(float y) const { // NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC. - auto box_in_root_rect = border_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state); + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state); float y_in_root = box_in_root_rect.y() + y; auto space = parent().space_used_by_floats(y_in_root); float containing_block_x = m_containing_block_state.offset.x(); @@ -68,7 +68,7 @@ float InlineFormattingContext::available_space_for_line(float y) const // NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC. auto& root_block = parent().root(); - auto box_in_root_rect = border_box_rect_in_ancestor_coordinate_space(containing_block(), root_block, m_state); + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), root_block, m_state); float y_in_root = box_in_root_rect.y() + y; auto space = parent().space_used_by_floats(y_in_root); diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index 9d8aeae6290..29911b212f1 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -132,6 +132,26 @@ Gfx::FloatRect border_box_rect_in_ancestor_coordinate_space(Box const& box, Box return rect; } +Gfx::FloatRect content_box_rect(Box const& box, LayoutState const& state) +{ + auto const& box_state = state.get(box); + return Gfx::FloatRect { box_state.offset, { box_state.content_width(), box_state.content_height() } }; +} + +Gfx::FloatRect content_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const& state) +{ + auto rect = content_box_rect(box, state); + for (auto const* current = box.parent(); current; current = current->parent()) { + if (current == &ancestor_box) + break; + if (is(*current)) { + auto const& current_state = state.get(static_cast(*current)); + rect.translate_by(current_state.offset); + } + } + return rect; +} + Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const& state) { auto rect = margin_box_rect(box, state); diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h index ddb4238499c..35f90439080 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.h +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h @@ -151,5 +151,7 @@ Gfx::FloatRect margin_box_rect(Box const&, LayoutState const&); Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const&); Gfx::FloatRect border_box_rect(Box const&, LayoutState const&); Gfx::FloatRect border_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const&); +Gfx::FloatRect content_box_rect(Box const&, LayoutState const&); +Gfx::FloatRect content_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const&); }