From 9e2b70661ef1c13252a4b213fbd3b735f7301116 Mon Sep 17 00:00:00 2001 From: Neil Viloria Date: Wed, 9 Oct 2024 23:45:12 -0600 Subject: [PATCH] LibWeb/Layout: Unify grid justify-content handling for grid area --- .../expected/grid/justify-content-cols.txt | 12 +- .../expected/grid/justify-content-fr.txt | 133 ++++++++++++++++++ .../Layout/input/grid/justify-content-fr.html | 56 ++++++++ .../LibWeb/Layout/GridFormattingContext.cpp | 20 +-- 4 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/grid/justify-content-fr.txt create mode 100644 Tests/LibWeb/Layout/input/grid/justify-content-fr.html diff --git a/Tests/LibWeb/Layout/expected/grid/justify-content-cols.txt b/Tests/LibWeb/Layout/expected/grid/justify-content-cols.txt index 280bf51a476..b8e387f3dea 100644 --- a/Tests/LibWeb/Layout/expected/grid/justify-content-cols.txt +++ b/Tests/LibWeb/Layout/expected/grid/justify-content-cols.txt @@ -60,13 +60,13 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline Box at (8,168) content-size 784x20 [GFC] children: not-inline BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> - BlockContainer
at (108.65625,168) content-size 60x20 [BFC] children: not-inline + BlockContainer
at (108.671875,168) content-size 60x20 [BFC] children: not-inline BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> - BlockContainer
at (369.984375,168) content-size 60x20 [BFC] children: not-inline + BlockContainer
at (370,168) content-size 60x20 [BFC] children: not-inline BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> - BlockContainer
at (631.3125,168) content-size 60x20 [BFC] children: not-inline + BlockContainer
at (631.328125,168) content-size 60x20 [BFC] children: not-inline BlockContainer <(anonymous)> (not painted) [BFC] children: inline TextNode <#text> BlockContainer <(anonymous)> at (8,208) content-size 784x0 children: inline @@ -124,9 +124,9 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer
) [160,128 60x20] PaintableWithLines (BlockContainer(anonymous)) [8,168 784x0] PaintableBox (Box
.grid.justify-space-around) [8,168 784x20] - PaintableWithLines (BlockContainer
) [108.65625,168 60x20] - PaintableWithLines (BlockContainer
) [369.984375,168 60x20] - PaintableWithLines (BlockContainer
) [631.3125,168 60x20] + PaintableWithLines (BlockContainer
) [108.671875,168 60x20] + PaintableWithLines (BlockContainer
) [370,168 60x20] + PaintableWithLines (BlockContainer
) [631.328125,168 60x20] PaintableWithLines (BlockContainer(anonymous)) [8,208 784x0] PaintableBox (Box
.grid.justify-space-between) [8,208 784x20] PaintableWithLines (BlockContainer
) [8,208 60x20] diff --git a/Tests/LibWeb/Layout/expected/grid/justify-content-fr.txt b/Tests/LibWeb/Layout/expected/grid/justify-content-fr.txt new file mode 100644 index 00000000000..4a31d4debf4 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/justify-content-fr.txt @@ -0,0 +1,133 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x252 [BFC] children: not-inline + Box at (28,28) content-size 744x196 flex-container(row) [FFC] children: not-inline + Box at (30,30) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (30,30) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (135,30) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (240,30) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + Box at (354,30) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (354,30) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (459,30) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (564,30) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + Box at (30,84) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (30,84) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (135,84) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (240,84) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + Box at (354,84) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (354,84) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (459,84) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (564,84) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + Box at (30,138) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (30,138) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (135,138) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (240,138) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + Box at (354,138) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (354,138) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (459,138) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (564,138) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + Box at (30,192) content-size 300x30 flex-item [GFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (30,192) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (135,192) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer at (240,192) content-size 90x30 [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x252] + PaintableBox (Box) [8,8 784x236] + PaintableBox (Box
.container) [28,28 304x34] + PaintableWithLines (BlockContainer
.item) [30,30 90x30] + PaintableWithLines (BlockContainer
.item) [135,30 90x30] + PaintableWithLines (BlockContainer
.item) [240,30 90x30] + PaintableBox (Box
.container) [352,28 304x34] + PaintableWithLines (BlockContainer
.item) [354,30 90x30] + PaintableWithLines (BlockContainer
.item) [459,30 90x30] + PaintableWithLines (BlockContainer
.item) [564,30 90x30] + PaintableBox (Box
.container) [28,82 304x34] + PaintableWithLines (BlockContainer
.item) [30,84 90x30] + PaintableWithLines (BlockContainer
.item) [135,84 90x30] + PaintableWithLines (BlockContainer
.item) [240,84 90x30] + PaintableBox (Box
.container) [352,82 304x34] + PaintableWithLines (BlockContainer
.item) [354,84 90x30] + PaintableWithLines (BlockContainer
.item) [459,84 90x30] + PaintableWithLines (BlockContainer
.item) [564,84 90x30] + PaintableBox (Box
.container) [28,136 304x34] + PaintableWithLines (BlockContainer
.item) [30,138 90x30] + PaintableWithLines (BlockContainer
.item) [135,138 90x30] + PaintableWithLines (BlockContainer
.item) [240,138 90x30] + PaintableBox (Box
.container) [352,136 304x34] + PaintableWithLines (BlockContainer
.item) [354,138 90x30] + PaintableWithLines (BlockContainer
.item) [459,138 90x30] + PaintableWithLines (BlockContainer
.item) [564,138 90x30] + PaintableBox (Box
.container) [28,190 304x34] + PaintableWithLines (BlockContainer
.item) [30,192 90x30] + PaintableWithLines (BlockContainer
.item) [135,192 90x30] + PaintableWithLines (BlockContainer
.item) [240,192 90x30] diff --git a/Tests/LibWeb/Layout/input/grid/justify-content-fr.html b/Tests/LibWeb/Layout/input/grid/justify-content-fr.html new file mode 100644 index 00000000000..93f3b0062b5 --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/justify-content-fr.html @@ -0,0 +1,56 @@ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 3f4d6a6d7c6..e5925a04612 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -1817,31 +1817,15 @@ CSSPixelRect GridFormattingContext::get_grid_area_rect(GridItem const& grid_item CSSPixels x_start = 0; CSSPixels x_end = 0; - if (justify_content == CSS::JustifyContent::Center) { + if (justify_content == CSS::JustifyContent::Center || justify_content == CSS::JustifyContent::SpaceAround || justify_content == CSS::JustifyContent::SpaceEvenly) { auto free_space = grid_container_width - sum_base_size_of_columns_and_gaps; + free_space = max(free_space, 0); x_start = free_space / 2; x_end = free_space / 2; } else if (justify_content == CSS::JustifyContent::End || justify_content == CSS::JustifyContent::Right) { auto free_space = grid_container_width - sum_base_size_of_columns_and_gaps; x_start = free_space; x_end = free_space; - } else if (justify_content == CSS::JustifyContent::SpaceAround) { - auto free_space = grid_container_width - sum_base_size_of_columns; - free_space = max(free_space, 0); - - auto gap_space = free_space / (m_column_gap_tracks.size() + 1); - auto gap_half_space = gap_space / 2; - - x_start = CSSPixels(gap_half_space); - x_end = CSSPixels(gap_half_space); - } else if (justify_content == CSS::JustifyContent::SpaceEvenly) { - auto free_space = grid_container_width - sum_base_size_of_columns; - free_space = max(free_space, 0); - - auto gap_space = free_space / (m_grid_columns.size() + 1); - - x_start = gap_space; - x_end = gap_space; } auto grid_container_height = m_available_space->height.to_px_or_zero();