Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (291596 => 291597)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-03-22 03:22:44 UTC (rev 291597)
@@ -1,3 +1,12 @@
+2022-03-21 Alex Christensen <achristen...@webkit.org>
+
+ Implement CSSNumericValue.mul, div, add, sub, max, and min
+ https://bugs.webkit.org/show_bug.cgi?id=238153
+
+ Reviewed by Simon Fraser.
+
+ * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt:
+
2022-03-21 Oriol Brufau <obru...@igalia.com>
[css-cascade] Let revert-layer roll back to preshints
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt (291596 => 291597)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt 2022-03-22 03:22:44 UTC (rev 291597)
@@ -1,65 +1,65 @@
PASS Calling CSSUnitValue.add with no arguments returns itself
PASS Calling CSSMathValue.add with no arguments returns itself
-FAIL Calling CSSNumericValue.add with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.add with a single CSSNumericValue returns correct type
PASS Calling CSSMathValue.add with a single CSSNumericValue returns correct type
-FAIL Calling CSSNumericValue.add with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.add with more than one number CSSNumericValues returns correct type
PASS Calling CSSNumericValue.add can take numberish values
-FAIL Calling CSSMathSum.add with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathSum"
+PASS Calling CSSMathSum.add with number CSSUnitValues simplifies to a CSSUnitValue
PASS Calling CSSNumericValue.add with incompatible types throws TypeError
PASS Calling CSSUnitValue.sub with no arguments returns itself
PASS Calling CSSMathValue.sub with no arguments returns itself
-FAIL Calling CSSNumericValue.sub with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.sub with a single CSSNumericValue returns correct type
PASS Calling CSSMathValue.sub with a single CSSNumericValue returns correct type
-FAIL Calling CSSNumericValue.sub with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.sub with more than one number CSSNumericValues returns correct type
PASS Calling CSSNumericValue.sub can take numberish values
-FAIL Calling CSSMathSum.sub with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathSum"
+PASS Calling CSSMathSum.sub with number CSSUnitValues simplifies to a CSSUnitValue
PASS Calling CSSNumericValue.sub with incompatible types throws TypeError
PASS Calling CSSUnitValue.mul with no arguments returns itself
PASS Calling CSSMathValue.mul with no arguments returns itself
-FAIL Calling CSSNumericValue.mul with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.mul with a single CSSNumericValue returns correct type
PASS Calling CSSMathValue.mul with a single CSSNumericValue returns correct type
-FAIL Calling CSSNumericValue.mul with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.mul with more than one number CSSNumericValues returns correct type
PASS Calling CSSNumericValue.mul can take numberish values
-FAIL Calling CSSMathProduct.mul with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathProduct"
+PASS Calling CSSMathProduct.mul with number CSSUnitValues simplifies to a CSSUnitValue
PASS Calling CSSNumericValue.mul with incompatible types throws TypeError
PASS Calling CSSUnitValue.div with no arguments returns itself
PASS Calling CSSMathValue.div with no arguments returns itself
-FAIL Calling CSSNumericValue.div with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.div with a single CSSNumericValue returns correct type
PASS Calling CSSMathValue.div with a single CSSNumericValue returns correct type
-FAIL Calling CSSNumericValue.div with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.div with more than one number CSSNumericValues returns correct type
PASS Calling CSSNumericValue.div can take numberish values
-FAIL Calling CSSMathProduct.div with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathProduct"
+PASS Calling CSSMathProduct.div with number CSSUnitValues simplifies to a CSSUnitValue
PASS Calling CSSNumericValue.div with incompatible types throws TypeError
PASS Calling CSSUnitValue.min with no arguments returns itself
PASS Calling CSSMathValue.min with no arguments returns itself
-FAIL Calling CSSNumericValue.min with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathMin" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.min with a single CSSNumericValue returns correct type
PASS Calling CSSMathValue.min with a single CSSNumericValue returns correct type
-FAIL Calling CSSNumericValue.min with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathMin" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.min with more than one number CSSNumericValues returns correct type
PASS Calling CSSNumericValue.min can take numberish values
-FAIL Calling CSSMathMin.min with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathMin"
+PASS Calling CSSMathMin.min with number CSSUnitValues simplifies to a CSSUnitValue
PASS Calling CSSNumericValue.min with incompatible types throws TypeError
PASS Calling CSSUnitValue.max with no arguments returns itself
PASS Calling CSSMathValue.max with no arguments returns itself
-FAIL Calling CSSNumericValue.max with a single CSSNumericValue returns correct type assert_equals: expected "CSSMathMax" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.max with a single CSSNumericValue returns correct type
PASS Calling CSSMathValue.max with a single CSSNumericValue returns correct type
-FAIL Calling CSSNumericValue.max with more than one number CSSNumericValues returns correct type assert_equals: expected "CSSMathMax" but got "CSSUnitValue"
+PASS Calling CSSNumericValue.max with more than one number CSSNumericValues returns correct type
PASS Calling CSSNumericValue.max can take numberish values
-FAIL Calling CSSMathMax.max with number CSSUnitValues simplifies to a CSSUnitValue assert_equals: expected "CSSUnitValue" but got "CSSMathMax"
+PASS Calling CSSMathMax.max with number CSSUnitValues simplifies to a CSSUnitValue
PASS Calling CSSNumericValue.max with incompatible types throws TypeError
-FAIL Calling CSSUnitValue.add with CSSUnitValues with same unit simplifies to a CSSUnitValue assert_equals: expected 17 but got 10
-FAIL Calling CSSUnitValue.sub with CSSUnitValues with same unit simplifies to a CSSUnitValue assert_equals: expected 3 but got 10
-FAIL Calling CSSUnitValue.mul with all numbers simplifies to a CSSUnitValue assert_equals: expected 100 but got 10
-FAIL Calling CSSUnitValue.mul with only one non-number simplifies to a CSSUnitValue assert_equals: expected 100 but got 10
-FAIL Calling CSSUnitValue.mul with more than one non-number does not simplify to a CSSUnitValue assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
-FAIL Calling CSSUnitValue.div with all numbers simplifies to a CSSUnitValue assert_equals: expected 1 but got 10
-FAIL Calling CSSUnitValue.div on a non-number value simplifies to a CSSUnitValue assert_equals: expected 1 but got 10
-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"
-FAIL Calling CSSUnitValue.min with CSSUnitValues with same unit simplifies to a CSSUnitValue assert_equals: expected 2 but got 10
+PASS Calling CSSUnitValue.add with CSSUnitValues with same unit simplifies to a CSSUnitValue
+PASS Calling CSSUnitValue.sub with CSSUnitValues with same unit simplifies to a CSSUnitValue
+PASS Calling CSSUnitValue.mul with all numbers simplifies to a CSSUnitValue
+PASS Calling CSSUnitValue.mul with only one non-number simplifies to a CSSUnitValue
+PASS Calling CSSUnitValue.mul with more than one non-number does not simplify to a CSSUnitValue
+PASS Calling CSSUnitValue.div with all numbers simplifies to a CSSUnitValue
+PASS Calling CSSUnitValue.div on a non-number value simplifies to a CSSUnitValue
+PASS Calling CSSUnitValue.div with a non-number value in the arguments does not simplify to a CSSUnitValue
+PASS Calling CSSUnitValue.min with CSSUnitValues with same unit simplifies to a CSSUnitValue
PASS Calling CSSUnitValue.max with CSSUnitValues with same unit simplifies to a CSSUnitValue
-FAIL Calling CSSNumericValue.sub negates all argument values assert_equals: expected "CSSMathSum" but got "CSSUnitValue"
-FAIL Calling CSSNumericValue.div inverts all argument values assert_equals: expected "CSSMathProduct" but got "CSSUnitValue"
-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
+PASS Calling CSSNumericValue.sub negates all argument values
+PASS Calling CSSNumericValue.div inverts all argument values
+PASS Can not divide with CSSUnitValue which has zero value and number type
FAIL 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
FAIL 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
Modified: trunk/Source/WebCore/ChangeLog (291596 => 291597)
--- trunk/Source/WebCore/ChangeLog 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/ChangeLog 2022-03-22 03:22:44 UTC (rev 291597)
@@ -1,3 +1,89 @@
+2022-03-21 Alex Christensen <achristen...@webkit.org>
+
+ Implement CSSNumericValue.mul, div, add, sub, max, and min
+ https://bugs.webkit.org/show_bug.cgi?id=238153
+
+ Reviewed by Simon Fraser.
+
+ 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.
+
2022-03-21 Oriol Brufau <obru...@igalia.com>
[css-cascade] Let revert-layer roll back to preshints
Modified: trunk/Source/WebCore/Sources.txt (291596 => 291597)
--- trunk/Source/WebCore/Sources.txt 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/Sources.txt 2022-03-22 03:22:44 UTC (rev 291597)
@@ -868,7 +868,6 @@
css/typedom/numeric/CSSMathNegate.cpp
css/typedom/numeric/CSSMathProduct.cpp
css/typedom/numeric/CSSMathSum.cpp
-css/typedom/numeric/CSSMathValue.cpp
css/typedom/numeric/CSSNumericArray.cpp
css/typedom/transform/CSSMatrixComponent.cpp
css/typedom/transform/CSSPerspective.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (291596 => 291597)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-03-22 03:22:44 UTC (rev 291597)
@@ -8034,7 +8034,6 @@
2AEF6FE326E802F000326D02 /* CSSMathNegate.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathNegate.cpp; sourceTree = "<group>"; };
2AEF6FE426E802F000326D02 /* CSSMathProduct.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathProduct.cpp; sourceTree = "<group>"; };
2AEF6FE526E802F100326D02 /* CSSMathSum.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathSum.cpp; sourceTree = "<group>"; };
- 2AEF6FE626E802F100326D02 /* CSSMathValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMathValue.cpp; sourceTree = "<group>"; };
2B42359F15250F6000DBBCD8 /* RenderSVGEllipse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGEllipse.cpp; sourceTree = "<group>"; };
2B4235A015250F6000DBBCD8 /* RenderSVGEllipse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGEllipse.h; sourceTree = "<group>"; };
2BE8E2C612A589EC00FAD550 /* HTMLMetaCharsetParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLMetaCharsetParser.h; sourceTree = "<group>"; };
@@ -20788,7 +20787,6 @@
2AEF6FE526E802F100326D02 /* CSSMathSum.cpp */,
2AEF6FC126E716EE00326D02 /* CSSMathSum.h */,
2AEF6FC326E716EE00326D02 /* CSSMathSum.idl */,
- 2AEF6FE626E802F100326D02 /* CSSMathValue.cpp */,
2AEF6FC726E716EE00326D02 /* CSSMathValue.h */,
2AEF6FBE26E716EE00326D02 /* CSSMathValue.idl */,
2AEF6FE026E802EF00326D02 /* CSSNumericArray.cpp */,
Modified: trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp (291596 => 291597)
--- trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -29,9 +29,16 @@
#if ENABLE(CSS_TYPED_OM)
#include "JSCSSKeywordValue.h"
+#include "JSCSSMathInvert.h"
+#include "JSCSSMathMax.h"
+#include "JSCSSMathMin.h"
+#include "JSCSSMathNegate.h"
+#include "JSCSSMathProduct.h"
+#include "JSCSSMathSum.h"
#include "JSCSSMathValue.h"
#include "JSCSSNumericValue.h"
#include "JSCSSStyleImageValue.h"
+#include "JSCSSTransformValue.h"
#include "JSCSSUnitValue.h"
#include "JSCSSUnparsedValue.h"
#include "JSDOMWrapperCache.h"
@@ -46,8 +53,18 @@
return createWrapper<CSSStyleImageValue>(globalObject, WTFMove(value));
case CSSStyleValueType::CSSNumericValue:
return createWrapper<CSSNumericValue>(globalObject, WTFMove(value));
- case CSSStyleValueType::CSSMathValue:
- return createWrapper<CSSMathValue>(globalObject, WTFMove(value));
+ case CSSStyleValueType::CSSMathInvert:
+ return createWrapper<CSSMathInvert>(globalObject, WTFMove(value));
+ case CSSStyleValueType::CSSMathMin:
+ return createWrapper<CSSMathMin>(globalObject, WTFMove(value));
+ case CSSStyleValueType::CSSMathMax:
+ return createWrapper<CSSMathMax>(globalObject, WTFMove(value));
+ case CSSStyleValueType::CSSMathNegate:
+ return createWrapper<CSSMathNegate>(globalObject, WTFMove(value));
+ case CSSStyleValueType::CSSMathProduct:
+ return createWrapper<CSSMathProduct>(globalObject, WTFMove(value));
+ case CSSStyleValueType::CSSMathSum:
+ return createWrapper<CSSMathSum>(globalObject, WTFMove(value));
case CSSStyleValueType::CSSUnitValue:
return createWrapper<CSSUnitValue>(globalObject, WTFMove(value));
case CSSStyleValueType::CSSUnparsedValue:
@@ -55,6 +72,7 @@
case CSSStyleValueType::CSSKeywordValue:
return createWrapper<CSSKeywordValue>(globalObject, WTFMove(value));
case CSSStyleValueType::CSSTransformValue:
+ return createWrapper<CSSTransformValue>(globalObject, WTFMove(value));
case CSSStyleValueType::CSSStyleValue:
return createWrapper<CSSStyleValue>(globalObject, WTFMove(value));
}
Modified: trunk/Source/WebCore/css/typedom/CSSKeywordValue.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/CSSKeywordValue.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/CSSKeywordValue.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -35,7 +35,7 @@
template<typename> class ExceptionOr;
-class CSSKeywordValue : public CSSStyleValue {
+class CSSKeywordValue final : public CSSStyleValue {
WTF_MAKE_ISO_ALLOCATED(CSSKeywordValue);
public:
static ExceptionOr<Ref<CSSKeywordValue>> create(const String&);
Modified: trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -30,14 +30,19 @@
#include "config.h"
#include "CSSNumericValue.h"
+#if ENABLE(CSS_TYPED_OM)
+
+#include "CSSMathInvert.h"
+#include "CSSMathMax.h"
+#include "CSSMathMin.h"
+#include "CSSMathNegate.h"
+#include "CSSMathProduct.h"
#include "CSSMathSum.h"
+#include "CSSNumericArray.h"
#include "CSSNumericFactory.h"
#include "CSSNumericType.h"
#include "CSSUnitValue.h"
#include "ExceptionOr.h"
-
-#if ENABLE(CSS_TYPED_OM)
-
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
@@ -44,54 +49,170 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSNumericValue);
-Ref<CSSNumericValue> CSSNumericValue::add(FixedVector<CSSNumberish>&& values)
+static Ref<CSSNumericValue> negate(Ref<CSSNumericValue>&& value)
{
- UNUSED_PARAM(values);
- // FIXME: add impl.
+ // https://drafts.css-houdini.org/css-typed-om/#cssmath-negate-a-cssnumericvalue
+ if (auto* mathNegate = dynamicDowncast<CSSMathNegate>(value.get()))
+ return mathNegate->value();
+ if (auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get()))
+ return CSSUnitValue::create(-unitValue->value(), unitValue->unit());
+ return CSSMathNegate::create(WTFMove(value));
+}
- return *this;
+static ExceptionOr<Ref<CSSNumericValue>> invert(Ref<CSSNumericValue>&& value)
+{
+ // https://drafts.css-houdini.org/css-typed-om/#cssmath-invert-a-cssnumericvalue
+ if (auto* mathInvert = dynamicDowncast<CSSMathInvert>(value.get()))
+ return Ref { mathInvert->value() };
+
+ if (auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get())) {
+ // FIXME: units should be either AtomicStrings or CSSUnitType enumeration values.
+ if (unitValue->unit() == "number") {
+ if (unitValue->value() == 0.0 || unitValue->value() == -0.0)
+ return Exception { RangeError };
+ return Ref<CSSNumericValue> { CSSUnitValue::create(1.0 / unitValue->value(), unitValue->unit()) };
+ }
+ }
+
+ return Ref<CSSNumericValue> { CSSMathInvert::create(WTFMove(value)) };
}
-Ref<CSSNumericValue> CSSNumericValue::sub(FixedVector<CSSNumberish>&& values)
+template<typename T>
+static RefPtr<CSSNumericValue> operationOnValuesOfSameUnit(T&& operation, const Vector<Ref<CSSNumericValue>>& values)
{
- UNUSED_PARAM(values);
- // FIXME: add impl.
+ bool allValuesHaveSameUnit = values.size() && WTF::allOf(values, [&] (const Ref<CSSNumericValue>& value) {
+ auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get());
+ return unitValue ? unitValue->unit() == downcast<CSSUnitValue>(values[0].get()).unit() : false;
+ });
+ if (allValuesHaveSameUnit) {
+ auto& firstUnitValue = downcast<CSSUnitValue>(values[0].get());
+ String unit = firstUnitValue.unit();
+ double result = firstUnitValue.value();
+ for (size_t i = 1; i < values.size(); i++)
+ result = operation(result, downcast<CSSUnitValue>(values[i].get()).value());
+ return CSSUnitValue::create(result, unit);
+ }
+ return nullptr;
+}
- return *this;
+template<typename T> Vector<Ref<CSSNumericValue>> CSSNumericValue::prependItemsOfTypeOrThis(Vector<Ref<CSSNumericValue>>&& numericValues)
+{
+ Vector<Ref<CSSNumericValue>> values;
+ if (T* t = dynamicDowncast<T>(*this))
+ values.appendVector(t->values().array());
+ else
+ values.append(*this);
+ values.appendVector(numericValues);
+ return values;
}
-Ref<CSSNumericValue> CSSNumericValue::mul(FixedVector<CSSNumberish>&& values)
+Ref<CSSNumericValue> CSSNumericValue::addInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
{
- UNUSED_PARAM(values);
- // FIXME: add impl.
+ // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-add
+ auto values = prependItemsOfTypeOrThis<CSSMathSum>(WTFMove(numericValues));
- return *this;
+ if (auto result = operationOnValuesOfSameUnit(std::plus<double>(), values))
+ return *result;
+
+ // FIXME: Implement step 4 to check that the types can be added.
+
+ return CSSMathSum::create(WTFMove(values));
}
-Ref<CSSNumericValue> CSSNumericValue::div(FixedVector<CSSNumberish>&& values)
+Ref<CSSNumericValue> CSSNumericValue::add(FixedVector<CSSNumberish>&& values)
{
- UNUSED_PARAM(values);
- // FIXME: add impl.
+ return addInternal(WTF::map(WTFMove(values), rectifyNumberish));
+}
- return *this;
+Ref<CSSNumericValue> CSSNumericValue::sub(FixedVector<CSSNumberish>&& values)
+{
+ return addInternal(WTF::map(WTFMove(values), [] (CSSNumberish&& numberish) {
+ return negate(rectifyNumberish(WTFMove(numberish)));
+ }));
}
-Ref<CSSNumericValue> CSSNumericValue::min(FixedVector<CSSNumberish>&& values)
+
+Ref<CSSNumericValue> CSSNumericValue::multiplyInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
{
- UNUSED_PARAM(values);
- // FIXME: add impl.
+ // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-mul
+ auto values = prependItemsOfTypeOrThis<CSSMathProduct>(WTFMove(numericValues));
- return *this;
+ bool allUnitValues = WTF::allOf(values, [&] (const Ref<CSSNumericValue>& value) {
+ return is<CSSUnitValue>(value.get());
+ });
+ if (allUnitValues) {
+ bool multipleUnitsFound { false };
+ std::optional<size_t> nonNumberUnitIndex;
+ for (size_t i = 0; i < values.size(); i++) {
+ auto& unit = downcast<CSSUnitValue>(values[i].get()).unit();
+ if (unit == "number")
+ continue;
+ if (nonNumberUnitIndex) {
+ multipleUnitsFound = true;
+ break;
+ }
+ nonNumberUnitIndex = i;
+ }
+ if (!multipleUnitsFound) {
+ double product = 1;
+ for (const Ref<CSSNumericValue>& value : values)
+ product *= downcast<CSSUnitValue>(value.get()).value();
+ String unit = nonNumberUnitIndex ? downcast<CSSUnitValue>(values[*nonNumberUnitIndex].get()).unit() : "number";
+ return CSSUnitValue::create(product, unit);
+ }
+ }
+
+ // FIXME: Implement step 5 to produce a unit of the correct type.
+
+ return CSSMathProduct::create(WTFMove(values));
}
-Ref<CSSNumericValue> CSSNumericValue::max(FixedVector<CSSNumberish>&& values)
+
+Ref<CSSNumericValue> CSSNumericValue::mul(FixedVector<CSSNumberish>&& values)
{
- UNUSED_PARAM(values);
- // FIXME: add impl.
+ return multiplyInternal(WTF::map(WTFMove(values), rectifyNumberish));
+}
- return *this;
+ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::div(FixedVector<CSSNumberish>&& values)
+{
+ Vector<Ref<CSSNumericValue>> invertedValues;
+ invertedValues.reserveInitialCapacity(values.size());
+ for (auto&& value : WTFMove(values)) {
+ auto inverted = invert(rectifyNumberish(WTFMove(value)));
+ if (inverted.hasException())
+ return inverted.releaseException();
+ invertedValues.uncheckedAppend(inverted.releaseReturnValue());
+ }
+ return multiplyInternal(WTFMove(invertedValues));
}
+Ref<CSSNumericValue> CSSNumericValue::min(FixedVector<CSSNumberish>&& numberishes)
+{
+ // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-min
+ auto values = prependItemsOfTypeOrThis<CSSMathMin>(WTF::map(WTFMove(numberishes), rectifyNumberish));
+
+ if (auto result = operationOnValuesOfSameUnit<const double&(*)(const double&, const double&)>(std::min<double>, values))
+ return *result;
+
+ // FIXME: Implement step 4 to check that the types can be added.
+
+ return CSSMathMin::create(WTFMove(values));
+}
+
+Ref<CSSNumericValue> CSSNumericValue::max(FixedVector<CSSNumberish>&& numberishes)
+{
+ // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-max
+ auto values = prependItemsOfTypeOrThis<CSSMathMax>(WTF::map(WTFMove(numberishes), rectifyNumberish));
+
+ if (auto result = operationOnValuesOfSameUnit<const double&(*)(const double&, const double&)>(std::max<double>, values))
+ return *result;
+
+ // FIXME: Implement step 4 to check that the types can be added.
+
+ return CSSMathMax::create(WTFMove(values));
+}
+
Ref<CSSNumericValue> CSSNumericValue::rectifyNumberish(CSSNumberish&& numberish)
{
+ // https://drafts.css-houdini.org/css-typed-om/#rectify-a-numberish-value
return WTF::switchOn(numberish, [](RefPtr<CSSNumericValue>& value) {
RELEASE_ASSERT(!!value);
return Ref<CSSNumericValue> { *value };
@@ -121,7 +242,7 @@
UNUSED_PARAM(units);
// https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-tosum
// FIXME: add impl.
- return CSSMathSum::create({ 1.0 });
+ return CSSMathSum::create(FixedVector<CSSNumberish> { 1.0 });
}
CSSNumericType CSSNumericValue::type()
Modified: trunk/Source/WebCore/css/typedom/CSSNumericValue.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/CSSNumericValue.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/CSSNumericValue.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -48,7 +48,7 @@
Ref<CSSNumericValue> add(FixedVector<CSSNumberish>&&);
Ref<CSSNumericValue> sub(FixedVector<CSSNumberish>&&);
Ref<CSSNumericValue> mul(FixedVector<CSSNumberish>&&);
- Ref<CSSNumericValue> div(FixedVector<CSSNumberish>&&);
+ ExceptionOr<Ref<CSSNumericValue>> div(FixedVector<CSSNumberish>&&);
Ref<CSSNumericValue> min(FixedVector<CSSNumberish>&&);
Ref<CSSNumericValue> max(FixedVector<CSSNumberish>&&);
@@ -60,10 +60,14 @@
static ExceptionOr<Ref<CSSNumericValue>> parse(String&&);
static Ref<CSSNumericValue> rectifyNumberish(CSSNumberish&&);
-
+
CSSStyleValueType getType() const override { return CSSStyleValueType::CSSNumericValue; }
protected:
+ Ref<CSSNumericValue> addInternal(Vector<Ref<CSSNumericValue>>&&);
+ Ref<CSSNumericValue> multiplyInternal(Vector<Ref<CSSNumericValue>>&&);
+ template<typename T> Vector<Ref<CSSNumericValue>> prependItemsOfTypeOrThis(Vector<Ref<CSSNumericValue>>&&);
+
CSSNumericValue() = default;
};
@@ -72,7 +76,7 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSNumericValue)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSNumericValue; }
+ static bool isType(const WebCore::CSSStyleValue& styleValue) { return isCSSNumericValue(styleValue.getType()); }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Modified: trunk/Source/WebCore/css/typedom/CSSStyleValue.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/CSSStyleValue.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/CSSStyleValue.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -44,12 +44,61 @@
CSSStyleImageValue,
CSSTransformValue,
CSSNumericValue,
- CSSMathValue,
+ CSSMathInvert,
+ CSSMathMin,
+ CSSMathMax,
+ CSSMathNegate,
+ CSSMathProduct,
+ CSSMathSum,
CSSUnitValue,
CSSUnparsedValue,
CSSKeywordValue
};
+inline bool isCSSNumericValue(CSSStyleValueType type)
+{
+ switch (type) {
+ case CSSStyleValueType::CSSNumericValue:
+ case CSSStyleValueType::CSSMathInvert:
+ case CSSStyleValueType::CSSMathMin:
+ case CSSStyleValueType::CSSMathMax:
+ case CSSStyleValueType::CSSMathNegate:
+ case CSSStyleValueType::CSSMathProduct:
+ case CSSStyleValueType::CSSMathSum:
+ case CSSStyleValueType::CSSUnitValue:
+ return true;
+ case CSSStyleValueType::CSSStyleValue:
+ case CSSStyleValueType::CSSStyleImageValue:
+ case CSSStyleValueType::CSSTransformValue:
+ case CSSStyleValueType::CSSUnparsedValue:
+ case CSSStyleValueType::CSSKeywordValue:
+ break;
+ }
+ return false;
+}
+
+inline bool isCSSMathValue(CSSStyleValueType type)
+{
+ switch (type) {
+ case CSSStyleValueType::CSSMathInvert:
+ case CSSStyleValueType::CSSMathMin:
+ case CSSStyleValueType::CSSMathMax:
+ case CSSStyleValueType::CSSMathNegate:
+ case CSSStyleValueType::CSSMathProduct:
+ case CSSStyleValueType::CSSMathSum:
+ return true;
+ case CSSStyleValueType::CSSNumericValue:
+ case CSSStyleValueType::CSSUnitValue:
+ case CSSStyleValueType::CSSStyleValue:
+ case CSSStyleValueType::CSSStyleImageValue:
+ case CSSStyleValueType::CSSTransformValue:
+ case CSSStyleValueType::CSSUnparsedValue:
+ case CSSStyleValueType::CSSKeywordValue:
+ break;
+ }
+ return false;
+}
+
class CSSStyleValue : public RefCounted<CSSStyleValue>, public ScriptWrappable {
WTF_MAKE_ISO_ALLOCATED(CSSStyleValue);
public:
Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/CSSUnitValue.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -66,7 +66,7 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSUnitValue)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSUnitValue; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSUnitValue; }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -42,8 +42,7 @@
}
CSSMathInvert::CSSMathInvert(CSSNumberish&& numberish)
- : CSSMathValue(CSSMathOperator::Invert)
- , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
+ : m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
{
}
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -31,13 +31,16 @@
namespace WebCore {
-class CSSMathInvert : public CSSMathValue {
+class CSSMathInvert final : public CSSMathValue {
WTF_MAKE_ISO_ALLOCATED(CSSMathInvert);
public:
static Ref<CSSMathInvert> create(CSSNumberish&&);
- const CSSNumericValue& value() const { return m_value.get(); }
+ CSSNumericValue& value() { return m_value.get(); }
private:
+ CSSMathOperator getOperator() const final { return CSSMathOperator::Invert; }
+ CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathInvert; }
+
CSSMathInvert(CSSNumberish&&);
Ref<CSSNumericValue> m_value;
};
@@ -45,9 +48,9 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathInvert)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
- static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Invert; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathInvert; }
+static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathInvert; }
+static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathInvert; }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -36,14 +36,13 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathMax);
-Ref<CSSMathMax> CSSMathMax::create(FixedVector<CSSNumberish>&& numberishes)
+CSSMathMax::CSSMathMax(FixedVector<CSSNumberish>&& numberishes)
+ : m_values(CSSNumericArray::create(WTFMove(numberishes)))
{
- return adoptRef(*new CSSMathMax(WTFMove(numberishes)));
}
-CSSMathMax::CSSMathMax(FixedVector<CSSNumberish>&& numberishes)
- : CSSMathValue(CSSMathOperator::Max)
- , m_values(CSSNumericArray::create(WTFMove(numberishes)))
+CSSMathMax::CSSMathMax(Vector<Ref<CSSNumericValue>>&& values)
+ : m_values(CSSNumericArray::create(WTFMove(values)))
{
}
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -34,14 +34,18 @@
class CSSNumericArray;
-class CSSMathMax : public CSSMathValue {
+class CSSMathMax final : public CSSMathValue {
WTF_MAKE_ISO_ALLOCATED(CSSMathMax);
public:
- static Ref<CSSMathMax> create(FixedVector<CSSNumberish>&&);
+ template<typename... Args> static Ref<CSSMathMax> create(Args&&... args) { return adoptRef(*new CSSMathMax(std::forward<Args>(args)...)); }
const CSSNumericArray& values() const;
-
+
private:
+ CSSMathOperator getOperator() const final { return CSSMathOperator::Max; }
+ CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMax; }
+
CSSMathMax(FixedVector<CSSNumberish>&&);
+ CSSMathMax(Vector<Ref<CSSNumericValue>>&&);
Ref<CSSNumericArray> m_values;
};
@@ -48,9 +52,9 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathMax)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
-static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Max; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathMax; }
+static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathMax; }
+static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathMax; }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -36,14 +36,13 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathMin);
-Ref<CSSMathMin> CSSMathMin::create(FixedVector<CSSNumberish>&& numberishes)
+CSSMathMin::CSSMathMin(FixedVector<CSSNumberish>&& numberishes)
+ : m_values(CSSNumericArray::create(WTFMove(numberishes)))
{
- return adoptRef(*new CSSMathMin(WTFMove(numberishes)));
}
-CSSMathMin::CSSMathMin(FixedVector<CSSNumberish>&& numberishes)
- : CSSMathValue(CSSMathOperator::Min)
- , m_values(CSSNumericArray::create(WTFMove(numberishes)))
+CSSMathMin::CSSMathMin(Vector<Ref<CSSNumericValue>>&& values)
+ : m_values(CSSNumericArray::create(WTFMove(values)))
{
}
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -34,14 +34,18 @@
class CSSNumericArray;
-class CSSMathMin : public CSSMathValue {
+class CSSMathMin final : public CSSMathValue {
WTF_MAKE_ISO_ALLOCATED(CSSMathMin);
public:
- static Ref<CSSMathMin> create(FixedVector<CSSNumberish>&&);
+ template<typename... Args> static Ref<CSSMathMin> create(Args&&... args) { return adoptRef(*new CSSMathMin(std::forward<Args>(args)...)); }
const CSSNumericArray& values() const;
-
+
private:
+ CSSMathOperator getOperator() const final { return CSSMathOperator::Min; }
+ CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMin; }
+
CSSMathMin(FixedVector<CSSNumberish>&&);
+ CSSMathMin(Vector<Ref<CSSNumericValue>>&&);
Ref<CSSNumericArray> m_values;
};
@@ -48,9 +52,9 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathMin)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
- static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Min; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathMin; }
+static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathMin; }
+static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathMin; }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -36,14 +36,13 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathNegate);
-Ref<CSSMathNegate> CSSMathNegate::create(CSSNumberish&& numberish)
+CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
+ : m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
{
- return adoptRef(*new CSSMathNegate(WTFMove(numberish)));
}
-CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
- : CSSMathValue(CSSMathOperator::Negate)
- , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
+CSSMathNegate::CSSMathNegate(Ref<CSSNumericValue>&& value)
+ : m_value(WTFMove(value))
{
}
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -34,14 +34,18 @@
class CSSNumericValue;
-class CSSMathNegate : public CSSMathValue {
+class CSSMathNegate final : public CSSMathValue {
WTF_MAKE_ISO_ALLOCATED(CSSMathNegate);
public:
- static Ref<CSSMathNegate> create(CSSNumberish&&);
- const CSSNumericValue& value() const { return m_value.get(); }
+ template<typename... Args> static Ref<CSSMathNegate> create(Args&&... args) { return adoptRef(*new CSSMathNegate(std::forward<Args>(args)...)); }
+ CSSNumericValue& value() { return m_value.get(); }
private:
+ CSSMathOperator getOperator() const final { return CSSMathOperator::Negate; }
+ CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathNegate; }
+
CSSMathNegate(CSSNumberish&&);
+ CSSMathNegate(Ref<CSSNumericValue>&&);
Ref<CSSNumericValue> m_value;
};
@@ -48,9 +52,9 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathNegate)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
- static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Negate; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathNegate; }
+static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathNegate; }
+static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathNegate; }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -36,14 +36,13 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathProduct);
-Ref<CSSMathProduct> CSSMathProduct::create(FixedVector<CSSNumberish>&& numberishes)
+CSSMathProduct::CSSMathProduct(FixedVector<CSSNumberish>&& numberishes)
+ : m_values(CSSNumericArray::create(WTFMove(numberishes)))
{
- return adoptRef(*new CSSMathProduct(WTFMove(numberishes)));
}
-CSSMathProduct::CSSMathProduct(FixedVector<CSSNumberish>&& numberishes)
- : CSSMathValue(CSSMathOperator::Product)
- , m_values(CSSNumericArray::create(WTFMove(numberishes)))
+CSSMathProduct::CSSMathProduct(Vector<Ref<CSSNumericValue>>&& values)
+ : m_values(CSSNumericArray::create(WTFMove(values)))
{
}
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -34,16 +34,18 @@
class CSSNumericArray;
-class CSSMathProduct : public CSSMathValue {
+class CSSMathProduct final : public CSSMathValue {
WTF_MAKE_ISO_ALLOCATED(CSSMathProduct);
public:
- static Ref<CSSMathProduct> create(FixedVector<CSSNumberish>&&);
+ template<typename... Args> static Ref<CSSMathProduct> create(Args&&... args) { return adoptRef(*new CSSMathProduct(std::forward<Args>(args)...)); }
const CSSNumericArray& values() const;
-
+
+private:
CSSMathOperator getOperator() const final { return CSSMathOperator::Product; }
+ CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathProduct; }
-private:
CSSMathProduct(FixedVector<CSSNumberish>&&);
+ CSSMathProduct(Vector<Ref<CSSNumericValue>>&&);
Ref<CSSNumericArray> m_values;
};
@@ -50,9 +52,9 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathProduct)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
- static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Product; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathProduct; }
+static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathProduct; }
+static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathProduct; }
SPECIALIZE_TYPE_TRAITS_END()
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -36,20 +36,14 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathSum);
-Ref<CSSMathSum> CSSMathSum::create(FixedVector<CSSNumberish>&& numberishes)
-{
- return adoptRef(*new CSSMathSum(WTFMove(numberishes)));
-}
-
CSSMathSum::CSSMathSum(FixedVector<CSSNumberish>&& numberishes)
- : CSSMathValue(CSSMathOperator::Sum)
- , m_values(CSSNumericArray::create(WTFMove(numberishes)))
+ : m_values(CSSNumericArray::create(WTFMove(numberishes)))
{
}
-const CSSNumericArray& CSSMathSum::values() const
+CSSMathSum::CSSMathSum(Vector<Ref<CSSNumericValue>>&& values)
+ : m_values(CSSNumericArray::create(WTFMove(values)))
{
- return m_values.get();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -35,14 +35,18 @@
class CSSNumericArray;
-class CSSMathSum : public CSSMathValue {
+class CSSMathSum final : public CSSMathValue {
WTF_MAKE_ISO_ALLOCATED(CSSMathSum);
public:
- static Ref<CSSMathSum> create(FixedVector<CSSNumberish>&&);
- const CSSNumericArray& values() const;
+ template<typename... Args> static Ref<CSSMathSum> create(Args&&... args) { return adoptRef(*new CSSMathSum(std::forward<Args>(args)...)); }
+ const CSSNumericArray& values() const { return m_values.get(); }
private:
+ CSSMathOperator getOperator() const final { return CSSMathOperator::Sum; }
+ CSSStyleValueType getType() const override { return CSSStyleValueType::CSSMathSum; }
+
CSSMathSum(FixedVector<CSSNumberish>&&);
+ CSSMathSum(Vector<Ref<CSSNumericValue>>&&);
Ref<CSSNumericArray> m_values;
};
@@ -49,9 +53,9 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathSum)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return is<WebCore::CSSNumericValue>(styleValue) && isType(downcast<WebCore::CSSNumericValue>(styleValue)); }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return is<WebCore::CSSMathValue>(numericValue) && isType(downcast<WebCore::CSSMathValue>(numericValue)); }
- static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getOperator() == WebCore::CSSMathOperator::Sum; }
+static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathSum; }
+static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathSum; }
+static bool isType(const WebCore::CSSMathValue& mathValue) { return mathValue.getType() == WebCore::CSSStyleValueType::CSSMathSum; }
SPECIALIZE_TYPE_TRAITS_END()
#endif
Deleted: trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "CSSMathValue.h"
-
-#if ENABLE(CSS_TYPED_OM)
-
-#include <wtf/IsoMallocInlines.h>
-
-namespace WebCore {
-
-WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathValue);
-
-CSSMathValue::CSSMathValue(CSSMathOperator mathOperator)
- : m_operator(mathOperator)
-{
-}
-
-} // namespace WebCore
-
-#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -34,22 +34,10 @@
namespace WebCore {
class CSSMathValue : public CSSNumericValue {
- WTF_MAKE_ISO_ALLOCATED(CSSMathValue);
public:
- virtual CSSMathOperator getOperator() const { return m_operator; }
-
- CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathValue; }
-
-protected:
- CSSMathValue(CSSMathOperator);
- CSSMathOperator m_operator;
+ virtual CSSMathOperator getOperator() const = 0;
};
} // namespace WebCore
-SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSMathValue)
- static bool isType(const WebCore::CSSStyleValue& styleValue) { return styleValue.getType() == WebCore::CSSStyleValueType::CSSMathValue; }
- static bool isType(const WebCore::CSSNumericValue& numericValue) { return numericValue.getType() == WebCore::CSSStyleValueType::CSSMathValue; }
-SPECIALIZE_TYPE_TRAITS_END()
-
#endif
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp 2022-03-22 03:22:44 UTC (rev 291597)
@@ -45,11 +45,16 @@
})));
}
-Ref<CSSNumericArray> CSSNumericArray::create(FixedVector<Ref<CSSNumericValue>>&& values)
+Ref<CSSNumericArray> CSSNumericArray::create(Vector<Ref<CSSNumericValue>>&& values)
{
return adoptRef(*new CSSNumericArray(WTFMove(values)));
}
+CSSNumericArray::CSSNumericArray(Vector<Ref<CSSNumericValue>>&& values)
+ : m_array(WTFMove(values))
+{
+}
+
CSSNumericArray::CSSNumericArray(FixedVector<Ref<CSSNumericValue>>&& values)
: m_array(WTFMove(values))
{
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -41,12 +41,14 @@
WTF_MAKE_ISO_ALLOCATED(CSSNumericArray);
public:
static Ref<CSSNumericArray> create(const FixedVector<CSSNumberish>&);
- static Ref<CSSNumericArray> create(FixedVector<Ref<CSSNumericValue>>&&);
+ static Ref<CSSNumericArray> create(Vector<Ref<CSSNumericValue>>&&);
size_t length() const { return m_array.size(); };
ExceptionOr<Ref<CSSNumericValue>> item(size_t index);
+ const Vector<Ref<CSSNumericValue>>& array() const { return m_array; }
private:
- FixedVector<Ref<CSSNumericValue>> m_array;
+ Vector<Ref<CSSNumericValue>> m_array;
+ CSSNumericArray(Vector<Ref<CSSNumericValue>>&&);
CSSNumericArray(FixedVector<Ref<CSSNumericValue>>&&);
};
Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -28,18 +28,19 @@
#if ENABLE(CSS_TYPED_OM)
#include "CSSNumericBaseType.h"
+#include <optional>
namespace WebCore {
struct CSSNumericType {
- long length;
- long angle;
- long time;
- long frequency;
- long resolution;
- long flex;
- long percent;
- CSSNumericBaseType percentHint;
+ long length { 0 };
+ long angle { 0 };
+ long time { 0 };
+ long frequency { 0 };
+ long resolution { 0 };
+ long flex { 0 };
+ long percent { 0 };
+ std::optional<CSSNumericBaseType> percentHint;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h (291596 => 291597)
--- trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h 2022-03-22 02:09:04 UTC (rev 291596)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h 2022-03-22 03:22:44 UTC (rev 291597)
@@ -37,7 +37,7 @@
class DOMMatrix;
template<typename> class ExceptionOr;
-class CSSTransformValue : public CSSStyleValue {
+class CSSTransformValue final : public CSSStyleValue {
WTF_MAKE_ISO_ALLOCATED(CSSTransformValue);
public:
static Ref<CSSTransformValue> create(Vector<RefPtr<CSSTransformComponent>>&& transforms);