From 37f5253ec9a0c3b28de8f5087a98af686631cefb Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 17 Aug 2023 20:25:51 +0200 Subject: [PATCH] LibWeb/Layout: Add support for `grid-auto-flow` in GFC --- .../Layout/expected/grid/auto-flow-column.txt | 21 +++++++++++++++++++ .../Layout/input/grid/auto-flow-column.html | 8 +++++++ .../LibWeb/Layout/GridFormattingContext.cpp | 12 ++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/grid/auto-flow-column.txt create mode 100644 Tests/LibWeb/Layout/input/grid/auto-flow-column.html diff --git a/Tests/LibWeb/Layout/expected/grid/auto-flow-column.txt b/Tests/LibWeb/Layout/expected/grid/auto-flow-column.txt new file mode 100644 index 00000000000..f125c2f16f3 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/auto-flow-column.txt @@ -0,0 +1,21 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x37.46875 [BFC] children: not-inline + Box at (10,10) content-size 200x19.46875 [GFC] children: not-inline + BlockContainer
at (11,11) content-size 98x17.46875 [BFC] children: inline + line 0 width: 36.84375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 5, rect: [11,11 36.84375x17.46875] + "hello" + TextNode <#text> + BlockContainer
at (111,11) content-size 98x17.46875 [BFC] children: inline + line 0 width: 55.359375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 7, rect: [111,11 55.359375x17.46875] + "friends" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x39.46875] + PaintableBox (Box) [9,9 202x21.46875] + PaintableWithLines (BlockContainer
) [10,10 100x19.46875] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer
) [110,10 100x19.46875] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/grid/auto-flow-column.html b/Tests/LibWeb/Layout/input/grid/auto-flow-column.html new file mode 100644 index 00000000000..5a144c8312a --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/auto-flow-column.html @@ -0,0 +1,8 @@ +
hello
friends
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index d9254332e83..cb4fd26602b 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -534,6 +534,8 @@ void GridFormattingContext::place_item_with_no_declared_position(Box const& chil row_span = child_box.computed_values().grid_row_end().raw_value(); auto found_unoccupied_area = false; + auto const& auto_flow = grid_container().computed_values().grid_auto_flow(); + while (true) { while (auto_placement_cursor_x <= m_occupation_grid.max_column_index()) { if (auto_placement_cursor_x + static_cast(column_span) <= m_occupation_grid.max_column_index() + 1) { @@ -562,9 +564,13 @@ void GridFormattingContext::place_item_with_no_declared_position(Box const& chil // row position (creating new rows in the implicit grid as necessary), set its column position to the // start-most column line in the implicit grid, and return to the previous step. if (!found_unoccupied_area) { - auto_placement_cursor_x = m_occupation_grid.min_column_index(); - auto_placement_cursor_y++; - row_start = auto_placement_cursor_y; + if (auto_flow.row) { + auto_placement_cursor_x = m_occupation_grid.min_column_index(); + auto_placement_cursor_y++; + } else { + m_occupation_grid.set_max_column_index(auto_placement_cursor_x); + auto_placement_cursor_y = m_occupation_grid.min_row_index(); + } } }