Changeset 295716 in webkit for trunk/Source/WebCore/css


Ignore:
Timestamp:
Jun 21, 2022, 8:00:34 PM (3 years ago)
Author:
[email protected]
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

Location:
trunk/Source/WebCore/css/typedom
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/typedom/CSSNumericValue.cpp

    r295219 r295716  
    226226}
    227227
    228 bool CSSNumericValue::equals(FixedVector<CSSNumberish>&& value)
    229 {
    230     UNUSED_PARAM(value);
     228bool CSSNumericValue::equals(FixedVector<CSSNumberish>&& values)
     229{
    231230    // https://drafts.css-houdini.org/css-typed-om/#dom-cssnumericvalue-equals
    232     // FIXME: add impl.
    233     return false;
     231    auto numericValues = WTF::map(WTFMove(values), rectifyNumberish);
     232    return WTF::allOf(numericValues, [&] (const Ref<CSSNumericValue>& value) {
     233        return this->equals(value.get());
     234    });
    234235}
    235236
  • trunk/Source/WebCore/css/typedom/CSSNumericValue.h

    r295219 r295716  
    6565    static Ref<CSSNumericValue> rectifyNumberish(CSSNumberish&&);
    6666
    67     CSSStyleValueType getType() const override { return CSSStyleValueType::CSSNumericValue; }
    68 
    6967    // https://drafts.css-houdini.org/css-typed-om/#sum-value-value
    7068    using UnitMap = HashMap<CSSUnitType, int, WTF::IntHash<CSSUnitType>, WTF::StrongEnumHashTraits<CSSUnitType>>;
     
    7573    using SumValue = Vector<Addend>;
    7674    virtual std::optional<SumValue> toSumValue() const = 0;
     75    virtual bool equals(const CSSNumericValue&) const = 0;
    7776
    7877protected:
  • trunk/Source/WebCore/css/typedom/CSSStyleValue.h

    r295692 r295716  
    4545    CSSStyleImageValue,
    4646    CSSTransformValue,
    47     CSSNumericValue,
    4847    CSSMathInvert,
    4948    CSSMathMin,
     
    6059{
    6160    switch (type) {
    62     case CSSStyleValueType::CSSNumericValue:
    6361    case CSSStyleValueType::CSSMathInvert:
    6462    case CSSStyleValueType::CSSMathMin:
     
    8987    case CSSStyleValueType::CSSMathSum:
    9088        return true;
    91     case CSSStyleValueType::CSSNumericValue:
    9289    case CSSStyleValueType::CSSUnitValue:
    9390    case CSSStyleValueType::CSSStyleValue:
  • trunk/Source/WebCore/css/typedom/CSSUnitValue.cpp

    r295219 r295716  
    175175}
    176176
     177bool CSSUnitValue::equals(const CSSNumericValue& other) const
     178{
     179    // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
     180    auto* otherUnitValue = dynamicDowncast<CSSUnitValue>(other);
     181    if (!otherUnitValue)
     182        return false;
     183    return m_value == otherUnitValue->m_value && m_unit == otherUnitValue->m_unit;
     184}
     185
    177186} // namespace WebCore
    178187
  • trunk/Source/WebCore/css/typedom/CSSUnitValue.h

    r295219 r295716  
    5757    CSSUnitValue(double, CSSUnitType);
    5858
     59    CSSStyleValueType getType() const final { return CSSStyleValueType::CSSUnitValue; }
    5960    std::optional<SumValue> toSumValue() const final;
    60     CSSStyleValueType getType() const final { return CSSStyleValueType::CSSUnitValue; }
     61    bool equals(const CSSNumericValue&) const final;
    6162
    6263    double m_value;
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp

    r295219 r295716  
    7070CSSMathInvert::CSSMathInvert(CSSNumberish&& numberish)
    7171    : CSSMathValue(negatedType(numberish))
    72     , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
     72    , m_value(rectifyNumberish(WTFMove(numberish)))
    7373{
    7474}
     
    106106}
    107107
     108bool CSSMathInvert::equals(const CSSNumericValue& other) const
     109{
     110    // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
     111    auto* otherInvert = dynamicDowncast<CSSMathInvert>(other);
     112    if (!otherInvert)
     113        return false;
     114    return m_value->equals(otherInvert->value());
     115
     116}
     117
    108118} // namespace WebCore
    109119
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathInvert.h

    r295219 r295716  
    4444    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
    4545    std::optional<SumValue> toSumValue() const final;
     46    bool equals(const CSSNumericValue&) const final;
    4647
    4748    CSSMathInvert(CSSNumberish&&);
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathMax.h

    r295219 r295716  
    4747    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
    4848    std::optional<SumValue> toSumValue() const final;
     49    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathMax>(other); }
    4950
    5051    CSSMathMax(Vector<Ref<CSSNumericValue>>&&, CSSNumericType&&);
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathMin.h

    r295219 r295716  
    4747    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
    4848    std::optional<SumValue> toSumValue() const final;
     49    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathMin>(other); }
    4950
    5051    CSSMathMin(Vector<Ref<CSSNumericValue>>&&, CSSNumericType&&);
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.cpp

    r295219 r295716  
    5252CSSMathNegate::CSSMathNegate(CSSNumberish&& numberish)
    5353    : CSSMathValue(copyType(numberish))
    54     , m_value(CSSNumericValue::rectifyNumberish(WTFMove(numberish)))
     54    , m_value(rectifyNumberish(WTFMove(numberish)))
    5555{
    5656}
     
    7878}
    7979
     80bool CSSMathNegate::equals(const CSSNumericValue& other) const
     81{
     82    // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
     83    auto* otherNegate = dynamicDowncast<CSSMathNegate>(other);
     84    if (!otherNegate)
     85        return false;
     86    return m_value->equals(otherNegate->value());
     87
     88}
     89
    8090} // namespace WebCore
    8191
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathNegate.h

    r295219 r295716  
    4747    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
    4848    std::optional<SumValue> toSumValue() const final;
     49    bool equals(const CSSNumericValue& other) const final;
    4950
    5051    CSSMathNegate(CSSNumberish&&);
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathProduct.h

    r295219 r295716  
    4747    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const;
    4848    std::optional<SumValue> toSumValue() const final;
     49    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathProduct>(other); }
    4950
    5051    CSSMathProduct(Vector<Ref<CSSNumericValue>>, CSSNumericType);
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathSum.h

    r295219 r295716  
    4848    void serialize(StringBuilder&, OptionSet<SerializationArguments>) const final;
    4949    std::optional<SumValue> toSumValue() const final;
     50    bool equals(const CSSNumericValue& other) const final { return equalsImpl<CSSMathSum>(other); }
    5051
    5152    CSSMathSum(Vector<Ref<CSSNumericValue>>, CSSNumericType);
  • trunk/Source/WebCore/css/typedom/numeric/CSSMathValue.h

    r292150 r295716  
    2929
    3030#include "CSSMathOperator.h"
     31#include "CSSNumericArray.h"
    3132#include "CSSNumericValue.h"
    3233#include "CSSStyleValue.h"
     
    3637class CSSMathValue : public CSSNumericValue {
    3738public:
    38     CSSMathValue(CSSNumericType type = { })
     39    CSSMathValue(CSSNumericType type)
    3940        : CSSNumericValue(WTFMove(type)) { }
    4041    virtual CSSMathOperator getOperator() const = 0;
     42
     43    template <typename T>
     44    bool equalsImpl(const CSSNumericValue& other) const
     45    {
     46        // https://drafts.css-houdini.org/css-typed-om/#equal-numeric-value
     47        auto* otherT = dynamicDowncast<T>(other);
     48        if (!otherT)
     49            return false;
     50
     51        ASSERT(getType() == other.getType());
     52        auto& thisValues = static_cast<const T*>(this)->values();
     53        auto& otherValues = otherT->values();
     54        auto length = thisValues.length();
     55        if (length != otherValues.length())
     56            return false;
     57
     58        for (size_t i = 0 ; i < length; ++i) {
     59            if (!thisValues.array()[i]->equals(otherValues.array()[i].get()))
     60                return false;
     61        }
     62
     63        return true;
     64
     65    }
    4166};
    4267
Note: See TracChangeset for help on using the changeset viewer.