summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2023-01-17 11:57:00 +0100
committerAndreas Kling <kling@serenityos.org>2023-01-21 14:45:09 +0100
commit56ceb6a10618fab5ead03f1067738ca4d846f30e (patch)
tree03f167872ff42fe49782f8585c7a137c281ec532
parent63cf9b973dead6241ec1d007020db90fc78c0aa1 (diff)
downloadserenity-56ceb6a10618fab5ead03f1067738ca4d846f30e.zip
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.
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp6
1 files changed, 5 insertions, 1 deletions
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 {