From 2efaadd63cbdd9d639411f369548ddf995c1b22a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 7 Dec 2023 15:12:30 +0000 Subject: [PATCH] LibWeb: Parse aspect-ratio property using TokenStream --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 15 ++++++++++----- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 1ef0e5be8c..47e5833778 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2682,13 +2682,13 @@ static void remove_property(Vector& properties, PropertyID property_ } // https://www.w3.org/TR/css-sizing-4/#aspect-ratio -RefPtr Parser::parse_aspect_ratio_value(Vector const& component_values) +RefPtr Parser::parse_aspect_ratio_value(TokenStream& tokens) { // `auto || ` RefPtr auto_value; RefPtr ratio_value; - auto tokens = TokenStream { component_values }; + auto transaction = tokens.begin_transaction(); while (tokens.has_next_token()) { auto maybe_value = parse_css_value_for_property(PropertyID::AspectRatio, tokens); if (!maybe_value) @@ -2712,16 +2712,21 @@ RefPtr Parser::parse_aspect_ratio_value(Vector const } if (auto_value && ratio_value) { + transaction.commit(); return StyleValueList::create( StyleValueVector { auto_value.release_nonnull(), ratio_value.release_nonnull() }, StyleValueList::Separator::Space); } - if (ratio_value) + if (ratio_value) { + transaction.commit(); return ratio_value.release_nonnull(); + } - if (auto_value) + if (auto_value) { + transaction.commit(); return auto_value.release_nonnull(); + } return nullptr; } @@ -5728,7 +5733,7 @@ Parser::ParseErrorOr> Parser::parse_css_value(Property auto tokens = TokenStream { component_values }; switch (property_id) { case PropertyID::AspectRatio: - if (auto parsed_value = parse_aspect_ratio_value(component_values)) + if (auto parsed_value = parse_aspect_ratio_value(tokens); parsed_value && !tokens.has_next_token()) return parsed_value.release_nonnull(); return ParseError::SyntaxError; case PropertyID::BackdropFilter: diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 3800b36a27..207469a165 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -225,7 +225,7 @@ private: RefPtr parse_simple_comma_separated_value_list(PropertyID, TokenStream&); RefPtr parse_filter_value_list_value(Vector const&); - RefPtr parse_aspect_ratio_value(Vector const&); + RefPtr parse_aspect_ratio_value(TokenStream&); RefPtr parse_background_value(Vector const&); RefPtr parse_single_background_position_x_or_y_value(TokenStream&, PropertyID); RefPtr parse_single_background_repeat_value(TokenStream&);