LibWeb: Use correct resolved type for round() CSS function

Function is defined as `round(<rounding-strategy>?, A, B?)`

With this change resolved type is `typeof(resolve(A))`, instead of
`typeof(A)`.

For example `round(up, 20%, 1px)` with 200px percentage basis is now
correctly resolved in 40px instead of 40%.

Progress on https://www.notion.so/ landing page.
This commit is contained in:
Aliaksandr Kalenik 2024-09-17 17:51:48 +02:00 committed by Alexander Kalenik
commit 41e37f0079
Notes: github-actions[bot] 2024-09-17 18:03:27 +00:00
4 changed files with 43 additions and 1 deletions

View file

@ -2079,7 +2079,6 @@ bool RoundCalculationNode::contains_percentage() const
CalculatedStyleValue::CalculationResult RoundCalculationNode::resolve(Optional<Length::ResolutionContext const&> context, CalculatedStyleValue::PercentageBasis const& percentage_basis) const
{
auto resolved_type = m_x->resolved_type().value();
auto node_a = m_x->resolve(context, percentage_basis);
auto node_b = m_y->resolve(context, percentage_basis);
@ -2089,6 +2088,8 @@ CalculatedStyleValue::CalculationResult RoundCalculationNode::resolve(Optional<L
auto upper_b = ceil(node_a_value / node_b_value) * node_b_value;
auto lower_b = floor(node_a_value / node_b_value) * node_b_value;
auto resolved_type = node_a.resolved_type();
if (m_strategy == RoundingStrategy::Nearest) {
auto upper_diff = fabs(upper_b - node_a_value);
auto lower_diff = fabs(node_a_value - lower_b);
@ -2594,6 +2595,19 @@ void CalculatedStyleValue::CalculationResult::invert()
});
}
CalculatedStyleValue::ResolvedType CalculatedStyleValue::CalculationResult::resolved_type() const
{
return m_value.visit(
[](Number const&) { return ResolvedType::Number; },
[](Angle const&) { return ResolvedType::Angle; },
[](Flex const&) { return ResolvedType::Flex; },
[](Frequency const&) { return ResolvedType::Frequency; },
[](Length const&) { return ResolvedType::Length; },
[](Percentage const&) { return ResolvedType::Percentage; },
[](Resolution const&) { return ResolvedType::Resolution; },
[](Time const&) { return ResolvedType::Time; });
}
String CalculatedStyleValue::to_string() const
{
// FIXME: Implement this according to https://www.w3.org/TR/css-values-4/#calc-serialize once that stabilizes.

View file

@ -65,6 +65,8 @@ public:
Value const& value() const { return m_value; }
ResolvedType resolved_type() const;
[[nodiscard]] bool operator==(CalculationResult const&) const = default;
private: