1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

LibWeb: Adjust grid columns size to fit spanning items

This change implements following paragraph from placement algorithm in
the spec:
"If the largest column span among all the items without a definite
column position is larger than the width of the implicit grid, add
columns to the end of the implicit grid to accommodate that column
span."

There were places in the grid implementation code with copies of this
text, but those were completely unrelated to the code where they were
being pasted so I removed them.
This commit is contained in:
Aliaksandr Kalenik 2023-07-13 15:49:07 +02:00 committed by Andreas Kling
parent c0f985ffcf
commit e2c5e31292
4 changed files with 34 additions and 10 deletions

View file

@ -362,11 +362,6 @@ void GridFormattingContext::place_item_with_row_position(Box const& child_box)
int column_start = 0;
size_t column_span = child_box.computed_values().grid_column_start().is_span() ? child_box.computed_values().grid_column_start().raw_value() : 1;
// https://drafts.csswg.org/css-grid/#auto-placement-algo
// 8.5. Grid Item Placement Algorithm
// 3.3. If the largest column span among all the items without a definite column position is larger
// than the width of the implicit grid, add columns to the end of the implicit grid to accommodate
// that column span.
bool found_available_column = false;
for (size_t column_index = column_start; column_index < m_occupation_grid.column_count(); column_index++) {
if (!m_occupation_grid.is_occupied(column_index, row_start)) {
@ -531,11 +526,6 @@ void GridFormattingContext::place_item_with_no_declared_position(Box const& chil
column_span = child_box.computed_values().grid_column_start().raw_value();
else if (child_box.computed_values().grid_column_end().is_span())
column_span = child_box.computed_values().grid_column_end().raw_value();
// https://drafts.csswg.org/css-grid/#auto-placement-algo
// 8.5. Grid Item Placement Algorithm
// 3.3. If the largest column span among all the items without a definite column position is larger
// than the width of the implicit grid, add columns to the end of the implicit grid to accommodate
// that column span.
auto row_start = 0;
size_t row_span = 1;
if (child_box.computed_values().grid_row_start().is_span())
@ -1371,6 +1361,20 @@ void GridFormattingContext::place_grid_items(AvailableSpace const& available_spa
// and 2, respectively. Adding columns for "items not yet positioned but with a definite column"
// will be done in step 4.
// 3.3. If the largest column span among all the items without a definite column position is larger
// than the width of the implicit grid, add columns to the end of the implicit grid to accommodate
// that column span.
for (auto const& child_box : m_boxes_to_place) {
int column_span = 1;
if (child_box->computed_values().grid_column_start().is_span())
column_span = child_box->computed_values().grid_column_start().raw_value();
else if (child_box->computed_values().grid_column_end().is_span())
column_span = child_box->computed_values().grid_column_end().raw_value();
if (column_span - 1 > m_occupation_grid.max_column_index())
m_occupation_grid.set_max_column_index(column_span - 1);
}
// 4. Position the remaining grid items.
// For each grid item that hasn't been positioned by the previous steps, in order-modified document
// order: