Changeset 282162 in webkit


Ignore:
Timestamp:
Sep 8, 2021 12:05:05 PM (10 months ago)
Author:
commit-queue@webkit.org
Message:

Implement sin, cos, tan, e and pi for calc
https://bugs.webkit.org/show_bug.cgi?id=229507

Patch by Nikos Mouchtaris <Nikos Mouchtaris> on 2021-09-08
Reviewed by Simon Fraser.

Source/WebCore:

Tests: css3/calc/simple-trig-functions.html

css3/calc/trig-functions-with-constants.html

Add support for sin, cos, and tan functions within calc. Also add e and pi
constant values within calc.

  • css/CSSValueKeywords.in:

Add sin,cos,e and pi keywords.

  • css/calc/CSSCalcExpressionNodeParser.cpp:

(WebCore::getConstantTable):
Add helper function with table mapping e and pi keywords to their
approximate numerical value.

(WebCore::CSSCalcExpressionNodeParser::parseCalcFunction):
Add handling for creation of sin,cos,tan operation nodes.

(WebCore::CSSCalcExpressionNodeParser::parseValue):
Add handling for creation of primitive css value when constant is parsed.

  • css/calc/CSSCalcOperationNode.cpp:

(WebCore::determineCategory):
Add sin,cos,tan to switch statement.

(WebCore::functionFromOperator):
Add sin,cos,tan to switch statement.

(WebCore::CSSCalcOperationNode::createTrig):
Add function for creation of sin,cos,tan operation node.

(WebCore::CSSCalcOperationNode::combineChildren):
Add handling for performing sin,cos,tan function on child node.

(WebCore::CSSCalcOperationNode::simplifyNode):
Add handling for sin,cos,tan.

(WebCore::CSSCalcOperationNode::primitiveType const):
Remove assert that is no longer correct. Trig functions take can take an
angle and return a number, so it is no longer the case that all children
of a node producing a number must be numbers themself.

(WebCore::CSSCalcOperationNode::doubleValue const):
Convert chilren nodes that are angles to radians.

(WebCore::functionPrefixForOperator):
Add handling for sin,cos,tan.

(WebCore::CSSCalcOperationNode::evaluateOperator):
Add functionality for sin,cos,tan functions.

  • css/calc/CSSCalcOperationNode.h:
  • css/calc/CSSCalcValue.cpp:

(WebCore::createCSS):
Add handling for creation of sin,cos,tan operation nodes.

(WebCore::CSSCalcValue::isCalcFunction):
Add handling for sin,cos,tan.

  • platform/calc/CalcExpressionOperation.cpp:

(WebCore::CalcExpressionOperation::evaluate const):
Add functionality for sin,cos,tan function.

  • platform/calc/CalcOperator.cpp:

(WebCore::operator<<):
Add handling for sin,cos,tan.

  • platform/calc/CalcOperator.h:

LayoutTests:

  • fast/css/calc-parsing.html:

Added parsing tests for sin, cos, tan, e and pi.

  • css3/calc/trig-functions-with-constants.html: Added.

Added additional tests for expected behavior of sin, cos, tan, e and pi.

  • LayoutTests/animations/calc-animation-test.html: Added.

Added animation test for expanding width of box given a width defined using a calc expression
Involving sin and cos.

Location:
trunk
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r282161 r282162  
     12021-09-08  Nikos Mouchtaris  <nmouchtaris@apple.com>
     2
     3        Implement sin, cos, tan, e and pi for calc
     4        https://bugs.webkit.org/show_bug.cgi?id=229507
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/css/calc-parsing.html:
     9        Added parsing tests for sin, cos, tan, e and pi.
     10
     11        * css3/calc/trig-functions-with-constants.html: Added.
     12        Added additional tests for expected behavior of sin, cos, tan, e and pi.
     13
     14        * LayoutTests/animations/calc-animation-test.html: Added.
     15        Added animation test for expanding width of box given a width defined using a calc expression
     16        Involving sin and cos.
     17       
     18
    1192021-09-08  Ayumi Kojima  <ayumi_kojima@apple.com>
    220
  • trunk/LayoutTests/fast/css/calc-parsing-expected.txt

    r276262 r282162  
    5353PASS getComputedStyle(element).getPropertyValue('width') is "100px"
    5454
     55element.style["width"] = "calc(sin(90deg) * 100px)"
     56PASS 100 is 100
     57
     58element.style["width"] = "calc(sin(45deg  +  45deg ) * 100px)"
     59PASS 100 is 100
     60
     61element.style["width"] = "calc(cos( 0 ) * 100px)"
     62PASS 100 is 100
     63
     64element.style["width"] = "calc(cos( 30deg - 30deg ) * 100px)"
     65PASS 100 is 100
     66
     67element.style["width"] = "calc(tan(45deg)*100px)"
     68PASS 100 is 100
     69
     70element.style["width"] = "calc(tan(30deg + 15deg) * 100px)"
     71PASS 100 is 100
     72
     73element.style["width"] = "calc(sin(pi/2) * 100px)"
     74PASS 100 is 100
     75
     76element.style["width"] = "calc(cos(e - e) * 100px)"
     77PASS 100 is 100
     78
    5579element.style["width"] = "calc(100px, 200px)"
    5680PASS element.style['width'] is "999px"
     
    102126
    103127element.style["width"] = "clamp(1px,2px,2px,4px)"
     128PASS element.style['width'] is "999px"
     129PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     130
     131element.style["width"] = "calc(sin(90px) * 100px)"
     132PASS element.style['width'] is "999px"
     133PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     134
     135element.style["width"] = "calc(sin(30deg + 1.0471967rad, 0) * 100px)"
     136PASS element.style['width'] is "999px"
     137PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     138
     139element.style["width"] = "calc(cos( 0 ,) * 100px)"
     140PASS element.style['width'] is "999px"
     141PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     142
     143element.style["width"] = "calc(cos( () 30deg - 0.523599rad ) * 100px)"
     144PASS element.style['width'] is "999px"
     145PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     146
     147element.style["width"] = "calc(tan(45deg ) ) * 100px)"
     148PASS element.style['width'] is "999px"
     149PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     150
     151element.style["width"] = "calc(tan(30deg, + 0.261799rad) * 100px)"
     152PASS element.style['width'] is "999px"
     153PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     154
     155element.style["width"] = "calc(sin(piiii/4) * 100px)"
     156PASS element.style['width'] is "999px"
     157PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     158
     159element.style["width"] = "calc(sin(e e/4) * 100px)"
     160PASS element.style['width'] is "999px"
     161PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     162
     163element.style["width"] = "calc(sin() * 100px)"
    104164PASS element.style['width'] is "999px"
    105165PASS getComputedStyle(element).getPropertyValue('width') is "999px"
     
    153213PASS getComputedStyle(element).getPropertyValue('min-width') is "clamp(100px, 0%, 1%)"
    154214
     215element.style["min-width"] = "calc(sin(90deg) * 100px)"
     216PASS 100 is 100
     217
     218element.style["min-width"] = "calc(sin(45deg  +  45deg ) * 100px)"
     219PASS 100 is 100
     220
     221element.style["min-width"] = "calc(cos( 0 ) * 100px)"
     222PASS 100 is 100
     223
     224element.style["min-width"] = "calc(cos( 30deg - 30deg ) * 100px)"
     225PASS 100 is 100
     226
     227element.style["min-width"] = "calc(tan(45deg)*100px)"
     228PASS 100 is 100
     229
     230element.style["min-width"] = "calc(tan(30deg + 15deg) * 100px)"
     231PASS 100 is 100
     232
     233element.style["min-width"] = "calc(sin(pi/2) * 100px)"
     234PASS 100 is 100
     235
     236element.style["min-width"] = "calc(cos(e - e) * 100px)"
     237PASS 100 is 100
     238
    155239element.style["min-width"] = "calc(100px, 200px)"
    156240PASS element.style['min-width'] is "999px"
     
    204288PASS element.style['min-width'] is "999px"
    205289PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     290
     291element.style["min-width"] = "calc(sin(90px) * 100px)"
     292PASS element.style['min-width'] is "999px"
     293PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     294
     295element.style["min-width"] = "calc(sin(30deg + 1.0471967rad, 0) * 100px)"
     296PASS element.style['min-width'] is "999px"
     297PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     298
     299element.style["min-width"] = "calc(cos( 0 ,) * 100px)"
     300PASS element.style['min-width'] is "999px"
     301PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     302
     303element.style["min-width"] = "calc(cos( () 30deg - 0.523599rad ) * 100px)"
     304PASS element.style['min-width'] is "999px"
     305PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     306
     307element.style["min-width"] = "calc(tan(45deg ) ) * 100px)"
     308PASS element.style['min-width'] is "999px"
     309PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     310
     311element.style["min-width"] = "calc(tan(30deg, + 0.261799rad) * 100px)"
     312PASS element.style['min-width'] is "999px"
     313PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     314
     315element.style["min-width"] = "calc(sin(piiii/4) * 100px)"
     316PASS element.style['min-width'] is "999px"
     317PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     318
     319element.style["min-width"] = "calc(sin(e e/4) * 100px)"
     320PASS element.style['min-width'] is "999px"
     321PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
     322
     323element.style["min-width"] = "calc(sin() * 100px)"
     324PASS element.style['min-width'] is "999px"
     325PASS getComputedStyle(element).getPropertyValue('min-width') is "999px"
    206326PASS successfullyParsed is true
    207327
  • trunk/LayoutTests/fast/css/calc-parsing.html

    r276262 r282162  
    2020                    shouldBeEqualToString(`getComputedStyle(element).getPropertyValue('${propertyName}')`, `${computedValue}`);
    2121                }
     22               
     23                function testValue(expression, computedValue)
     24                {
     25                    debug('');
     26                    element.style[propertyName] = '999px';
     27                    evalAndLog(`element.style["${propertyName}"] = "${expression}"`);
     28                    var value = Math.round(getComputedStyle(element).getPropertyValue(propertyName).slice(0,-2));
     29                    shouldBe(`${value}`, computedValue);
     30                }
    2231
    2332                // Valid expressions.
     
    3443                testExpression('max(100px,0%)', 'max(100px, 0%)', propertyName == 'width' ? '100px' : "max(100px, 0%)");
    3544                testExpression('clamp(100px,0%,1%)', 'clamp(100px, 0%, 1%)', propertyName == 'width' ? '100px' : "clamp(100px, 0%, 1%)");
     45                testValue('calc(sin(90deg) * 100px)', '100');
     46                testValue('calc(sin(45deg  +  45deg ) * 100px)', '100');
     47                testValue('calc(cos( 0 ) * 100px)', '100');
     48                testValue('calc(cos( 30deg - 30deg ) * 100px)', '100');
     49                testValue('calc(tan(45deg)*100px)', '100');
     50                testValue('calc(tan(30deg + 15deg) * 100px)', '100');
     51                testValue('calc(sin(pi/2) * 100px)', '100');
     52                testValue('calc(cos(e - e) * 100px)', '100');
    3653
    3754                // Non-parsing expressions.
     
    4966                testExpression('clamp((),,300px)', '999px', '999px');
    5067                testExpression('clamp(1px,2px,2px,4px)', '999px', '999px');
     68                testExpression('calc(sin(90px) * 100px)', '999px', '999px');
     69                testExpression('calc(sin(30deg + 1.0471967rad, 0) * 100px)', '999px', '999px');
     70                testExpression('calc(cos( 0 ,) * 100px)', '999px', '999px');
     71                testExpression('calc(cos( () 30deg - 0.523599rad ) * 100px)', '999px', '999px');
     72                testExpression('calc(tan(45deg ) ) * 100px)', '999px', '999px');
     73                testExpression('calc(tan(30deg, + 0.261799rad) * 100px)', '999px', '999px');
     74                testExpression('calc(sin(piiii/4) * 100px)', '999px', '999px');
     75                testExpression('calc(sin(e e/4) * 100px)', '999px', '999px');
     76                testExpression('calc(sin() * 100px)', '999px', '999px');
    5177            }
    5278
  • trunk/Source/WebCore/ChangeLog

    r282160 r282162  
     12021-09-08  Nikos Mouchtaris  <nmouchtaris@apple.com>
     2
     3        Implement sin, cos, tan, e and pi for calc
     4        https://bugs.webkit.org/show_bug.cgi?id=229507
     5
     6        Reviewed by Simon Fraser.
     7
     8        Tests: css3/calc/simple-trig-functions.html
     9               css3/calc/trig-functions-with-constants.html
     10       
     11        Add support for sin, cos, and tan functions within calc. Also add e and pi
     12        constant values within calc.
     13       
     14        * css/CSSValueKeywords.in:
     15        Add sin,cos,e and pi keywords.
     16       
     17        * css/calc/CSSCalcExpressionNodeParser.cpp:
     18        (WebCore::getConstantTable):
     19        Add helper function with table mapping e and pi keywords to their
     20        approximate numerical value.
     21       
     22        (WebCore::CSSCalcExpressionNodeParser::parseCalcFunction):
     23        Add handling for creation of sin,cos,tan operation nodes.
     24       
     25        (WebCore::CSSCalcExpressionNodeParser::parseValue):
     26        Add handling for creation of primitive css value when constant is parsed.
     27       
     28        * css/calc/CSSCalcOperationNode.cpp:
     29        (WebCore::determineCategory):
     30        Add sin,cos,tan to switch statement.
     31       
     32        (WebCore::functionFromOperator):
     33        Add sin,cos,tan to switch statement.
     34       
     35        (WebCore::CSSCalcOperationNode::createTrig):
     36        Add function for creation of sin,cos,tan operation node.
     37       
     38        (WebCore::CSSCalcOperationNode::combineChildren):
     39        Add handling for performing sin,cos,tan function on child node.
     40       
     41        (WebCore::CSSCalcOperationNode::simplifyNode):
     42        Add handling for sin,cos,tan.
     43       
     44        (WebCore::CSSCalcOperationNode::primitiveType const):
     45        Remove assert that is no longer correct. Trig functions take can take an
     46        angle and return a number, so it is no longer the case that all children
     47        of a node producing a number must be numbers themself.
     48       
     49        (WebCore::CSSCalcOperationNode::doubleValue const):
     50        Convert chilren nodes that are angles to radians.
     51       
     52        (WebCore::functionPrefixForOperator):
     53        Add handling for sin,cos,tan.
     54       
     55        (WebCore::CSSCalcOperationNode::evaluateOperator):
     56        Add functionality for sin,cos,tan functions.
     57       
     58        * css/calc/CSSCalcOperationNode.h:
     59        * css/calc/CSSCalcValue.cpp:
     60        (WebCore::createCSS):
     61        Add handling for creation of sin,cos,tan operation nodes.
     62       
     63        (WebCore::CSSCalcValue::isCalcFunction):
     64        Add handling for sin,cos,tan.
     65       
     66        * platform/calc/CalcExpressionOperation.cpp:
     67        (WebCore::CalcExpressionOperation::evaluate const):
     68        Add functionality for sin,cos,tan function.
     69       
     70        * platform/calc/CalcOperator.cpp:
     71        (WebCore::operator<<):
     72        Add handling for sin,cos,tan.
     73       
     74        * platform/calc/CalcOperator.h:
     75
    1762021-09-08  Kimmo Kinnunen  <kkinnunen@apple.com>
    277
  • trunk/Source/WebCore/css/CSSValueKeywords.in

    r282143 r282162  
    13521352max
    13531353clamp
     1354sin
     1355cos
     1356e
     1357pi
    13541358
    13551359from-image
  • trunk/Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp

    r279358 r282162  
    9696};
    9797
     98static const CSSCalcSymbolTable getConstantTable()
     99{
     100    return { { CSSValuePi, CSSUnitType::CSS_NUMBER, piDouble }, { CSSValueE, CSSUnitType::CSS_NUMBER, std::exp(1.0) } };
     101}
     102
    98103static ParseState checkDepthAndIndex(int depth, CSSParserTokenRange tokens)
    99104{
     
    125130        maxArgumentCount = 3;
    126131        break;
     132    case CSSValueSin:
     133    case CSSValueCos:
     134    case CSSValueTan:
    127135    case CSSValueCalc:
    128136        maxArgumentCount = 1;
     
    167175        result = CSSCalcOperationNode::createMinOrMaxOrClamp(CalcOperator::Clamp, WTFMove(nodes), m_destinationCategory);
    168176        break;
     177    case CSSValueSin:
     178        result = CSSCalcOperationNode::createTrig(CalcOperator::Sin, WTFMove(nodes));
     179        break;
     180    case CSSValueCos:
     181        result = CSSCalcOperationNode::createTrig(CalcOperator::Cos, WTFMove(nodes));
     182        break;
     183    case CSSValueTan:
     184        result = CSSCalcOperationNode::createTrig(CalcOperator::Tan, WTFMove(nodes));
     185        break;
    169186    case CSSValueWebkitCalc:
    170187    case CSSValueCalc:
     
    194211    case IdentToken: {
    195212        auto value = m_symbolTable.get(token.id());
     213        value = value ? value : getConstantTable().get(token.id());
    196214        if (!value)
    197215            return false;
  • trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp

    r278283 r282162  
    7373            return CalculationCategory::Other;
    7474        return leftCategory;
     75    case CalcOperator::Sin:
     76    case CalcOperator::Cos:
     77    case CalcOperator::Tan:
    7578    case CalcOperator::Min:
    7679    case CalcOperator::Max:
     
    141144            break;
    142145        }
    143 
     146        case CalcOperator::Sin:
     147        case CalcOperator::Cos:
     148        case CalcOperator::Tan:
    144149        case CalcOperator::Min:
    145150        case CalcOperator::Max:
     
    256261    case CalcOperator::Clamp:
    257262        return CSSValueClamp;
     263    case CalcOperator::Sin:
     264        return CSSValueSin;
     265    case CalcOperator::Cos:
     266        return CSSValueCos;
     267    case CalcOperator::Tan:
     268        return CSSValueTan;
    258269    }
    259270    return CSSValueCalc;
     
    342353}
    343354
     355RefPtr<CSSCalcOperationNode> CSSCalcOperationNode::createTrig(CalcOperator op, Vector<Ref<CSSCalcExpressionNode>>&& values)
     356{
     357    if (values.size() != 1)
     358        return nullptr;
     359   
     360    auto childCategory = values[0]->category();
     361    if (childCategory != CalculationCategory::Number && childCategory != CalculationCategory::Angle) {
     362        LOG_WITH_STREAM(Calc, stream << "Failed to create trig node because unable to determine category from " << prettyPrintNodes(values));
     363        return nullptr;
     364    }
     365
     366    return adoptRef(new CSSCalcOperationNode(CalculationCategory::Number, op, WTFMove(values)));
     367}
     368
    344369void CSSCalcOperationNode::hoistChildrenWithOperator(CalcOperator op)
    345370{
     
    406431void CSSCalcOperationNode::combineChildren()
    407432{
    408     if (m_children.size() < 2)
     433    if (m_children.size() < 2) {
     434        if (m_children.size() == 1 && isTrigNode()) {
     435            double resolvedValue = doubleValue(m_children[0]->primitiveType());
     436            auto newChild = CSSCalcPrimitiveValueNode::create(CSSPrimitiveValue::create(resolvedValue, CSSUnitType::CSS_NUMBER));
     437
     438            m_children.clear();
     439            m_children.append(WTFMove(newChild));
     440        }
    409441        return;
    410 
     442    }
     443   
    411444    if (shouldSortChildren()) {
    412445        // <https://drafts.csswg.org/css-values-4/#sort-a-calculations-children>
     
    596629    if (is<CSSCalcOperationNode>(rootNode)) {
    597630        auto& calcOperationNode = downcast<CSSCalcOperationNode>(rootNode.get());
    598         // Don't simplify at the root, otherwise we lose track of the operation for serialization.
    599         if (calcOperationNode.children().size() == 1 && depth)
     631        // Simplify operations with only one child node (other than root and operations that only need one node).
     632        if (calcOperationNode.children().size() == 1 && depth && !calcOperationNode.isTrigNode())
    600633            return WTFMove(calcOperationNode.children()[0]);
    601634       
     
    612645        if (calcOperationNode.isMinOrMaxNode())
    613646            calcOperationNode.combineChildren();
    614 
     647       
     648        if (calcOperationNode.isTrigNode())
     649            calcOperationNode.combineChildren();
     650       
    615651        // If only one child remains, return the child (except at the root).
    616652        auto shouldCombineParentWithOnlyChild = [](const CSSCalcOperationNode& parent, int depth)
     
    677713    switch (unitCategory) {
    678714    case CalculationCategory::Number:
    679 #if ASSERT_ENABLED
    680         for (auto& child : m_children)
    681             ASSERT(child->category() == CalculationCategory::Number);
    682 #endif
    683715        return CSSUnitType::CSS_NUMBER;
    684 
    685716    case CalculationCategory::Percent: {
    686717        if (m_children.isEmpty())
     
    749780        if (allowNumbers && unitType != CSSUnitType::CSS_NUMBER && child->primitiveType() == CSSUnitType::CSS_NUMBER)
    750781            childType = CSSUnitType::CSS_NUMBER;
     782        if (isTrigNode() && unitType != CSSUnitType::CSS_NUMBER)
     783            childType = CSSUnitType::CSS_RAD;
    751784        return child->doubleValue(childType);
    752785    }));
     
    801834        ASSERT_NOT_REACHED();
    802835        return "";
     836    case CalcOperator::Sin: return "sin(";
     837    case CalcOperator::Cos: return "cos(";
     838    case CalcOperator::Tan: return "tan(";
    803839    case CalcOperator::Min: return "min(";
    804840    case CalcOperator::Max: return "max(";
     
    10051041        return std::max(min, std::min(value, max));
    10061042    }
     1043    case CalcOperator::Sin: {
     1044        if (children.size() != 1)
     1045            return std::numeric_limits<double>::quiet_NaN();
     1046        return std::sin(children[0]);
     1047    }
     1048    case CalcOperator::Cos: {
     1049        if (children.size() != 1)
     1050            return std::numeric_limits<double>::quiet_NaN();
     1051        return std::cos(children[0]);
     1052    }
     1053    case CalcOperator::Tan: {
     1054        if (children.size() != 1)
     1055            return std::numeric_limits<double>::quiet_NaN();
     1056        return std::tan(children[0]);
     1057    }
    10071058    }
    10081059    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/css/calc/CSSCalcOperationNode.h

    r278283 r282162  
    3838    static RefPtr<CSSCalcOperationNode> createProduct(Vector<Ref<CSSCalcExpressionNode>>&& values);
    3939    static RefPtr<CSSCalcOperationNode> createMinOrMaxOrClamp(CalcOperator, Vector<Ref<CSSCalcExpressionNode>>&& values, CalculationCategory destinationCategory);
     40    static RefPtr<CSSCalcOperationNode> createTrig(CalcOperator, Vector<Ref<CSSCalcExpressionNode>>&& values);
    4041
    4142    static Ref<CSSCalcExpressionNode> simplify(Ref<CSSCalcExpressionNode>&&);
     
    4748    bool isCalcProductNode() const { return m_operator == CalcOperator::Multiply; }
    4849    bool isMinOrMaxNode() const { return m_operator == CalcOperator::Min || m_operator == CalcOperator::Max; }
     50    bool isTrigNode() const { return m_operator == CalcOperator::Sin || m_operator == CalcOperator::Cos || m_operator == CalcOperator::Tan; }
    4951    bool shouldSortChildren() const { return isCalcSumNode() || isCalcProductNode(); }
    5052
  • trunk/Source/WebCore/css/calc/CSSCalcValue.cpp

    r278698 r282162  
    165165            return CSSCalcOperationNode::createProduct(createCSS(operationChildren, style));
    166166        }
     167        case CalcOperator::Cos:
     168        case CalcOperator::Tan:
     169        case CalcOperator::Sin: {
     170            auto children = createCSS(operationChildren, style);
     171            if (children.size() != 1)
     172                return nullptr;
     173            return CSSCalcOperationNode::createTrig(op, WTFMove(children));
     174        }
    167175        case CalcOperator::Min:
    168176        case CalcOperator::Max:
     
    284292    case CSSValueMax:
    285293    case CSSValueClamp:
     294    case CSSValueSin:
     295    case CSSValueCos:
     296    case CSSValueTan:
    286297        return true;
    287298    default:
  • trunk/Source/WebCore/platform/calc/CalcExpressionOperation.cpp

    r278246 r282162  
    2727#include "CalcExpressionOperation.h"
    2828
     29#include <cmath>
    2930#include <wtf/text/TextStream.h>
    3031
     
    8788        return std::max(min, std::min(value, max));
    8889    }
     90    case CalcOperator::Sin: {
     91        if (m_children.size() != 1)
     92            return std::numeric_limits<double>::quiet_NaN();
     93        return std::sin(m_children[0]->evaluate(maxValue));
     94    }
     95    case CalcOperator::Cos: {
     96        if (m_children.size() != 1)
     97            return std::numeric_limits<double>::quiet_NaN();
     98        return std::cos(m_children[0]->evaluate(maxValue));
     99    }
     100    case CalcOperator::Tan: {
     101        if (m_children.size() != 1)
     102            return std::numeric_limits<double>::quiet_NaN();
     103        return std::tan(m_children[0]->evaluate(maxValue));
     104    }
    89105    }
    90106    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/platform/calc/CalcOperator.cpp

    r278246 r282162  
    4141    case CalcOperator::Max: ts << "max"; break;
    4242    case CalcOperator::Clamp: ts << "clamp"; break;
     43    case CalcOperator::Sin: ts << "sin"; break;
     44    case CalcOperator::Cos: ts << "cos"; break;
     45    case CalcOperator::Tan: ts << "tan"; break;
    4346    }
    4447    return ts;
  • trunk/Source/WebCore/platform/calc/CalcOperator.h

    r278246 r282162  
    3939    Max,
    4040    Clamp,
     41    Sin,
     42    Cos,
     43    Tan,
    4144};
    4245
Note: See TracChangeset for help on using the changeset viewer.