Title: [274546] trunk/Source/WebCore
Revision
274546
Author
commit-qu...@webkit.org
Date
2021-03-16 19:12:13 -0700 (Tue, 16 Mar 2021)

Log Message

Add CSSValuePair.h in preparation for Pair.h refactor
https://bugs.webkit.org/show_bug.cgi?id=223205

Patch by Tyler Wilcock <twilc...@protonmail.com> on 2021-03-16
Reviewed by Simon Fraser.

Add new CSSValuePair class, which is intended to replace Pair.h.
Pair.h has some problems, namely:

1. It's not a sub-class of CSSValue, making it awkward to use.
2. It can only contain CSSPrimitiveValues.

CSSValuePair will fix both of these shortcomings.

* Sources.txt:
Add CSSValuePair.cpp.

* css/CSSValue.cpp:
(WebCore::CSSValue::cssText const):
Handle new ValuePairClass value.
(WebCore::CSSValue::separatorCssText const):
Added.
(WebCore::CSSValue::destroy):
Handle new ValuePairClass value.

* css/CSSValue.h:
(WebCore::CSSValue::isValuePair const):
Added.
(WebCore::CSSValue::CSSValue):
Add new ValuePairClass value. Rename m_valueListSeparator to m_valueSeparator,
ValueListSeparator to ValueSeparator, and
ValueListSeparatorBits to ValueSeparatorBits.

* css/CSSValueList.cpp:
(WebCore::CSSValueList::CSSValueList):
(WebCore::CSSValueList::copy):
(WebCore::CSSValueList::customCSSText const):
Refactor to use new separatorCssText() function.
(WebCore::CSSValueList::equals const):
Rename m_valueListSeparator to m_valueSeparator,
ValueListSeparator to ValueSeparator, and
ValueListSeparatorBits to ValueSeparatorBits.

* css/CSSValueList.h:
(WebCore::CSSValueList::separator const):
Rename m_valueListSeparator to m_valueSeparator.

* css/CSSValuePair.cpp:
(WebCore::CSSValuePair::customCSSText const):
(WebCore::CSSValuePair::equals const):
Added.

* css/CSSValuePair.h:
(WebCore::CSSValuePair::create):
(WebCore::CSSValuePair::first const):
(WebCore::CSSValuePair::second const):
(WebCore::CSSValuePair::CSSValuePair):
Added.

* css/DeprecatedCSSOMValue.h:
* css/DeprecatedCSSOMValueList.cpp:
(WebCore::DeprecatedCSSOMValueList::cssText const):
* css/DeprecatedCSSOMValueList.h:
(WebCore::DeprecatedCSSOMValueList::DeprecatedCSSOMValueList):
Rename m_valueListSeparator to m_valueSeparator,
ValueListSeparator to ValueSeparator, and
ValueListSeparatorBits to ValueSeparatorBits.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274545 => 274546)


--- trunk/Source/WebCore/ChangeLog	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/ChangeLog	2021-03-17 02:12:13 UTC (rev 274546)
@@ -1,3 +1,73 @@
+2021-03-16  Tyler Wilcock  <twilc...@protonmail.com>
+
+        Add CSSValuePair.h in preparation for Pair.h refactor
+        https://bugs.webkit.org/show_bug.cgi?id=223205
+
+        Reviewed by Simon Fraser.
+
+        Add new CSSValuePair class, which is intended to replace Pair.h.
+        Pair.h has some problems, namely:
+
+        1. It's not a sub-class of CSSValue, making it awkward to use.
+        2. It can only contain CSSPrimitiveValues.
+
+        CSSValuePair will fix both of these shortcomings.
+
+        * Sources.txt:
+        Add CSSValuePair.cpp.
+
+        * css/CSSValue.cpp:
+        (WebCore::CSSValue::cssText const):
+        Handle new ValuePairClass value.
+        (WebCore::CSSValue::separatorCssText const):
+        Added.
+        (WebCore::CSSValue::destroy):
+        Handle new ValuePairClass value.
+
+        * css/CSSValue.h:
+        (WebCore::CSSValue::isValuePair const):
+        Added.
+        (WebCore::CSSValue::CSSValue):
+        Add new ValuePairClass value. Rename m_valueListSeparator to m_valueSeparator,
+        ValueListSeparator to ValueSeparator, and
+        ValueListSeparatorBits to ValueSeparatorBits.
+
+        * css/CSSValueList.cpp:
+        (WebCore::CSSValueList::CSSValueList):
+        (WebCore::CSSValueList::copy):
+        (WebCore::CSSValueList::customCSSText const):
+        Refactor to use new separatorCssText() function.
+        (WebCore::CSSValueList::equals const):
+        Rename m_valueListSeparator to m_valueSeparator,
+        ValueListSeparator to ValueSeparator, and
+        ValueListSeparatorBits to ValueSeparatorBits.
+
+        * css/CSSValueList.h:
+        (WebCore::CSSValueList::separator const):
+        Rename m_valueListSeparator to m_valueSeparator.
+
+        * css/CSSValuePair.cpp:
+        (WebCore::CSSValuePair::customCSSText const):
+        (WebCore::CSSValuePair::equals const):
+        Added.
+
+        * css/CSSValuePair.h:
+        (WebCore::CSSValuePair::create):
+        (WebCore::CSSValuePair::first const):
+        (WebCore::CSSValuePair::second const):
+        (WebCore::CSSValuePair::CSSValuePair):
+        Added.
+
+        * css/DeprecatedCSSOMValue.h:
+        * css/DeprecatedCSSOMValueList.cpp:
+        (WebCore::DeprecatedCSSOMValueList::cssText const):
+        * css/DeprecatedCSSOMValueList.h:
+        (WebCore::DeprecatedCSSOMValueList::DeprecatedCSSOMValueList):
+        Rename m_valueListSeparator to m_valueSeparator,
+        ValueListSeparator to ValueSeparator, and
+        ValueListSeparatorBits to ValueSeparatorBits.
+
+
 2021-03-16  Chris Dumez  <cdu...@apple.com>
 
         Avoid heap allocation under AudioSummingJunction::updateRenderingState()

Modified: trunk/Source/WebCore/Sources.txt (274545 => 274546)


--- trunk/Source/WebCore/Sources.txt	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/Sources.txt	2021-03-17 02:12:13 UTC (rev 274546)
@@ -780,6 +780,7 @@
 css/CSSUnsetValue.cpp
 css/CSSValue.cpp
 css/CSSValueList.cpp
+css/CSSValuePair.cpp
 css/CSSValuePool.cpp
 css/CSSVariableData.cpp
 css/CSSVariableReferenceValue.cpp

Modified: trunk/Source/WebCore/css/CSSValue.cpp (274545 => 274546)


--- trunk/Source/WebCore/css/CSSValue.cpp	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/CSSValue.cpp	2021-03-17 02:12:13 UTC (rev 274546)
@@ -62,6 +62,7 @@
 #include "CSSUnicodeRangeValue.h"
 #include "CSSUnsetValue.h"
 #include "CSSValueList.h"
+#include "CSSValuePair.h"
 #include "CSSVariableReferenceValue.h"
 
 #include "CSSGridAutoRepeatValue.h"
@@ -312,6 +313,8 @@
         return downcast<CSSUnicodeRangeValue>(*this).customCSSText();
     case ValueListClass:
         return downcast<CSSValueList>(*this).customCSSText();
+    case ValuePairClass:
+        return downcast<CSSValuePair>(*this).customCSSText();
     case LineBoxContainClass:
         return downcast<CSSLineBoxContainValue>(*this).customCSSText();
     case CalculationClass:
@@ -338,6 +341,21 @@
     return String();
 }
 
+String CSSValue::separatorCssText() const
+{
+    switch (m_valueSeparator) {
+    case SpaceSeparator:
+        return " "_s;
+    case CommaSeparator:
+        return ", "_s;
+    case SlashSeparator:
+        return " / "_s;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+    return " "_s;
+}
+
 void CSSValue::destroy()
 {
     switch (classType()) {
@@ -434,6 +452,9 @@
     case ValueListClass:
         delete downcast<CSSValueList>(this);
         return;
+    case ValuePairClass:
+        delete downcast<CSSValuePair>(this);
+        return;
     case LineBoxContainClass:
         delete downcast<CSSLineBoxContainValue>(this);
         return;

Modified: trunk/Source/WebCore/css/CSSValue.h (274545 => 274546)


--- trunk/Source/WebCore/css/CSSValue.h	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/CSSValue.h	2021-03-17 02:12:13 UTC (rev 274546)
@@ -77,9 +77,11 @@
 
     Type cssValueType() const;
     String cssText() const;
+    String separatorCssText() const;
 
     bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
     bool isValueList() const { return m_classType >= ValueListClass; }
+    bool isValuePair() const { return m_classType == ValuePairClass; }
     
     bool isBaseValueList() const { return m_classType == ValueListClass; }
         
@@ -198,6 +200,7 @@
         LineBoxContainClass,
         CalculationClass,
         GridTemplateAreasClass,
+        ValuePairClass,
 
         CSSContentDistributionClass,
 
@@ -219,8 +222,8 @@
     };
 
 public:
-    static const size_t ValueListSeparatorBits = 2;
-    enum ValueListSeparator {
+    static const size_t ValueSeparatorBits = 2;
+    enum ValueSeparator {
         SpaceSeparator,
         CommaSeparator,
         SlashSeparator
@@ -233,7 +236,7 @@
     explicit CSSValue(ClassType classType)
         : m_primitiveUnitType(0)
         , m_hasCachedCSSText(false)
-        , m_valueListSeparator(SpaceSeparator)
+        , m_valueSeparator(SpaceSeparator)
         , m_classType(classType)
     {
     }
@@ -259,7 +262,7 @@
     unsigned m_primitiveUnitType : 7; // CSSUnitType
     mutable unsigned m_hasCachedCSSText : 1;
 
-    unsigned m_valueListSeparator : ValueListSeparatorBits;
+    unsigned m_valueSeparator : ValueSeparatorBits;
 
 private:
     unsigned m_classType : ClassTypeBits; // ClassType

Modified: trunk/Source/WebCore/css/CSSValueList.cpp (274545 => 274546)


--- trunk/Source/WebCore/css/CSSValueList.cpp	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/CSSValueList.cpp	2021-03-17 02:12:13 UTC (rev 274546)
@@ -26,16 +26,16 @@
 
 namespace WebCore {
 
-CSSValueList::CSSValueList(ClassType classType, ValueListSeparator listSeparator)
+CSSValueList::CSSValueList(ClassType classType, ValueSeparator listSeparator)
     : CSSValue(classType)
 {
-    m_valueListSeparator = listSeparator;
+    m_valueSeparator = listSeparator;
 }
 
-CSSValueList::CSSValueList(ValueListSeparator listSeparator)
+CSSValueList::CSSValueList(ValueSeparator listSeparator)
     : CSSValue(ValueListClass)
 {
-    m_valueListSeparator = listSeparator;
+    m_valueSeparator = listSeparator;
 }
 
 bool CSSValueList::removeAll(CSSValue* value)
@@ -65,7 +65,7 @@
 Ref<CSSValueList> CSSValueList::copy()
 {
     RefPtr<CSSValueList> newList;
-    switch (m_valueListSeparator) {
+    switch (m_valueSeparator) {
     case SpaceSeparator:
         newList = createSpaceSeparated();
         break;
@@ -86,21 +86,7 @@
 String CSSValueList::customCSSText() const
 {
     StringBuilder result;
-    String separator;
-    switch (m_valueListSeparator) {
-    case SpaceSeparator:
-        separator = " "_s;
-        break;
-    case CommaSeparator:
-        separator = ", "_s;
-        break;
-    case SlashSeparator:
-        separator = " / "_s;
-        break;
-    default:
-        ASSERT_NOT_REACHED();
-    }
-
+    String separator = separatorCssText();
     for (auto& value : m_values) {
         if (!result.isEmpty())
             result.append(separator);
@@ -112,7 +98,7 @@
 
 bool CSSValueList::equals(const CSSValueList& other) const
 {
-    if (m_valueListSeparator != other.m_valueListSeparator)
+    if (m_valueSeparator != other.m_valueSeparator)
         return false;
 
     if (m_values.size() != other.m_values.size())

Modified: trunk/Source/WebCore/css/CSSValueList.h (274545 => 274546)


--- trunk/Source/WebCore/css/CSSValueList.h	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/CSSValueList.h	2021-03-17 02:12:13 UTC (rev 274546)
@@ -71,13 +71,13 @@
 
     bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
 
-    unsigned separator() const { return m_valueListSeparator; }
+    unsigned separator() const { return m_valueSeparator; }
 
 protected:
-    CSSValueList(ClassType, ValueListSeparator);
+    CSSValueList(ClassType, ValueSeparator);
 
 private:
-    explicit CSSValueList(ValueListSeparator);
+    explicit CSSValueList(ValueSeparator);
 
     Vector<Ref<CSSValue>, 4> m_values;
 };

Copied: trunk/Source/WebCore/css/CSSValuePair.cpp (from rev 274545, trunk/Source/WebCore/css/DeprecatedCSSOMValueList.cpp) (0 => 274546)


--- trunk/Source/WebCore/css/CSSValuePair.cpp	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSValuePair.cpp	2021-03-17 02:12:13 UTC (rev 274546)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 Tyler Wilcock <twilc...@protonmail.com>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CSSValuePair.h"
+
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+String CSSValuePair::customCSSText() const
+{
+    String first = this->first()->cssText();
+    String second = this->second()->cssText();
+    if (m_encoding == IdenticalValueEncoding::Coalesce && first == second)
+        return first;
+    return makeString(first, separatorCssText(), second);
+}
+
+bool CSSValuePair::equals(const CSSValuePair &other) const
+{
+    return m_valueSeparator == other.m_valueSeparator && m_first.get().equals(other.m_first) && m_second.get().equals(other.m_second);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/css/CSSValuePair.h (0 => 274546)


--- trunk/Source/WebCore/css/CSSValuePair.h	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSValuePair.h	2021-03-17 02:12:13 UTC (rev 274546)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2021 Tyler Wilcock <twilc...@protonmail.com>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CSSValue.h"
+
+namespace WebCore {
+
+/**
+ * Represents a pair of CSS values.
+ */
+class CSSValuePair : public CSSValue {
+public:
+    enum class IdenticalValueEncoding : uint8_t {
+        DoNotCoalesce,
+        Coalesce
+    };
+
+    static Ref<CSSValuePair> create(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator)
+    {
+        return adoptRef(*new CSSValuePair(WTFMove(first), WTFMove(second), separator));
+    }
+    static Ref<CSSValuePair> create(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator, IdenticalValueEncoding encoding)
+    {
+        return adoptRef(*new CSSValuePair(WTFMove(first), WTFMove(second), separator, encoding));
+    }
+
+    Ref<CSSValue> first() const { return m_first; }
+    Ref<CSSValue> second() const { return m_second; }
+
+    String customCSSText() const;
+    bool equals(const CSSValuePair& other) const;
+
+private:
+    explicit CSSValuePair(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator)
+        : CSSValue(ValuePairClass)
+        , m_first(WTFMove(first))
+        , m_second(WTFMove(second))
+    {
+        m_valueSeparator = separator;
+    }
+
+    explicit CSSValuePair(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator, IdenticalValueEncoding encoding)
+        : CSSValue(ValuePairClass)
+        , m_encoding(encoding)
+        , m_first(WTFMove(first))
+        , m_second(WTFMove(second))
+    {
+        m_valueSeparator = separator;
+    }
+
+    IdenticalValueEncoding m_encoding { IdenticalValueEncoding::Coalesce };
+    Ref<CSSValue> m_first;
+    Ref<CSSValue> m_second;
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSValuePair, isValuePair())

Modified: trunk/Source/WebCore/css/DeprecatedCSSOMValue.h (274545 => 274546)


--- trunk/Source/WebCore/css/DeprecatedCSSOMValue.h	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/DeprecatedCSSOMValue.h	2021-03-17 02:12:13 UTC (rev 274546)
@@ -89,7 +89,7 @@
     WEBCORE_EXPORT void destroy();
 
 protected:
-    unsigned m_valueListSeparator : CSSValue::ValueListSeparatorBits;
+    unsigned m_valueSeparator : CSSValue::ValueSeparatorBits;
     unsigned m_classType : ClassTypeBits; // ClassType
     
     Ref<CSSStyleDeclaration> m_owner;

Modified: trunk/Source/WebCore/css/DeprecatedCSSOMValueList.cpp (274545 => 274546)


--- trunk/Source/WebCore/css/DeprecatedCSSOMValueList.cpp	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/DeprecatedCSSOMValueList.cpp	2021-03-17 02:12:13 UTC (rev 274546)
@@ -34,7 +34,7 @@
 {
     StringBuilder result;
     String separator;
-    switch (m_valueListSeparator) {
+    switch (m_valueSeparator) {
     case CSSValue::SpaceSeparator:
         separator = " "_s;
         break;

Modified: trunk/Source/WebCore/css/DeprecatedCSSOMValueList.h (274545 => 274546)


--- trunk/Source/WebCore/css/DeprecatedCSSOMValueList.h	2021-03-17 01:27:46 UTC (rev 274545)
+++ trunk/Source/WebCore/css/DeprecatedCSSOMValueList.h	2021-03-17 02:12:13 UTC (rev 274546)
@@ -48,7 +48,7 @@
     DeprecatedCSSOMValueList(const CSSValueList& value, CSSStyleDeclaration& owner)
         : DeprecatedCSSOMValue(DeprecatedValueListClass, owner)
     {
-        m_valueListSeparator = value.separator();
+        m_valueSeparator = value.separator();
         m_values.reserveInitialCapacity(value.length());
         for (unsigned i = 0, size = value.length(); i < size; ++i)
             m_values.uncheckedAppend(value.itemWithoutBoundsCheck(i)->createDeprecatedCSSOMWrapper(owner));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to