Title: [292150] trunk
Revision
292150
Author
[email protected]
Date
2022-03-31 03:21:18 -0700 (Thu, 31 Mar 2022)

Log Message

Implement units for CSS Typed OM
https://bugs.webkit.org/show_bug.cgi?id=238532

Patch by Alex Christensen <[email protected]> on 2022-03-31
Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-typed-om/stylevalue-serialization/cssUnitValue.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/add-two-types.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/create-a-type.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathInvert-type-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathNegate-type-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathValue.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssnumericvalue-multiply-two-types.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/to.tentative-expected.txt:

Source/WebCore:

This feature is off by default and this part is covered by WPT tests.

* css/typedom/CSSNumericFactory.h:
* css/typedom/CSSNumericValue.cpp:
(WebCore::negate):
(WebCore::invert):
(WebCore::operationOnValuesOfSameUnit):
(WebCore::CSSNumericValue::addInternal):
(WebCore::CSSNumericValue::add):
(WebCore::CSSNumericValue::sub):
(WebCore::CSSNumericValue::multiplyInternal):
(WebCore::CSSNumericValue::mul):
(WebCore::CSSNumericValue::to):
(WebCore::CSSNumericValue::toSum):
(WebCore::CSSNumericValue::type): Deleted.
* css/typedom/CSSNumericValue.h:
(WebCore::CSSNumericValue::type const):
(WebCore::CSSNumericValue::CSSNumericValue):
* css/typedom/CSSUnitValue.cpp:
(WebCore::numericType):
(WebCore::parseUnit):
(WebCore::CSSUnitValue::unit const):
(WebCore::CSSUnitValue::unitSerialization const):
(WebCore::CSSUnitValue::create):
(WebCore::CSSUnitValue::CSSUnitValue):
* css/typedom/CSSUnitValue.h:
* css/typedom/numeric/CSSMathInvert.cpp:
(WebCore::negatedType):
(WebCore::CSSMathInvert::CSSMathInvert):
* css/typedom/numeric/CSSMathNegate.cpp:
(WebCore::copyType):
(WebCore::CSSMathNegate::CSSMathNegate):
* css/typedom/numeric/CSSMathProduct.cpp:
(WebCore::multiplyTypes):
(WebCore::CSSMathProduct::create):
(WebCore::CSSMathProduct::CSSMathProduct):
(WebCore::CSSMathProduct::values const): Deleted.
* css/typedom/numeric/CSSMathProduct.h:
* css/typedom/numeric/CSSMathSum.cpp:
(WebCore::addTypes):
(WebCore::CSSMathSum::create):
(WebCore::CSSMathSum::CSSMathSum):
* css/typedom/numeric/CSSMathSum.h:
* css/typedom/numeric/CSSMathValue.h:
(WebCore::CSSMathValue::CSSMathValue):
* css/typedom/numeric/CSSNumericArray.cpp:
(WebCore::CSSNumericArray::create):
* css/typedom/numeric/CSSNumericBaseType.h:
(WebCore::eachBaseType):
(WebCore::debugString):
(): Deleted.
* css/typedom/numeric/CSSNumericType.h:
(WebCore::CSSNumericType::operator== const):
(WebCore::CSSNumericType::valueForType):
(WebCore::CSSNumericType::applyPercentHint):
(WebCore::CSSNumericType::debugString const):
(): Deleted.
* css/typedom/numeric/CSSNumericType.idl:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,3 +1,21 @@
+2022-03-31  Alex Christensen  <[email protected]>
+
+        Implement units for CSS Typed OM
+        https://bugs.webkit.org/show_bug.cgi?id=238532
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/css-typed-om/stylevalue-serialization/cssUnitValue.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/add-two-types.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/create-a-type.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathInvert-type-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathNegate-type-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathValue.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssnumericvalue-multiply-two-types.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/to.tentative-expected.txt:
+
 2022-03-30  Antti Koivisto  <[email protected]>
 
         [CSS Container Queries] Keep colon syntax when serializing container condition

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssUnitValue.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssUnitValue.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssUnitValue.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,8 +1,8 @@
 
-FAIL CSSUnitValue with length unit constructed from IDL serializes correctly assert_equals: expected "3.14px" but got "3px"
-FAIL CSSUnitValue with unit "percent" constructed from IDL serializes correctly assert_equals: expected "3.14%" but got "3percent"
-FAIL CSSUnitValue with unit "number" constructed from IDL serializes correctly assert_equals: expected "3.14" but got "3number"
-FAIL CSSUnitValue with integer values constructed from IDL serializes correctly assert_equals: expected "3" but got "3number"
-FAIL CSSKeywordValue from DOMString modified by "value" setter serializes correctly assert_equals: expected "3.14px" but got "3px"
-FAIL CSSKeywordValue from CSSOM modified by "value" setter serializes correctly assert_equals: expected "3.14px" but got "3px"
+PASS CSSUnitValue with length unit constructed from IDL serializes correctly
+PASS CSSUnitValue with unit "percent" constructed from IDL serializes correctly
+PASS CSSUnitValue with unit "number" constructed from IDL serializes correctly
+PASS CSSUnitValue with integer values constructed from IDL serializes correctly
+PASS CSSKeywordValue from DOMString modified by "value" setter serializes correctly
+PASS CSSKeywordValue from CSSOM modified by "value" setter serializes correctly
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/add-two-types.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/add-two-types.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/add-two-types.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,9 +1,9 @@
 
-FAIL Adding two types with different non-null percent hints throws TypeError assert_throws_js: function "() => new CSSMathSum(a, b)" did not throw
-FAIL Adding two types with the same nonzero values returns same type assert_equals: length expected 1 but got 0
-FAIL Adding two types with empty maps with returns empty map assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Adding a type with percent returns type with percent hint assert_equals: length expected 1 but got 0
-FAIL Adding a type with percent 2 returns type with percent hint throws TypeError assert_throws_js: function "() => new CSSMathSum(a, b)" did not throw
-FAIL Adding a type with a percent hint returns a type with the percent hint assert_equals: length expected 1 but got 0
-FAIL Adding two types with the same percent hint returns a type with the percent hint assert_equals: length expected 1 but got 0
+PASS Adding two types with different non-null percent hints throws TypeError
+PASS Adding two types with the same nonzero values returns same type
+PASS Adding two types with empty maps with returns empty map
+PASS Adding a type with percent returns type with percent hint
+PASS Adding a type with percent 2 returns type with percent hint throws TypeError
+PASS Adding a type with a percent hint returns a type with the percent hint
+PASS Adding two types with the same percent hint returns a type with the percent hint
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/arithmetic.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -60,6 +60,6 @@
 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
+PASS CSSNumericValue.add should throw TypeError when the types are different.
+PASS CSSNumericValue.sub should throw TypeError when the types are different.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/create-a-type.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/create-a-type.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/create-a-type.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,10 +1,10 @@
 
-FAIL Creating a type from "number" returns {} assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Creating a type from "percent" returns { percent: 1 } assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Creating a type from <length> returns { length: 1 } assert_equals: length expected 1 but got 0
-FAIL Creating a type from <angle> returns { angle: 1 } assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Creating a type from <time> returns { time: 1 } assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Creating a type from <frequency> returns { frequency: 1 } assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Creating a type from <resolution> returns { resolution: 1 } assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Creating a type from <flex> returns { flex: 1 } assert_equals: length expected (undefined) undefined but got (number) 0
+PASS Creating a type from "number" returns {}
+PASS Creating a type from "percent" returns { percent: 1 }
+PASS Creating a type from <length> returns { length: 1 }
+PASS Creating a type from <angle> returns { angle: 1 }
+PASS Creating a type from <time> returns { time: 1 }
+PASS Creating a type from <frequency> returns { frequency: 1 }
+PASS Creating a type from <resolution> returns { resolution: 1 }
+PASS Creating a type from <flex> returns { flex: 1 }
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathInvert-type-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathInvert-type-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathInvert-type-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,5 +1,5 @@
 
-FAIL Inverting a type with empty map returns the empty map assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Inverting a type negates all its exponents assert_equals: length expected -1 but got 0
-FAIL Inverting an inverted type returns the original type assert_equals: length expected 1 but got 0
+PASS Inverting a type with empty map returns the empty map
+PASS Inverting a type negates all its exponents
+PASS Inverting an inverted type returns the original type
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathNegate-type-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathNegate-type-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathNegate-type-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,4 +1,4 @@
 
-FAIL Negating a type with empty map returns the empty map assert_equals: length expected (undefined) undefined but got (number) 0
-FAIL Negating a type returns the same type assert_equals: length expected 1 but got 0
+PASS Negating a type with empty map returns the empty map
+PASS Negating a type returns the same type
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathValue.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathValue.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssMathValue.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,9 +1,9 @@
 
-FAIL Constructing a CSSMathSum with no arguments throws a SyntaxError assert_throws_dom: function "() => new subclass()" did not throw
+PASS Constructing a CSSMathSum with no arguments throws a SyntaxError
 PASS CSSMathSum can be constructed from a single number CSSUnitValue
 PASS CSSMathSum can be constructed from more than one number CSSUnitValue
 PASS CSSMathSum.operator is readonly
-FAIL Constructing a CSSMathProduct with no arguments throws a SyntaxError assert_throws_dom: function "() => new subclass()" did not throw
+PASS Constructing a CSSMathProduct with no arguments throws a SyntaxError
 PASS CSSMathProduct can be constructed from a single number CSSUnitValue
 PASS CSSMathProduct can be constructed from more than one number CSSUnitValue
 PASS CSSMathProduct.operator is readonly

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,6 +1,6 @@
 
-FAIL Constructing CSSUnitValue with an unknown unit throws a TypeError assert_throws_js: function "() => new CSSUnitValue(0, 'lemon')" did not throw
-FAIL Constructing CSSUnitValue with a empty string unit throws a TypeError assert_throws_js: function "() => new CSSUnitValue(0, '')" did not throw
+PASS Constructing CSSUnitValue with an unknown unit throws a TypeError
+PASS Constructing CSSUnitValue with a empty string unit throws a TypeError
 PASS CSSUnitValue can be constructed with number
 PASS CSSUnitValue can be constructed with percent
 PASS CSSUnitValue can be constructed with em
@@ -18,7 +18,7 @@
 PASS CSSUnitValue can be constructed with vmax
 PASS CSSUnitValue can be constructed with cm
 PASS CSSUnitValue can be constructed with mm
-FAIL CSSUnitValue can be constructed with Q assert_equals: unit is same as given by constructor expected "q" but got "Q"
+PASS CSSUnitValue can be constructed with Q
 PASS CSSUnitValue can be constructed with in
 PASS CSSUnitValue can be constructed with pt
 PASS CSSUnitValue can be constructed with pc
@@ -29,8 +29,8 @@
 PASS CSSUnitValue can be constructed with turn
 PASS CSSUnitValue can be constructed with s
 PASS CSSUnitValue can be constructed with ms
-FAIL CSSUnitValue can be constructed with Hz assert_equals: unit is same as given by constructor expected "hz" but got "Hz"
-FAIL CSSUnitValue can be constructed with kHz assert_equals: unit is same as given by constructor expected "khz" but got "kHz"
+PASS CSSUnitValue can be constructed with Hz
+PASS CSSUnitValue can be constructed with kHz
 PASS CSSUnitValue can be constructed with dpi
 PASS CSSUnitValue can be constructed with dpcm
 PASS CSSUnitValue can be constructed with dppx

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssnumericvalue-multiply-two-types.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssnumericvalue-multiply-two-types.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssnumericvalue-multiply-two-types.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,9 +1,9 @@
 
-FAIL Multiplying two types with different non-null percent hints throws TypeError assert_throws_js: function "() => new CSSMathProduct(a, b)" did not throw
-FAIL Multiplying two types with same base types adds exponents assert_equals: length expected 2 but got 0
-FAIL Multiplying two types with different base types adds exponents assert_equals: length expected 1 but got 0
-FAIL Multiplying two types respects the sign of the exponents assert_equals: length expected 1 but got 0
-FAIL Multiplying a type with no exponents is a no-op assert_equals: length expected 1 but got 0
-FAIL Multiplying a type with percent hint applies the percent hint assert_equals: length expected 2 but got 0
-FAIL Multiplying two types with same percent hint applies the percent hint assert_equals: length expected 2 but got 0
+PASS Multiplying two types with different non-null percent hints throws TypeError
+PASS Multiplying two types with same base types adds exponents
+PASS Multiplying two types with different base types adds exponents
+PASS Multiplying two types respects the sign of the exponents
+PASS Multiplying a type with no exponents is a no-op
+PASS Multiplying a type with percent hint applies the percent hint
+PASS Multiplying two types with same percent hint applies the percent hint
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/to.tentative-expected.txt (292149 => 292150)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/to.tentative-expected.txt	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/to.tentative-expected.txt	2022-03-31 10:21:18 UTC (rev 292150)
@@ -13,5 +13,5 @@
 FAIL Converting a CSSMathMax to a single unit with different units throws a TypeError assert_throws_js: function "() => new CSSMathMax(CSS.px(2), CSS.s(3)).to('px')" did not throw
 FAIL Converting a CSSMathNegate to a single unit negates its value assert_approx_equals: expected -1 +/- 0.000001 but got 1
 FAIL Converting a CSSMathInvert to a single unit inverts its value and units assert_approx_equals: expected 2 +/- 0.000001 but got 1
-FAIL Converting a complex _expression_ to a single unit assert_approx_equals: expected 3500 +/- 0.000001 but got 1
+FAIL Converting a complex _expression_ to a single unit Type error
 

Modified: trunk/Source/WebCore/ChangeLog (292149 => 292150)


--- trunk/Source/WebCore/ChangeLog	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/ChangeLog	2022-03-31 10:21:18 UTC (rev 292150)
@@ -1,3 +1,69 @@
+2022-03-31  Alex Christensen  <[email protected]>
+
+        Implement units for CSS Typed OM
+        https://bugs.webkit.org/show_bug.cgi?id=238532
+
+        Reviewed by Simon Fraser.
+
+        This feature is off by default and this part is covered by WPT tests.
+
+        * css/typedom/CSSNumericFactory.h:
+        * css/typedom/CSSNumericValue.cpp:
+        (WebCore::negate):
+        (WebCore::invert):
+        (WebCore::operationOnValuesOfSameUnit):
+        (WebCore::CSSNumericValue::addInternal):
+        (WebCore::CSSNumericValue::add):
+        (WebCore::CSSNumericValue::sub):
+        (WebCore::CSSNumericValue::multiplyInternal):
+        (WebCore::CSSNumericValue::mul):
+        (WebCore::CSSNumericValue::to):
+        (WebCore::CSSNumericValue::toSum):
+        (WebCore::CSSNumericValue::type): Deleted.
+        * css/typedom/CSSNumericValue.h:
+        (WebCore::CSSNumericValue::type const):
+        (WebCore::CSSNumericValue::CSSNumericValue):
+        * css/typedom/CSSUnitValue.cpp:
+        (WebCore::numericType):
+        (WebCore::parseUnit):
+        (WebCore::CSSUnitValue::unit const):
+        (WebCore::CSSUnitValue::unitSerialization const):
+        (WebCore::CSSUnitValue::create):
+        (WebCore::CSSUnitValue::CSSUnitValue):
+        * css/typedom/CSSUnitValue.h:
+        * css/typedom/numeric/CSSMathInvert.cpp:
+        (WebCore::negatedType):
+        (WebCore::CSSMathInvert::CSSMathInvert):
+        * css/typedom/numeric/CSSMathNegate.cpp:
+        (WebCore::copyType):
+        (WebCore::CSSMathNegate::CSSMathNegate):
+        * css/typedom/numeric/CSSMathProduct.cpp:
+        (WebCore::multiplyTypes):
+        (WebCore::CSSMathProduct::create):
+        (WebCore::CSSMathProduct::CSSMathProduct):
+        (WebCore::CSSMathProduct::values const): Deleted.
+        * css/typedom/numeric/CSSMathProduct.h:
+        * css/typedom/numeric/CSSMathSum.cpp:
+        (WebCore::addTypes):
+        (WebCore::CSSMathSum::create):
+        (WebCore::CSSMathSum::CSSMathSum):
+        * css/typedom/numeric/CSSMathSum.h:
+        * css/typedom/numeric/CSSMathValue.h:
+        (WebCore::CSSMathValue::CSSMathValue):
+        * css/typedom/numeric/CSSNumericArray.cpp:
+        (WebCore::CSSNumericArray::create):
+        * css/typedom/numeric/CSSNumericBaseType.h:
+        (WebCore::eachBaseType):
+        (WebCore::debugString):
+        (): Deleted.
+        * css/typedom/numeric/CSSNumericType.h:
+        (WebCore::CSSNumericType::operator== const):
+        (WebCore::CSSNumericType::valueForType):
+        (WebCore::CSSNumericType::applyPercentHint):
+        (WebCore::CSSNumericType::debugString const):
+        (): Deleted.
+        * css/typedom/numeric/CSSNumericType.idl:
+
 2022-03-31  Zan Dobersek  <[email protected]>
 
         [GTK][WPE] Make ENABLE(GPU_PROCESS) code buildable

Modified: trunk/Source/WebCore/css/parser/CSSParserToken.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/parser/CSSParserToken.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/parser/CSSParserToken.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -44,7 +44,6 @@
 CSSUnitType cssPrimitiveValueUnitFromTrie(const CharacterType* data, unsigned length)
 {
     ASSERT(data);
-    ASSERT(length);
     switch (length) {
     case 1:
         switch (toASCIILower(data[0])) {
@@ -328,7 +327,7 @@
     return CSSUnitType::CSS_UNKNOWN;
 }
 
-static CSSUnitType stringToUnitType(StringView stringView)
+CSSUnitType CSSParserToken::stringToUnitType(StringView stringView)
 {
     if (stringView.is8Bit())
         return cssPrimitiveValueUnitFromTrie(stringView.characters8(), stringView.length());

Modified: trunk/Source/WebCore/css/parser/CSSParserToken.h (292149 => 292150)


--- trunk/Source/WebCore/css/parser/CSSParserToken.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/parser/CSSParserToken.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -105,6 +105,8 @@
 
     CSSParserToken(HashTokenType, StringView);
 
+    static CSSUnitType stringToUnitType(StringView);
+
     bool operator==(const CSSParserToken& other) const;
     bool operator!=(const CSSParserToken& other) const { return !(*this == other); }
 

Modified: trunk/Source/WebCore/css/typedom/CSSNumericFactory.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/CSSNumericFactory.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/CSSNumericFactory.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -43,64 +43,64 @@
 public:
     explicit CSSNumericFactory(DOMCSSNamespace&) { }
 
-    static Ref<CSSUnitValue> number(double value) { return CSSUnitValue::create(value, "number"_s); }
-    static Ref<CSSUnitValue> percent(double value) { return CSSUnitValue::create(value, "percent"_s); }
+    static Ref<CSSUnitValue> number(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_NUMBER); }
+    static Ref<CSSUnitValue> percent(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_PERCENTAGE); }
 
 
     // <length>
-    static Ref<CSSUnitValue> em(double value) { return CSSUnitValue::create(value, "em"_s); }
-    static Ref<CSSUnitValue> ex(double value) { return CSSUnitValue::create(value, "ex"_s); }
-    static Ref<CSSUnitValue> ch(double value) { return CSSUnitValue::create(value, "ch"_s); }
-    static Ref<CSSUnitValue> ic(double value) { return CSSUnitValue::create(value, "ic"_s); }
-    static Ref<CSSUnitValue> rem(double value) { return CSSUnitValue::create(value, "rem"_s); }
-    static Ref<CSSUnitValue> lh(double value) { return CSSUnitValue::create(value, "lh"_s); }
-    static Ref<CSSUnitValue> rlh(double value) { return CSSUnitValue::create(value, "rlh"_s); }
-    static Ref<CSSUnitValue> vw(double value) { return CSSUnitValue::create(value, "vw"_s); }
-    static Ref<CSSUnitValue> vh(double value) { return CSSUnitValue::create(value, "vh"_s); }
-    static Ref<CSSUnitValue> vi(double value) { return CSSUnitValue::create(value, "vi"_s); }
-    static Ref<CSSUnitValue> vb(double value) { return CSSUnitValue::create(value, "vb"_s); }
-    static Ref<CSSUnitValue> vmin(double value) { return CSSUnitValue::create(value, "vmin"_s); }
-    static Ref<CSSUnitValue> vmax(double value) { return CSSUnitValue::create(value, "vmax"_s); }
-    static Ref<CSSUnitValue> cm(double value) { return CSSUnitValue::create(value, "cm"_s); }
-    static Ref<CSSUnitValue> mm(double value) { return CSSUnitValue::create(value, "mm"_s); }
-    static Ref<CSSUnitValue> q(double value) { return CSSUnitValue::create(value, "q"_s); }
-    static Ref<CSSUnitValue> in(double value) { return CSSUnitValue::create(value, "in"_s); }
-    static Ref<CSSUnitValue> pt(double value) { return CSSUnitValue::create(value, "pt"_s); }
-    static Ref<CSSUnitValue> pc(double value) { return CSSUnitValue::create(value, "pc"_s); }
-    static Ref<CSSUnitValue> px(double value) { return CSSUnitValue::create(value, "px"_s); }
-    static Ref<CSSUnitValue> cqw(double value) { return CSSUnitValue::create(value, "cqw"_s); }
-    static Ref<CSSUnitValue> cqh(double value) { return CSSUnitValue::create(value, "cqh"_s); }
-    static Ref<CSSUnitValue> cqi(double value) { return CSSUnitValue::create(value, "cqi"_s); }
-    static Ref<CSSUnitValue> cqb(double value) { return CSSUnitValue::create(value, "cqb"_s); }
-    static Ref<CSSUnitValue> cqmin(double value) { return CSSUnitValue::create(value, "cqmin"_s); }
-    static Ref<CSSUnitValue> cqmax(double value) { return CSSUnitValue::create(value, "cqmax"_s); }
+    static Ref<CSSUnitValue> em(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_EMS); }
+    static Ref<CSSUnitValue> ex(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_EXS); }
+    static Ref<CSSUnitValue> ch(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CHS); }
+    static Ref<CSSUnitValue> ic(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_IC); }
+    static Ref<CSSUnitValue> rem(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_REMS); }
+    static Ref<CSSUnitValue> lh(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_LHS); }
+    static Ref<CSSUnitValue> rlh(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_RLHS); }
+    static Ref<CSSUnitValue> vw(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_VW); }
+    static Ref<CSSUnitValue> vh(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_VH); }
+    static Ref<CSSUnitValue> vi(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_VI); }
+    static Ref<CSSUnitValue> vb(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_VB); }
+    static Ref<CSSUnitValue> vmin(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_VMIN); }
+    static Ref<CSSUnitValue> vmax(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_VMAX); }
+    static Ref<CSSUnitValue> cm(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CM); }
+    static Ref<CSSUnitValue> mm(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_MM); }
+    static Ref<CSSUnitValue> q(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_Q); }
+    static Ref<CSSUnitValue> in(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_IN); }
+    static Ref<CSSUnitValue> pt(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_PT); }
+    static Ref<CSSUnitValue> pc(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_PC); }
+    static Ref<CSSUnitValue> px(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_PX); }
+    static Ref<CSSUnitValue> cqw(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CQW); }
+    static Ref<CSSUnitValue> cqh(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CQH); }
+    static Ref<CSSUnitValue> cqi(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CQI); }
+    static Ref<CSSUnitValue> cqb(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CQB); }
+    static Ref<CSSUnitValue> cqmin(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CQMIN); }
+    static Ref<CSSUnitValue> cqmax(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_CQMAX); }
 
 
     // <angle>
-    static Ref<CSSUnitValue> deg(double value) { return CSSUnitValue::create(value, "deg"_s); }
-    static Ref<CSSUnitValue> grad(double value) { return CSSUnitValue::create(value, "grad"_s); }
-    static Ref<CSSUnitValue> rad(double value) { return CSSUnitValue::create(value, "rad"_s); }
-    static Ref<CSSUnitValue> turn(double value) { return CSSUnitValue::create(value, "turn"_s); }
+    static Ref<CSSUnitValue> deg(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_DEG); }
+    static Ref<CSSUnitValue> grad(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_GRAD); }
+    static Ref<CSSUnitValue> rad(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_RAD); }
+    static Ref<CSSUnitValue> turn(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_TURN); }
 
 
     // <time>
-    static Ref<CSSUnitValue> s(double value) { return CSSUnitValue::create(value, "s"_s); }
-    static Ref<CSSUnitValue> ms(double value) { return CSSUnitValue::create(value, "ms"_s); }
+    static Ref<CSSUnitValue> s(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_S); }
+    static Ref<CSSUnitValue> ms(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_MS); }
 
 
     // <frequency>
-    static Ref<CSSUnitValue> hz(double value) { return CSSUnitValue::create(value, "hz"_s); }
-    static Ref<CSSUnitValue> kHz(double value) { return CSSUnitValue::create(value, "khz"_s); }
+    static Ref<CSSUnitValue> hz(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_HZ); }
+    static Ref<CSSUnitValue> kHz(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_KHZ); }
 
 
     // <resolution>
-    static Ref<CSSUnitValue> dpi(double value) { return CSSUnitValue::create(value, "dpi"_s); }
-    static Ref<CSSUnitValue> dpcm(double value) { return CSSUnitValue::create(value, "dpcm"_s); }
-    static Ref<CSSUnitValue> dppx(double value) { return CSSUnitValue::create(value, "dppx"_s); }
+    static Ref<CSSUnitValue> dpi(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_DPI); }
+    static Ref<CSSUnitValue> dpcm(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_DPCM); }
+    static Ref<CSSUnitValue> dppx(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_DPPX); }
 
 
     // <flex>
-    static Ref<CSSUnitValue> fr(double value) { return CSSUnitValue::create(value, "fr"_s); }
+    static Ref<CSSUnitValue> fr(double value) { return CSSUnitValue::create(value, CSSUnitType::CSS_FR); }
 
 
 private:

Modified: trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -56,7 +56,7 @@
     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 CSSUnitValue::create(-unitValue->value(), unitValue->unitEnum());
     return CSSMathNegate::create(WTFMove(value));
 }
 
@@ -67,11 +67,10 @@
         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->unitEnum() == CSSUnitType::CSS_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> { CSSUnitValue::create(1.0 / unitValue->value(), unitValue->unitEnum()) };
         }
     }
 
@@ -83,11 +82,11 @@
 {
     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;
+        return unitValue ? unitValue->unitEnum() == downcast<CSSUnitValue>(values[0].get()).unitEnum() : false;
     });
     if (allValuesHaveSameUnit) {
         auto& firstUnitValue = downcast<CSSUnitValue>(values[0].get());
-        String unit = firstUnitValue.unit();
+        auto unit = firstUnitValue.unitEnum();
         double result = firstUnitValue.value();
         for (size_t i = 1; i < values.size(); i++)
             result = operation(result, downcast<CSSUnitValue>(values[i].get()).value());
@@ -107,25 +106,26 @@
     return values;
 }
 
-Ref<CSSNumericValue> CSSNumericValue::addInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
+ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::addInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
 {
     // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-add
     auto values = prependItemsOfTypeOrThis<CSSMathSum>(WTFMove(numericValues));
 
     if (auto result = operationOnValuesOfSameUnit(std::plus<double>(), values))
-        return *result;
+        return { *result };
 
-    // FIXME: Implement step 4 to check that the types can be added.
-
-    return CSSMathSum::create(WTFMove(values));
+    auto sum = CSSMathSum::create(WTFMove(values));
+    if (sum.hasException())
+        return sum.releaseException();
+    return Ref<CSSNumericValue> { sum.releaseReturnValue() };
 }
 
-Ref<CSSNumericValue> CSSNumericValue::add(FixedVector<CSSNumberish>&& values)
+ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::add(FixedVector<CSSNumberish>&& values)
 {
     return addInternal(WTF::map(WTFMove(values), rectifyNumberish));
 }
 
-Ref<CSSNumericValue> CSSNumericValue::sub(FixedVector<CSSNumberish>&& values)
+ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::sub(FixedVector<CSSNumberish>&& values)
 {
     return addInternal(WTF::map(WTFMove(values), [] (CSSNumberish&& numberish) {
         return negate(rectifyNumberish(WTFMove(numberish)));
@@ -132,7 +132,7 @@
     }));
 }
 
-Ref<CSSNumericValue> CSSNumericValue::multiplyInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
+ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::multiplyInternal(Vector<Ref<CSSNumericValue>>&& numericValues)
 {
     // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-mul
     auto values = prependItemsOfTypeOrThis<CSSMathProduct>(WTFMove(numericValues));
@@ -144,8 +144,8 @@
         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")
+            auto unit = downcast<CSSUnitValue>(values[i].get()).unitEnum();
+            if (unit == CSSUnitType::CSS_NUMBER)
                 continue;
             if (nonNumberUnitIndex) {
                 multipleUnitsFound = true;
@@ -157,17 +157,18 @@
             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"_s;
-            return CSSUnitValue::create(product, unit);
+            auto unit = nonNumberUnitIndex ? downcast<CSSUnitValue>(values[*nonNumberUnitIndex].get()).unitEnum() : CSSUnitType::CSS_NUMBER;
+            return { CSSUnitValue::create(product, unit) };
         }
     }
 
-    // FIXME: Implement step 5 to produce a unit of the correct type.
-
-    return CSSMathProduct::create(WTFMove(values));
+    auto product = CSSMathProduct::create(WTFMove(values));
+    if (product.hasException())
+        return product.releaseException();
+    return Ref<CSSNumericValue> { product.releaseReturnValue() };
 }
 
-Ref<CSSNumericValue> CSSNumericValue::mul(FixedVector<CSSNumberish>&& values)
+ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::mul(FixedVector<CSSNumberish>&& values)
 {
     return multiplyInternal(WTF::map(WTFMove(values), rectifyNumberish));
 }
@@ -235,10 +236,10 @@
     UNUSED_PARAM(unit);
     // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-to
     // FIXME: add impl.
-    return CSSUnitValue::create(1.0, "number"_s);
+    return CSSUnitValue::create(1.0, CSSUnitType::CSS_NUMBER);
 }
 
-Ref<CSSMathSum> CSSNumericValue::toSum(FixedVector<String>&& units)
+ExceptionOr<Ref<CSSMathSum>> CSSNumericValue::toSum(FixedVector<String>&& units)
 {
     UNUSED_PARAM(units);
     // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-tosum
@@ -246,13 +247,6 @@
     return CSSMathSum::create(FixedVector<CSSNumberish> { 1.0 });
 }
 
-CSSNumericType CSSNumericValue::type()
-{
-    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-type
-    // FIXME: add impl.
-    return CSSNumericType { };
-}
-
 ExceptionOr<Ref<CSSNumericValue>> CSSNumericValue::parse(String&& cssText)
 {
     UNUSED_PARAM(cssText);

Modified: trunk/Source/WebCore/css/typedom/CSSNumericValue.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/CSSNumericValue.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/CSSNumericValue.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -27,6 +27,7 @@
 
 #if ENABLE(CSS_TYPED_OM)
 
+#include "CSSNumericType.h"
 #include "CSSStyleValue.h"
 #include <variant>
 #include <wtf/FixedVector.h>
@@ -36,7 +37,6 @@
 class CSSNumericValue;
 class CSSUnitValue;
 class CSSMathSum;
-struct CSSNumericType;
 
 template<typename> class ExceptionOr;
 
@@ -46,9 +46,9 @@
     WTF_MAKE_ISO_ALLOCATED(CSSNumericValue);
 public:
 
-    Ref<CSSNumericValue> add(FixedVector<CSSNumberish>&&);
-    Ref<CSSNumericValue> sub(FixedVector<CSSNumberish>&&);
-    Ref<CSSNumericValue> mul(FixedVector<CSSNumberish>&&);
+    ExceptionOr<Ref<CSSNumericValue>> add(FixedVector<CSSNumberish>&&);
+    ExceptionOr<Ref<CSSNumericValue>> sub(FixedVector<CSSNumberish>&&);
+    ExceptionOr<Ref<CSSNumericValue>> mul(FixedVector<CSSNumberish>&&);
     ExceptionOr<Ref<CSSNumericValue>> div(FixedVector<CSSNumberish>&&);
     Ref<CSSNumericValue> min(FixedVector<CSSNumberish>&&);
     Ref<CSSNumericValue> max(FixedVector<CSSNumberish>&&);
@@ -56,8 +56,9 @@
     bool equals(FixedVector<CSSNumberish>&&);
     
     Ref<CSSUnitValue> to(String&&);
-    Ref<CSSMathSum> toSum(FixedVector<String>&&);
-    CSSNumericType type();
+    ExceptionOr<Ref<CSSMathSum>> toSum(FixedVector<String>&&);
+
+    const CSSNumericType& type() const { return m_type; }
     
     static ExceptionOr<Ref<CSSNumericValue>> parse(String&&);
     static Ref<CSSNumericValue> rectifyNumberish(CSSNumberish&&);
@@ -65,11 +66,14 @@
     CSSStyleValueType getType() const override { return CSSStyleValueType::CSSNumericValue; }
 
 protected:
-    Ref<CSSNumericValue> addInternal(Vector<Ref<CSSNumericValue>>&&);
-    Ref<CSSNumericValue> multiplyInternal(Vector<Ref<CSSNumericValue>>&&);
+    ExceptionOr<Ref<CSSNumericValue>> addInternal(Vector<Ref<CSSNumericValue>>&&);
+    ExceptionOr<Ref<CSSNumericValue>> multiplyInternal(Vector<Ref<CSSNumericValue>>&&);
     template<typename T> Vector<Ref<CSSNumericValue>> prependItemsOfTypeOrThis(Vector<Ref<CSSNumericValue>>&&);
 
-    CSSNumericValue() = default;
+    CSSNumericValue(CSSNumericType type = { })
+        : m_type(WTFMove(type)) { }
+
+    CSSNumericType m_type;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -32,6 +32,8 @@
 
 #if ENABLE(CSS_TYPED_OM)
 
+#include "CSSParserToken.h"
+#include "CSSPrimitiveValue.h"
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
@@ -38,6 +40,97 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(CSSUnitValue);
 
+static std::optional<CSSNumericType> numericType(CSSUnitType unit)
+{
+    // https://drafts.css-houdini.org/css-typed-om/#cssnumericvalue-create-a-type
+    CSSNumericType type;
+    switch (unitCategory(unit)) {
+    case CSSUnitCategory::Number:
+        return { WTFMove(type) };
+    case CSSUnitCategory::Percent:
+        type.percent = 1;
+        return { WTFMove(type) };
+    case CSSUnitCategory::Length:
+        type.length = 1;
+        return { WTFMove(type) };
+    case CSSUnitCategory::Angle:
+        type.angle = 1;
+        return { WTFMove(type) };
+    case CSSUnitCategory::Time:
+        type.time = 1;
+        return { WTFMove(type) };
+    case CSSUnitCategory::Frequency:
+        type.frequency = 1;
+        return { WTFMove(type) };
+    case CSSUnitCategory::Resolution:
+        type.resolution = 1;
+        return { WTFMove(type) };
+    case CSSUnitCategory::Other:
+        if (unit == CSSUnitType::CSS_FR) {
+            type.flex = 1;
+            return { WTFMove(type) };
+        }
+        break;
+    }
+    
+    return std::nullopt;
+}
+
+static CSSUnitType parseUnit(const String& unit)
+{
+    if (unit == "number"_s)
+        return CSSUnitType::CSS_NUMBER;
+    if (unit == "percent"_s)
+        return CSSUnitType::CSS_PERCENTAGE;
+
+    // FIXME: Remove these when LineHeightUnitsEnabled is changed back to true or removed
+    // https://bugs.webkit.org/show_bug.cgi?id=211351
+    if (unit == "lh"_s)
+        return CSSUnitType::CSS_LHS;
+    if (unit == "rlh"_s)
+        return CSSUnitType::CSS_RLHS;
+
+    return CSSParserToken::stringToUnitType(unit);
+}
+
+String CSSUnitValue::unit() const
+{
+    switch (m_unit) {
+    case CSSUnitType::CSS_NUMBER:
+        return "number"_s;
+    case CSSUnitType::CSS_PERCENTAGE:
+        return "percent"_s;
+    default:
+        break;
+    }
+    return unitSerialization();
+}
+
+String CSSUnitValue::unitSerialization() const
+{
+    return CSSPrimitiveValue::unitTypeString(m_unit);
+}
+
+ExceptionOr<Ref<CSSUnitValue>> CSSUnitValue::create(double value, const String& unit)
+{
+    auto parsedUnit = parseUnit(unit);
+    if (parsedUnit == CSSUnitType::CSS_UNKNOWN)
+        return Exception { TypeError };
+    auto type = numericType(parsedUnit);
+    if (!type)
+        return Exception { TypeError };
+    auto unitValue = adoptRef(*new CSSUnitValue(value, parsedUnit));
+    unitValue->m_type = WTFMove(*type);
+    return unitValue;
+}
+
+CSSUnitValue::CSSUnitValue(double value, CSSUnitType unit)
+    : CSSNumericValue(numericType(unit).value_or(CSSNumericType()))
+    , m_value(value)
+    , m_unit(unit)
+{
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/CSSUnitValue.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -34,33 +34,29 @@
 
 namespace WebCore {
 
+enum class CSSUnitType : uint8_t;
+
 class CSSUnitValue final : public CSSNumericValue {
     WTF_MAKE_ISO_ALLOCATED(CSSUnitValue);
 public:
-    static Ref<CSSUnitValue> create(double value, const String& unit)
-    {
-        return adoptRef(*new CSSUnitValue(value, unit));
-    }
+    static ExceptionOr<Ref<CSSUnitValue>> create(double value, const String& unit);
+    static Ref<CSSUnitValue> create(double value, CSSUnitType unit) { return adoptRef(*new CSSUnitValue(value, unit)); }
 
-    // FIXME: not correct.
-    String toString() const final { return makeString((int) m_value, m_unit); }
+    String toString() const final { return makeString(FormattedCSSNumber::create(m_value), unitSerialization()); }
 
     double value() const { return m_value; }
     void setValue(double value) { m_value = value; }
-    const String& unit() const { return m_unit; }
-    void setUnit(const String& unit) { m_unit = unit; }
+    String unit() const;
+    String unitSerialization() const;
+    CSSUnitType unitEnum() const { return m_unit; }
 
 private:
-    CSSUnitValue(double value, const String& unit)
-        : m_value(value)
-        , m_unit(unit)
-    {
-    }
+    CSSUnitValue(double, CSSUnitType);
 
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSUnitValue; }
 
     double m_value;
-    String m_unit;
+    const CSSUnitType m_unit;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -41,8 +41,34 @@
     return adoptRef(*new CSSMathInvert(WTFMove(numberish)));
 }
 
+static CSSNumericType negatedType(const CSSNumberish& numberish)
+{
+    // https://drafts.css-houdini.org/css-typed-om/#type-of-a-cssmathvalue
+    return WTF::switchOn(numberish,
+        [] (double) { return CSSNumericType(); },
+        [] (const RefPtr<CSSNumericValue>& value) {
+            if (!value)
+                return CSSNumericType();
+            CSSNumericType type = value->type();
+            auto negate = [] (auto& optional) {
+                if (optional)
+                    optional = *optional * -1;
+            };
+            negate(type.length);
+            negate(type.angle);
+            negate(type.time);
+            negate(type.frequency);
+            negate(type.resolution);
+            negate(type.flex);
+            negate(type.percent);
+            return type;
+        }
+    );
+}
+
 CSSMathInvert::CSSMathInvert(CSSNumberish&& numberish)
-    : m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
+    : CSSMathValue(negatedType(numberish))
+    , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
 {
 }
 

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -36,13 +36,27 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathNegate);
 
+static CSSNumericType copyType(const CSSNumberish& numberish)
+{
+    return WTF::switchOn(numberish,
+        [] (double) { return CSSNumericType(); },
+        [] (const RefPtr<CSSNumericValue>& value) {
+            if (!value)
+                return CSSNumericType();
+            return value->type();
+        }
+    );
+}
+
 CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
-    : m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
+    : CSSMathValue(copyType(numberish))
+    , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
 {
 }
 
 CSSMathNegate::CSSMathNegate(Ref<CSSNumericValue>&& value)
-    : m_value(WTFMove(value))
+    : CSSMathValue(value->type())
+    , m_value(WTFMove(value))
 {
 }
 

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -26,10 +26,10 @@
 #include "config.h"
 #include "CSSMathProduct.h"
 
-#include "CSSNumericArray.h"
-
 #if ENABLE(CSS_TYPED_OM)
 
+#include "CSSNumericArray.h"
+#include "ExceptionOr.h"
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
@@ -36,21 +36,58 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathProduct);
 
-CSSMathProduct::CSSMathProduct(FixedVector<CSSNumberish>&& numberishes)
-    : m_values(CSSNumericArray::create(WTFMove(numberishes)))
+static std::optional<CSSNumericType> multiplyTypes(const CSSNumericType& a, const CSSNumericType& b)
 {
+    // https://drafts.css-houdini.org/css-typed-om/#cssnumericvalue-multiply-two-types
+    if (a.percentHint && b.percentHint && *a.percentHint != *b.percentHint)
+        return std::nullopt;
+
+    auto add = [] (auto left, auto right) -> std::optional<unsigned> {
+        if (!left)
+            return right;
+        if (!right)
+            return left;
+        return *left + *right;
+    };
+    
+    return { {
+        add(a.length, b.length),
+        add(a.angle, b.angle),
+        add(a.time, b.time),
+        add(a.frequency, b.frequency),
+        add(a.resolution, b.resolution),
+        add(a.flex, b.flex),
+        add(a.percent, b.percent),
+        a.percentHint ? a.percentHint : b.percentHint
+    } };
 }
 
-CSSMathProduct::CSSMathProduct(Vector<Ref<CSSNumericValue>>&& values)
-    : m_values(CSSNumericArray::create(WTFMove(values)))
+ExceptionOr<Ref<CSSMathProduct>> CSSMathProduct::create(FixedVector<CSSNumberish> numberishes)
 {
+    return create(WTF::map(WTFMove(numberishes), rectifyNumberish));
 }
 
-const CSSNumericArray& CSSMathProduct::values() const
+ExceptionOr<Ref<CSSMathProduct>> CSSMathProduct::create(Vector<Ref<CSSNumericValue>> values)
 {
-    return m_values.get();
+    if (values.isEmpty())
+        return Exception { SyntaxError };
+    
+    std::optional<CSSNumericType> type = values[0]->type();
+    for (size_t i = 1; i < values.size(); i++) {
+        type = multiplyTypes(*type, values[i]->type());
+        if (!type)
+            return Exception { TypeError };
+    }
+
+    return adoptRef(*new CSSMathProduct(WTFMove(values), WTFMove(*type)));
 }
 
+CSSMathProduct::CSSMathProduct(Vector<Ref<CSSNumericValue>> values, CSSNumericType type)
+    : CSSMathValue(WTFMove(type))
+    , m_values(CSSNumericArray::create(WTFMove(values)))
+{
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -37,15 +37,15 @@
 class CSSMathProduct final : public CSSMathValue {
     WTF_MAKE_ISO_ALLOCATED(CSSMathProduct);
 public:
-    template<typename... Args> static Ref<CSSMathProduct> create(Args&&... args) { return adoptRef(*new CSSMathProduct(std::forward<Args>(args)...)); }
-    const CSSNumericArray& values() const;
+    static ExceptionOr<Ref<CSSMathProduct>> create(FixedVector<CSSNumberish>);
+    static ExceptionOr<Ref<CSSMathProduct>> create(Vector<Ref<CSSNumericValue>>);
+    const CSSNumericArray& values() const { return m_values.get(); }
 
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Product; }
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathProduct; }
 
-    CSSMathProduct(FixedVector<CSSNumberish>&&);
-    CSSMathProduct(Vector<Ref<CSSNumericValue>>&&);
+    CSSMathProduct(Vector<Ref<CSSNumericValue>>, CSSNumericType);
     Ref<CSSNumericArray> m_values;
 };
 

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -26,10 +26,10 @@
 #include "config.h"
 #include "CSSMathSum.h"
 
-#include "CSSNumericArray.h"
-
 #if ENABLE(CSS_TYPED_OM)
 
+#include "CSSNumericArray.h"
+#include <wtf/Algorithms.h>
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
@@ -36,16 +36,60 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(CSSMathSum);
 
-CSSMathSum::CSSMathSum(FixedVector<CSSNumberish>&& numberishes)
-    : m_values(CSSNumericArray::create(WTFMove(numberishes)))
+static std::optional<CSSNumericType> addTypes(CSSNumericType a, CSSNumericType b)
 {
+    // https://drafts.css-houdini.org/css-typed-om/#cssnumericvalue-add-two-types
+    if (a.percentHint && b.percentHint && *a.percentHint != *b.percentHint)
+        return std::nullopt;
+
+    if (a.percentHint)
+        b.applyPercentHint(*a.percentHint);
+    if (b.percentHint)
+        a.applyPercentHint(*b.percentHint);
+
+    if (a == b)
+        return { WTFMove(a) };
+
+    for (auto type : eachBaseType()) {
+        if (type == CSSNumericBaseType::Percent)
+            continue;
+        if (!a.valueForType(type) && !b.valueForType(type))
+            continue;
+        a.applyPercentHint(type);
+        b.applyPercentHint(type);
+        if (a.valueForType(type) != b.valueForType(type))
+            return std::nullopt;
+    }
+
+    return { WTFMove(a) };
 }
 
-CSSMathSum::CSSMathSum(Vector<Ref<CSSNumericValue>>&& values)
-    : m_values(CSSNumericArray::create(WTFMove(values)))
+ExceptionOr<Ref<CSSMathSum>> CSSMathSum::create(FixedVector<CSSNumberish> numberishes)
 {
+    return create(WTF::map(WTFMove(numberishes), rectifyNumberish));
 }
 
+ExceptionOr<Ref<CSSMathSum>> CSSMathSum::create(Vector<Ref<CSSNumericValue>> values)
+{
+    if (values.isEmpty())
+        return Exception { SyntaxError };
+
+    std::optional<CSSNumericType> type = values[0]->type();
+    for (size_t i = 1; i < values.size(); i++) {
+        type = addTypes(*type, values[i]->type());
+        if (!type)
+            return Exception { TypeError };
+    }
+
+    return adoptRef(*new CSSMathSum(WTFMove(values), WTFMove(*type)));
+}
+
+CSSMathSum::CSSMathSum(Vector<Ref<CSSNumericValue>> values, CSSNumericType type)
+    : CSSMathValue(WTFMove(type))
+    , m_values(CSSNumericArray::create(WTFMove(values)))
+{
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -38,7 +38,8 @@
 class CSSMathSum final : public CSSMathValue {
     WTF_MAKE_ISO_ALLOCATED(CSSMathSum);
 public:
-    template<typename... Args> static Ref<CSSMathSum> create(Args&&... args) { return adoptRef(*new CSSMathSum(std::forward<Args>(args)...)); }
+    static ExceptionOr<Ref<CSSMathSum>> create(FixedVector<CSSNumberish>);
+    static ExceptionOr<Ref<CSSMathSum>> create(Vector<Ref<CSSNumericValue>>);
     const CSSNumericArray& values() const { return m_values.get(); }
 
 private:
@@ -45,8 +46,7 @@
     CSSMathOperator getOperator() const final { return CSSMathOperator::Sum; }
     CSSStyleValueType getType() const override { return CSSStyleValueType::CSSMathSum; }
 
-    CSSMathSum(FixedVector<CSSNumberish>&&);
-    CSSMathSum(Vector<Ref<CSSNumericValue>>&&);
+    CSSMathSum(Vector<Ref<CSSNumericValue>>, CSSNumericType);
     Ref<CSSNumericArray> m_values;
 };
 

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -35,6 +35,8 @@
 
 class CSSMathValue : public CSSNumericValue {
 public:
+    CSSMathValue(CSSNumericType type = { })
+        : CSSNumericValue(WTFMove(type)) { }
     virtual CSSMathOperator getOperator() const = 0;
 };
 

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp	2022-03-31 10:21:18 UTC (rev 292150)
@@ -38,11 +38,9 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(CSSNumericArray);
 
-Ref<CSSNumericArray> CSSNumericArray::create(const FixedVector<CSSNumberish>& numberishes)
+Ref<CSSNumericArray> CSSNumericArray::create(FixedVector<CSSNumberish>&& numberishes)
 {
-    return adoptRef(*new CSSNumericArray(WTF::map(numberishes, [](auto& numberish) -> Ref<CSSNumericValue> {
-        return CSSNumericValue::rectifyNumberish(const_cast<CSSNumberish&&>(numberish));
-    })));
+    return adoptRef(*new CSSNumericArray(WTF::map(WTFMove(numberishes), CSSNumericValue::rectifyNumberish)));
 }
 
 Ref<CSSNumericArray> CSSNumericArray::create(Vector<Ref<CSSNumericValue>>&& values)

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -40,7 +40,7 @@
 class CSSNumericArray : public RefCounted<CSSNumericArray> {
     WTF_MAKE_ISO_ALLOCATED(CSSNumericArray);
 public:
-    static Ref<CSSNumericArray> create(const FixedVector<CSSNumberish>&);
+    static Ref<CSSNumericArray> create(FixedVector<CSSNumberish>&&);
     static Ref<CSSNumericArray> create(Vector<Ref<CSSNumericValue>>&&);
     size_t length() const { return m_array.size(); };
     ExceptionOr<Ref<CSSNumericValue>> item(size_t index);

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericBaseType.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericBaseType.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericBaseType.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -27,9 +27,11 @@
 
 #if ENABLE(CSS_TYPED_OM)
 
+#include <array>
+
 namespace WebCore {
 
-enum class CSSNumericBaseType: uint8_t {
+enum class CSSNumericBaseType : uint8_t {
     Length,
     Angle,
     Time,
@@ -39,6 +41,40 @@
     Percent,
 };
 
+constexpr std::array<CSSNumericBaseType, 7> eachBaseType()
+{
+    return {
+        CSSNumericBaseType::Length,
+        CSSNumericBaseType::Angle,
+        CSSNumericBaseType::Time,
+        CSSNumericBaseType::Frequency,
+        CSSNumericBaseType::Resolution,
+        CSSNumericBaseType::Flex,
+        CSSNumericBaseType::Percent
+    };
+}
+
+constexpr const char* debugString(CSSNumericBaseType type)
+{
+    switch (type) {
+    case CSSNumericBaseType::Length:
+        return "length";
+    case CSSNumericBaseType::Angle:
+        return "angle";
+    case CSSNumericBaseType::Time:
+        return "time";
+    case CSSNumericBaseType::Frequency:
+        return "frequency";
+    case CSSNumericBaseType::Resolution:
+        return "resolution";
+    case CSSNumericBaseType::Flex:
+        return "flex";
+    case CSSNumericBaseType::Percent:
+        return "percent";
+    }
+    return "invalid";
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.h	2022-03-31 10:21:18 UTC (rev 292150)
@@ -29,18 +29,78 @@
 
 #include "CSSNumericBaseType.h"
 #include <optional>
+#include <wtf/text/StringConcatenateNumbers.h>
 
 namespace WebCore {
 
+// https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-type
 struct CSSNumericType {
-    long length { 0 };
-    long angle { 0 };
-    long time { 0 };
-    long frequency { 0 };
-    long resolution { 0 };
-    long flex { 0 };
-    long percent { 0 };
+    std::optional<long> length;
+    std::optional<long> angle;
+    std::optional<long> time;
+    std::optional<long> frequency;
+    std::optional<long> resolution;
+    std::optional<long> flex;
+    std::optional<long> percent;
     std::optional<CSSNumericBaseType> percentHint;
+
+    bool operator==(const CSSNumericType& other) const
+    {
+        return length == other.length
+            && angle == other.angle
+            && time == other.time
+            && frequency == other.frequency
+            && resolution == other.resolution
+            && flex == other.flex
+            && percent == other.percent
+            && percentHint == other.percentHint;
+    }
+
+    std::optional<long>& valueForType(CSSNumericBaseType type)
+    {
+        switch (type) {
+        case CSSNumericBaseType::Length:
+            return length;
+        case CSSNumericBaseType::Angle:
+            return angle;
+        case CSSNumericBaseType::Time:
+            return time;
+        case CSSNumericBaseType::Frequency:
+            return frequency;
+        case CSSNumericBaseType::Resolution:
+            return resolution;
+        case CSSNumericBaseType::Flex:
+            return flex;
+        case CSSNumericBaseType::Percent:
+            return percent;
+        }
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+
+    void applyPercentHint(CSSNumericBaseType hint)
+    {
+        // https://drafts.css-houdini.org/css-typed-om/#apply-the-percent-hint
+        auto& optional = valueForType(hint);
+        if (!optional)
+            optional = 0;
+        if (percent)
+            *optional += *std::exchange(percent, 0);
+        percentHint = hint;
+    }
+
+    String debugString() const
+    {
+        return makeString("{",
+            length ? makeString(" length:", *length) : String(),
+            angle ? makeString(" angle:", *angle) : String(),
+            time ? makeString(" time:", *time) : String(),
+            frequency ? makeString(" frequency:", *frequency) : String(),
+            resolution ? makeString(" resolution:", *resolution) : String(),
+            flex ? makeString(" flex:", *flex) : String(),
+            percent ? makeString(" percent:", *percent) : String(),
+            percentHint ? makeString(" percentHint:", WebCore::debugString(*percentHint)) : String(),
+        " }");
+    }
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.idl (292149 => 292150)


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.idl	2022-03-31 09:56:04 UTC (rev 292149)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericType.idl	2022-03-31 10:21:18 UTC (rev 292150)
@@ -23,6 +23,8 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+// https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-type
+
 [
     Conditional=CSS_TYPED_OM,
     JSGenerateToJSObject,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to