Skip to content

Commit 2efaadd

Browse files
committed
LibWeb: Parse aspect-ratio property using TokenStream
1 parent 647d52f commit 2efaadd

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,13 +2682,13 @@ static void remove_property(Vector<PropertyID>& properties, PropertyID property_
26822682
}
26832683

26842684
// https://www.w3.org/TR/css-sizing-4/#aspect-ratio
2685-
RefPtr<StyleValue> Parser::parse_aspect_ratio_value(Vector<ComponentValue> const& component_values)
2685+
RefPtr<StyleValue> Parser::parse_aspect_ratio_value(TokenStream<ComponentValue>& tokens)
26862686
{
26872687
// `auto || <ratio>`
26882688
RefPtr<StyleValue> auto_value;
26892689
RefPtr<StyleValue> ratio_value;
26902690

2691-
auto tokens = TokenStream { component_values };
2691+
auto transaction = tokens.begin_transaction();
26922692
while (tokens.has_next_token()) {
26932693
auto maybe_value = parse_css_value_for_property(PropertyID::AspectRatio, tokens);
26942694
if (!maybe_value)
@@ -2712,16 +2712,21 @@ RefPtr<StyleValue> Parser::parse_aspect_ratio_value(Vector<ComponentValue> const
27122712
}
27132713

27142714
if (auto_value && ratio_value) {
2715+
transaction.commit();
27152716
return StyleValueList::create(
27162717
StyleValueVector { auto_value.release_nonnull(), ratio_value.release_nonnull() },
27172718
StyleValueList::Separator::Space);
27182719
}
27192720

2720-
if (ratio_value)
2721+
if (ratio_value) {
2722+
transaction.commit();
27212723
return ratio_value.release_nonnull();
2724+
}
27222725

2723-
if (auto_value)
2726+
if (auto_value) {
2727+
transaction.commit();
27242728
return auto_value.release_nonnull();
2729+
}
27252730

27262731
return nullptr;
27272732
}
@@ -5728,7 +5733,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
57285733
auto tokens = TokenStream { component_values };
57295734
switch (property_id) {
57305735
case PropertyID::AspectRatio:
5731-
if (auto parsed_value = parse_aspect_ratio_value(component_values))
5736+
if (auto parsed_value = parse_aspect_ratio_value(tokens); parsed_value && !tokens.has_next_token())
57325737
return parsed_value.release_nonnull();
57335738
return ParseError::SyntaxError;
57345739
case PropertyID::BackdropFilter:

Userland/Libraries/LibWeb/CSS/Parser/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class Parser {
225225
RefPtr<StyleValue> parse_simple_comma_separated_value_list(PropertyID, TokenStream<ComponentValue>&);
226226

227227
RefPtr<StyleValue> parse_filter_value_list_value(Vector<ComponentValue> const&);
228-
RefPtr<StyleValue> parse_aspect_ratio_value(Vector<ComponentValue> const&);
228+
RefPtr<StyleValue> parse_aspect_ratio_value(TokenStream<ComponentValue>&);
229229
RefPtr<StyleValue> parse_background_value(Vector<ComponentValue> const&);
230230
RefPtr<StyleValue> parse_single_background_position_x_or_y_value(TokenStream<ComponentValue>&, PropertyID);
231231
RefPtr<StyleValue> parse_single_background_repeat_value(TokenStream<ComponentValue>&);

0 commit comments

Comments
 (0)