diff options
author | stelar7 <dudedbz@gmail.com> | 2023-05-30 20:56:09 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-06-02 05:22:12 +0200 |
commit | 570e43a66a38bcdef17bbe1a92e7dd704d3f4294 (patch) | |
tree | 788c47d6b65e5e20e54586b2b0e16a7abb8a761a /Userland | |
parent | 47fc91ed43cf4ae30cd7ef1e2e082e90eea70b25 (diff) | |
download | serenity-570e43a66a38bcdef17bbe1a92e7dd704d3f4294.zip |
LibWeb: Move function parsing to separate method
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 34 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 1 |
2 files changed, 22 insertions, 13 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index ba322bdc9f..80ee476c55 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -3439,18 +3439,31 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_dynamic_value(ComponentValue const& co if (component_value.is_function()) { auto const& function = component_value.function(); - if (function.name().equals_ignoring_ascii_case("calc"sv)) - return parse_calculated_value(function.values()); - if (function.name().equals_ignoring_ascii_case("var"sv)) { // Declarations using `var()` should already be parsed as an UnresolvedStyleValue before this point. VERIFY_NOT_REACHED(); } + + auto function_node = TRY(parse_a_calc_function_node(function)); + if (!function_node) + return nullptr; + + auto function_type = function_node->resolved_type().value(); + return CalculatedStyleValue::create(function_node.release_nonnull(), function_type); } return nullptr; } +ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calc_function_node(Function const& function) +{ + if (function.name().equals_ignoring_ascii_case("calc"sv)) + return TRY(parse_a_calculation(function.values())); + + dbgln_if(CSS_PARSER_DEBUG, "We didn't implement `{}` function yet", function.name()); + return nullptr; +} + Optional<Parser::Dimension> Parser::parse_dimension(ComponentValue const& component_value) { if (component_value.is(Token::Type::Dimension)) { @@ -8068,19 +8081,14 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal // NOTE: All function tokens at this point should be math functions. else if (component_value.is_function()) { auto& function = component_value.function(); - if (function.name().equals_ignoring_ascii_case("calc"sv)) { - auto leaf_calculation = TRY(parse_a_calculation(function.values())); - if (!leaf_calculation) { - parsing_failed_for_child_node = true; - return {}; - } - node = leaf_calculation.release_nonnull(); - return {}; - } else { - // FIXME: Parse more math functions once we have them. + auto leaf_calculation = TRY(parse_a_calc_function_node(function)); + if (!leaf_calculation) { parsing_failed_for_child_node = true; return {}; } + + node = leaf_calculation.release_nonnull(); + return {}; } // NOTE: If we get here, then we have an UnparsedCalculationNode that didn't get replaced with something else. diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 43c3a5d86a..48991b36bf 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -289,6 +289,7 @@ private: ErrorOr<RefPtr<StyleValue>> parse_builtin_value(ComponentValue const&); ErrorOr<RefPtr<StyleValue>> parse_dynamic_value(ComponentValue const&); ErrorOr<RefPtr<CalculatedStyleValue>> parse_calculated_value(Vector<ComponentValue> const&); + ErrorOr<OwnPtr<CalculationNode>> parse_a_calc_function_node(Function const&); ErrorOr<RefPtr<StyleValue>> parse_dimension_value(ComponentValue const&); ErrorOr<RefPtr<StyleValue>> parse_integer_value(TokenStream<ComponentValue>&); ErrorOr<RefPtr<StyleValue>> parse_number_value(TokenStream<ComponentValue>&); |