summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authormartinfalisse <martinmotteditfalisse@gmail.com>2022-10-01 13:06:45 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-06 21:16:01 +0200
commit4dc2bd3df04369fd4f6284afdaea33cacbb3af43 (patch)
tree9bf9f7aa6cd0059046334c3bdb10a87d2a28c6b3 /Userland
parent6c22f9bf3f6a7eb22e30d2af0d253372a65481c1 (diff)
downloadserenity-4dc2bd3df04369fd4f6284afdaea33cacbb3af43.zip
LibWeb: Handle different span properties for GridTrackPlacement parsing
These changes improve the parsing of the span property, including handling negative values for the span (defaults to 1), as well as when no number is passed (also defaults to 1).
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp39
1 files changed, 31 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 287726e55e..6885994c70 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -5452,19 +5452,29 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
if (!tokens.has_next_token()) {
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("auto"sv))
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement());
+ // https://drafts.csswg.org/css-grid/#grid-placement-span-int
+ // If the <integer> is omitted, it defaults to 1.
+ if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv))
+ return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(1, true));
if (current_token.is(Token::Type::Number) && current_token.number().is_integer())
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value())));
return {};
}
- auto has_span = false;
+ auto is_span = false;
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv)) {
- has_span = true;
+ is_span = true;
tokens.skip_whitespace();
current_token = tokens.next_token().token();
}
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && !tokens.has_next_token())
- return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), has_span));
+
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && !tokens.has_next_token()) {
+ // https://drafts.csswg.org/css-grid/#grid-placement-span-int
+ // Negative integers or zero are invalid.
+ if (is_span && static_cast<int>(current_token.number_value()) < 1)
+ return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(1, is_span));
+ return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), is_span));
+ }
return {};
}
@@ -5476,20 +5486,33 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
if (!tokens.has_next_token()) {
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("auto"sv))
return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement::make_auto());
+ // https://drafts.csswg.org/css-grid/#grid-placement-span-int
+ // If the <integer> is omitted, it defaults to 1.
+ if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv))
+ return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(1, true));
if (current_token.is(Token::Type::Number) && current_token.number().is_integer())
return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(current_token.number_value()));
return {};
}
auto calculate_grid_track_placement = [](auto& current_token, auto& tokens) -> CSS::GridTrackPlacement {
- auto has_span = false;
+ auto is_span = false;
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv)) {
- has_span = true;
+ is_span = true;
tokens.skip_whitespace();
current_token = tokens.next_token().token();
}
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer())
- return CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), has_span);
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer()) {
+ // https://drafts.csswg.org/css-grid/#grid-placement-span-int
+ // Negative integers or zero are invalid.
+ if (is_span && static_cast<int>(current_token.number_value()) < 1)
+ return CSS::GridTrackPlacement(1, true);
+ return CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), is_span);
+ }
+ // https://drafts.csswg.org/css-grid/#grid-placement-span-int
+ // If the <integer> is omitted, it defaults to 1.
+ if (is_span && current_token.is(Token::Type::Delim) && current_token.delim() == "/"sv)
+ return CSS::GridTrackPlacement(1, true);
return CSS::GridTrackPlacement();
};