diff --git a/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp b/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp index 762d96e99b2..aa64110d47b 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp @@ -135,10 +135,13 @@ Optional> Parser::parse_angular_color_stop_l [](Dimension& dimension) { return dimension.angle_percentage(); }); } -RefPtr Parser::parse_linear_gradient_function(ComponentValue const& component_value) +RefPtr Parser::parse_linear_gradient_function(TokenStream& outer_tokens) { using GradientType = LinearGradientStyleValue::GradientType; + auto transaction = outer_tokens.begin_transaction(); + auto& component_value = outer_tokens.next_token(); + if (!component_value.is_function()) return nullptr; @@ -260,11 +263,15 @@ RefPtr Parser::parse_linear_gradient_function(ComponentValue const& if (!color_stops.has_value()) return nullptr; + transaction.commit(); return LinearGradientStyleValue::create(gradient_direction, move(*color_stops), gradient_type, repeating_gradient); } -RefPtr Parser::parse_conic_gradient_function(ComponentValue const& component_value) +RefPtr Parser::parse_conic_gradient_function(TokenStream& outer_tokens) { + auto transaction = outer_tokens.begin_transaction(); + auto& component_value = outer_tokens.next_token(); + if (!component_value.is_function()) return nullptr; @@ -360,10 +367,11 @@ RefPtr Parser::parse_conic_gradient_function(ComponentValue const& c if (!at_position) at_position = PositionStyleValue::create_center(); + transaction.commit(); return ConicGradientStyleValue::create(from_angle, at_position.release_nonnull(), move(*color_stops), repeating_gradient); } -RefPtr Parser::parse_radial_gradient_function(ComponentValue const& component_value) +RefPtr Parser::parse_radial_gradient_function(TokenStream& outer_tokens) { using EndingShape = RadialGradientStyleValue::EndingShape; using Extent = RadialGradientStyleValue::Extent; @@ -371,6 +379,9 @@ RefPtr Parser::parse_radial_gradient_function(ComponentValue const& using EllipseSize = RadialGradientStyleValue::EllipseSize; using Size = RadialGradientStyleValue::Size; + auto transaction = outer_tokens.begin_transaction(); + auto& component_value = outer_tokens.next_token(); + if (!component_value.is_function()) return nullptr; @@ -511,6 +522,7 @@ RefPtr Parser::parse_radial_gradient_function(ComponentValue const& if (!at_position) at_position = PositionStyleValue::create_center(); + transaction.commit(); return RadialGradientStyleValue::create(ending_shape, size, at_position.release_nonnull(), move(*color_stops), repeating_gradient); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index b6bbbe9d15d..e158af0d537 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -3199,26 +3199,18 @@ RefPtr Parser::parse_string_value(TokenStream& token RefPtr Parser::parse_image_value(TokenStream& tokens) { - auto transaction = tokens.begin_transaction(); - - if (auto url = parse_url_function(tokens); url.has_value()) { - transaction.commit(); + if (auto url = parse_url_function(tokens); url.has_value()) return ImageStyleValue::create(url.value()); - } - auto& token = tokens.next_token(); - if (auto linear_gradient = parse_linear_gradient_function(token)) { - transaction.commit(); + if (auto linear_gradient = parse_linear_gradient_function(tokens)) return linear_gradient; - } - if (auto conic_gradient = parse_conic_gradient_function(token)) { - transaction.commit(); + + if (auto conic_gradient = parse_conic_gradient_function(tokens)) return conic_gradient; - } - if (auto radial_gradient = parse_radial_gradient_function(token)) { - transaction.commit(); + + if (auto radial_gradient = parse_radial_gradient_function(tokens)) return radial_gradient; - } + return nullptr; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index cf3e7f65cf0..7d49ed6279d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -271,9 +271,9 @@ private: Optional> parse_linear_color_stop_list(TokenStream&); Optional> parse_angular_color_stop_list(TokenStream&); - RefPtr parse_linear_gradient_function(ComponentValue const&); - RefPtr parse_conic_gradient_function(ComponentValue const&); - RefPtr parse_radial_gradient_function(ComponentValue const&); + RefPtr parse_linear_gradient_function(TokenStream&); + RefPtr parse_conic_gradient_function(TokenStream&); + RefPtr parse_radial_gradient_function(TokenStream&); ParseErrorOr> parse_css_value(PropertyID, TokenStream&); RefPtr parse_css_value_for_property(PropertyID, TokenStream&);