From 749dcac196aea3429e84ba49c03621a7ad925845 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 6 Mar 2024 16:44:35 +0100 Subject: [PATCH] LibWeb: Add record_grid_placement() helper in GFC When placement position is found we always want to do following: - Mark the occupied cells in the occupation grid - Add the item to the list of placed items Therefore, having helper that does both is useful --- .../LibWeb/Layout/GridFormattingContext.cpp | 19 ++++++++++--------- .../LibWeb/Layout/GridFormattingContext.h | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index d70d27e319..46d1422d46 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -223,14 +223,12 @@ void GridFormattingContext::place_item_with_row_and_column_position(Box const& c auto column_start = column_placement_position.start; auto column_span = column_placement_position.span; - m_grid_items.append(GridItem { + record_grid_placement(GridItem { .box = child_box, .row = row_start, .row_span = row_span, .column = column_start, .column_span = column_span }); - - m_occupation_grid.set_occupied(column_start, column_start + column_span, row_start, row_start + row_span); } void GridFormattingContext::place_item_with_row_position(Box const& child_box) @@ -254,9 +252,8 @@ void GridFormattingContext::place_item_with_row_position(Box const& child_box) if (!found_available_column) { column_start = m_occupation_grid.column_count(); } - m_occupation_grid.set_occupied(column_start, column_start + column_span, row_start, row_start + row_span); - m_grid_items.append(GridItem { + record_grid_placement(GridItem { .box = child_box, .row = row_start, .row_span = row_span, @@ -289,9 +286,8 @@ void GridFormattingContext::place_item_with_column_position(Box const& child_box } // 4.1.1.3. Set the item's row-start line to the cursor's row position, and set the item's row-end // line according to its span from that position. - m_occupation_grid.set_occupied(column_start, column_start + column_span, auto_placement_cursor_y, auto_placement_cursor_y + row_span); - m_grid_items.append(GridItem { + record_grid_placement(GridItem { .box = child_box, .row = auto_placement_cursor_y, .row_span = row_span, @@ -384,8 +380,7 @@ void GridFormattingContext::place_item_with_no_declared_position(Box const& chil auto_placement_cursor_y += row_span - 1; } - m_occupation_grid.set_occupied(column_start, column_start + column_span, row_start, row_start + row_span); - m_grid_items.append(GridItem { + record_grid_placement(GridItem { .box = child_box, .row = row_start, .row_span = row_span, @@ -393,6 +388,12 @@ void GridFormattingContext::place_item_with_no_declared_position(Box const& chil .column_span = column_span }); } +void GridFormattingContext::record_grid_placement(GridItem grid_item) +{ + m_occupation_grid.set_occupied(grid_item.column, grid_item.column + grid_item.column_span, grid_item.row, grid_item.row + grid_item.row_span); + m_grid_items.append(grid_item); +} + void GridFormattingContext::initialize_grid_tracks_from_definition(GridDimension dimension) { auto const& grid_computed_values = grid_container().computed_values(); diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h index a0e58df1ad..7f06b0151e 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h @@ -266,6 +266,7 @@ private: 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 record_grid_placement(GridItem); void initialize_grid_tracks_from_definition(GridDimension); void initialize_grid_tracks_for_columns_and_rows();