Procházet zdrojové kódy

LibWeb/Layout: Add support for `grid-auto-flow` in GFC

Aliaksandr Kalenik před 1 rokem
rodič
revize
37f5253ec9

+ 21 - 0
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 <html> at (1,1) content-size 798x37.46875 [BFC] children: not-inline
+    Box <body> at (10,10) content-size 200x19.46875 [GFC] children: not-inline
+      BlockContainer <div> 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 <div> 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<HTML>) [0,0 800x39.46875]
+    PaintableBox (Box<BODY>) [9,9 202x21.46875]
+      PaintableWithLines (BlockContainer<DIV>) [10,10 100x19.46875]
+        TextPaintable (TextNode<#text>)
+      PaintableWithLines (BlockContainer<DIV>) [110,10 100x19.46875]
+        TextPaintable (TextNode<#text>)

+ 8 - 0
Tests/LibWeb/Layout/input/grid/auto-flow-column.html

@@ -0,0 +1,8 @@
+<!doctype html><style>
+    * { border: 1px solid black; }
+    body {
+        display: grid;
+        grid-auto-flow: column;
+        width: 200px;
+    }
+</style><body><div>hello</div><div>friends</div>

+ 9 - 3
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<int>(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();
+            }
         }
     }