Source/WebCore/ChangeLog

 12021-03-15 Tyler Wilcock <twilco.o@protonmail.com>
 2
 3 Add CSSValuePair.h in preparation for Pair.h refactor
 4 https://bugs.webkit.org/show_bug.cgi?id=223205
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Add new CSSValuePair class, which is intended to replace Pair.h.
 9 Pair.h has some problems, namely:
 10
 11 1. It's not a sub-class of CSSValue, making it awkward to use.
 12 2. It can only contain CSSPrimitiveValues.
 13
 14 CSSValuePair will fix both of these shortcomings.
 15
 16 * Sources.txt:
 17 Add CSSValuePair.cpp.
 18
 19 * css/CSSValue.cpp:
 20 (WebCore::CSSValue::cssText const):
 21 Handle new ValuePairClass value.
 22 (WebCore::CSSValue::separatorCssText const):
 23 Added.
 24 (WebCore::CSSValue::destroy):
 25 Handle new ValuePairClass value.
 26
 27 * css/CSSValue.h:
 28 (WebCore::CSSValue::isValuePair const):
 29 Added.
 30 (WebCore::CSSValue::CSSValue):
 31 Add new ValuePairClass value. Rename m_valueListSeparator to m_valueSeparator,
 32 ValueListSeparator to ValueSeparator, and
 33 ValueListSeparatorBits to ValueSeparatorBits.
 34
 35 * css/CSSValueList.cpp:
 36 (WebCore::CSSValueList::CSSValueList):
 37 (WebCore::CSSValueList::copy):
 38 (WebCore::CSSValueList::customCSSText const):
 39 Refactor to use new separatorCssText() function.
 40 (WebCore::CSSValueList::equals const):
 41 Rename m_valueListSeparator to m_valueSeparator,
 42 ValueListSeparator to ValueSeparator, and
 43 ValueListSeparatorBits to ValueSeparatorBits.
 44
 45 * css/CSSValueList.h:
 46 (WebCore::CSSValueList::separator const):
 47 Rename m_valueListSeparator to m_valueSeparator.
 48
 49 * css/CSSValuePair.cpp:
 50 (WebCore::CSSValuePair::customCSSText const):
 51 (WebCore::CSSValuePair::equals const):
 52 Added.
 53
 54 * css/CSSValuePair.h:
 55 (WebCore::CSSValuePair::create):
 56 (WebCore::CSSValuePair::first const):
 57 (WebCore::CSSValuePair::second const):
 58 (WebCore::CSSValuePair::CSSValuePair):
 59 Added.
 60
 61 * css/DeprecatedCSSOMValue.h:
 62 * css/DeprecatedCSSOMValueList.cpp:
 63 (WebCore::DeprecatedCSSOMValueList::cssText const):
 64 * css/DeprecatedCSSOMValueList.h:
 65 (WebCore::DeprecatedCSSOMValueList::DeprecatedCSSOMValueList):
 66 Rename m_valueListSeparator to m_valueSeparator,
 67 ValueListSeparator to ValueSeparator, and
 68 ValueListSeparatorBits to ValueSeparatorBits.
 69
 70
1712021-03-15 Chris Dumez <cdumez@apple.com>
272
373 Stop calling [NSHTTPCookieStorage sharedHTTPCookieStorage] in the WebProcess

Source/WebCore/Sources.txt

@@css/CSSUnits.cpp
780780css/CSSUnsetValue.cpp
781781css/CSSValue.cpp
782782css/CSSValueList.cpp
 783css/CSSValuePair.cpp
783784css/CSSValuePool.cpp
784785css/CSSVariableData.cpp
785786css/CSSVariableReferenceValue.cpp

Source/WebCore/css/CSSValue.cpp

6262#include "CSSUnicodeRangeValue.h"
6363#include "CSSUnsetValue.h"
6464#include "CSSValueList.h"
 65#include "CSSValuePair.h"
6566#include "CSSVariableReferenceValue.h"
6667
6768#include "CSSGridAutoRepeatValue.h"

@@String CSSValue::cssText() const
312313 return downcast<CSSUnicodeRangeValue>(*this).customCSSText();
313314 case ValueListClass:
314315 return downcast<CSSValueList>(*this).customCSSText();
 316 case ValuePairClass:
 317 return downcast<CSSValuePair>(*this).customCSSText();
315318 case LineBoxContainClass:
316319 return downcast<CSSLineBoxContainValue>(*this).customCSSText();
317320 case CalculationClass:

@@String CSSValue::cssText() const
338341 return String();
339342}
340343
 344String CSSValue::separatorCssText() const
 345{
 346 switch (m_valueSeparator) {
 347 case SpaceSeparator:
 348 return " "_s;
 349 case CommaSeparator:
 350 return ", "_s;
 351 case SlashSeparator:
 352 return " / "_s;
 353 default:
 354 ASSERT_NOT_REACHED();
 355 }
 356 return " "_s;
 357}
 358
341359void CSSValue::destroy()
342360{
343361 switch (classType()) {

@@void CSSValue::destroy()
434452 case ValueListClass:
435453 delete downcast<CSSValueList>(this);
436454 return;
 455 case ValuePairClass:
 456 delete downcast<CSSValuePair>(this);
 457 return;
437458 case LineBoxContainClass:
438459 delete downcast<CSSLineBoxContainValue>(this);
439460 return;

Source/WebCore/css/CSSValue.h

@@public:
7777
7878 Type cssValueType() const;
7979 String cssText() const;
 80 String separatorCssText() const;
8081
8182 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
8283 bool isValueList() const { return m_classType >= ValueListClass; }
 84 bool isValuePair() const { return m_classType == ValuePairClass; }
8385
8486 bool isBaseValueList() const { return m_classType == ValueListClass; }
8587

@@protected:
198200 LineBoxContainClass,
199201 CalculationClass,
200202 GridTemplateAreasClass,
 203 ValuePairClass,
201204
202205 CSSContentDistributionClass,
203206

@@protected:
219222 };
220223
221224public:
222  static const size_t ValueListSeparatorBits = 2;
223  enum ValueListSeparator {
 225 static const size_t ValueSeparatorBits = 2;
 226 enum ValueSeparator {
224227 SpaceSeparator,
225228 CommaSeparator,
226229 SlashSeparator

@@protected:
233236 explicit CSSValue(ClassType classType)
234237 : m_primitiveUnitType(0)
235238 , m_hasCachedCSSText(false)
236  , m_valueListSeparator(SpaceSeparator)
 239 , m_valueSeparator(SpaceSeparator)
237240 , m_classType(classType)
238241 {
239242 }

@@protected:
259262 unsigned m_primitiveUnitType : 7; // CSSUnitType
260263 mutable unsigned m_hasCachedCSSText : 1;
261264
262  unsigned m_valueListSeparator : ValueListSeparatorBits;
 265 unsigned m_valueSeparator : ValueSeparatorBits;
263266
264267private:
265268 unsigned m_classType : ClassTypeBits; // ClassType

Source/WebCore/css/CSSValueList.cpp

2626
2727namespace WebCore {
2828
29 CSSValueList::CSSValueList(ClassType classType, ValueListSeparator listSeparator)
 29CSSValueList::CSSValueList(ClassType classType, ValueSeparator listSeparator)
3030 : CSSValue(classType)
3131{
32  m_valueListSeparator = listSeparator;
 32 m_valueSeparator = listSeparator;
3333}
3434
35 CSSValueList::CSSValueList(ValueListSeparator listSeparator)
 35CSSValueList::CSSValueList(ValueSeparator listSeparator)
3636 : CSSValue(ValueListClass)
3737{
38  m_valueListSeparator = listSeparator;
 38 m_valueSeparator = listSeparator;
3939}
4040
4141bool CSSValueList::removeAll(CSSValue* value)

@@bool CSSValueList::hasValue(CSSValue* val) const
6565Ref<CSSValueList> CSSValueList::copy()
6666{
6767 RefPtr<CSSValueList> newList;
68  switch (m_valueListSeparator) {
 68 switch (m_valueSeparator) {
6969 case SpaceSeparator:
7070 newList = createSpaceSeparated();
7171 break;

@@Ref<CSSValueList> CSSValueList::copy()
8686String CSSValueList::customCSSText() const
8787{
8888 StringBuilder result;
89  String separator;
90  switch (m_valueListSeparator) {
91  case SpaceSeparator:
92  separator = " "_s;
93  break;
94  case CommaSeparator:
95  separator = ", "_s;
96  break;
97  case SlashSeparator:
98  separator = " / "_s;
99  break;
100  default:
101  ASSERT_NOT_REACHED();
102  }
103 
 89 String separator = separatorCssText();
10490 for (auto& value : m_values) {
10591 if (!result.isEmpty())
10692 result.append(separator);

@@String CSSValueList::customCSSText() const
11298
11399bool CSSValueList::equals(const CSSValueList& other) const
114100{
115  if (m_valueListSeparator != other.m_valueListSeparator)
 101 if (m_valueSeparator != other.m_valueSeparator)
116102 return false;
117103
118104 if (m_values.size() != other.m_values.size())

Source/WebCore/css/CSSValueList.h

@@public:
7171
7272 bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
7373
74  unsigned separator() const { return m_valueListSeparator; }
 74 unsigned separator() const { return m_valueSeparator; }
7575
7676protected:
77  CSSValueList(ClassType, ValueListSeparator);
 77 CSSValueList(ClassType, ValueSeparator);
7878
7979private:
80  explicit CSSValueList(ValueListSeparator);
 80 explicit CSSValueList(ValueSeparator);
8181
8282 Vector<Ref<CSSValue>, 4> m_values;
8383};

Source/WebCore/css/CSSValuePair.cpp

 1/*
 2 * Copyright (C) 2021 Tyler Wilcock <twilco.o@protonmail.com>.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "CSSValuePair.h"
 28
 29namespace WebCore {
 30
 31String CSSValuePair::customCSSText() const
 32{
 33 String first = this->first()->cssText();
 34 String second = this->second()->cssText();
 35 if (m_encoding == IdenticalValueEncoding::Coalesce && first == second)
 36 return first;
 37 return first + separatorCssText() + second;
 38}
 39
 40bool CSSValuePair::equals(const CSSValuePair &other) const
 41{
 42 return m_valueSeparator == other.m_valueSeparator && m_first.get().equals(other.m_first) && m_second.get().equals(other.m_second);
 43}
 44
 45} // namespace WebCore

Source/WebCore/css/CSSValuePair.h

 1/*
 2 * Copyright (C) 2021 Tyler Wilcock <twilco.o@protonmail.com>.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include "CSSValue.h"
 29
 30namespace WebCore {
 31
 32/**
 33 * Represents a pair of CSS values.
 34 *
 35 * Intended to replace Pair.h, which is only capable of containing CSSPrimitiveValues, and is not a sub-class of
 36 * CSSValue itself. See https://bugs.webkit.org/show_bug.cgi?id=223204.
 37 */
 38class CSSValuePair : public CSSValue {
 39public:
 40 enum class IdenticalValueEncoding : uint8_t {
 41 DoNotCoalesce,
 42 Coalesce
 43 };
 44
 45 static Ref<CSSValuePair> create(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator)
 46 {
 47 return adoptRef(*new CSSValuePair(WTFMove(first), WTFMove(second), separator));
 48 }
 49 static Ref<CSSValuePair> create(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator, IdenticalValueEncoding encoding)
 50 {
 51 return adoptRef(*new CSSValuePair(WTFMove(first), WTFMove(second), separator, encoding));
 52 }
 53
 54 Ref<CSSValue> first() const { return m_first; }
 55 Ref<CSSValue> second() const { return m_second; }
 56
 57 String customCSSText() const;
 58 bool equals(const CSSValuePair& other) const;
 59
 60private:
 61 explicit CSSValuePair(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator)
 62 : CSSValue(ValuePairClass)
 63 , m_first(WTFMove(first))
 64 , m_second(WTFMove(second))
 65 {
 66 m_valueSeparator = separator;
 67 }
 68
 69 explicit CSSValuePair(Ref<CSSValue>&& first, Ref<CSSValue>&& second, ValueSeparator separator, IdenticalValueEncoding encoding)
 70 : CSSValue(ValuePairClass)
 71 , m_encoding(encoding)
 72 , m_first(WTFMove(first))
 73 , m_second(WTFMove(second))
 74 {
 75 m_valueSeparator = separator;
 76 }
 77
 78 IdenticalValueEncoding m_encoding { IdenticalValueEncoding::Coalesce };
 79 Ref<CSSValue> m_first;
 80 Ref<CSSValue> m_second;
 81};
 82
 83} // namespace WebCore
 84
 85SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSValuePair, isValuePair())

Source/WebCore/css/DeprecatedCSSOMValue.h

@@private:
8989 WEBCORE_EXPORT void destroy();
9090
9191protected:
92  unsigned m_valueListSeparator : CSSValue::ValueListSeparatorBits;
 92 unsigned m_valueSeparator : CSSValue::ValueSeparatorBits;
9393 unsigned m_classType : ClassTypeBits; // ClassType
9494
9595 Ref<CSSStyleDeclaration> m_owner;

Source/WebCore/css/DeprecatedCSSOMValueList.cpp

@@String DeprecatedCSSOMValueList::cssText() const
3434{
3535 StringBuilder result;
3636 String separator;
37  switch (m_valueListSeparator) {
 37 switch (m_valueSeparator) {
3838 case CSSValue::SpaceSeparator:
3939 separator = " "_s;
4040 break;

Source/WebCore/css/DeprecatedCSSOMValueList.h

@@protected:
4848 DeprecatedCSSOMValueList(const CSSValueList& value, CSSStyleDeclaration& owner)
4949 : DeprecatedCSSOMValue(DeprecatedValueListClass, owner)
5050 {
51  m_valueListSeparator = value.separator();
 51 m_valueSeparator = value.separator();
5252 m_values.reserveInitialCapacity(value.length());
5353 for (unsigned i = 0, size = value.length(); i < size; ++i)
5454 m_values.uncheckedAppend(value.itemWithoutBoundsCheck(i)->createDeprecatedCSSOMWrapper(owner));