Changeset 291597 in webkit


Ignore:
Timestamp:
Mar 21, 2022 8:22:44 PM (4 months ago)
Author:
commit-queue@webkit.org
Message:

Implement CSSNumericValue.mul, div, add, sub, max, and min
https://bugs.webkit.org/show_bug.cgi?id=238153

Patch by Alex Christensen <achristensen@webkit.org> on 2022-03-21
Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt:

Source/WebCore:

This implements all except the derived units of multiplication and the unit checking of the others.
They are an off-by-default experimental feature right now, part of css-typed-om which is being implemented.
They are covered by wpt tests.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSCSSStyleValueCustom.cpp:

(WebCore::toJSNewlyCreated):

  • css/typedom/CSSKeywordValue.h:

(WebCore::CSSKeywordValue::value const): Deleted.
(WebCore::CSSKeywordValue::CSSKeywordValue): Deleted.

  • css/typedom/CSSNumericValue.cpp:

(WebCore::negate):
(WebCore::invert):
(WebCore::operationOnValuesOfSameUnit):
(WebCore::CSSNumericValue::prependItemsOfTypeOrThis):
(WebCore::CSSNumericValue::addInternal):
(WebCore::CSSNumericValue::add):
(WebCore::CSSNumericValue::sub):
(WebCore::CSSNumericValue::multiplyInternal):
(WebCore::CSSNumericValue::mul):
(WebCore::CSSNumericValue::div):
(WebCore::CSSNumericValue::min):
(WebCore::CSSNumericValue::max):
(WebCore::CSSNumericValue::rectifyNumberish):
(WebCore::CSSNumericValue::toSum):

  • css/typedom/CSSNumericValue.h:

(isType):

  • css/typedom/CSSStyleValue.h:

(WebCore::isCSSNumericValue):
(WebCore::isCSSMathValue):

  • css/typedom/CSSUnitValue.h:

(isType):

  • css/typedom/numeric/CSSMathInvert.cpp:

(WebCore::CSSMathInvert::CSSMathInvert):

  • css/typedom/numeric/CSSMathInvert.h:

(isType):
(WebCore::CSSMathInvert::value const): Deleted.

  • css/typedom/numeric/CSSMathMax.cpp:

(WebCore::CSSMathMax::CSSMathMax):
(WebCore::CSSMathMax::create): Deleted.

  • css/typedom/numeric/CSSMathMax.h:

(isType):

  • css/typedom/numeric/CSSMathMin.cpp:

(WebCore::CSSMathMin::CSSMathMin):
(WebCore::CSSMathMin::create): Deleted.

  • css/typedom/numeric/CSSMathMin.h:

(isType):

  • css/typedom/numeric/CSSMathNegate.cpp:

(WebCore::CSSMathNegate::CSSMathNegate):
(WebCore::CSSMathNegate::create): Deleted.

  • css/typedom/numeric/CSSMathNegate.h:

(isType):
(WebCore::CSSMathNegate::value const): Deleted.

  • css/typedom/numeric/CSSMathProduct.cpp:

(WebCore::CSSMathProduct::CSSMathProduct):
(WebCore::CSSMathProduct::create): Deleted.

  • css/typedom/numeric/CSSMathProduct.h:

(isType):

  • css/typedom/numeric/CSSMathSum.cpp:

(WebCore::CSSMathSum::CSSMathSum):
(WebCore::CSSMathSum::create): Deleted.
(WebCore::CSSMathSum::values const): Deleted.

  • css/typedom/numeric/CSSMathSum.h:

(isType):

  • css/typedom/numeric/CSSMathValue.cpp: Removed.
  • css/typedom/numeric/CSSMathValue.h:

(WebCore::CSSMathValue::getOperator const): Deleted.
(): Deleted.
(isType): Deleted.

  • css/typedom/numeric/CSSNumericArray.cpp:

(WebCore::CSSNumericArray::create):
(WebCore::CSSNumericArray::CSSNumericArray):

  • css/typedom/numeric/CSSNumericArray.h:

(WebCore::CSSNumericArray::array const):

  • css/typedom/numeric/CSSNumericType.h:
  • css/typedom/transform/CSSTransformValue.h:

(WebCore::CSSTransformValue::length const): Deleted.

Location:
trunk
Files:
1 deleted
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r291594 r291597  
     12022-03-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement CSSNumericValue.mul, div, add, sub, max, and min
     4        https://bugs.webkit.org/show_bug.cgi?id=238153
     5
     6        Reviewed by Simon Fraser.
     7
     8        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt:
     9
    1102022-03-21  Oriol Brufau  <obrufau@igalia.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt

    r282356 r291597  
    22PASS Calling CSSUnitValue.add with no arguments returns itself
    33PASS Calling CSSMathValue.add with no arguments returns itself
    4 FAIL Calling CSSNumericValue.add with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
     4PASS Calling CSSNumericValue.add with a single CSSNumericValue returns correct type
    55PASS Calling CSSMathValue.add with a single CSSNumericValue returns correct type
    6 FAIL Calling CSSNumericValue.add with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
     6PASS Calling CSSNumericValue.add with more than one number CSSNumericValues returns correct type
    77PASS Calling CSSNumericValue.add can take numberish values
    8 FAIL Calling CSSMathSum.add with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathSum"
     8PASS Calling CSSMathSum.add with number CSSUnitValues simplifies to a CSSUnitValue
    99PASS Calling CSSNumericValue.add with incompatible types throws TypeError
    1010PASS Calling CSSUnitValue.sub with no arguments returns itself
    1111PASS Calling CSSMathValue.sub with no arguments returns itself
    12 FAIL Calling CSSNumericValue.sub with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
     12PASS Calling CSSNumericValue.sub with a single CSSNumericValue returns correct type
    1313PASS Calling CSSMathValue.sub with a single CSSNumericValue returns correct type
    14 FAIL Calling CSSNumericValue.sub with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
     14PASS Calling CSSNumericValue.sub with more than one number CSSNumericValues returns correct type
    1515PASS Calling CSSNumericValue.sub can take numberish values
    16 FAIL Calling CSSMathSum.sub with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathSum"
     16PASS Calling CSSMathSum.sub with number CSSUnitValues simplifies to a CSSUnitValue
    1717PASS Calling CSSNumericValue.sub with incompatible types throws TypeError
    1818PASS Calling CSSUnitValue.mul with no arguments returns itself
    1919PASS Calling CSSMathValue.mul with no arguments returns itself
    20 FAIL Calling CSSNumericValue.mul with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
     20PASS Calling CSSNumericValue.mul with a single CSSNumericValue returns correct type
    2121PASS Calling CSSMathValue.mul with a single CSSNumericValue returns correct type
    22 FAIL Calling CSSNumericValue.mul with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
     22PASS Calling CSSNumericValue.mul with more than one number CSSNumericValues returns correct type
    2323PASS Calling CSSNumericValue.mul can take numberish values
    24 FAIL Calling CSSMathProduct.mul with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathProduct"
     24PASS Calling CSSMathProduct.mul with number CSSUnitValues simplifies to a CSSUnitValue
    2525PASS Calling CSSNumericValue.mul with incompatible types throws TypeError
    2626PASS Calling CSSUnitValue.div with no arguments returns itself
    2727PASS Calling CSSMathValue.div with no arguments returns itself
    28 FAIL Calling CSSNumericValue.div with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
     28PASS Calling CSSNumericValue.div with a single CSSNumericValue returns correct type
    2929PASS Calling CSSMathValue.div with a single CSSNumericValue returns correct type
    30 FAIL Calling CSSNumericValue.div with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
     30PASS Calling CSSNumericValue.div with more than one number CSSNumericValues returns correct type
    3131PASS Calling CSSNumericValue.div can take numberish values
    32 FAIL Calling CSSMathProduct.div with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathProduct"
     32PASS Calling CSSMathProduct.div with number CSSUnitValues simplifies to a CSSUnitValue
    3333PASS Calling CSSNumericValue.div with incompatible types throws TypeError
    3434PASS Calling CSSUnitValue.min with no arguments returns itself
    3535PASS Calling CSSMathValue.min with no arguments returns itself
    36 FAIL Calling CSSNumericValue.min with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathMin" but got "CSSUnitValue"
     36PASS Calling CSSNumericValue.min with a single CSSNumericValue returns correct type
    3737PASS Calling CSSMathValue.min with a single CSSNumericValue returns correct type
    38 FAIL Calling CSSNumericValue.min with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathMin" but got "CSSUnitValue"
     38PASS Calling CSSNumericValue.min with more than one number CSSNumericValues returns correct type
    3939PASS Calling CSSNumericValue.min can take numberish values
    40 FAIL Calling CSSMathMin.min with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathMin"
     40PASS Calling CSSMathMin.min with number CSSUnitValues simplifies to a CSSUnitValue
    4141PASS Calling CSSNumericValue.min with incompatible types throws TypeError
    4242PASS Calling CSSUnitValue.max with no arguments returns itself
    4343PASS Calling CSSMathValue.max with no arguments returns itself
    44 FAIL Calling CSSNumericValue.max with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathMax" but got "CSSUnitValue"
     44PASS Calling CSSNumericValue.max with a single CSSNumericValue returns correct type
    4545PASS Calling CSSMathValue.max with a single CSSNumericValue returns correct type
    46 FAIL Calling CSSNumericValue.max with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathMax" but got "CSSUnitValue"
     46PASS Calling CSSNumericValue.max with more than one number CSSNumericValues returns correct type
    4747PASS Calling CSSNumericValue.max can take numberish values
    48 FAIL Calling CSSMathMax.max with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathMax"
     48PASS Calling CSSMathMax.max with number CSSUnitValues simplifies to a CSSUnitValue
    4949PASS Calling CSSNumericValue.max with incompatible types throws TypeError
    50 FAIL Calling CSSUnitValue.add with CSSUnitValues with same unit simplifies to a CSSUnitValue assert_equals: expected 17 but got 10
    51 FAIL Calling CSSUnitValue.sub with CSSUnitValues with same unit simplifies to a CSSUnitValue assert_equals: expected 3 but got 10
    52 FAIL Calling CSSUnitValue.mul with all numbers simplifies to a CSSUnitValue assert_equals: expected 100 but got 10
    53 FAIL Calling CSSUnitValue.mul with only one non-number simplifies to a CSSUnitValue assert_equals: expected 100 but got 10
    54 FAIL Calling CSSUnitValue.mul with more than one non-number does not simplify to a CSSUnitValue assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
    55 FAIL Calling CSSUnitValue.div with all numbers simplifies to a CSSUnitValue assert_equals: expected 1 but got 10
    56 FAIL Calling CSSUnitValue.div on a non-number value simplifies to a CSSUnitValue assert_equals: expected 1 but got 10
    57 FAIL Calling CSSUnitValue.div with a non-number value in the arguments does not simplify to a CSSUnitValue assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
    58 FAIL Calling CSSUnitValue.min with CSSUnitValues with same unit simplifies to a CSSUnitValue assert_equals: expected 2 but got 10
     50PASS Calling CSSUnitValue.add with CSSUnitValues with same unit simplifies to a CSSUnitValue
     51PASS Calling CSSUnitValue.sub with CSSUnitValues with same unit simplifies to a CSSUnitValue
     52PASS Calling CSSUnitValue.mul with all numbers simplifies to a CSSUnitValue
     53PASS Calling CSSUnitValue.mul with only one non-number simplifies to a CSSUnitValue
     54PASS Calling CSSUnitValue.mul with more than one non-number does not simplify to a CSSUnitValue
     55PASS Calling CSSUnitValue.div with all numbers simplifies to a CSSUnitValue
     56PASS Calling CSSUnitValue.div on a non-number value simplifies to a CSSUnitValue
     57PASS Calling CSSUnitValue.div with a non-number value in the arguments does not simplify to a CSSUnitValue
     58PASS Calling CSSUnitValue.min with CSSUnitValues with same unit simplifies to a CSSUnitValue
    5959PASS Calling CSSUnitValue.max with CSSUnitValues with same unit simplifies to a CSSUnitValue
    60 FAIL Calling CSSNumericValue.sub negates all argument values assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
    61 FAIL Calling CSSNumericValue.div inverts all argument values assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
    62 FAIL Can not divide with CSSUnitValue which has zero value and number type assert_throws_js: function "() => CSS.number(2).div(CSS.number(0))" did not throw
     60PASS Calling CSSNumericValue.sub negates all argument values
     61PASS Calling CSSNumericValue.div inverts all argument values
     62PASS Can not divide with CSSUnitValue which has zero value and number type
    6363FAIL CSSNumericValue.add should throw TypeError when the types are different. assert_throws_js: function "() => CSS.number(3).add(CSS.px(10) ,CSS.number(0))" did not throw
    6464FAIL CSSNumericValue.sub should throw TypeError when the types are different. assert_throws_js: function "() => CSS.number(3).sub(CSS.px(10) ,CSS.number(0))" did not throw
  • trunk/Source/WebCore/ChangeLog

    r291594 r291597  
     12022-03-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement CSSNumericValue.mul, div, add, sub, max, and min
     4        https://bugs.webkit.org/show_bug.cgi?id=238153
     5
     6        Reviewed by Simon Fraser.
     7
     8        This implements all except the derived units of multiplication and the unit checking of the others.
     9        They are an off-by-default experimental feature right now, part of css-typed-om which is being implemented.
     10        They are covered by wpt tests.
     11
     12        * Sources.txt:
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * bindings/js/JSCSSStyleValueCustom.cpp:
     15        (WebCore::toJSNewlyCreated):
     16        * css/typedom/CSSKeywordValue.h:
     17        (WebCore::CSSKeywordValue::value const): Deleted.
     18        (WebCore::CSSKeywordValue::CSSKeywordValue): Deleted.
     19        * css/typedom/CSSNumericValue.cpp:
     20        (WebCore::negate):
     21        (WebCore::invert):
     22        (WebCore::operationOnValuesOfSameUnit):
     23        (WebCore::CSSNumericValue::prependItemsOfTypeOrThis):
     24        (WebCore::CSSNumericValue::addInternal):
     25        (WebCore::CSSNumericValue::add):
     26        (WebCore::CSSNumericValue::sub):
     27        (WebCore::CSSNumericValue::multiplyInternal):
     28        (WebCore::CSSNumericValue::mul):
     29        (WebCore::CSSNumericValue::div):
     30        (WebCore::CSSNumericValue::min):
     31        (WebCore::CSSNumericValue::max):
     32        (WebCore::CSSNumericValue::rectifyNumberish):
     33        (WebCore::CSSNumericValue::toSum):
     34        * css/typedom/CSSNumericValue.h:
     35        (isType):
     36        * css/typedom/CSSStyleValue.h:
     37        (WebCore::isCSSNumericValue):
     38        (WebCore::isCSSMathValue):
     39        * css/typedom/CSSUnitValue.h:
     40        (isType):
     41        * css/typedom/numeric/CSSMathInvert.cpp:
     42        (WebCore::CSSMathInvert::CSSMathInvert):
     43        * css/typedom/numeric/CSSMathInvert.h:
     44        (isType):
     45        (WebCore::CSSMathInvert::value const): Deleted.
     46        * css/typedom/numeric/CSSMathMax.cpp:
     47        (WebCore::CSSMathMax::CSSMathMax):
     48        (WebCore::CSSMathMax::create): Deleted.
     49        * css/typedom/numeric/CSSMathMax.h:
     50        (isType):
     51        * css/typedom/numeric/CSSMathMin.cpp:
     52        (WebCore::CSSMathMin::CSSMathMin):
     53        (WebCore::CSSMathMin::create): Deleted.
     54        * css/typedom/numeric/CSSMathMin.h:
     55        (isType):
     56        * css/typedom/numeric/CSSMathNegate.cpp:
     57        (WebCore::CSSMathNegate::CSSMathNegate):
     58        (WebCore::CSSMathNegate::create): Deleted.
     59        * css/typedom/numeric/CSSMathNegate.h:
     60        (isType):
     61        (WebCore::CSSMathNegate::value const): Deleted.
     62        * css/typedom/numeric/CSSMathProduct.cpp:
     63        (WebCore::CSSMathProduct::CSSMathProduct):
     64        (WebCore::CSSMathProduct::create): Deleted.
     65        * css/typedom/numeric/CSSMathProduct.h:
     66        (isType):
     67        * css/typedom/numeric/CSSMathSum.cpp:
     68        (WebCore::CSSMathSum::CSSMathSum):
     69        (WebCore::CSSMathSum::create): Deleted.
     70        (WebCore::CSSMathSum::values const): Deleted.
     71        * css/typedom/numeric/CSSMathSum.h:
     72        (isType):
     73        * css/typedom/numeric/CSSMathValue.cpp: Removed.
     74        * css/typedom/numeric/CSSMathValue.h:
     75        (WebCore::CSSMathValue::getOperator const): Deleted.
     76        (): Deleted.
     77        (isType): Deleted.
     78        * css/typedom/numeric/CSSNumericArray.cpp:
     79        (WebCore::CSSNumericArray::create):
     80        (WebCore::CSSNumericArray::CSSNumericArray):
     81        * css/typedom/numeric/CSSNumericArray.h:
     82        (WebCore::CSSNumericArray::array const):
     83        * css/typedom/numeric/CSSNumericType.h:
     84        * css/typedom/transform/CSSTransformValue.h:
     85        (WebCore::CSSTransformValue::length const): Deleted.
     86
    1872022-03-21  Oriol Brufau  <obrufau@igalia.com>
    288
  • trunk/Source/WebCore/Sources.txt

    r291364 r291597  
    869869css/typedom/numeric/CSSMathProduct.cpp
    870870css/typedom/numeric/CSSMathSum.cpp
    871 css/typedom/numeric/CSSMathValue.cpp
    872871css/typedom/numeric/CSSNumericArray.cpp
    873872css/typedom/transform/CSSMatrixComponent.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r291589 r291597  
    80358035                2AEF6FE426E802F000326D02 /* CSSMathProduct.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathProduct.cpp; sourceTree = "<group>"; };
    80368036                2AEF6FE526E802F100326D02 /* CSSMathSum.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathSum.cpp; sourceTree = "<group>"; };
    8037                 2AEF6FE626E802F100326D02 /* CSSMathValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathValue.cpp; sourceTree = "<group>"; };
    80388037                2B42359F15250F6000DBBCD8 /* RenderSVGEllipse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGEllipse.cpp; sourceTree = "<group>"; };
    80398038                2B4235A015250F6000DBBCD8 /* RenderSVGEllipse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGEllipse.h; sourceTree = "<group>"; };
     
    2078920788                                2AEF6FC126E716EE00326D02 /* CSSMathSum.h */,
    2079020789                                2AEF6FC326E716EE00326D02 /* CSSMathSum.idl */,
    20791                                 2AEF6FE626E802F100326D02 /* CSSMathValue.cpp */,
    2079220790                                2AEF6FC726E716EE00326D02 /* CSSMathValue.h */,
    2079320791                                2AEF6FBE26E716EE00326D02 /* CSSMathValue.idl */,
  • trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp

    r289219 r291597  
    3030
    3131#include "JSCSSKeywordValue.h"
     32#include "JSCSSMathInvert.h"
     33#include "JSCSSMathMax.h"
     34#include "JSCSSMathMin.h"
     35#include "JSCSSMathNegate.h"
     36#include "JSCSSMathProduct.h"
     37#include "JSCSSMathSum.h"
    3238#include "JSCSSMathValue.h"
    3339#include "JSCSSNumericValue.h"
    3440#include "JSCSSStyleImageValue.h"
     41#include "JSCSSTransformValue.h"
    3542#include "JSCSSUnitValue.h"
    3643#include "JSCSSUnparsedValue.h"
     
    4754    case CSSStyleValueType::CSSNumericValue:
    4855        return createWrapper<CSSNumericValue>(globalObject, WTFMove(value));
    49     case CSSStyleValueType::CSSMathValue:
    50         return createWrapper<CSSMathValue>(globalObject, WTFMove(value));
     56    case CSSStyleValueType::CSSMathInvert:
     57        return createWrapper<CSSMathInvert>(globalObject, WTFMove(value));
     58    case CSSStyleValueType::CSSMathMin:
     59        return createWrapper<CSSMathMin>(globalObject, WTFMove(value));
     60    case CSSStyleValueType::CSSMathMax:
     61        return createWrapper<CSSMathMax>(globalObject, WTFMove(value));
     62    case CSSStyleValueType::CSSMathNegate:
     63        return createWrapper<CSSMathNegate>(globalObject, WTFMove(value));
     64    case CSSStyleValueType::CSSMathProduct:
     65        return createWrapper<CSSMathProduct>(globalObject, WTFMove(value));
     66    case CSSStyleValueType::CSSMathSum:
     67        return createWrapper<CSSMathSum>(globalObject, WTFMove(value));
    5168    case CSSStyleValueType::CSSUnitValue:
    5269        return createWrapper<CSSUnitValue>(globalObject, WTFMove(value));
     
    5673        return createWrapper<CSSKeywordValue>(globalObject, WTFMove(value));
    5774    case CSSStyleValueType::CSSTransformValue:
     75        return createWrapper<CSSTransformValue>(globalObject, WTFMove(value));
    5876    case CSSStyleValueType::CSSStyleValue:
    5977        return createWrapper<CSSStyleValue>(globalObject, WTFMove(value));
  • trunk/Source/WebCore/css/typedom/CSSKeywordValue.h

    r282706 r291597  
    3636template<typename> class ExceptionOr;
    3737
    38 class CSSKeywordValue : public CSSStyleValue {
     38class CSSKeywordValue final : public CSSStyleValue {
    3939    WTF_MAKE_ISO_ALLOCATED(CSSKeywordValue);
    4040public:
  • trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp

    r287294 r291597  
    3131#include "CSSNumericValue.h"
    3232
     33#if ENABLE(CSS_TYPED_OM)
     34
     35#include "CSSMathInvert.h"
     36#include "CSSMathMax.h"
     37#include "CSSMathMin.h"
     38#include "CSSMathNegate.h"
     39#include "CSSMathProduct.h"
    3340#include "CSSMathSum.h"
     41#include "CSSNumericArray.h"
    3442#include "CSSNumericFactory.h"
    3543#include "CSSNumericType.h"
    3644#include "CSSUnitValue.h"
    3745#include "ExceptionOr.h"
    38 
    39 #if ENABLE(CSS_TYPED_OM)
    40 
    4146#include <wtf/IsoMallocInlines.h>
    4247
     
    4550WTF_MAKE_ISO_ALLOCATED_IMPL(CSSNumericValue);
    4651
     52static Ref<CSSNumericValue> negate(Ref<CSSNumericValue>&& value)
     53{
     54    // https://drafts.css-houdini.org/css-typed-om/#cssmath-negate-a-cssnumericvalue
     55    if (auto* mathNegate = dynamicDowncast<CSSMathNegate>(value.get()))
     56        return mathNegate->value();
     57    if (auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get()))
     58        return CSSUnitValue::create(-unitValue->value(), unitValue->unit());
     59    return CSSMathNegate::create(WTFMove(value));
     60}
     61
     62static ExceptionOr<Ref<CSSNumericValue>> invert(Ref<CSSNumericValue>&& value)
     63{
     64    // https://drafts.css-houdini.org/css-typed-om/#cssmath-invert-a-cssnumericvalue
     65    if (auto* mathInvert = dynamicDowncast<CSSMathInvert>(value.get()))
     66        return Ref { mathInvert->value() };
     67
     68    if (auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get())) {
     69        // FIXME: units should be either AtomicStrings or CSSUnitType enumeration values.
     70        if (unitValue->unit() == "number") {
     71            if (unitValue->value() == 0.0 || unitValue->value() == -0.0)
     72                return Exception { RangeError };
     73            return Ref<CSSNumericValue> { CSSUnitValue::create(1.0 / unitValue->value(), unitValue->unit()) };
     74        }
     75    }
     76
     77    return Ref<CSSNumericValue> { CSSMathInvert::create(WTFMove(value)) };
     78}
     79
     80template<typename T>
     81static RefPtr<CSSNumericValue> operationOnValuesOfSameUnit(T&& operation, const Vector<Ref<CSSNumericValue>>& values)
     82{
     83    bool allValuesHaveSameUnit = values.size() && WTF::allOf(values, [&] (const Ref<CSSNumericValue>& value) {
     84        auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get());
     85        return unitValue ? unitValue->unit() == downcast<CSSUnitValue>(values[0].get()).unit() : false;
     86    });
     87    if (allValuesHaveSameUnit) {
     88        auto& firstUnitValue = downcast<CSSUnitValue>(values[0].get());
     89        String unit = firstUnitValue.unit();
     90        double result = firstUnitValue.value();
     91        for (size_t i = 1; i < values.size(); i++)
     92            result = operation(result, downcast<CSSUnitValue>(values[i].get()).value());
     93        return CSSUnitValue::create(result, unit);
     94    }
     95    return nullptr;
     96}
     97
     98template<typename T> Vector<Ref<CSSNumericValue>> CSSNumericValue::prependItemsOfTypeOrThis(Vector<Ref<CSSNumericValue>>&& numericValues)
     99{
     100    Vector<Ref<CSSNumericValue>> values;
     101    if (T* t = dynamicDowncast<T>(*this))
     102        values.appendVector(t->values().array());
     103    else
     104        values.append(*this);
     105    values.appendVector(numericValues);
     106    return values;
     107}
     108
     109Ref<CSSNumericValue> CSSNumericValue::addInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
     110{
     111    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-add
     112    auto values = prependItemsOfTypeOrThis<CSSMathSum>(WTFMove(numericValues));
     113
     114    if (auto result = operationOnValuesOfSameUnit(std::plus<double>(), values))
     115        return *result;
     116
     117    // FIXME: Implement step 4 to check that the types can be added.
     118
     119    return CSSMathSum::create(WTFMove(values));
     120}
     121
    47122Ref<CSSNumericValue> CSSNumericValue::add(FixedVector<CSSNumberish>&& values)
    48123{
    49     UNUSED_PARAM(values);
    50     // FIXME: add impl.
    51 
    52     return *this;
     124    return addInternal(WTF::map(WTFMove(values), rectifyNumberish));
    53125}
    54126
    55127Ref<CSSNumericValue> CSSNumericValue::sub(FixedVector<CSSNumberish>&& values)
    56128{
    57     UNUSED_PARAM(values);
    58     // FIXME: add impl.
    59 
    60     return *this;
     129    return addInternal(WTF::map(WTFMove(values), [] (CSSNumberish&& numberish) {
     130        return negate(rectifyNumberish(WTFMove(numberish)));
     131    }));
     132}
     133
     134Ref<CSSNumericValue> CSSNumericValue::multiplyInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
     135{
     136    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-mul
     137    auto values = prependItemsOfTypeOrThis<CSSMathProduct>(WTFMove(numericValues));
     138
     139    bool allUnitValues = WTF::allOf(values, [&] (const Ref<CSSNumericValue>& value) {
     140        return is<CSSUnitValue>(value.get());
     141    });
     142    if (allUnitValues) {
     143        bool multipleUnitsFound { false };
     144        std::optional<size_t> nonNumberUnitIndex;
     145        for (size_t i = 0; i < values.size(); i++) {
     146            auto& unit = downcast<CSSUnitValue>(values[i].get()).unit();
     147            if (unit == "number")
     148                continue;
     149            if (nonNumberUnitIndex) {
     150                multipleUnitsFound = true;
     151                break;
     152            }
     153            nonNumberUnitIndex = i;
     154        }
     155        if (!multipleUnitsFound) {
     156            double product = 1;
     157            for (const Ref<CSSNumericValue>& value : values)
     158                product *= downcast<CSSUnitValue>(value.get()).value();
     159            String unit = nonNumberUnitIndex ? downcast<CSSUnitValue>(values[*nonNumberUnitIndex].get()).unit() : "number";
     160            return CSSUnitValue::create(product, unit);
     161        }
     162    }
     163
     164    // FIXME: Implement step 5 to produce a unit of the correct type.
     165
     166    return CSSMathProduct::create(WTFMove(values));
    61167}
    62168
    63169Ref<CSSNumericValue> CSSNumericValue::mul(FixedVector<CSSNumberish>&& values)
    64170{
    65     UNUSED_PARAM(values);
    66     // FIXME: add impl.
    67 
    68     return *this;
    69 }
    70 
    71 Ref<CSSNumericValue> CSSNumericValue::div(FixedVector<CSSNumberish>&& values)
    72 {
    73     UNUSED_PARAM(values);
    74     // FIXME: add impl.
    75 
    76     return *this;
    77 }
    78 Ref<CSSNumericValue> CSSNumericValue::min(FixedVector<CSSNumberish>&& values)
    79 {
    80     UNUSED_PARAM(values);
    81     // FIXME: add impl.
    82 
    83     return *this;
    84 }
    85 Ref<CSSNumericValue> CSSNumericValue::max(FixedVector<CSSNumberish>&& values)
    86 {
    87     UNUSED_PARAM(values);
    88     // FIXME: add impl.
    89 
    90     return *this;
     171    return multiplyInternal(WTF::map(WTFMove(values), rectifyNumberish));
     172}
     173
     174ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::div(FixedVector<CSSNumberish>&& values)
     175{
     176    Vector<Ref<CSSNumericValue>> invertedValues;
     177    invertedValues.reserveInitialCapacity(values.size());
     178    for (auto&& value : WTFMove(values)) {
     179        auto inverted = invert(rectifyNumberish(WTFMove(value)));
     180        if (inverted.hasException())
     181            return inverted.releaseException();
     182        invertedValues.uncheckedAppend(inverted.releaseReturnValue());
     183    }
     184    return multiplyInternal(WTFMove(invertedValues));
     185}
     186
     187Ref<CSSNumericValue> CSSNumericValue::min(FixedVector<CSSNumberish>&& numberishes)
     188{
     189    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-min
     190    auto values = prependItemsOfTypeOrThis<CSSMathMin>(WTF::map(WTFMove(numberishes), rectifyNumberish));
     191   
     192    if (auto result = operationOnValuesOfSameUnit<const double&(*)(const double&, const double&)>(std::min<double>, values))
     193        return *result;
     194
     195    // FIXME: Implement step 4 to check that the types can be added.
     196
     197    return CSSMathMin::create(WTFMove(values));
     198}
     199
     200Ref<CSSNumericValue> CSSNumericValue::max(FixedVector<CSSNumberish>&& numberishes)
     201{
     202    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-max
     203    auto values = prependItemsOfTypeOrThis<CSSMathMax>(WTF::map(WTFMove(numberishes), rectifyNumberish));
     204   
     205    if (auto result = operationOnValuesOfSameUnit<const double&(*)(const double&, const double&)>(std::max<double>, values))
     206        return *result;
     207
     208    // FIXME: Implement step 4 to check that the types can be added.
     209
     210    return CSSMathMax::create(WTFMove(values));
    91211}
    92212
    93213Ref<CSSNumericValue> CSSNumericValue::rectifyNumberish(CSSNumberish&& numberish)
    94214{
     215    // https://drafts.css-houdini.org/css-typed-om/#rectify-a-numberish-value
    95216    return WTF::switchOn(numberish, [](RefPtr<CSSNumericValue>& value) {
    96217        RELEASE_ASSERT(!!value);
     
    122243    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-tosum
    123244    // FIXME: add impl.
    124     return CSSMathSum::create({ 1.0 });
     245    return CSSMathSum::create(FixedVector<CSSNumberish> { 1.0 });
    125246}
    126247
  • trunk/Source/WebCore/css/typedom/CSSNumericValue.h

    r287294 r291597  
    4949    Ref<CSSNumericValue> sub(FixedVector<CSSNumberish>&&);
    5050    Ref<CSSNumericValue> mul(FixedVector<CSSNumberish>&&);
    51     Ref<CSSNumericValue> div(FixedVector<CSSNumberish>&&);
     51    ExceptionOr<Ref<CSSNumericValue>> div(FixedVector<CSSNumberish>&&);
    5252    Ref<CSSNumericValue> min(FixedVector<CSSNumberish>&&);
    5353    Ref<CSSNumericValue> max(FixedVector<CSSNumberish>&&);
     
    6161    static ExceptionOr<Ref<CSSNumericValue>> parse(String&&);
    6262    static Ref<CSSNumericValue> rectifyNumberish(CSSNumberish&&);
    63    
     63
    6464    CSSStyleValueType getType() const override { return CSSStyleValueType::CSSNumericValue; }
    6565
    6666protected:
     67    Ref<CSSNumericValue> addInternal(Vector<Ref<CSSNumericValue>>&&);
     68    Ref<CSSNumericValue> multiplyInternal(Vector<Ref<CSSNumericValue>>&&);
     69    template<typename T> Vector<Ref<CSSNumericValue>> prependItemsOfTypeOrThis(Vector<Ref<CSSNumericValue>>&&);
     70
    6771    CSSNumericValue() = default;
    6872};
     
    7377
    7478SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSNumericValue)
    75     static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSNumericValue; }
     79    static bool isType(const WebCore::CSSStyleValue& styleValue) { return isCSSNumericValue(styleValue.getType()); }
    7680SPECIALIZE_TYPE_TRAITS_END()
    7781
  • trunk/Source/WebCore/css/typedom/CSSStyleValue.h

    r282758 r291597  
    4545    CSSTransformValue,
    4646    CSSNumericValue,
    47     CSSMathValue,
     47    CSSMathInvert,
     48    CSSMathMin,
     49    CSSMathMax,
     50    CSSMathNegate,
     51    CSSMathProduct,
     52    CSSMathSum,
    4853    CSSUnitValue,
    4954    CSSUnparsedValue,
    5055    CSSKeywordValue
    5156};
     57
     58inline bool isCSSNumericValue(CSSStyleValueType type)
     59{
     60    switch (type) {
     61    case CSSStyleValueType::CSSNumericValue:
     62    case CSSStyleValueType::CSSMathInvert:
     63    case CSSStyleValueType::CSSMathMin:
     64    case CSSStyleValueType::CSSMathMax:
     65    case CSSStyleValueType::CSSMathNegate:
     66    case CSSStyleValueType::CSSMathProduct:
     67    case CSSStyleValueType::CSSMathSum:
     68    case CSSStyleValueType::CSSUnitValue:
     69        return true;
     70    case CSSStyleValueType::CSSStyleValue:
     71    case CSSStyleValueType::CSSStyleImageValue:
     72    case CSSStyleValueType::CSSTransformValue:
     73    case CSSStyleValueType::CSSUnparsedValue:
     74    case CSSStyleValueType::CSSKeywordValue:
     75        break;
     76    }
     77    return false;
     78}
     79
     80inline bool isCSSMathValue(CSSStyleValueType type)
     81{
     82    switch (type) {
     83    case CSSStyleValueType::CSSMathInvert:
     84    case CSSStyleValueType::CSSMathMin:
     85    case CSSStyleValueType::CSSMathMax:
     86    case CSSStyleValueType::CSSMathNegate:
     87    case CSSStyleValueType::CSSMathProduct:
     88    case CSSStyleValueType::CSSMathSum:
     89        return true;
     90    case CSSStyleValueType::CSSNumericValue:
     91    case CSSStyleValueType::CSSUnitValue:
     92    case CSSStyleValueType::CSSStyleValue:
     93    case CSSStyleValueType::CSSStyleImageValue:
     94    case CSSStyleValueType::CSSTransformValue:
     95    case CSSStyleValueType::CSSUnparsedValue:
     96    case CSSStyleValueType::CSSKeywordValue:
     97        break;
     98    }
     99    return false;
     100}
    52101
    53102class CSSStyleValue : public RefCounted<CSSStyleValue>, public ScriptWrappable {
  • trunk/Source/WebCore/css/typedom/CSSUnitValue.h

    r282039 r291597  
    6767
    6868SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSUnitValue)
    69     static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSUnitValue; }
     69static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSUnitValue; }
    7070SPECIALIZE_TYPE_TRAITS_END()
    7171
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp

    r282356 r291597  
    4343
    4444CSSMathInvert::CSSMathInvert(CSSNumberish&& numberish)
    45     : CSSMathValue(CSSMathOperator::Invert)
    46     , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
     45    : m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
    4746{
    4847}
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h

    r282356 r291597  
    3232namespace WebCore {
    3333
    34 class CSSMathInvert : public CSSMathValue {
     34class CSSMathInvert final : public CSSMathValue {
    3535    WTF_MAKE_ISO_ALLOCATED(CSSMathInvert);
    3636public:
    3737    static Ref<CSSMathInvert> create(CSSNumberish&&);
    38     const CSSNumericValue& value() const { return m_value.get(); }
     38    CSSNumericValue& value() { return m_value.get(); }
    3939   
    4040private:
     41    CSSMathOperator getOperator() const final { return CSSMathOperator::Invert; }
     42    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathInvert; }
     43
    4144    CSSMathInvert(CSSNumberish&&);
    4245    Ref<CSSNumericValue> m_value;
     
    4649
    4750SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathInvert)
    48     static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
    49     static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
    50     static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Invert; }
     51static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathInvert; }
     52static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathInvert; }
     53static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathInvert; }
    5154SPECIALIZE_TYPE_TRAITS_END()
    5255
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp

    r287294 r291597  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathMax);
    3838
    39 Ref<CSSMathMax> CSSMathMax::create(FixedVector<CSSNumberish>&& numberishes)
     39CSSMathMax::CSSMathMax(FixedVector<CSSNumberish>&& numberishes)
     40    : m_values(CSSNumericArray::create(WTFMove(numberishes)))
    4041{
    41     return adoptRef(*new CSSMathMax(WTFMove(numberishes)));
    4242}
    4343
    44 CSSMathMax::CSSMathMax(FixedVector<CSSNumberish>&& numberishes)
    45     : CSSMathValue(CSSMathOperator::Max)
    46     , m_values(CSSNumericArray::create(WTFMove(numberishes)))
     44CSSMathMax::CSSMathMax(Vector<Ref<CSSNumericValue>>&& values)
     45    : m_values(CSSNumericArray::create(WTFMove(values)))
    4746{
    4847}
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h

    r287294 r291597  
    3535class CSSNumericArray;
    3636
    37 class CSSMathMax : public CSSMathValue {
     37class CSSMathMax final : public CSSMathValue {
    3838    WTF_MAKE_ISO_ALLOCATED(CSSMathMax);
    3939public:
    40     static Ref<CSSMathMax> create(FixedVector<CSSNumberish>&&);
     40    template<typename... Args> static Ref<CSSMathMax> create(Args&&... args) { return adoptRef(*new CSSMathMax(std::forward<Args>(args)...)); }
    4141    const CSSNumericArray& values() const;
    42    
     42
    4343private:
     44    CSSMathOperator getOperator() const final { return CSSMathOperator::Max; }
     45    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMax; }
     46
    4447    CSSMathMax(FixedVector<CSSNumberish>&&);
     48    CSSMathMax(Vector<Ref<CSSNumericValue>>&&);
    4549    Ref<CSSNumericArray> m_values;
    4650};
     
    4953
    5054SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathMax)
    51     static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
    52     static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
    53 static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Max; }
     55static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathMax; }
     56static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathMax; }
     57static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathMax; }
    5458SPECIALIZE_TYPE_TRAITS_END()
    5559
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp

    r287294 r291597  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathMin);
    3838
    39 Ref<CSSMathMin> CSSMathMin::create(FixedVector<CSSNumberish>&& numberishes)
     39CSSMathMin::CSSMathMin(FixedVector<CSSNumberish>&& numberishes)
     40    : m_values(CSSNumericArray::create(WTFMove(numberishes)))
    4041{
    41     return adoptRef(*new CSSMathMin(WTFMove(numberishes)));
    4242}
    4343
    44 CSSMathMin::CSSMathMin(FixedVector<CSSNumberish>&& numberishes)
    45     : CSSMathValue(CSSMathOperator::Min)
    46     , m_values(CSSNumericArray::create(WTFMove(numberishes)))
     44CSSMathMin::CSSMathMin(Vector<Ref<CSSNumericValue>>&& values)
     45    : m_values(CSSNumericArray::create(WTFMove(values)))
    4746{
    4847}
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h

    r287294 r291597  
    3535class CSSNumericArray;
    3636
    37 class CSSMathMin : public CSSMathValue {
     37class CSSMathMin final : public CSSMathValue {
    3838    WTF_MAKE_ISO_ALLOCATED(CSSMathMin);
    3939public:
    40     static Ref<CSSMathMin> create(FixedVector<CSSNumberish>&&);
     40    template<typename... Args> static Ref<CSSMathMin> create(Args&&... args) { return adoptRef(*new CSSMathMin(std::forward<Args>(args)...)); }
    4141    const CSSNumericArray& values() const;
    42    
     42
    4343private:
     44    CSSMathOperator getOperator() const final { return CSSMathOperator::Min; }
     45    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMin; }
     46
    4447    CSSMathMin(FixedVector<CSSNumberish>&&);
     48    CSSMathMin(Vector<Ref<CSSNumericValue>>&&);
    4549    Ref<CSSNumericArray> m_values;
    4650};
     
    4953
    5054SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathMin)
    51     static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
    52     static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
    53     static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Min; }
     55static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathMin; }
     56static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathMin; }
     57static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathMin; }
    5458SPECIALIZE_TYPE_TRAITS_END()
    5559
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp

    r282356 r291597  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathNegate);
    3838
    39 Ref<CSSMathNegate> CSSMathNegate::create(CSSNumberish&& numberish)
     39CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
     40    : m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
    4041{
    41     return adoptRef(*new CSSMathNegate(WTFMove(numberish)));
    4242}
    4343
    44 CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
    45     : CSSMathValue(CSSMathOperator::Negate)
    46     , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
     44CSSMathNegate::CSSMathNegate(Ref<CSSNumericValue>&& value)
     45    : m_value(WTFMove(value))
    4746{
    4847}
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h

    r282356 r291597  
    3535class CSSNumericValue;
    3636
    37 class CSSMathNegate : public CSSMathValue {
     37class CSSMathNegate final : public CSSMathValue {
    3838    WTF_MAKE_ISO_ALLOCATED(CSSMathNegate);
    3939public:
    40     static Ref<CSSMathNegate> create(CSSNumberish&&);
    41     const CSSNumericValue& value() const { return m_value.get(); }
     40    template<typename... Args> static Ref<CSSMathNegate> create(Args&&... args) { return adoptRef(*new CSSMathNegate(std::forward<Args>(args)...)); }
     41    CSSNumericValue& value() { return m_value.get(); }
    4242   
    4343private:
     44    CSSMathOperator getOperator() const final { return CSSMathOperator::Negate; }
     45    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathNegate; }
     46
    4447    CSSMathNegate(CSSNumberish&&);
     48    CSSMathNegate(Ref<CSSNumericValue>&&);
    4549    Ref<CSSNumericValue> m_value;
    4650};
     
    4953
    5054SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathNegate)
    51     static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
    52     static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
    53     static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Negate; }
     55static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathNegate; }
     56static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathNegate; }
     57static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathNegate; }
    5458SPECIALIZE_TYPE_TRAITS_END()
    5559
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp

    r287294 r291597  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathProduct);
    3838
    39 Ref<CSSMathProduct> CSSMathProduct::create(FixedVector<CSSNumberish>&& numberishes)
     39CSSMathProduct::CSSMathProduct(FixedVector<CSSNumberish>&& numberishes)
     40    : m_values(CSSNumericArray::create(WTFMove(numberishes)))
    4041{
    41     return adoptRef(*new CSSMathProduct(WTFMove(numberishes)));
    4242}
    4343
    44 CSSMathProduct::CSSMathProduct(FixedVector<CSSNumberish>&& numberishes)
    45     : CSSMathValue(CSSMathOperator::Product)
    46     , m_values(CSSNumericArray::create(WTFMove(numberishes)))
     44CSSMathProduct::CSSMathProduct(Vector<Ref<CSSNumericValue>>&& values)
     45    : m_values(CSSNumericArray::create(WTFMove(values)))
    4746{
    4847}
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h

    r287294 r291597  
    3535class CSSNumericArray;
    3636
    37 class CSSMathProduct : public CSSMathValue {
     37class CSSMathProduct final : public CSSMathValue {
    3838    WTF_MAKE_ISO_ALLOCATED(CSSMathProduct);
    3939public:
    40     static Ref<CSSMathProduct> create(FixedVector<CSSNumberish>&&);
     40    template<typename... Args> static Ref<CSSMathProduct> create(Args&&... args) { return adoptRef(*new CSSMathProduct(std::forward<Args>(args)...)); }
    4141    const CSSNumericArray& values() const;
    42    
    43     CSSMathOperator getOperator() const final { return CSSMathOperator::Product; }
    4442
    4543private:
     44    CSSMathOperator getOperator() const final { return CSSMathOperator::Product; }
     45    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathProduct; }
     46
    4647    CSSMathProduct(FixedVector<CSSNumberish>&&);
     48    CSSMathProduct(Vector<Ref<CSSNumericValue>>&&);
    4749    Ref<CSSNumericArray> m_values;
    4850};
     
    5153
    5254SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathProduct)
    53     static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
    54     static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
    55     static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Product; }
     55static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathProduct; }
     56static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathProduct; }
     57static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathProduct; }
    5658SPECIALIZE_TYPE_TRAITS_END()
    5759
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp

    r287294 r291597  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathSum);
    3838
    39 Ref<CSSMathSum> CSSMathSum::create(FixedVector<CSSNumberish>&& numberishes)
    40 {
    41     return adoptRef(*new CSSMathSum(WTFMove(numberishes)));
    42 }
    43 
    4439CSSMathSum::CSSMathSum(FixedVector<CSSNumberish>&& numberishes)
    45     : CSSMathValue(CSSMathOperator::Sum)
    46     , m_values(CSSNumericArray::create(WTFMove(numberishes)))
     40    : m_values(CSSNumericArray::create(WTFMove(numberishes)))
    4741{
    4842}
    4943
    50 const CSSNumericArray& CSSMathSum::values() const
     44CSSMathSum::CSSMathSum(Vector<Ref<CSSNumericValue>>&& values)
     45    : m_values(CSSNumericArray::create(WTFMove(values)))
    5146{
    52     return m_values.get();
    5347}
    5448
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h

    r287294 r291597  
    3636class CSSNumericArray;
    3737
    38 class CSSMathSum : public CSSMathValue {
     38class CSSMathSum final : public CSSMathValue {
    3939    WTF_MAKE_ISO_ALLOCATED(CSSMathSum);
    4040public:
    41     static Ref<CSSMathSum> create(FixedVector<CSSNumberish>&&);
    42     const CSSNumericArray& values() const;
     41    template<typename... Args> static Ref<CSSMathSum> create(Args&&... args) { return adoptRef(*new CSSMathSum(std::forward<Args>(args)...)); }
     42    const CSSNumericArray& values() const { return m_values.get(); }
    4343
    4444private:
     45    CSSMathOperator getOperator() const final { return CSSMathOperator::Sum; }
     46    CSSStyleValueType getType() const override { return CSSStyleValueType::CSSMathSum; }
     47
    4548    CSSMathSum(FixedVector<CSSNumberish>&&);
     49    CSSMathSum(Vector<Ref<CSSNumericValue>>&&);
    4650    Ref<CSSNumericArray> m_values;
    4751};
     
    5054
    5155SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathSum)
    52     static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
    53     static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
    54     static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Sum; }
     56static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathSum; }
     57static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathSum; }
     58static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathSum; }
    5559SPECIALIZE_TYPE_TRAITS_END()
    5660
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h

    r282356 r291597  
    3535
    3636class CSSMathValue : public CSSNumericValue {
    37     WTF_MAKE_ISO_ALLOCATED(CSSMathValue);
    3837public:
    39     virtual CSSMathOperator getOperator() const { return m_operator; }
    40    
    41     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathValue; }
    42    
    43 protected:
    44     CSSMathValue(CSSMathOperator);
    45     CSSMathOperator m_operator;
     38    virtual CSSMathOperator getOperator() const = 0;
    4639};
    4740
    4841} // namespace WebCore
    4942
    50 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathValue)
    51     static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathValue; }
    52     static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathValue; }
    53 SPECIALIZE_TYPE_TRAITS_END()
    54 
    5543#endif
  • trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp

    r287294 r291597  
    4646}
    4747
    48 Ref<CSSNumericArray> CSSNumericArray::create(FixedVector<Ref<CSSNumericValue>>&& values)
     48Ref<CSSNumericArray> CSSNumericArray::create(Vector<Ref<CSSNumericValue>>&& values)
    4949{
    5050    return adoptRef(*new CSSNumericArray(WTFMove(values)));
     51}
     52
     53CSSNumericArray::CSSNumericArray(Vector<Ref<CSSNumericValue>>&& values)
     54    : m_array(WTFMove(values))
     55{
    5156}
    5257
  • trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h

    r287294 r291597  
    4242public:
    4343    static Ref<CSSNumericArray> create(const FixedVector<CSSNumberish>&);
    44     static Ref<CSSNumericArray> create(FixedVector<Ref<CSSNumericValue>>&&);
     44    static Ref<CSSNumericArray> create(Vector<Ref<CSSNumericValue>>&&);
    4545    size_t length() const { return m_array.size(); };
    4646    ExceptionOr<Ref<CSSNumericValue>> item(size_t index);
     47    const Vector<Ref<CSSNumericValue>>& array() const { return m_array; }
    4748
    4849private:
    49     FixedVector<Ref<CSSNumericValue>> m_array;
     50    Vector<Ref<CSSNumericValue>> m_array;
     51    CSSNumericArray(Vector<Ref<CSSNumericValue>>&&);
    5052    CSSNumericArray(FixedVector<Ref<CSSNumericValue>>&&);
    5153};
  • trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h

    r282356 r291597  
    2929
    3030#include "CSSNumericBaseType.h"
     31#include <optional>
    3132
    3233namespace WebCore {
    3334
    3435struct CSSNumericType {
    35     long length;
    36     long angle;
    37     long time;
    38     long frequency;
    39     long resolution;
    40     long flex;
    41     long percent;
    42     CSSNumericBaseType percentHint;
     36    long length { 0 };
     37    long angle { 0 };
     38    long time { 0 };
     39    long frequency { 0 };
     40    long resolution { 0 };
     41    long flex { 0 };
     42    long percent { 0 };
     43    std::optional<CSSNumericBaseType> percentHint;
    4344};
    4445
  • trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h

    r282758 r291597  
    3838template<typename> class ExceptionOr;
    3939
    40 class CSSTransformValue : public CSSStyleValue {
     40class CSSTransformValue final : public CSSStyleValue {
    4141    WTF_MAKE_ISO_ALLOCATED(CSSTransformValue);
    4242public:
Note: See TracChangeset for help on using the changeset viewer.