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

LibWeb: Implement CSS cos()

This commit is contained in:
stelar7 2023-05-27 23:57:01 +02:00 committed by Sam Atkins
parent c73f476915
commit 46a5efe388
4 changed files with 100 additions and 0 deletions

View file

@ -3618,6 +3618,30 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_sin_function(Function const& func
return TRY(SinCalculationNode::create(calculation_node.release_nonnull()));
}
ErrorOr<OwnPtr<CalculationNode>> Parser::parse_cos_function(Function const& function)
{
auto calculation_node = TRY(parse_a_calculation(function.values()));
if (!calculation_node) {
dbgln_if(CSS_PARSER_DEBUG, "cos() 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 cos() parameter"sv);
return nullptr;
}
auto resolved_type = maybe_parameter_type.value();
if (resolved_type != CalculatedStyleValue::ResolvedType::Number && resolved_type != CalculatedStyleValue::ResolvedType::Angle) {
dbgln_if(CSS_PARSER_DEBUG, "cos() parameter must be a number or angle"sv);
return nullptr;
}
return TRY(CosCalculationNode::create(calculation_node.release_nonnull()));
}
ErrorOr<RefPtr<StyleValue>> Parser::parse_dynamic_value(ComponentValue const& component_value)
{
if (component_value.is_function()) {
@ -3665,6 +3689,9 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calc_function_node(Function con
if (function.name().equals_ignoring_ascii_case("sin"sv))
return TRY(parse_sin_function(function));
if (function.name().equals_ignoring_ascii_case("cos"sv))
return TRY(parse_cos_function(function));
dbgln_if(CSS_PARSER_DEBUG, "We didn't implement `{}` function yet", function.name());
return nullptr;
}