From 4f9df88699b9a1008f3d8fdc77bcf4c1ecc05d88 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 11 Sep 2024 01:14:56 +0200 Subject: [PATCH] LibWeb: Skip abspos boxes layout in intrinsic sizing mode Absolutely positioned boxes do not affect the size of the formatting context box they belong to, so it's safe to skip their layout entirely when calculating intrinsic size. (cherry picked from commit 4eb16b144e20d615db2febaa42c78e89ecbc3e24) --- .../LibWeb/Layout/BlockFormattingContext.cpp | 14 ++++++++------ .../LibWeb/Layout/FlexFormattingContext.cpp | 3 +++ .../LibWeb/Layout/GridFormattingContext.cpp | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 919ceedc155508..0fed36dde550a6 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -108,12 +108,14 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box() box_state.set_content_x(float_containing_block_width - floating_box->offset_from_edge); } - // We can also layout absolutely positioned boxes within this BFC. - for (auto& box : m_absolutely_positioned_boxes) { - auto& cb_state = m_state.get(*box->containing_block()); - auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right); - auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom); - layout_absolutely_positioned_element(box, AvailableSpace(available_width, available_height)); + if (m_layout_mode == LayoutMode::Normal) { + // We can also layout absolutely positioned boxes within this BFC. + for (auto& box : m_absolutely_positioned_boxes) { + auto& cb_state = m_state.get(*box->containing_block()); + auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right); + auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom); + layout_absolutely_positioned_element(box, AvailableSpace(available_width, available_height)); + } } } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 6af2bb8f86541b..b4522d6529146b 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -181,6 +181,9 @@ void FlexFormattingContext::run(AvailableSpace const& available_space) void FlexFormattingContext::parent_context_did_dimension_child_root_box() { + if (m_layout_mode != LayoutMode::Normal) + return; + flex_container().for_each_child_of_type([&](Layout::Box& box) { if (box.is_absolutely_positioned()) { auto& cb_state = m_state.get(*box.containing_block()); diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 0a0c8783e00f20..1f438f0d4c1b16 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -2098,6 +2098,9 @@ void GridFormattingContext::layout_absolutely_positioned_element(Box const& box, void GridFormattingContext::parent_context_did_dimension_child_root_box() { + if (m_layout_mode != LayoutMode::Normal) + return; + grid_container().for_each_child_of_type([&](Layout::Box& box) { if (box.is_absolutely_positioned()) { auto& cb_state = m_state.get(*box.containing_block());