Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 529c5725dd7d740cc2d2d7801ede2a0cde8a709b
      
https://github.com/WebKit/WebKit/commit/529c5725dd7d740cc2d2d7801ede2a0cde8a709b
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-05-07 (Thu, 07 May 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-computed-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-computed-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/tree-counting/trig-functions-with-runtime-angle-arguments-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/tree-counting/trig-functions-with-runtime-angle-arguments.html
    M Source/WebCore/css/calc/CSSCalcTree+Evaluation.cpp
    M Source/WebCore/css/calc/CSSCalcTree+Parser.cpp
    M Source/WebCore/css/calc/CSSCalcTree+Serialization.cpp
    M Source/WebCore/css/calc/CSSCalcTree+Simplification.cpp
    M Source/WebCore/css/calc/CSSCalcTree+Simplification.h
    M Source/WebCore/css/calc/CSSCalcTree.cpp
    M Source/WebCore/css/calc/CSSCalcTree.h
    M Source/WebCore/style/calc/StyleCalculationTree+Conversion.cpp

  Log Message:
  -----------
  [CSS Calc] Trig functions should convert degrees to radians during 
evaluateDouble()
https://bugs.webkit.org/show_bug.cgi?id=313300
rdar://175575617

Reviewed by Sam Weinig.

The simplification path for sin()/cos()/tan() correctly calls deg2rad()
when the argument is a CanonicalDimension (angle in degrees). However,
when the argument is a complex expression that cannot be simplified at
parse time (e.g. it contains sibling-index() or other runtime-dependent
values), the trig node is left as-is in the tree. Later, evaluateDouble()
evaluates it by passing the raw double — which is in degrees — directly
to std::cos() et al., which expect radians.

This causes incorrect results for any property that resolves calc values
through the evaluateDouble() path (e.g. rotate, skew) rather than the
copyAndSimplify() path (e.g. translateX with percentage). It explains
why using @property to register custom properties as <number> works
around the bug: the runtime-dependent values resolve to plain numbers
before substitution, so cos() can be fully simplified at parse time
with the correct deg2rad conversion.

The fix introduces an explicit Deg2Rad conversion node that the parser
inserts inside sin(), cos() and tan() whenever the argument is an
<angle>. Evaluation, simplification, and serialization handle Deg2Rad
directly — Deg2Rad(CanonicalDimension(angle)) simplifies to
Number(deg2rad(value)) at parse time, Deg2Rad is transparent during
serialization, and its evaluation multiplies by the radians-per-degree
constant. This makes the degrees-to-radians conversion explicit in
the tree structure, so evaluateTrig() no longer has to inspect its
child's Type to decide whether to convert (previously the only place
outside the parser and simplification that called getType()).

For conversion to Style::Calculation::Tree (which has no Deg2Rad
node), Deg2Rad is materialized as a Product by radiansPerDegreeDouble,
preserving semantics for the rare case where a Deg2Rad survives
simplification all the way to conversion.

Test: 
imported/w3c/web-platform-tests/css/css-values/tree-counting/trig-functions-with-runtime-angle-arguments.html

* 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/tree-counting/trig-functions-with-runtime-angle-arguments-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/tree-counting/trig-functions-with-runtime-angle-arguments.html:
 Added.
* Source/WebCore/css/calc/CSSCalcTree+Evaluation.cpp:
(WebCore::CSSCalc::evaluate):
(WebCore::CSSCalc::evaluateTrig):
* Source/WebCore/css/calc/CSSCalcTree+Parser.cpp:
(WebCore::CSSCalc::consumeExactlyOneArgument):
* Source/WebCore/css/calc/CSSCalcTree+Serialization.cpp:
(WebCore::CSSCalc::serializeCalculationTree):
(WebCore::CSSCalc::serializeMathFunction):
* Source/WebCore/css/calc/CSSCalcTree+Simplification.cpp:
(WebCore::CSSCalc::simplifyForTrig):
(WebCore::CSSCalc::simplify):
* Source/WebCore/css/calc/CSSCalcTree+Simplification.h:
* Source/WebCore/css/calc/CSSCalcTree.cpp:
(WebCore::CSSCalc::toType):
* Source/WebCore/css/calc/CSSCalcTree.h:
(WebCore::CSSCalc::get):
* Source/WebCore/style/calc/StyleCalculationTree+Conversion.cpp:
(WebCore::Style::Calculation::toStyle):

> Progressions:
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-computed-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-computed-expected.txt:

Canonical link: https://commits.webkit.org/312860@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to