summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Tests/LibWeb/Layout/expected/grid/intrinsic-sized-column.txt6
-rw-r--r--Tests/LibWeb/Layout/expected/grid/intrinsic-sized-grid.txt6
-rw-r--r--Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp26
-rw-r--r--Userland/Libraries/LibWeb/Layout/GridFormattingContext.h2
4 files changed, 34 insertions, 6 deletions
diff --git a/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-column.txt b/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-column.txt
index f38e75368d..235abf0d33 100644
--- a/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-column.txt
+++ b/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-column.txt
@@ -1,10 +1,10 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x35.46875 [BFC] children: inline
TextNode <#text>
- BlockContainer <body> at (8,8) content-size 0x19.46875 floating [BFC] children: not-inline
- BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
+ BlockContainer <body> at (8,8) content-size 22x19.46875 floating [BFC] children: not-inline
+ BlockContainer <(anonymous)> at (8,8) content-size 22x0 children: inline
TextNode <#text>
- Box <div.grid> at (8,8) content-size 0x19.46875 [GFC] children: not-inline
+ Box <div.grid> at (8,8) content-size 22x19.46875 [GFC] children: not-inline
BlockContainer <(anonymous)> [BFC] children: inline
TextNode <#text>
BlockContainer <div.whee> at (9,9) content-size 18x17.46875 [BFC] children: inline
diff --git a/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-grid.txt b/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-grid.txt
index 6769ed3a4a..755d429042 100644
--- a/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-grid.txt
+++ b/Tests/LibWeb/Layout/expected/grid/intrinsic-sized-grid.txt
@@ -1,8 +1,8 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (1,1) content-size 798x39.46875 [BFC] children: not-inline
- BlockContainer <body> at (10,10) content-size 2x21.46875 floating [BFC] children: not-inline
- Box <div.grid> at (11,11) content-size 0x19.46875 [GFC] children: not-inline
- BlockContainer <div.whee> at (12,12) content-size 35.953125x17.46875 [BFC] children: inline
+ BlockContainer <body> at (10,10) content-size 41.953125x21.46875 floating [BFC] children: not-inline
+ Box <div.grid> at (11,11) content-size 39.953125x19.46875 [GFC] children: not-inline
+ BlockContainer <div.whee> at (12,12) content-size 37.953125x17.46875 [BFC] children: inline
line 0 width: 37.953125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 4, rect: [12,12 37.953125x17.46875]
"whee"
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index b0677f1762..821aa2bb0f 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -1487,12 +1487,38 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
grid_item.box());
}
+ if (available_space.height.is_intrinsic_sizing_constraint() || available_space.width.is_intrinsic_sizing_constraint())
+ determine_intrinsic_size_of_grid_container(available_space);
+
CSSPixels total_y = 0;
for (auto& grid_row : m_grid_rows)
total_y += grid_row.full_vertical_size();
m_automatic_content_height = total_y;
}
+void GridFormattingContext::determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space)
+{
+ // https://www.w3.org/TR/css-grid-1/#intrinsic-sizes
+ // The max-content size (min-content size) of a grid container is the sum of the grid container’s track sizes
+ // (including gutters) in the appropriate axis, when the grid is sized under a max-content constraint (min-content constraint).
+
+ if (available_space.height.is_intrinsic_sizing_constraint()) {
+ CSSPixels grid_container_height = 0;
+ for (auto& track : m_grid_rows) {
+ grid_container_height += track.full_vertical_size();
+ }
+ m_state.get_mutable(grid_container()).set_content_height(grid_container_height);
+ }
+
+ if (available_space.width.is_intrinsic_sizing_constraint()) {
+ CSSPixels grid_container_width = 0;
+ for (auto& track : m_grid_columns) {
+ grid_container_width += track.full_horizontal_size();
+ }
+ m_state.get_mutable(grid_container()).set_content_width(grid_container_width);
+ }
+}
+
CSSPixels GridFormattingContext::automatic_content_width() const
{
return greatest_child_width(context_box());
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
index 9eb9ffcfd7..2db8d0399f 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
@@ -146,6 +146,8 @@ private:
Vector<GridItem> m_grid_items;
Vector<JS::NonnullGCPtr<Box const>> m_boxes_to_place;
+ void determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space);
+
AvailableSize get_free_space(AvailableSize const& available_size, Vector<TemporaryTrack> const& tracks) const;
int get_line_index_by_line_name(String const& line_name, CSS::GridTrackSizeList);