1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

LibWeb: Implement CSS asin()

This commit is contained in:
stelar7 2023-05-28 10:55:52 +02:00 committed by Sam Atkins
parent 64f0349a9e
commit 708b5ef447
4 changed files with 100 additions and 0 deletions

View file

@ -3666,6 +3666,30 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_tan_function(Function const& func
return TRY(TanCalculationNode::create(calculation_node.release_nonnull()));
}
ErrorOr<OwnPtr<CalculationNode>> Parser::parse_asin_function(Function const& function)
{
auto calculation_node = TRY(parse_a_calculation(function.values()));
if (!calculation_node) {
dbgln_if(CSS_PARSER_DEBUG, "asin() parameter must be a valid calculation"sv);
return nullptr;
}
auto maybe_parameter_type = calculation_node->resolved_type();
if (!maybe_parameter_type.has_value()) {
dbgln_if(CSS_PARSER_DEBUG, "Failed to resolve type for asin() parameter"sv);
return nullptr;
}
auto resolved_type = maybe_parameter_type.value();
if (resolved_type != CalculatedStyleValue::ResolvedType::Number) {
dbgln_if(CSS_PARSER_DEBUG, "asin() parameter must be a number"sv);
return nullptr;
}
return TRY(AsinCalculationNode::create(calculation_node.release_nonnull()));
}
ErrorOr<RefPtr<StyleValue>> Parser::parse_dynamic_value(ComponentValue const& component_value)
{
if (component_value.is_function()) {
@ -3719,6 +3743,9 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calc_function_node(Function con
if (function.name().equals_ignoring_ascii_case("tan"sv))
return TRY(parse_tan_function(function));
if (function.name().equals_ignoring_ascii_case("asin"sv))
return TRY(parse_asin_function(function));
dbgln_if(CSS_PARSER_DEBUG, "We didn't implement `{}` function yet", function.name());
return nullptr;
}