From 767cdf7b113a07749521d3b220f2e83b85295a1b Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 19 Nov 2022 05:11:38 +0300 Subject: [PATCH] LibWeb: Return content box position from calculate_static_position This change makes calculate_static_position to return content box for both x and y (at least for the case when children are not inline). It makes it possible to be consistent about x and y when calculating box offset inside layout_absolutely_positioned_element. --- .../Libraries/LibWeb/Layout/FormattingContext.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index f170c755e3..b4e36a2021 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -916,6 +916,7 @@ Gfx::FloatPoint FormattingContext::calculate_static_position(Box const& box) con // Easy case: no previous sibling, we're at the top of the containing block. } } else { + x = m_state.get(box).margin_box_left(); // We're among block siblings, Y can be calculated easily. y = compute_box_y_position_with_respect_to_siblings(box); } @@ -986,9 +987,8 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box, Ava - box_state.border_box_right(); used_offset.set_x(width_of_containing_block + x_offset - box_state.content_width() - box_state.margin_right); } else { - float x_offset = box_state.margin_box_left() - + static_position.x(); - used_offset.set_x(x_offset); + // NOTE: static position is content box position so border_box and margin should not be added + used_offset.set_x(static_position.x()); } if (!computed_top.is_auto()) { @@ -1001,9 +1001,8 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box, Ava - box_state.border_box_bottom(); used_offset.set_y(height_of_containing_block + y_offset - box_state.content_height() - box_state.margin_bottom); } else { - float y_offset = box_state.margin_box_top() - + static_position.y(); - used_offset.set_y(y_offset); + // NOTE: static position is content box position so border_box and margin should not be added + used_offset.set_y(static_position.y()); } // NOTE: Absolutely positioned boxes are relative to the *padding edge* of the containing block.