From 62d26a5afbfcfaec25a341fa3819936b56e1f3a5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 9 May 2023 18:25:04 +0300 Subject: LibWeb: Move grid items placement algorithm into separate method in GFC Let's follow pattern of other formatting context where steps of layout are separated into method. --- .../LibWeb/Layout/GridFormattingContext.cpp | 27 ++++++++++++++-------- .../LibWeb/Layout/GridFormattingContext.h | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 868e41bcaa..3de1a00d2d 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -542,8 +542,13 @@ finish: m_grid_items.append(GridItem(child_box, row_start, row_span, column_start, column_span)); } -void GridFormattingContext::initialize_grid_tracks(AvailableSpace const& available_space, int column_count, int row_count) +void GridFormattingContext::initialize_grid_tracks(AvailableSpace const& available_space) { + auto grid_template_columns = grid_container().computed_values().grid_template_columns(); + auto grid_template_rows = grid_container().computed_values().grid_template_rows(); + auto column_count = get_count_of_tracks(grid_template_columns.track_list(), available_space); + auto row_count = get_count_of_tracks(grid_template_rows.track_list(), available_space); + for (auto const& track_in_list : grid_container().computed_values().grid_template_columns().track_list()) { auto repeat_count = (track_in_list.is_repeat() && track_in_list.repeat().is_default()) ? track_in_list.repeat().repeat_count() : 1; if (track_in_list.is_repeat()) { @@ -1218,10 +1223,12 @@ int GridFormattingContext::find_valid_grid_area(String const& needle) return -1; } -void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const& available_space) +void GridFormattingContext::place_grid_items(AvailableSpace const& available_space) { - auto grid_template_columns = box.computed_values().grid_template_columns(); - auto grid_template_rows = box.computed_values().grid_template_rows(); + auto grid_template_columns = grid_container().computed_values().grid_template_columns(); + auto grid_template_rows = grid_container().computed_values().grid_template_rows(); + auto column_count = get_count_of_tracks(grid_template_columns.track_list(), available_space); + auto row_count = get_count_of_tracks(grid_template_rows.track_list(), available_space); // https://drafts.csswg.org/css-grid/#overview-placement // 2.2. Placing Items @@ -1229,16 +1236,13 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const // flex items), which are then assigned to predefined areas in the grid. They can be explicitly // placed using coordinates through the grid-placement properties or implicitly placed into // empty areas using auto-placement. - box.for_each_child_of_type([&](Box& child_box) { + grid_container().for_each_child_of_type([&](Box& child_box) { if (can_skip_is_anonymous_text_run(child_box)) return IterationDecision::Continue; m_boxes_to_place.append(child_box); return IterationDecision::Continue; }); - auto column_count = get_count_of_tracks(grid_template_columns.track_list(), available_space); - auto row_count = get_count_of_tracks(grid_template_rows.track_list(), available_space); - m_occupation_grid = OccupationGrid(column_count, row_count); build_valid_grid_areas(); @@ -1306,6 +1310,11 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const // FIXME: 4.2. For dense packing: } +} + +void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const& available_space) +{ + place_grid_items(available_space); // https://drafts.csswg.org/css-grid/#overview-sizing // 2.3. Sizing the Grid @@ -1326,7 +1335,7 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const // - A flexible sizing function (). // The grid sizing algorithm defines how to resolve these sizing constraints into used track sizes. - initialize_grid_tracks(available_space, column_count, row_count); + initialize_grid_tracks(available_space); // https://www.w3.org/TR/css-grid-2/#algo-overview // 12.1. Grid Sizing Algorithm diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h index fa3feaa6f0..429510c88b 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h @@ -156,12 +156,13 @@ private: void build_valid_grid_areas(); int find_valid_grid_area(String const& needle); + void place_grid_items(AvailableSpace const& available_space); void place_item_with_row_and_column_position(Box const& child_box); void place_item_with_row_position(Box const& child_box); void place_item_with_column_position(Box const& child_box, int& auto_placement_cursor_x, int& auto_placement_cursor_y); void place_item_with_no_declared_position(Box const& child_box, int& auto_placement_cursor_x, int& auto_placement_cursor_y); - void initialize_grid_tracks(AvailableSpace const&, int column_count, int row_count); + void initialize_grid_tracks(AvailableSpace const&); void run_track_sizing(GridDimension const dimension, AvailableSpace const& available_space, Vector& tracks); CSSPixels content_based_minimum_height(GridItem const&); -- cgit v1.2.3