summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp68
1 files changed, 22 insertions, 46 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 9ec03bdc88..e1e187c664 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -5489,59 +5489,35 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
auto tokens = TokenStream { component_values };
auto current_token = tokens.next_token().token();
- 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));
- // https://drafts.csswg.org/css-grid/#grid-placement-int
- // [ <integer [−∞,−1]> | <integer [1,∞]> ] && <custom-ident>?
- // An <integer> value of zero makes the declaration invalid.
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() != 0)
- return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(current_token.number_value()));
- return {};
+ Vector<ComponentValue> track_start_placement_tokens;
+ while (true) {
+ if (current_token.is(Token::Type::Delim) && current_token.delim() == "/"sv)
+ break;
+ track_start_placement_tokens.append(current_token);
+ if (!tokens.has_next_token())
+ break;
+ current_token = tokens.next_token().token();
}
- auto calculate_grid_track_placement = [](auto& current_token, auto& tokens) -> Optional<CSS::GridTrackPlacement> {
- auto is_span = false;
- if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv)) {
- is_span = true;
- tokens.skip_whitespace();
+ Vector<ComponentValue> track_end_placement_tokens;
+ if (tokens.has_next_token()) {
+ current_token = tokens.next_token().token();
+ while (true) {
+ track_end_placement_tokens.append(current_token);
+ if (!tokens.has_next_token())
+ break;
current_token = tokens.next_token().token();
}
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() != 0) {
- // 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-int
- // [ <integer [−∞,−1]> | <integer [1,∞]> ] && <custom-ident>?
- // An <integer> value of zero makes the declaration invalid.
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() == 0)
- return {};
- // 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();
- };
+ }
- auto first_grid_track_placement = calculate_grid_track_placement(current_token, tokens);
- if (!tokens.has_next_token() && first_grid_track_placement.has_value())
- return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(first_grid_track_placement.value()));
+ auto parsed_start_value = parse_grid_track_placement(track_start_placement_tokens);
+ if (parsed_start_value && track_end_placement_tokens.is_empty())
+ return GridTrackPlacementShorthandStyleValue::create(parsed_start_value.release_nonnull()->as_grid_track_placement().grid_track_placement());
- tokens.skip_whitespace();
- current_token = tokens.next_token().token();
- tokens.skip_whitespace();
- current_token = tokens.next_token().token();
+ auto parsed_end_value = parse_grid_track_placement(track_end_placement_tokens);
+ if (parsed_start_value && parsed_end_value)
+ return GridTrackPlacementShorthandStyleValue::create(parsed_start_value.release_nonnull()->as_grid_track_placement(), parsed_end_value.release_nonnull()->as_grid_track_placement());
- auto second_grid_track_placement = calculate_grid_track_placement(current_token, tokens);
- if (!tokens.has_next_token() && first_grid_track_placement.has_value() && second_grid_track_placement.has_value())
- return GridTrackPlacementShorthandStyleValue::create(GridTrackPlacementStyleValue::create(first_grid_track_placement.value()), GridTrackPlacementStyleValue::create(second_grid_track_placement.value()));
return {};
}