From ae5bb13f1f6af2dc141d69179b09c8b747fdd99e Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 15 May 2023 15:54:25 +0300 Subject: [PATCH] LibWeb: Do not layout grid items during grid container intrinsic sizing There is not need to run layout inside grid items for intrinsic sizing of grid container. --- .../LibWeb/Layout/GridFormattingContext.cpp | 23 ++++++++++++------- .../LibWeb/Layout/GridFormattingContext.h | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 5310c1db6ad..8c45f0aea19 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -1316,6 +1316,14 @@ void GridFormattingContext::place_grid_items(AvailableSpace const& available_spa } } +void GridFormattingContext::determine_grid_container_height() +{ + CSSPixels total_y = 0; + for (auto& grid_row : m_grid_rows_and_gaps) + total_y += grid_row.full_vertical_size(); + m_automatic_content_height = total_y; +} + void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const& available_space) { place_grid_items(available_space); @@ -1327,6 +1335,13 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const run_track_sizing(available_space, GridDimension::Column); run_track_sizing(available_space, GridDimension::Row); + determine_grid_container_height(); + + if (available_space.height.is_intrinsic_sizing_constraint() || available_space.width.is_intrinsic_sizing_constraint()) { + determine_intrinsic_size_of_grid_container(available_space); + return; + } + auto layout_box = [&](int row_start, int row_end, int column_start, int column_end, Box const& child_box) -> void { if (column_start < 0 || row_start < 0) return; @@ -1393,14 +1408,6 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const grid_item.gap_adjusted_column(box) + resolved_column_span, grid_item.box()); } - - if (available_space.height.is_intrinsic_sizing_constraint() || available_space.width.is_intrinsic_sizing_constraint()) - determine_intrinsic_size_of_grid_container(available_space); - - CSSPixels total_y = 0; - for (auto& grid_row : m_grid_rows_and_gaps) - total_y += grid_row.full_vertical_size(); - m_automatic_content_height = total_y; } void GridFormattingContext::determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space) diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h index dc8742d5729..9c17b8ae5bf 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h @@ -167,6 +167,7 @@ private: Vector m_grid_items; Vector> m_boxes_to_place; + void determine_grid_container_height(); void determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space); AvailableSize get_free_space(AvailableSpace const&, GridDimension const) const;