Title: [293052] trunk
Revision
293052
Author
[email protected]
Date
2022-04-19 17:45:27 -0700 (Tue, 19 Apr 2022)

Log Message

Implement most of CSS typed OM object stringifiers
https://bugs.webkit.org/show_bug.cgi?id=239483

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

LayoutTests/imported/w3c:

* web-platform-tests/css/css-typed-om/stylevalue-serialization/cssKeywordValue.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-serialization/cssMathValue.tentative-expected.txt:
* web-platform-tests/css/css-typed-om/stylevalue-serialization/cssTransformValue.tentative-expected.txt:

Source/WebCore:

This is an off-by-default experimental feature.
Covered by web platform tests.

* css/typedom/CSSKeywordValue.cpp:
(WebCore::CSSKeywordValue::serialize const):
* css/typedom/CSSKeywordValue.h:
* css/typedom/CSSOMVariableReferenceValue.cpp:
(WebCore::CSSOMVariableReferenceValue::toString const):
(WebCore::CSSOMVariableReferenceValue::serialize const):
* css/typedom/CSSOMVariableReferenceValue.h:
* css/typedom/CSSStyleImageValue.cpp:
(WebCore::CSSStyleImageValue::serialize const):
(WebCore::CSSStyleImageValue::document const):
* css/typedom/CSSStyleImageValue.h:
* css/typedom/CSSStyleValue.cpp:
(WebCore::CSSStyleValue::toString const):
(WebCore::CSSStyleValue::serialize const):
* css/typedom/CSSStyleValue.h:
* css/typedom/CSSUnitValue.cpp:
(WebCore::CSSUnitValue::serialize const):
* css/typedom/CSSUnitValue.h:
* css/typedom/CSSUnparsedValue.cpp:
(WebCore::CSSUnparsedValue::serialize const):
(WebCore::CSSUnparsedValue::toString const): Deleted.
* css/typedom/CSSUnparsedValue.h:
* css/typedom/numeric/CSSMathInvert.cpp:
(WebCore::CSSMathInvert::serialize const):
* css/typedom/numeric/CSSMathInvert.h:
* css/typedom/numeric/CSSMathMax.cpp:
(WebCore::CSSMathMax::serialize const):
* css/typedom/numeric/CSSMathMax.h:
* css/typedom/numeric/CSSMathMin.cpp:
(WebCore::CSSMathMin::serialize const):
* css/typedom/numeric/CSSMathMin.h:
* css/typedom/numeric/CSSMathNegate.cpp:
(WebCore::CSSMathNegate::serialize const):
* css/typedom/numeric/CSSMathNegate.h:
* css/typedom/numeric/CSSMathProduct.cpp:
(WebCore::CSSMathProduct::serialize const):
* css/typedom/numeric/CSSMathProduct.h:
* css/typedom/numeric/CSSMathSum.cpp:
(WebCore::CSSMathSum::serialize const):
* css/typedom/numeric/CSSMathSum.h:
* css/typedom/numeric/CSSNumericArray.cpp:
(WebCore::CSSNumericArray::forEach):
* css/typedom/numeric/CSSNumericArray.h:
* css/typedom/transform/CSSMatrixComponent.cpp:
(WebCore::CSSMatrixComponent::serialize const):
(WebCore::CSSMatrixComponent::toMatrix):
(WebCore::CSSMatrixComponent::toString const): Deleted.
* css/typedom/transform/CSSMatrixComponent.h:
* css/typedom/transform/CSSPerspective.cpp:
(WebCore::CSSPerspective::serialize const):
(WebCore::CSSPerspective::toMatrix):
(WebCore::CSSPerspective::toString const): Deleted.
* css/typedom/transform/CSSPerspective.h:
* css/typedom/transform/CSSRotate.cpp:
(WebCore::CSSRotate::serialize const):
(WebCore::CSSRotate::toMatrix):
(WebCore::CSSRotate::toString const): Deleted.
* css/typedom/transform/CSSRotate.h:
* css/typedom/transform/CSSScale.cpp:
(WebCore::CSSScale::serialize const):
(WebCore::CSSScale::toMatrix):
(WebCore::CSSScale::toString const): Deleted.
* css/typedom/transform/CSSScale.h:
* css/typedom/transform/CSSSkew.cpp:
(WebCore::CSSSkew::serialize const):
(WebCore::CSSSkew::toMatrix):
(WebCore::CSSSkew::toString const): Deleted.
* css/typedom/transform/CSSSkew.h:
* css/typedom/transform/CSSSkewX.cpp:
(WebCore::CSSSkewX::serialize const):
(WebCore::CSSSkewX::toMatrix):
(WebCore::CSSSkewX::toString const): Deleted.
* css/typedom/transform/CSSSkewX.h:
* css/typedom/transform/CSSSkewY.cpp:
(WebCore::CSSSkewY::serialize const):
(WebCore::CSSSkewY::toMatrix):
(WebCore::CSSSkewY::toString const): Deleted.
* css/typedom/transform/CSSSkewY.h:
* css/typedom/transform/CSSTransformComponent.cpp:
(WebCore::CSSTransformComponent::toString const):
* css/typedom/transform/CSSTransformComponent.h:
* css/typedom/transform/CSSTransformValue.cpp:
(WebCore::CSSTransformValue::serialize const):
* css/typedom/transform/CSSTransformValue.h:
* css/typedom/transform/CSSTranslate.cpp:
(WebCore::CSSTranslate::serialize const):
(WebCore::CSSTranslate::toMatrix):
(WebCore::CSSTranslate::toString const): Deleted.
* css/typedom/transform/CSSTranslate.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293051 => 293052)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-20 00:45:27 UTC (rev 293052)
@@ -1,3 +1,14 @@
+2022-04-19  Alex Christensen  <[email protected]>
+
+        Implement most of CSS typed OM object stringifiers
+        https://bugs.webkit.org/show_bug.cgi?id=239483
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/css-typed-om/stylevalue-serialization/cssKeywordValue.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-serialization/cssMathValue.tentative-expected.txt:
+        * web-platform-tests/css/css-typed-om/stylevalue-serialization/cssTransformValue.tentative-expected.txt:
+
 2022-04-19  Tim Nguyen  <[email protected]>
 
         user-select: none shouldn't affect editability

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssKeywordValue.tentative-expected.txt	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssKeywordValue.tentative-expected.txt	2022-04-20 00:45:27 UTC (rev 293052)
@@ -1,6 +1,6 @@
 
-FAIL CSSKeywordValue constructed from IDL serializes correctly assert_equals: expected "auto" but got ""
-FAIL CSSKeywordValue constructed from IDL serializes to escaped strings assert_equals: expected "\\ Hello\\ World" but got ""
+PASS CSSKeywordValue constructed from IDL serializes correctly
+FAIL CSSKeywordValue constructed from IDL serializes to escaped strings assert_equals: expected "\\ Hello\\ World" but got " Hello World"
 FAIL CSSKeywordValue from DOMString modified through "value" setter serializes correctly assert_equals: expected "lemon" but got "auto"
 FAIL CSSKeywordValue from CSSOM modified through "value" setter serializes correctly assert_equals: expected "lemon" but got "auto"
 

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssMathValue.tentative-expected.txt	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssMathValue.tentative-expected.txt	2022-04-20 00:45:27 UTC (rev 293052)
@@ -1,22 +1,22 @@
 
-FAIL CSSMathMax with one argument serializes correctly assert_equals: expected "max(1)" but got ""
-FAIL CSSMathMax with more than one argument serializes correctly assert_equals: expected "max(1, 2, 3)" but got ""
-FAIL CSSMathMax containing nested CSSMathValues serializes correctly assert_equals: expected "max(1 + 2, 3)" but got ""
-FAIL CSSMathMin with one argument serializes correctly assert_equals: expected "min(1)" but got ""
-FAIL CSSMathMin with more than one argument serializes correctly assert_equals: expected "min(1, 2, 3)" but got ""
-FAIL CSSMathMin containing nested CSSMathValues serializes correctly assert_equals: expected "min(1 + 2, 3)" but got ""
-FAIL CSSMathSum with one argument serializes correctly assert_equals: expected "calc(1)" but got ""
-FAIL CSSMathSum with more than one argument serializes correctly assert_equals: expected "calc(1 + 2 + 3)" but got ""
-FAIL CSSMathSum with a CSSMathNegate as first value serializes correctly assert_equals: expected "calc((-1) + 2 + 3)" but got ""
-FAIL CSSMathSum containing a CSSMathNegate after first value serializes correctly assert_equals: expected "calc(1 - 2 + 3)" but got ""
-FAIL CSSMathSum nested inside a CSSMathValue serializes correctly assert_equals: expected "calc((1 + 2) + 3)" but got ""
-FAIL CSSMathNegate serializes correctly assert_equals: expected "calc(-1)" but got ""
-FAIL CSSMathNegate nested inside a CSSMathValue serializes correctly assert_equals: expected "calc((-1))" but got ""
-FAIL CSSMathProduct with one argument serializes correctly assert_equals: expected "calc(1)" but got ""
-FAIL CSSMathProduct with more than one argument serializes correctly assert_equals: expected "calc(1 * 2 * 3)" but got ""
-FAIL CSSMathProduct with a CSSMathInvert as first value serializes correctly assert_equals: expected "calc((1 / 1) * 2 * 3)" but got ""
-FAIL CSSMathProduct containing a CSSMathInvert after first value serializes correctly assert_equals: expected "calc(1 / 2 * 3)" but got ""
-FAIL CSSMathProduct nested inside a CSSMathValue serializes correctly assert_equals: expected "calc((1 * 2) * 3)" but got ""
-FAIL CSSMathInvert serializes correctly assert_equals: expected "calc(1 / 1)" but got ""
-FAIL CSSMathInvert nested inside a CSSMathValue serializes correctly assert_equals: expected "calc((1 / 1))" but got ""
+PASS CSSMathMax with one argument serializes correctly
+PASS CSSMathMax with more than one argument serializes correctly
+PASS CSSMathMax containing nested CSSMathValues serializes correctly
+PASS CSSMathMin with one argument serializes correctly
+PASS CSSMathMin with more than one argument serializes correctly
+PASS CSSMathMin containing nested CSSMathValues serializes correctly
+PASS CSSMathSum with one argument serializes correctly
+PASS CSSMathSum with more than one argument serializes correctly
+PASS CSSMathSum with a CSSMathNegate as first value serializes correctly
+PASS CSSMathSum containing a CSSMathNegate after first value serializes correctly
+PASS CSSMathSum nested inside a CSSMathValue serializes correctly
+PASS CSSMathNegate serializes correctly
+PASS CSSMathNegate nested inside a CSSMathValue serializes correctly
+PASS CSSMathProduct with one argument serializes correctly
+PASS CSSMathProduct with more than one argument serializes correctly
+PASS CSSMathProduct with a CSSMathInvert as first value serializes correctly
+PASS CSSMathProduct containing a CSSMathInvert after first value serializes correctly
+PASS CSSMathProduct nested inside a CSSMathValue serializes correctly
+PASS CSSMathInvert serializes correctly
+PASS CSSMathInvert nested inside a CSSMathValue serializes correctly
 

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssTransformValue.tentative-expected.txt	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssTransformValue.tentative-expected.txt	2022-04-20 00:45:27 UTC (rev 293052)
@@ -1,20 +1,20 @@
 
-FAIL CSSTranslate with 2 arguments serializes correctly assert_equals: expected "translate(1%, 1px)" but got ""
-FAIL CSSTranslate with 3 arguments serializes correctly assert_equals: expected "translate3d(1px, 2%, 3px)" but got ""
-FAIL CSSScale with 2 arguments serializes correctly assert_equals: expected "scale(2, 3)" but got ""
-FAIL CSSScale with 3 arguments serializes correctly assert_equals: expected "scale3d(1, 2, 3)" but got ""
-FAIL CSSRotate with 1 argument serializes correctly assert_equals: expected "rotate(90deg)" but got ""
-FAIL CSSRotate with 4 arguments serializes correctly assert_equals: expected "rotate3d(1, 2, 3, 90deg)" but got ""
-FAIL CSSSkew serializes correctly assert_equals: expected "skew(90deg, 45deg)" but got ""
-FAIL CSSSkew with Y which is 0 value serializes correctly assert_equals: expected "skew(90deg)" but got ""
-FAIL CSSSkewX serializes correctly assert_equals: expected "skewX(90deg)" but got ""
-FAIL CSSSkewY serializes correctly assert_equals: expected "skewY(90deg)" but got ""
-FAIL CSSPerspective serializes correctly assert_equals: expected "perspective(1px)" but got ""
-FAIL CSSPerspective with negative length serializes correctly assert_equals: expected "perspective(calc(-1px))" but got ""
-FAIL CSSTransformValue with a single transform serializes correctly assert_equals: expected "perspective(1px)" but got ""
-FAIL CSSTransformValue with multiple transforms serializes correctly assert_equals: expected "translate(1px, 0px) rotate(90deg) perspective(1px) skew(90deg, 45deg) scale3d(1, 2, 3)" but got ""
-FAIL CSSTransformValue containing CSSMathValues serializes correctly assert_equals: expected "translate(calc(1px + 1em), 0px) rotate(calc(90deg + 1turn)) perspective(calc(1px + 1em)) skew(calc(90deg * 2), calc(1turn * 2)) scale3d(calc(1 * 2), calc(1 + 1), calc(3))" but got ""
+PASS CSSTranslate with 2 arguments serializes correctly
+PASS CSSTranslate with 3 arguments serializes correctly
+PASS CSSScale with 2 arguments serializes correctly
+PASS CSSScale with 3 arguments serializes correctly
+PASS CSSRotate with 1 argument serializes correctly
+PASS CSSRotate with 4 arguments serializes correctly
+PASS CSSSkew serializes correctly
+PASS CSSSkew with Y which is 0 value serializes correctly
+PASS CSSSkewX serializes correctly
+PASS CSSSkewY serializes correctly
+PASS CSSPerspective serializes correctly
+PASS CSSPerspective with negative length serializes correctly
+PASS CSSTransformValue with a single transform serializes correctly
+PASS CSSTransformValue with multiple transforms serializes correctly
+PASS CSSTransformValue containing CSSMathValues serializes correctly
 FAIL CSSMatrixComponent with 6 elements serializes correctly assert_equals: expected "matrix(1, 2, 3, 4, 5, 6)" but got ""
 FAIL CSSMatrixComponent with 16 elements serializes correctly assert_equals: expected "matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)" but got ""
-FAIL CSSTransformValue with updated is2D serializes as 2D transforms assert_equals: expected "translate(1px, 2px) rotate(90deg) scale(1, 2)" but got ""
+PASS CSSTransformValue with updated is2D serializes as 2D transforms
 

Modified: trunk/Source/WebCore/ChangeLog (293051 => 293052)


--- trunk/Source/WebCore/ChangeLog	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/ChangeLog	2022-04-20 00:45:27 UTC (rev 293052)
@@ -1,3 +1,103 @@
+2022-04-19  Alex Christensen  <[email protected]>
+
+        Implement most of CSS typed OM object stringifiers
+        https://bugs.webkit.org/show_bug.cgi?id=239483
+
+        Reviewed by Simon Fraser.
+
+        This is an off-by-default experimental feature.
+        Covered by web platform tests.
+
+        * css/typedom/CSSKeywordValue.cpp:
+        (WebCore::CSSKeywordValue::serialize const):
+        * css/typedom/CSSKeywordValue.h:
+        * css/typedom/CSSOMVariableReferenceValue.cpp:
+        (WebCore::CSSOMVariableReferenceValue::toString const):
+        (WebCore::CSSOMVariableReferenceValue::serialize const):
+        * css/typedom/CSSOMVariableReferenceValue.h:
+        * css/typedom/CSSStyleImageValue.cpp:
+        (WebCore::CSSStyleImageValue::serialize const):
+        (WebCore::CSSStyleImageValue::document const):
+        * css/typedom/CSSStyleImageValue.h:
+        * css/typedom/CSSStyleValue.cpp:
+        (WebCore::CSSStyleValue::toString const):
+        (WebCore::CSSStyleValue::serialize const):
+        * css/typedom/CSSStyleValue.h:
+        * css/typedom/CSSUnitValue.cpp:
+        (WebCore::CSSUnitValue::serialize const):
+        * css/typedom/CSSUnitValue.h:
+        * css/typedom/CSSUnparsedValue.cpp:
+        (WebCore::CSSUnparsedValue::serialize const):
+        (WebCore::CSSUnparsedValue::toString const): Deleted.
+        * css/typedom/CSSUnparsedValue.h:
+        * css/typedom/numeric/CSSMathInvert.cpp:
+        (WebCore::CSSMathInvert::serialize const):
+        * css/typedom/numeric/CSSMathInvert.h:
+        * css/typedom/numeric/CSSMathMax.cpp:
+        (WebCore::CSSMathMax::serialize const):
+        * css/typedom/numeric/CSSMathMax.h:
+        * css/typedom/numeric/CSSMathMin.cpp:
+        (WebCore::CSSMathMin::serialize const):
+        * css/typedom/numeric/CSSMathMin.h:
+        * css/typedom/numeric/CSSMathNegate.cpp:
+        (WebCore::CSSMathNegate::serialize const):
+        * css/typedom/numeric/CSSMathNegate.h:
+        * css/typedom/numeric/CSSMathProduct.cpp:
+        (WebCore::CSSMathProduct::serialize const):
+        * css/typedom/numeric/CSSMathProduct.h:
+        * css/typedom/numeric/CSSMathSum.cpp:
+        (WebCore::CSSMathSum::serialize const):
+        * css/typedom/numeric/CSSMathSum.h:
+        * css/typedom/numeric/CSSNumericArray.cpp:
+        (WebCore::CSSNumericArray::forEach):
+        * css/typedom/numeric/CSSNumericArray.h:
+        * css/typedom/transform/CSSMatrixComponent.cpp:
+        (WebCore::CSSMatrixComponent::serialize const):
+        (WebCore::CSSMatrixComponent::toMatrix):
+        (WebCore::CSSMatrixComponent::toString const): Deleted.
+        * css/typedom/transform/CSSMatrixComponent.h:
+        * css/typedom/transform/CSSPerspective.cpp:
+        (WebCore::CSSPerspective::serialize const):
+        (WebCore::CSSPerspective::toMatrix):
+        (WebCore::CSSPerspective::toString const): Deleted.
+        * css/typedom/transform/CSSPerspective.h:
+        * css/typedom/transform/CSSRotate.cpp:
+        (WebCore::CSSRotate::serialize const):
+        (WebCore::CSSRotate::toMatrix):
+        (WebCore::CSSRotate::toString const): Deleted.
+        * css/typedom/transform/CSSRotate.h:
+        * css/typedom/transform/CSSScale.cpp:
+        (WebCore::CSSScale::serialize const):
+        (WebCore::CSSScale::toMatrix):
+        (WebCore::CSSScale::toString const): Deleted.
+        * css/typedom/transform/CSSScale.h:
+        * css/typedom/transform/CSSSkew.cpp:
+        (WebCore::CSSSkew::serialize const):
+        (WebCore::CSSSkew::toMatrix):
+        (WebCore::CSSSkew::toString const): Deleted.
+        * css/typedom/transform/CSSSkew.h:
+        * css/typedom/transform/CSSSkewX.cpp:
+        (WebCore::CSSSkewX::serialize const):
+        (WebCore::CSSSkewX::toMatrix):
+        (WebCore::CSSSkewX::toString const): Deleted.
+        * css/typedom/transform/CSSSkewX.h:
+        * css/typedom/transform/CSSSkewY.cpp:
+        (WebCore::CSSSkewY::serialize const):
+        (WebCore::CSSSkewY::toMatrix):
+        (WebCore::CSSSkewY::toString const): Deleted.
+        * css/typedom/transform/CSSSkewY.h:
+        * css/typedom/transform/CSSTransformComponent.cpp:
+        (WebCore::CSSTransformComponent::toString const):
+        * css/typedom/transform/CSSTransformComponent.h:
+        * css/typedom/transform/CSSTransformValue.cpp:
+        (WebCore::CSSTransformValue::serialize const):
+        * css/typedom/transform/CSSTransformValue.h:
+        * css/typedom/transform/CSSTranslate.cpp:
+        (WebCore::CSSTranslate::serialize const):
+        (WebCore::CSSTranslate::toMatrix):
+        (WebCore::CSSTranslate::toString const): Deleted.
+        * css/typedom/transform/CSSTranslate.h:
+
 2022-04-19  Chris Dumez  <[email protected]>
 
         Use SortedArrayMap in parseEnumeration<>() in the JS bindings

Modified: trunk/Source/WebCore/css/typedom/CSSKeywordValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSKeywordValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSKeywordValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -67,6 +67,11 @@
     return { };
 }
 
+void CSSKeywordValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments>) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#keywordvalue-serialization
+    builder.append(m_value);
+}
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/css/typedom/CSSKeywordValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSKeywordValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSKeywordValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -50,6 +50,8 @@
     static Ref<CSSKeywordValue> rectifyKeywordish(CSSKeywordish&&);
 
 private:
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
+
     explicit CSSKeywordValue(const String& value)
         : m_value(value) { }
     String m_value;

Modified: trunk/Source/WebCore/css/typedom/CSSOMVariableReferenceValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSOMVariableReferenceValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSOMVariableReferenceValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -61,18 +61,17 @@
 String CSSOMVariableReferenceValue::toString() const
 {
     StringBuilder builder;
-    serialize(builder);
-    
+    serialize(builder, { });
     return builder.toString();
 }
 
-void CSSOMVariableReferenceValue::serialize(StringBuilder& builder) const
+void CSSOMVariableReferenceValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
 {
     builder.append("var(");
     builder.append(m_variable);
     if (m_fallback) {
         builder.append(", ");
-        m_fallback->serialize(builder);
+        m_fallback->serialize(builder, arguments);
     }
     builder.append(')');
 }

Modified: trunk/Source/WebCore/css/typedom/CSSOMVariableReferenceValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSOMVariableReferenceValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSOMVariableReferenceValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -43,7 +43,7 @@
     
     ExceptionOr<void> setVariable(String&&);
     String toString() const;
-    void serialize(StringBuilder&) const;
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const;
 
     const String& variable() const { return m_variable; }
     CSSUnparsedValue* fallback() { return m_fallback.get(); }

Modified: trunk/Source/WebCore/css/typedom/CSSStyleImageValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSStyleImageValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSStyleImageValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -46,8 +46,16 @@
 {
 }
 
-Document* CSSStyleImageValue::document() const { return m_document.get(); }
+void CSSStyleImageValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments>) const
+{
+    builder.append(m_cssValue->cssText());
+}
 
+Document* CSSStyleImageValue::document() const
+{
+    return m_document.get();
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/CSSStyleImageValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSStyleImageValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSStyleImageValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -46,7 +46,7 @@
         return adoptRef(*new CSSStyleImageValue(WTFMove(cssValue), document));
     }
 
-    String toString() const final { return m_cssValue->cssText(); }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     CachedImage* image() { return m_cssValue->cachedImage(); }
     Document* document() const;

Modified: trunk/Source/WebCore/css/typedom/CSSStyleValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSStyleValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSStyleValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -82,15 +82,19 @@
 {
 }
 
-
 String CSSStyleValue::toString() const
 {
-    if (!m_propertyValue)
-        return emptyString();
-    
-    return m_propertyValue->cssText();
+    StringBuilder builder;
+    serialize(builder);
+    return builder.toString();
 }
 
+void CSSStyleValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments>) const
+{
+    if (m_propertyValue)
+        builder.append(m_propertyValue->cssText());
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/CSSStyleValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSStyleValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSStyleValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -30,6 +30,7 @@
 #include "CSSPropertyNames.h"
 #include "CSSValue.h"
 #include "ScriptWrappable.h"
+#include <wtf/OptionSet.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
 
@@ -99,10 +100,16 @@
     return false;
 }
 
+enum class SerializationArguments : uint8_t {
+    Nested = 0x1,
+    WithoutParentheses = 0x2,
+};
+
 class CSSStyleValue : public RefCounted<CSSStyleValue>, public ScriptWrappable {
     WTF_MAKE_ISO_ALLOCATED(CSSStyleValue);
 public:
-    virtual String toString() const;
+    String toString() const;
+    virtual void serialize(StringBuilder&, OptionSet<SerializationArguments> = { }) const;
     virtual ~CSSStyleValue() = default;
 
     virtual CSSStyleValueType getType() const { return CSSStyleValueType::CSSStyleValue; }

Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -111,6 +111,12 @@
     return CSSPrimitiveValue::unitTypeString(m_unit);
 }
 
+void CSSUnitValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments>) const
+{
+    builder.append(FormattedCSSNumber::create(m_value));
+    builder.append(unitSerialization());
+}
+
 ExceptionOr<Ref<CSSUnitValue>> CSSUnitValue::create(double value, const String& unit)
 {
     auto parsedUnit = parseUnit(unit);

Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSUnitValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -42,7 +42,7 @@
     static ExceptionOr<Ref<CSSUnitValue>> create(double value, const String& unit);
     static Ref<CSSUnitValue> create(double value, CSSUnitType unit) { return adoptRef(*new CSSUnitValue(value, unit)); }
 
-    String toString() const final { return makeString(FormattedCSSNumber::create(m_value), unitSerialization()); }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     double value() const { return m_value; }
     void setValue(double value) { m_value = value; }

Modified: trunk/Source/WebCore/css/typedom/CSSUnparsedValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSUnparsedValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSUnparsedValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -119,21 +119,13 @@
 {
 }
 
-String CSSUnparsedValue::toString() const
+void CSSUnparsedValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
 {
-    StringBuilder builder;
-    serialize(builder);
-    
-    return builder.toString();
-}
-
-void CSSUnparsedValue::serialize(StringBuilder& builder) const
-{
     for (auto& segment : m_segments) {
         std::visit(WTF::makeVisitor([&] (const String& value) {
             builder.append(value);
         }, [&] (const RefPtr<CSSOMVariableReferenceValue>& value) {
-            value->serialize(builder);
+            value->serialize(builder, arguments);
         }), segment);
     }
 }

Modified: trunk/Source/WebCore/css/typedom/CSSUnparsedValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/CSSUnparsedValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/CSSUnparsedValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -44,8 +44,7 @@
     static Ref<CSSUnparsedValue> create(Vector<CSSUnparsedSegment>&&);
     static Ref<CSSUnparsedValue> create(CSSParserTokenRange);
 
-    String toString() const final;
-    void serialize(StringBuilder&) const;
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
     size_t length() const { return m_segments.size(); }
     
     ExceptionOr<CSSUnparsedSegment> item(size_t);

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -31,6 +31,7 @@
 #if ENABLE(CSS_TYPED_OM)
 
 #include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -72,6 +73,17 @@
 {
 }
 
+void CSSMathInvert::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#calc-serialization
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(arguments.contains(SerializationArguments::Nested) ? "(" : "calc(");
+    builder.append("1 / ");
+    m_value->serialize(builder, arguments);
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(')');
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -36,10 +36,12 @@
 public:
     static Ref<CSSMathInvert> create(CSSNumberish&&);
     CSSNumericValue& value() { return m_value.get(); }
-    
+    const CSSNumericValue& value() const { return m_value.get(); }
+
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Invert; }
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathInvert; }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     CSSMathInvert(CSSNumberish&&);
     Ref<CSSNumericValue> m_value;

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -31,6 +31,7 @@
 #if ENABLE(CSS_TYPED_OM)
 
 #include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -51,6 +52,20 @@
     return m_values.get();
 }
 
+void CSSMathMax::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#calc-serialization
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append("max(");
+    m_values->forEach([&](auto& numericValue, bool first) {
+        if (!first)
+            builder.append(", ");
+        numericValue.serialize(builder, { SerializationArguments::Nested, SerializationArguments::WithoutParentheses });
+    });
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(')');
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -43,6 +43,7 @@
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Max; }
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMax; }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     CSSMathMax(FixedVector<CSSNumberish>&&);
     CSSMathMax(Vector<Ref<CSSNumericValue>>&&);

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -51,6 +51,20 @@
     return m_values.get();
 }
 
+void CSSMathMin::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#calc-serialization
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append("min(");
+    m_values->forEach([&](auto& numericValue, bool first) {
+        if (!first)
+            builder.append(", ");
+        numericValue.serialize(builder, { SerializationArguments::Nested, SerializationArguments::WithoutParentheses });
+    });
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(')');
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -43,6 +43,7 @@
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Min; }
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMin; }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     CSSMathMin(FixedVector<CSSNumberish>&&);
     CSSMathMin(Vector<Ref<CSSNumericValue>>&&);

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -54,10 +54,15 @@
 {
 }
 
-CSSMathNegate::CSSMathNegate(Ref<CSSNumericValue>&& value)
-    : CSSMathValue(value->type())
-    , m_value(WTFMove(value))
+void CSSMathNegate::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
 {
+    // https://drafts.css-houdini.org/css-typed-om/#calc-serialization
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(arguments.contains(SerializationArguments::Nested) ? "(" : "calc(");
+    builder.append('-');
+    m_value->serialize(builder, arguments);
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(')');
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -39,13 +39,14 @@
 public:
     template<typename... Args> static Ref<CSSMathNegate> create(Args&&... args) { return adoptRef(*new CSSMathNegate(std::forward<Args>(args)...)); }
     CSSNumericValue& value() { return m_value.get(); }
-    
+    const CSSNumericValue& value() const { return m_value.get(); }
+
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Negate; }
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathNegate; }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     CSSMathNegate(CSSNumberish&&);
-    CSSMathNegate(Ref<CSSNumericValue>&&);
     Ref<CSSNumericValue> m_value;
 };
 

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -88,6 +88,28 @@
 {
 }
 
+void CSSMathProduct::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#calc-serialization
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(arguments.contains(SerializationArguments::Nested) ? "(" : "calc(");
+    m_values->forEach([&](auto& numericValue, bool first) {
+        OptionSet<SerializationArguments> operandSerializationArguments { SerializationArguments::Nested };
+        operandSerializationArguments.set(SerializationArguments::WithoutParentheses, arguments.contains(SerializationArguments::WithoutParentheses));
+        if (!first) {
+            if (auto* mathNegate = dynamicDowncast<CSSMathInvert>(numericValue)) {
+                builder.append(" / ");
+                mathNegate->value().serialize(builder, operandSerializationArguments);
+                return;
+            }
+            builder.append(" * ");
+        }
+        numericValue.serialize(builder, operandSerializationArguments);
+    });
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(')');
+}
+
 } // namespace WebCore
 
 #endif

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -44,6 +44,7 @@
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Product; }
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathProduct; }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const;
 
     CSSMathProduct(Vector<Ref<CSSNumericValue>>, CSSNumericType);
     Ref<CSSNumericArray> m_values;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -91,6 +91,28 @@
 {
 }
 
+void CSSMathSum::serialize(StringBuilder& builder, OptionSet<SerializationArguments> arguments) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#calc-serialization
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(arguments.contains(SerializationArguments::Nested) ? "(" : "calc(");
+    m_values->forEach([&](auto& numericValue, bool first) {
+        OptionSet<SerializationArguments> operandSerializationArguments { SerializationArguments::Nested };
+        operandSerializationArguments.set(SerializationArguments::WithoutParentheses, arguments.contains(SerializationArguments::WithoutParentheses));
+        if (!first) {
+            if (auto* mathNegate = dynamicDowncast<CSSMathNegate>(numericValue)) {
+                builder.append(" - ");
+                mathNegate->value().serialize(builder, operandSerializationArguments);
+                return;
+            }
+            builder.append(" + ");
+        }
+        numericValue.serialize(builder, operandSerializationArguments);
+    });
+    if (!arguments.contains(SerializationArguments::WithoutParentheses))
+        builder.append(')');
+}
+
 } // namespace WebCore
 
 #endif

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -45,6 +45,7 @@
 private:
     CSSMathOperator getOperator() const final { return CSSMathOperator::Sum; }
     CSSStyleValueType getType() const override { return CSSStyleValueType::CSSMathSum; }
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     CSSMathSum(Vector<Ref<CSSNumericValue>>, CSSNumericType);
     Ref<CSSNumericArray> m_values;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -65,6 +65,12 @@
     return m_array[index].copyRef();
 }
 
+void CSSNumericArray::forEach(Function<void(const CSSNumericValue&, bool first)> function)
+{
+    for (size_t i = 0; i < m_array.size(); i++)
+        function(m_array[i], !i);
+}
+
 } // namespace WebCore
 
 #endif

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSNumericArray.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -45,6 +45,7 @@
     size_t length() const { return m_array.size(); };
     ExceptionOr<Ref<CSSNumericValue>> item(size_t index);
     const Vector<Ref<CSSNumericValue>>& array() const { return m_array; }
+    void forEach(Function<void(const CSSNumericValue&, bool first)>);
 
 private:
     Vector<Ref<CSSNumericValue>> m_array;

Modified: trunk/Source/WebCore/css/typedom/transform/CSSMatrixComponent.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSMatrixComponent.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSMatrixComponent.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -52,15 +52,14 @@
 {
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSMatrixComponent::toString() const
+void CSSMatrixComponent::serialize(StringBuilder&) const
 {
-    return emptyString();
+    // FIXME: Implement.
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSMatrixComponent::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSMatrixComponent.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSMatrixComponent.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSMatrixComponent.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -43,8 +43,8 @@
     
     DOMMatrix& matrix();
     void setMatrix(Ref<DOMMatrix>&&);
-    
-    String toString() const final;
+
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
     
     CSSTransformType getType() const final { return CSSTransformType::MatrixComponent; }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSPerspective.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSPerspective.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSPerspective.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -33,6 +33,7 @@
 #if ENABLE(CSS_TYPED_OM)
 
 #include "CSSKeywordValue.h"
+#include "CSSUnitValue.h"
 #include "DOMMatrix.h"
 #include "ExceptionOr.h"
 #include <wtf/IsoMallocInlines.h>
@@ -88,15 +89,32 @@
     // https://drafts.css-houdini.org/css-typed-om/#dom-cssperspective-is2d says to do nothing here.
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSPerspective::toString() const
+void CSSPerspective::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-cssperspective
+    builder.append("perspective(");
+    WTF::switchOn(m_length,
+        [&] (const RefPtr<CSSNumericValue>& value) {
+            if (auto* unitValue = dynamicDowncast<CSSUnitValue>(value.get()); unitValue && unitValue->value() < 0.0) {
+                builder.append("calc(");
+                value->serialize(builder);
+                builder.append(')');
+                return;
+            }
+            if (value)
+                value->serialize(builder);
+        }, [&] (const String& value) {
+            builder.append(value);
+        }, [&] (const RefPtr<CSSKeywordValue>& value) {
+            if (CSSStyleValue* styleValue = value.get())
+                styleValue->serialize(builder);
+        });
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSPerspective::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSPerspective.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSPerspective.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSPerspective.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -43,8 +43,8 @@
     
     const CSSPerspectiveValue& length() const { return m_length; }
     ExceptionOr<void> setLength(CSSPerspectiveValue);
-    
-    String toString() const final;
+
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
     
     CSSTransformType getType() const final { return CSSTransformType::Perspective; }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSRotate.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSRotate.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSRotate.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -114,15 +114,25 @@
     return { };
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSRotate::toString() const
+void CSSRotate::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-cssrotate
+    builder.append(is2D() ? "rotate(" : "rotate3d(");
+    if (!is2D()) {
+        m_x->serialize(builder);
+        builder.append(", ");
+        m_y->serialize(builder);
+        builder.append(", ");
+        m_z->serialize(builder);
+        builder.append(", ");
+    }
+    m_angle->serialize(builder);
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSRotate::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSRotate.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSRotate.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSRotate.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -50,7 +50,7 @@
     ExceptionOr<void> setZ(CSSNumberish);
     ExceptionOr<void> setAngle(Ref<CSSNumericValue>);
 
-    String toString() const final;
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
     
     CSSTransformType getType() const final { return CSSTransformType::Rotate; }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSScale.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSScale.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSScale.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -80,15 +80,23 @@
     m_z = CSSNumericValue::rectifyNumberish(WTFMove(z));
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSScale::toString() const
+void CSSScale::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-cssscale
+    builder.append(is2D() ? "scale(" : "scale3d(");
+    m_x->serialize(builder);
+    builder.append(", ");
+    m_y->serialize(builder);
+    if (!is2D()) {
+        builder.append(", ");
+        m_z->serialize(builder);
+    }
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSScale::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSScale.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSScale.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSScale.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -39,7 +39,7 @@
 public:
     static ExceptionOr<Ref<CSSScale>> create(CSSNumberish x, CSSNumberish y, std::optional<CSSNumberish> z);
 
-    String toString() const final;
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
 
     CSSNumberish x() const { return m_x.ptr(); }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSSkew.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSSkew.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSSkew.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -55,15 +55,21 @@
 {
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSSkew::toString() const
+void CSSSkew::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-cssskew
+    builder.append("skew(");
+    m_ax->serialize(builder);
+    if (!is<CSSUnitValue>(m_ay) || downcast<CSSUnitValue>(m_ay.get()).value()) {
+        builder.append(", ");
+        m_ay->serialize(builder);
+    }
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSSkew::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSSkew.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSSkew.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSSkew.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -44,8 +44,8 @@
     
     void setAx(Ref<CSSNumericValue> ax) { m_ax = WTFMove(ax); }
     void setAy(Ref<CSSNumericValue> ay) { m_ay = WTFMove(ay); }
-    
-    String toString() const final;
+
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
     
     CSSTransformType getType() const final { return CSSTransformType::Skew; }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSSkewX.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSSkewX.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSSkewX.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -53,15 +53,17 @@
 {
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSSkewX::toString() const
+void CSSSkewX::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-cssskewx
+    builder.append("skewX(");
+    m_ax->serialize(builder);
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSSkewX::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSSkewX.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSSkewX.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSSkewX.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -41,8 +41,8 @@
     
     const CSSNumericValue& ax() const { return m_ax.get(); }
     void setAx(Ref<CSSNumericValue> ax) { m_ax = WTFMove(ax); }
-    
-    String toString() const final;
+
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
     
     CSSTransformType getType() const final { return CSSTransformType::SkewX; }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSSkewY.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSSkewY.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSSkewY.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -53,15 +53,17 @@
 {
 }
 
-// FIXME: Fix all the following virtual functions
-
-String CSSSkewY::toString() const
+void CSSSkewY::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-cssskewy
+    builder.append("skewY(");
+    m_ay->serialize(builder);
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSSkewY::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSSkewY.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSSkewY.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSSkewY.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -41,8 +41,8 @@
     
     const CSSNumericValue& ay() const { return m_ay.get(); }
     void setAy(Ref<CSSNumericValue> ay) { m_ay = WTFMove(ay); }
-    
-    String toString() const final;
+
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
     
     CSSTransformType getType() const final { return CSSTransformType::SkewY; }

Modified: trunk/Source/WebCore/css/typedom/transform/CSSTransformComponent.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSTransformComponent.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTransformComponent.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -32,16 +32,15 @@
 
 #if ENABLE(CSS_TYPED_OM)
 
-#include "DOMMatrix.h"
-#include "ExceptionOr.h"
-#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
 String CSSTransformComponent::toString() const
 {
-    // FIXME: implement.
-    return emptyString();
+    StringBuilder builder;
+    serialize(builder);
+    return builder.toString();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/typedom/transform/CSSTransformComponent.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSTransformComponent.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTransformComponent.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -53,7 +53,8 @@
     CSSTransformComponent(Is2D is2D)
         : m_is2D(is2D) { }
 public:
-    virtual String toString() const;
+    String toString() const;
+    virtual void serialize(StringBuilder&) const = 0;
     bool is2D() const { return m_is2D == Is2D::Yes; }
     virtual void setIs2D(bool is2D) { m_is2D = is2D ? Is2D::Yes : Is2D::No; }
     virtual ExceptionOr<Ref<DOMMatrix>> toMatrix() = 0;

Modified: trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -91,6 +91,15 @@
 {
 }
 
+void CSSTransformValue::serialize(StringBuilder& builder, OptionSet<SerializationArguments>) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-csstransformvalue
+    for (size_t i = 0; i < m_components.size(); i++) {
+        if (i)
+            builder.append(' ');
+        m_components[i]->serialize(builder);
+    }
+}
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTransformValue.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -53,6 +53,7 @@
     CSSStyleValueType getType() const override { return CSSStyleValueType::CSSTransformValue; }
 private:
     CSSTransformValue(Vector<RefPtr<CSSTransformComponent>>&&);
+    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
 
     Vector<RefPtr<CSSTransformComponent>> m_components;
 };

Modified: trunk/Source/WebCore/css/typedom/transform/CSSTranslate.cpp (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSTranslate.cpp	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTranslate.cpp	2022-04-20 00:45:27 UTC (rev 293052)
@@ -65,16 +65,23 @@
 {
 }
 
-
-// FIXME: Fix all the following virtual functions
-
-String CSSTranslate::toString() const
+void CSSTranslate::serialize(StringBuilder& builder) const
 {
-    return emptyString();
+    // https://drafts.css-houdini.org/css-typed-om/#serialize-a-csstranslate
+    builder.append(is2D() ? "translate(" : "translate3d(");
+    m_x->serialize(builder);
+    builder.append(", ");
+    m_y->serialize(builder);
+    if (!is2D()) {
+        builder.append(", ");
+        m_z->serialize(builder);
+    }
+    builder.append(')');
 }
 
 ExceptionOr<Ref<DOMMatrix>> CSSTranslate::toMatrix()
 {
+    // FIXME: Implement.
     return DOMMatrix::fromMatrix(DOMMatrixInit { });
 }
 

Modified: trunk/Source/WebCore/css/typedom/transform/CSSTranslate.h (293051 => 293052)


--- trunk/Source/WebCore/css/typedom/transform/CSSTranslate.h	2022-04-20 00:25:17 UTC (rev 293051)
+++ trunk/Source/WebCore/css/typedom/transform/CSSTranslate.h	2022-04-20 00:45:27 UTC (rev 293052)
@@ -47,7 +47,7 @@
     void setY(Ref<CSSNumericValue> y) { m_y = WTFMove(y); }
     void setZ(Ref<CSSNumericValue> z) { m_z = WTFMove(z); }
     
-    String toString() const final;
+    void serialize(StringBuilder&) const final;
     ExceptionOr<Ref<DOMMatrix>> toMatrix() final;
 
 private:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to