summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authormartinfalisse <martinmotteditfalisse@gmail.com>2023-04-01 19:09:19 +0200
committerAndreas Kling <kling@serenityos.org>2023-04-02 19:08:04 +0200
commit6f52272d34baa4c6da2e0976a05ba71beec67eb5 (patch)
tree81817b3983b43be78bc7d9a86664cabdf93b272b /Userland/Libraries
parente65f4b3dc5b6224241aa466abff308cc04b83085 (diff)
downloadserenity-6f52272d34baa4c6da2e0976a05ba71beec67eb5.zip
LibWeb: Fix regression in definite grid row heights
Fixes a row height bug when a grid item in a row has a definite height.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp23
-rw-r--r--Userland/Libraries/LibWeb/Layout/GridFormattingContext.h2
2 files changed, 20 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index efec5fc9d5..31dbc54287 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -1261,7 +1261,7 @@ void GridFormattingContext::calculate_sizes_of_rows(Box const& box)
case CSS::GridSize::Type::MinContent: {
CSSPixels row_height = 0;
for (auto& grid_item : grid_items_of_row)
- row_height = max(row_height, calculate_min_content_height(grid_item.box(), AvailableSize::make_definite(m_grid_columns[grid_item.gap_adjusted_column(box)].base_size)));
+ row_height = max(row_height, content_based_minimum_height(grid_item, box));
grid_row.base_size = row_height;
} break;
// - For max-content minimums:
@@ -1270,7 +1270,7 @@ void GridFormattingContext::calculate_sizes_of_rows(Box const& box)
case CSS::GridSize::Type::MaxContent: {
CSSPixels row_height = 0;
for (auto& grid_item : grid_items_of_row)
- row_height = max(row_height, calculate_max_content_height(grid_item.box(), AvailableSize::make_definite(m_grid_columns[grid_item.gap_adjusted_column(box)].base_size)));
+ row_height = max(row_height, content_based_minimum_height(grid_item, box));
grid_row.base_size = row_height;
} break;
// - For auto minimums:
@@ -1294,7 +1294,7 @@ void GridFormattingContext::calculate_sizes_of_rows(Box const& box)
case CSS::GridSize::Type::FlexibleLength: {
CSSPixels grid_row_height = 0;
for (auto& grid_item : grid_items_of_row)
- grid_row_height = max(grid_row_height, calculate_min_content_height(grid_item.box(), AvailableSize::make_definite(m_grid_columns[grid_item.gap_adjusted_column(box)].base_size)));
+ grid_row_height = max(grid_row_height, content_based_minimum_height(grid_item, box));
grid_row.base_size = grid_row_height;
} break;
default:
@@ -1308,7 +1308,7 @@ void GridFormattingContext::calculate_sizes_of_rows(Box const& box)
case CSS::GridSize::Type::MinContent: {
CSSPixels row_height = 0;
for (auto& grid_item : grid_items_of_row)
- row_height = max(row_height, calculate_max_content_height(grid_item.box(), AvailableSize::make_definite(m_grid_columns[grid_item.gap_adjusted_column(box)].base_size)));
+ row_height = max(row_height, content_based_minimum_height(grid_item, box));
grid_row.base_size = row_height;
} break;
// - For max-content maximums:
@@ -1318,7 +1318,7 @@ void GridFormattingContext::calculate_sizes_of_rows(Box const& box)
case CSS::GridSize::Type::MaxContent: {
CSSPixels row_height = 0;
for (auto& grid_item : grid_items_of_row)
- row_height = max(row_height, calculate_max_content_height(grid_item.box(), AvailableSize::make_definite(m_grid_columns[grid_item.gap_adjusted_column(box)].base_size)));
+ row_height = max(row_height, content_based_minimum_height(grid_item, box));
grid_row.base_size = row_height;
} break;
case CSS::GridSize::Type::Length:
@@ -2056,4 +2056,17 @@ int GridItem::gap_adjusted_column(Box const& parent_box) const
return parent_box.computed_values().column_gap().is_auto() ? m_column : m_column * 2;
}
+// https://www.w3.org/TR/css-grid-2/#min-size-auto
+CSSPixels GridFormattingContext::content_based_minimum_height(GridItem const& item, Box const& parent_box)
+{
+ // The content-based minimum size for a grid item in a given dimension is its specified size suggestion if it exists
+ if (!item.box().computed_values().height().is_auto()) {
+ if (item.box().computed_values().height().is_length())
+ return item.box().computed_values().height().length().to_px(item.box());
+ }
+ // FIXME: otherwise its transferred size suggestion if that exists
+ // else its content size suggestion
+ return calculate_min_content_height(item.box(), AvailableSize::make_definite(m_grid_columns[item.gap_adjusted_column(parent_box)].base_size));
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
index b2f4a2b8f6..94655e4d9c 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
@@ -145,6 +145,8 @@ private:
void initialize_grid_tracks(Box const&, AvailableSpace const&, int column_count, int row_count);
void calculate_sizes_of_columns(Box const&, AvailableSpace const&);
void calculate_sizes_of_rows(Box const&);
+
+ CSSPixels content_based_minimum_height(GridItem const&, Box const& parent_box);
};
}