From ed77dee405783b68244dcc1c131958058421dce2 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 8 Dec 2023 17:28:41 +0000 Subject: [PATCH] LibWeb: Parse text-decoration property using TokenStream --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 7 ++++--- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 2753b5af85..63a9b4cbc9 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -4617,7 +4617,7 @@ RefPtr Parser::parse_quotes_value(TokenStream& token return StyleValueList::create(move(string_values), StyleValueList::Separator::Space); } -RefPtr Parser::parse_text_decoration_value(Vector const& component_values) +RefPtr Parser::parse_text_decoration_value(TokenStream& tokens) { RefPtr decoration_line; RefPtr decoration_thickness; @@ -4626,7 +4626,7 @@ RefPtr Parser::parse_text_decoration_value(Vector co auto remaining_longhands = Vector { PropertyID::TextDecorationColor, PropertyID::TextDecorationLine, PropertyID::TextDecorationStyle, PropertyID::TextDecorationThickness }; - auto tokens = TokenStream { component_values }; + auto transaction = tokens.begin_transaction(); while (tokens.has_next_token()) { auto property_and_value = parse_css_value_for_properties(remaining_longhands, tokens); if (!property_and_value.has_value()) @@ -4673,6 +4673,7 @@ RefPtr Parser::parse_text_decoration_value(Vector co if (!decoration_color) decoration_color = property_initial_value(m_context.realm(), PropertyID::TextDecorationColor); + transaction.commit(); return ShorthandStyleValue::create(PropertyID::TextDecoration, { PropertyID::TextDecorationLine, PropertyID::TextDecorationThickness, PropertyID::TextDecorationStyle, PropertyID::TextDecorationColor }, { decoration_line.release_nonnull(), decoration_thickness.release_nonnull(), decoration_style.release_nonnull(), decoration_color.release_nonnull() }); @@ -5931,7 +5932,7 @@ Parser::ParseErrorOr> Parser::parse_css_value(Property return parsed_value.release_nonnull(); return ParseError::SyntaxError; case PropertyID::TextDecoration: - if (auto parsed_value = parse_text_decoration_value(component_values)) + if (auto parsed_value = parse_text_decoration_value(tokens); parsed_value && !tokens.has_next_token()) return parsed_value.release_nonnull(); return ParseError::SyntaxError; case PropertyID::TextDecorationLine: { diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 1032d94b21..9ddfffacb5 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -253,7 +253,7 @@ private: }; RefPtr parse_shadow_value(TokenStream&, AllowInsetKeyword); RefPtr parse_single_shadow_value(TokenStream&, AllowInsetKeyword); - RefPtr parse_text_decoration_value(Vector const&); + RefPtr parse_text_decoration_value(TokenStream&); RefPtr parse_text_decoration_line_value(TokenStream&); RefPtr parse_easing_value(TokenStream&); RefPtr parse_transform_value(Vector const&);