1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

LibWeb: Implement CSS atan()

This commit is contained in:
stelar7 2023-05-28 11:04:57 +02:00 committed by Sam Atkins
parent 784e1cfb72
commit 1aa84dfddd
4 changed files with 100 additions and 0 deletions

View file

@ -3714,6 +3714,30 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_acos_function(Function const& fun
return TRY(AcosCalculationNode::create(calculation_node.release_nonnull()));
}
ErrorOr<OwnPtr<CalculationNode>> Parser::parse_atan_function(Function const& function)
{
auto calculation_node = TRY(parse_a_calculation(function.values()));
if (!calculation_node) {
dbgln_if(CSS_PARSER_DEBUG, "atan() 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 atan() parameter"sv);
return nullptr;
}
auto resolved_type = maybe_parameter_type.value();
if (resolved_type != CalculatedStyleValue::ResolvedType::Number) {
dbgln_if(CSS_PARSER_DEBUG, "atan() parameter must be a number"sv);
return nullptr;
}
return TRY(AtanCalculationNode::create(calculation_node.release_nonnull()));
}
ErrorOr<RefPtr<StyleValue>> Parser::parse_dynamic_value(ComponentValue const& component_value)
{
if (component_value.is_function()) {
@ -3773,6 +3797,9 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calc_function_node(Function con
if (function.name().equals_ignoring_ascii_case("acos"sv))
return TRY(parse_acos_function(function));
if (function.name().equals_ignoring_ascii_case("atan"sv))
return TRY(parse_atan_function(function));
dbgln_if(CSS_PARSER_DEBUG, "We didn't implement `{}` function yet", function.name());
return nullptr;
}