Title: [295716] trunk
Revision
295716
Author
[email protected]
Date
2022-06-21 20:00:34 -0700 (Tue, 21 Jun 2022)

Log Message

Implement CSSNumericValue.equals
https://bugs.webkit.org/show_bug.cgi?id=241378

Reviewed by Chris Dumez.

This is an off-by-default experimental feature.

* LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/equals.tentative-expected.txt:
* Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp:
(WebCore::toJSNewlyCreated):
* Source/WebCore/css/typedom/CSSNumericValue.cpp:
(WebCore::CSSNumericValue::equals):
* Source/WebCore/css/typedom/CSSNumericValue.h:
(): Deleted.
* Source/WebCore/css/typedom/CSSStyleValue.h:
(WebCore::isCSSNumericValue):
(WebCore::isCSSMathValue):
* Source/WebCore/css/typedom/CSSUnitValue.cpp:
(WebCore::CSSUnitValue::equals const):
* Source/WebCore/css/typedom/CSSUnitValue.h:
* Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp:
(WebCore::CSSMathInvert::CSSMathInvert):
(WebCore::CSSMathInvert::equals const):
* Source/WebCore/css/typedom/numeric/CSSMathInvert.h:
* Source/WebCore/css/typedom/numeric/CSSMathMax.h:
* Source/WebCore/css/typedom/numeric/CSSMathMin.h:
* Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp:
(WebCore::CSSMathNegate::CSSMathNegate):
(WebCore::CSSMathNegate::equals const):
* Source/WebCore/css/typedom/numeric/CSSMathNegate.h:
* Source/WebCore/css/typedom/numeric/CSSMathProduct.h:
* Source/WebCore/css/typedom/numeric/CSSMathSum.h:
* Source/WebCore/css/typedom/numeric/CSSMathValue.h:
(WebCore::CSSMathValue::CSSMathValue):
(WebCore::CSSMathValue::equalsImpl const):

Canonical link: https://commits.webkit.org/251721@main

Modified Paths

Diff

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


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/equals.tentative-expected.txt	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/numeric-objects/equals.tentative-expected.txt	2022-06-22 03:00:34 UTC (rev 295716)
@@ -1,11 +1,11 @@
 
-FAIL Two CSSUnitValues with same value and unit are equal assert_true: expected true got false
+PASS Two CSSUnitValues with same value and unit are equal
 PASS Two CSSUnitValues with different values are not equal
 PASS Two CSSUnitValues with different units are not equal
 PASS Two CSSMathValues with different types are not equal
 PASS Two CSSMathValues with different number of values are not equal
 PASS Two CSSMathValues with different values are not equal
-FAIL Two CSSMathValues with same structure are equal assert_true: expected true got false
-FAIL Multiple CSSMathValues with same structure are equal assert_true: expected true got false
+PASS Two CSSMathValues with same structure are equal
+PASS Multiple CSSMathValues with same structure are equal
 PASS Multiple CSSMathValues with one different are not equal
 

Modified: trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp (295715 => 295716)


--- trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/bindings/js/JSCSSStyleValueCustom.cpp	2022-06-22 03:00:34 UTC (rev 295716)
@@ -51,8 +51,6 @@
     switch (value->getType()) {
     case CSSStyleValueType::CSSStyleImageValue:
         return createWrapper<CSSStyleImageValue>(globalObject, WTFMove(value));
-    case CSSStyleValueType::CSSNumericValue:
-        return createWrapper<CSSNumericValue>(globalObject, WTFMove(value));
     case CSSStyleValueType::CSSMathInvert:
         return createWrapper<CSSMathInvert>(globalObject, WTFMove(value));
     case CSSStyleValueType::CSSMathMin:

Modified: trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp (295715 => 295716)


--- trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp	2022-06-22 03:00:34 UTC (rev 295716)
@@ -225,12 +225,13 @@
     });
 }
 
-bool CSSNumericValue::equals(FixedVector<CSSNumberish>&& value)
+bool CSSNumericValue::equals(FixedVector<CSSNumberish>&& values)
 {
-    UNUSED_PARAM(value);
     // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-equals
-    // FIXME: add impl.
-    return false;
+    auto numericValues = WTF::map(WTFMove(values), rectifyNumberish);
+    return WTF::allOf(numericValues, [&] (const Ref<CSSNumericValue>& value) {
+        return this->equals(value.get());
+    });
 }
 
 ExceptionOr<Ref<CSSUnitValue>> CSSNumericValue::to(String&& unit)

Modified: trunk/Source/WebCore/css/typedom/CSSNumericValue.h (295715 => 295716)


--- trunk/Source/WebCore/css/typedom/CSSNumericValue.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/CSSNumericValue.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -64,8 +64,6 @@
     static ExceptionOr<Ref<CSSNumericValue>> parse(String&&);
     static Ref<CSSNumericValue> rectifyNumberish(CSSNumberish&&);
 
-    CSSStyleValueType getType() const override { return CSSStyleValueType::CSSNumericValue; }
-
     // https://drafts.css-houdini.org/css-typed-om/#sum-value-value
     using UnitMap = HashMap<CSSUnitType, int, WTF::IntHash<CSSUnitType>, WTF::StrongEnumHashTraits<CSSUnitType>>;
     struct Addend {
@@ -74,6 +72,7 @@
     };
     using SumValue = Vector<Addend>;
     virtual std::optional<SumValue> toSumValue() const = 0;
+    virtual bool equals(const CSSNumericValue&) const = 0;
 
 protected:
     ExceptionOr<Ref<CSSNumericValue>> addInternal(Vector<Ref<CSSNumericValue>>&&);

Modified: trunk/Source/WebCore/css/typedom/CSSStyleValue.h (295715 => 295716)


--- trunk/Source/WebCore/css/typedom/CSSStyleValue.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/CSSStyleValue.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -44,7 +44,6 @@
     CSSStyleValue,
     CSSStyleImageValue,
     CSSTransformValue,
-    CSSNumericValue,
     CSSMathInvert,
     CSSMathMin,
     CSSMathMax,
@@ -59,7 +58,6 @@
 inline bool isCSSNumericValue(CSSStyleValueType type)
 {
     switch (type) {
-    case CSSStyleValueType::CSSNumericValue:
     case CSSStyleValueType::CSSMathInvert:
     case CSSStyleValueType::CSSMathMin:
     case CSSStyleValueType::CSSMathMax:
@@ -88,7 +86,6 @@
     case CSSStyleValueType::CSSMathProduct:
     case CSSStyleValueType::CSSMathSum:
         return true;
-    case CSSStyleValueType::CSSNumericValue:
     case CSSStyleValueType::CSSUnitValue:
     case CSSStyleValueType::CSSStyleValue:
     case CSSStyleValueType::CSSStyleImageValue:

Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp (295715 => 295716)


--- trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp	2022-06-22 03:00:34 UTC (rev 295716)
@@ -174,6 +174,15 @@
     return { { { convertedValue, { { canonicalUnit, 1 } } } } };
 }
 
+bool CSSUnitValue::equals(const CSSNumericValue& other) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
+    auto* otherUnitValue = dynamicDowncast<CSSUnitValue>(other);
+    if (!otherUnitValue)
+        return false;
+    return m_value == otherUnitValue->m_value && m_unit == otherUnitValue->m_unit;
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/typedom/CSSUnitValue.h (295715 => 295716)


--- trunk/Source/WebCore/css/typedom/CSSUnitValue.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/CSSUnitValue.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -56,8 +56,9 @@
 private:
     CSSUnitValue(double, CSSUnitType);
 
+    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSUnitValue; }
     std::optional<SumValue> toSumValue() const final;
-    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSUnitValue; }
+    bool equals(const CSSNumericValue&) const final;
 
     double m_value;
     const CSSUnitType m_unit;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp	2022-06-22 03:00:34 UTC (rev 295716)
@@ -69,7 +69,7 @@
 
 CSSMathInvert::CSSMathInvert(CSSNumberish&& numberish)
     : CSSMathValue(negatedType(numberish))
-    , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
+    , m_value(rectifyNumberish(WTFMove(numberish)))
 {
 }
 
@@ -105,6 +105,16 @@
     return values;
 }
 
+bool CSSMathInvert::equals(const CSSNumericValue& other) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
+    auto* otherInvert = dynamicDowncast<CSSMathInvert>(other);
+    if (!otherInvert)
+        return false;
+    return m_value->equals(otherInvert->value());
+
+}
+
 } // namespace WebCore
 
 #endif

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -43,6 +43,7 @@
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathInvert; }
     void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
     std::optional<SumValue> toSumValue() const final;
+    bool equals(const CSSNumericValue&) const final;
 
     CSSMathInvert(CSSNumberish&&);
     Ref<CSSNumericValue> m_value;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -46,6 +46,7 @@
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMax; }
     void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
     std::optional<SumValue> toSumValue() const final;
+    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathMax>(other); }
 
     CSSMathMax(Vector<Ref<CSSNumericValue>>&&, CSSNumericType&&);
     Ref<CSSNumericArray> m_values;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -46,6 +46,7 @@
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathMin; }
     void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
     std::optional<SumValue> toSumValue() const final;
+    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathMin>(other); }
 
     CSSMathMin(Vector<Ref<CSSNumericValue>>&&, CSSNumericType&&);
     Ref<CSSNumericArray> m_values;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp	2022-06-22 03:00:34 UTC (rev 295716)
@@ -51,7 +51,7 @@
 
 CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
     : CSSMathValue(copyType(numberish))
-    , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
+    , m_value(rectifyNumberish(WTFMove(numberish)))
 {
 }
 
@@ -77,6 +77,16 @@
     return values;
 }
 
+bool CSSMathNegate::equals(const CSSNumericValue& other) const
+{
+    // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
+    auto* otherNegate = dynamicDowncast<CSSMathNegate>(other);
+    if (!otherNegate)
+        return false;
+    return m_value->equals(otherNegate->value());
+
+}
+
 } // namespace WebCore
 
 #endif

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -46,6 +46,7 @@
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathNegate; }
     void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
     std::optional<SumValue> toSumValue() const final;
+    bool equals(const CSSNumericValue& other) const final;
 
     CSSMathNegate(CSSNumberish&&);
     Ref<CSSNumericValue> m_value;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -46,6 +46,7 @@
     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSMathProduct; }
     void serialize(StringBuilder&, OptionSet<SerializationArguments>) const;
     std::optional<SumValue> toSumValue() const final;
+    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathProduct>(other); }
 
     CSSMathProduct(Vector<Ref<CSSNumericValue>>, CSSNumericType);
     Ref<CSSNumericArray> m_values;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -47,6 +47,7 @@
     CSSStyleValueType getType() const override { return CSSStyleValueType::CSSMathSum; }
     void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
     std::optional<SumValue> toSumValue() const final;
+    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathSum>(other); }
 
     CSSMathSum(Vector<Ref<CSSNumericValue>>, CSSNumericType);
     Ref<CSSNumericArray> m_values;

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


--- trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h	2022-06-22 02:41:14 UTC (rev 295715)
+++ trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h	2022-06-22 03:00:34 UTC (rev 295716)
@@ -28,6 +28,7 @@
 #if ENABLE(CSS_TYPED_OM)
 
 #include "CSSMathOperator.h"
+#include "CSSNumericArray.h"
 #include "CSSNumericValue.h"
 #include "CSSStyleValue.h"
 
@@ -35,9 +36,33 @@
 
 class CSSMathValue : public CSSNumericValue {
 public:
-    CSSMathValue(CSSNumericType type = { })
+    CSSMathValue(CSSNumericType type)
         : CSSNumericValue(WTFMove(type)) { }
     virtual CSSMathOperator getOperator() const = 0;
+
+    template <typename T>
+    bool equalsImpl(const CSSNumericValue& other) const
+    {
+        // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
+        auto* otherT = dynamicDowncast<T>(other);
+        if (!otherT)
+            return false;
+
+        ASSERT(getType() == other.getType());
+        auto& thisValues = static_cast<const T*>(this)->values();
+        auto& otherValues = otherT->values();
+        auto length = thisValues.length();
+        if (length != otherValues.length())
+            return false;
+
+        for (size_t i = 0 ; i < length; ++i) {
+            if (!thisValues.array()[i]->equals(otherValues.array()[i].get()))
+                return false;
+        }
+
+        return true;
+
+    }
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to