diff --git a/Tests/LibWeb/Text/expected/getComputedStyle-grid-template-rows-columns.txt b/Tests/LibWeb/Text/expected/getComputedStyle-grid-template-rows-columns.txt
new file mode 100644
index 0000000000..4e418b8e1f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/getComputedStyle-grid-template-rows-columns.txt
@@ -0,0 +1,2 @@
+ 100px 100px
+50px 50px
diff --git a/Tests/LibWeb/Text/input/getComputedStyle-grid-template-rows-columns.html b/Tests/LibWeb/Text/input/getComputedStyle-grid-template-rows-columns.html
new file mode 100644
index 0000000000..b75e03aa34
--- /dev/null
+++ b/Tests/LibWeb/Text/input/getComputedStyle-grid-template-rows-columns.html
@@ -0,0 +1,21 @@
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
index c5abdca7ce..af68458823 100644
--- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
@@ -250,6 +250,16 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert
return style_value_for_shadow(layout_node.computed_values().box_shadow());
case PropertyID::Color:
return CSSColorValue::create_from_color(layout_node.computed_values().color());
+ // For grid-template-columns and grid-template-rows the resolved value is the used value.
+ // https://www.w3.org/TR/css-grid-2/#resolved-track-list-standalone
+ case PropertyID::GridTemplateColumns: {
+ auto const& paintable_box = verify_cast(*layout_node.paintable());
+ return paintable_box.used_values_for_grid_template_columns();
+ }
+ case PropertyID::GridTemplateRows: {
+ auto const& paintable_box = verify_cast(*layout_node.paintable());
+ return paintable_box.used_values_for_grid_template_rows();
+ }
case PropertyID::OutlineColor:
return CSSColorValue::create_from_color(layout_node.computed_values().outline_color());
case PropertyID::TextDecorationColor:
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index b55efa2ef4..5c475a930b 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -1873,6 +1873,23 @@ void GridFormattingContext::run(Box const&, LayoutMode, AvailableSpace const& av
if (auto independent_formatting_context = layout_inside(grid_item.box, LayoutMode::Normal, available_space_for_children))
independent_formatting_context->parent_context_did_dimension_child_root_box();
}
+
+ Vector> grid_track_columns;
+ grid_track_columns.ensure_capacity(m_grid_columns.size());
+ for (auto const& column : m_grid_columns) {
+ grid_track_columns.append(CSS::ExplicitGridTrack { CSS::GridSize { CSS::LengthPercentage(CSS::Length::make_px(column.base_size)) } });
+ }
+
+ Vector> grid_track_rows;
+ grid_track_rows.ensure_capacity(m_grid_rows.size());
+ for (auto const& row : m_grid_rows) {
+ grid_track_rows.append(CSS::ExplicitGridTrack { CSS::GridSize { CSS::LengthPercentage(CSS::Length::make_px(row.base_size)) } });
+ }
+
+ // getComputedStyle() needs to return the resolved values of grid-template-columns and grid-template-rows
+ // so they need to be saved in the state, and then assigned to paintables in LayoutState::commit()
+ m_state.get_mutable(grid_container()).set_grid_template_columns(CSS::GridTrackSizeListStyleValue::create(move(grid_track_columns)));
+ m_state.get_mutable(grid_container()).set_grid_template_rows(CSS::GridTrackSizeListStyleValue::create(move(grid_track_rows)));
}
void GridFormattingContext::layout_absolutely_positioned_element(Box const& box, AvailableSpace const& available_space)
diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp
index 9f55d639aa..5cea70823e 100644
--- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp
@@ -278,6 +278,11 @@ void LayoutState::commit(Box& root)
auto& svg_geometry_paintable = static_cast(paintable_box);
svg_geometry_paintable.set_computed_path(move(*used_values.computed_svg_path()));
}
+
+ if (node.display().is_grid_inside()) {
+ paintable_box.set_used_values_for_grid_template_columns(used_values.grid_template_columns());
+ paintable_box.set_used_values_for_grid_template_rows(used_values.grid_template_rows());
+ }
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h
index fe0f0fcfb0..0bab0f50ef 100644
--- a/Userland/Libraries/LibWeb/Layout/LayoutState.h
+++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h
@@ -139,6 +139,12 @@ struct LayoutState {
void set_computed_svg_transforms(Painting::SVGGraphicsPaintable::ComputedTransforms const& computed_transforms) { m_computed_svg_transforms = computed_transforms; }
auto const& computed_svg_transforms() const { return m_computed_svg_transforms; }
+ void set_grid_template_columns(RefPtr used_values_for_grid_template_columns) { m_grid_template_columns = move(used_values_for_grid_template_columns); }
+ auto const& grid_template_columns() const { return m_grid_template_columns; }
+
+ void set_grid_template_rows(RefPtr used_values_for_grid_template_rows) { m_grid_template_rows = move(used_values_for_grid_template_rows); }
+ auto const& grid_template_rows() const { return m_grid_template_rows; }
+
private:
AvailableSize available_width_inside() const;
AvailableSize available_height_inside() const;
@@ -166,6 +172,9 @@ struct LayoutState {
Optional m_computed_svg_path;
Optional m_computed_svg_transforms;
+
+ RefPtr m_grid_template_columns;
+ RefPtr m_grid_template_rows;
};
// Commits the used values produced by layout and builds a paintable tree.
diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.h b/Userland/Libraries/LibWeb/Painting/PaintableBox.h
index 973d69f38c..448528cbeb 100644
--- a/Userland/Libraries/LibWeb/Painting/PaintableBox.h
+++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.h
@@ -6,6 +6,7 @@
#pragma once
+#include
#include
#include
#include
@@ -227,6 +228,12 @@ public:
[[nodiscard]] bool is_scrollable() const;
+ void set_used_values_for_grid_template_columns(RefPtr style_value) { m_used_values_for_grid_template_columns = move(style_value); }
+ RefPtr const& used_values_for_grid_template_columns() const { return m_used_values_for_grid_template_columns; }
+
+ void set_used_values_for_grid_template_rows(RefPtr style_value) { m_used_values_for_grid_template_rows = move(style_value); }
+ RefPtr const& used_values_for_grid_template_rows() const { return m_used_values_for_grid_template_rows; }
+
protected:
explicit PaintableBox(Layout::Box const&);
@@ -287,6 +294,9 @@ private:
ResolvedBackground m_resolved_background;
OwnPtr m_sticky_insets;
+
+ RefPtr m_used_values_for_grid_template_columns;
+ RefPtr m_used_values_for_grid_template_rows;
};
class PaintableWithLines : public PaintableBox {