From 56ceb6a10618fab5ead03f1067738ca4d846f30e Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 17 Jan 2023 11:57:00 +0100 Subject: [PATCH] LibWeb: Fix floats y offset calculation There is a difference in y offset position calculation for floats when LineBuilder provides final y position while for blocks it needs to be adjusted by `y_offset`. This difference already accounted in floating box position calculation and this patch also makes it accounted in check whether a floating boxes on the same line intersect between each other. --- Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index dd0c2efde5..e33d184b49 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -773,7 +773,11 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer if (fits_on_line) { auto const previous_rect = margin_box_rect_in_ancestor_coordinate_space(previous_box.box, root(), m_state); - if (previous_rect.contains_vertically(y_in_root + side_data.y_offset)) { + // NOTE: If we're in inline layout, the LineBuilder has already provided the right Y offset. + // In block layout, we adjust by the side's current Y offset here. + if (!line_builder) + y_in_root += side_data.y_offset; + if (previous_rect.contains_vertically(y_in_root)) { // This box touches another already floating box. Stack after others. offset_from_edge = wanted_offset_from_edge; } else {