Skip to content

Commit 6b649b6

Browse files
martinfalisseawesomekling
authored andcommitted
LibWeb: Start sizing grid tracks
The second part of formatting the display grid is calculating the sizes of the columns and rows.
1 parent 902bdc8 commit 6b649b6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,45 @@ void GridFormattingContext::run(Box const& box, LayoutMode)
368368

369369
// FIXME: 4.2. For dense packing:
370370
}
371+
372+
// https://drafts.csswg.org/css-grid/#overview-sizing
373+
// 2.3. Sizing the Grid
374+
// Once the grid items have been placed, the sizes of the grid tracks (rows and columns) are
375+
// calculated, accounting for the sizes of their contents and/or available space as specified in
376+
// the grid definition.
377+
378+
// https://drafts.csswg.org/css-grid/#layout-algorithm
379+
// 12. Grid Sizing
380+
// This section defines the grid sizing algorithm, which determines the size of all grid tracks and,
381+
// by extension, the entire grid.
382+
383+
// Each track has specified minimum and maximum sizing functions (which may be the same). Each
384+
// sizing function is either:
385+
386+
// - A fixed sizing function (<length> or resolvable <percentage>).
387+
// - An intrinsic sizing function (min-content, max-content, auto, fit-content()).
388+
// - A flexible sizing function (<flex>).
389+
390+
// The grid sizing algorithm defines how to resolve these sizing constraints into used track sizes.
391+
392+
struct GridTrack {
393+
CSS::GridTrackSize min_track_sizing_function;
394+
CSS::GridTrackSize max_track_sizing_function;
395+
float base_size { 0 };
396+
float growth_limit { 0 };
397+
};
398+
Vector<GridTrack> grid_rows;
399+
Vector<GridTrack> grid_columns;
400+
401+
for (auto& column_size : box.computed_values().grid_template_columns())
402+
grid_columns.append({ column_size, column_size });
403+
for (auto& row_size : box.computed_values().grid_template_rows())
404+
grid_rows.append({ row_size, row_size });
405+
406+
for (int column_index = grid_columns.size(); column_index < static_cast<int>(occupation_grid[0].size()); column_index++)
407+
grid_columns.append({ CSS::GridTrackSize::make_auto(), CSS::GridTrackSize::make_auto() });
408+
for (int row_index = grid_rows.size(); row_index < static_cast<int>(occupation_grid.size()); row_index++)
409+
grid_rows.append({ CSS::GridTrackSize::make_auto(), CSS::GridTrackSize::make_auto() });
371410
}
372411

373412
}

0 commit comments

Comments
 (0)