1 | /*
|
---|
2 | * (C) 1999-2003 Lars Knoll ([email protected])
|
---|
3 | * Copyright (C) 2004, 2005, 2006, 2015 Apple Inc.
|
---|
4 | *
|
---|
5 | * This library is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU Library General Public
|
---|
7 | * License as published by the Free Software Foundation; either
|
---|
8 | * version 2 of the License, or (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This library is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | * Library General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU Library General Public License
|
---|
16 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
18 | * Boston, MA 02110-1301, USA.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #pragma once
|
---|
22 |
|
---|
23 | #include <wtf/RefCounted.h>
|
---|
24 |
|
---|
25 | namespace WebCore {
|
---|
26 |
|
---|
27 | class CSSPrimitiveValue;
|
---|
28 |
|
---|
29 | // A primitive value representing a pair. This is useful for properties like border-radius, background-size/position,
|
---|
30 | // and border-spacing (all of which are space-separated sets of two values). At the moment we are only using it for
|
---|
31 | // border-radius and background-size, but (FIXME) border-spacing and background-position could be converted over to use
|
---|
32 | // it (eliminating some extra -webkit- internal properties).
|
---|
33 | class Pair : public RefCounted<Pair> {
|
---|
34 | public:
|
---|
35 | enum class IdenticalValueEncoding : uint8_t {
|
---|
36 | DoNotCoalesce,
|
---|
37 | Coalesce
|
---|
38 | };
|
---|
39 |
|
---|
40 | static Ref<Pair> create(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second)
|
---|
41 | {
|
---|
42 | return adoptRef(*new Pair(WTFMove(first), WTFMove(second)));
|
---|
43 | }
|
---|
44 | static Ref<Pair> create(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second, IdenticalValueEncoding encoding)
|
---|
45 | {
|
---|
46 | return adoptRef(*new Pair(WTFMove(first), WTFMove(second), encoding));
|
---|
47 | }
|
---|
48 | CSSPrimitiveValue* first() const { return m_first.get(); }
|
---|
49 | CSSPrimitiveValue* second() const { return m_second.get(); }
|
---|
50 |
|
---|
51 | String cssText() const
|
---|
52 | {
|
---|
53 | String first = this->first()->cssText();
|
---|
54 | String second = this->second()->cssText();
|
---|
55 | if (m_encoding == IdenticalValueEncoding::Coalesce && first == second)
|
---|
56 | return first;
|
---|
57 | return first + ' ' + second;
|
---|
58 | }
|
---|
59 |
|
---|
60 | bool equals(const Pair& other) const { return compareCSSValuePtr(m_first, other.m_first) && compareCSSValuePtr(m_second, other.m_second); }
|
---|
61 |
|
---|
62 | private:
|
---|
63 | Pair(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second)
|
---|
64 | : m_first(WTFMove(first))
|
---|
65 | , m_second(WTFMove(second))
|
---|
66 | { }
|
---|
67 |
|
---|
68 | Pair(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second, IdenticalValueEncoding encoding)
|
---|
69 | : m_encoding(encoding)
|
---|
70 | , m_first(WTFMove(first))
|
---|
71 | , m_second(WTFMove(second))
|
---|
72 | { }
|
---|
73 |
|
---|
74 | IdenticalValueEncoding m_encoding { IdenticalValueEncoding::Coalesce };
|
---|
75 | RefPtr<CSSPrimitiveValue> m_first;
|
---|
76 | RefPtr<CSSPrimitiveValue> m_second;
|
---|
77 | };
|
---|
78 |
|
---|
79 | } // namespace
|
---|