1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibWeb: Parse grid-template-columns and grid-template-rows

Add functionality to begin parsing grid-template-columns and
grid-template-rows. There are still things to be added, like parsing
functions, but I would say a couple of the major points are already
adressed like length, percentage, and flexible-length.
This commit is contained in:
martinfalisse 2022-08-23 19:49:07 +02:00 committed by Andreas Kling
parent c40dd9ee78
commit 92a00648b1
8 changed files with 87 additions and 0 deletions

View file

@ -5301,6 +5301,30 @@ RefPtr<StyleValue> Parser::parse_as_css_value(PropertyID property_id)
return parsed_value.release_value();
}
RefPtr<StyleValue> Parser::parse_grid_track_sizes(Vector<ComponentValue> const& component_values)
{
Vector<CSS::GridTrackSize> params;
for (auto& component_value : component_values) {
// FIXME: Incomplete as a GridTrackSize can be a function like minmax(min, max), etc.
if (component_value.is_function())
return {};
if (component_value.is(Token::Type::Ident) && component_value.token().ident().equals_ignoring_case("auto"sv)) {
params.append(Length::make_auto());
continue;
}
auto dimension = parse_dimension(component_value);
if (!dimension.has_value())
return {};
if (dimension->is_length())
params.append(dimension->length());
if (dimension->is_percentage())
params.append(dimension->percentage());
}
if (params.size() == 0)
return {};
return GridTrackSizeStyleValue::create(params);
}
Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(PropertyID property_id, TokenStream<ComponentValue>& tokens)
{
auto function_contains_var_or_attr = [](Function const& function, auto&& recurse) -> bool {
@ -5431,6 +5455,14 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
if (auto parsed_value = parse_font_family_value(component_values))
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::GridTemplateColumns:
if (auto parsed_value = parse_grid_track_sizes(component_values))
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::GridTemplateRows:
if (auto parsed_value = parse_grid_track_sizes(component_values))
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::ListStyle:
if (auto parsed_value = parse_list_style_value(component_values))
return parsed_value.release_nonnull();