1 | /*
|
---|
2 | * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
|
---|
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 | #include "CSSVariableData.h"
|
---|
30 | #include "CSSVariableReferenceValue.h"
|
---|
31 | #include "Length.h"
|
---|
32 | #include "StyleImage.h"
|
---|
33 | #include <variant>
|
---|
34 |
|
---|
35 | namespace WebCore {
|
---|
36 |
|
---|
37 | class CSSParserToken;
|
---|
38 |
|
---|
39 | class CSSCustomPropertyValue final : public CSSValue {
|
---|
40 | public:
|
---|
41 | using VariantValue = std::variant<std::monostate, Ref<CSSVariableReferenceValue>, CSSValueID, Ref<CSSVariableData>, Length, Ref<StyleImage>>;
|
---|
42 |
|
---|
43 | static Ref<CSSCustomPropertyValue> createEmpty(const AtomString& name);
|
---|
44 |
|
---|
45 | static Ref<CSSCustomPropertyValue> createUnresolved(const AtomString& name, Ref<CSSVariableReferenceValue>&& value)
|
---|
46 | {
|
---|
47 | return adoptRef(*new CSSCustomPropertyValue(name, { WTFMove(value) }));
|
---|
48 | }
|
---|
49 |
|
---|
50 | static Ref<CSSCustomPropertyValue> createUnresolved(const AtomString& name, CSSValueID value)
|
---|
51 | {
|
---|
52 | return adoptRef(*new CSSCustomPropertyValue(name, { value }));
|
---|
53 | }
|
---|
54 |
|
---|
55 | static Ref<CSSCustomPropertyValue> createWithID(const AtomString& name, CSSValueID);
|
---|
56 |
|
---|
57 | static Ref<CSSCustomPropertyValue> createSyntaxAll(const AtomString& name, Ref<CSSVariableData>&& value)
|
---|
58 | {
|
---|
59 | return adoptRef(*new CSSCustomPropertyValue(name, { WTFMove(value) }));
|
---|
60 | }
|
---|
61 |
|
---|
62 | static Ref<CSSCustomPropertyValue> createSyntaxLength(const AtomString& name, Length value)
|
---|
63 | {
|
---|
64 | ASSERT(!value.isUndefined());
|
---|
65 | ASSERT(!value.isCalculated());
|
---|
66 | return adoptRef(*new CSSCustomPropertyValue(name, { WTFMove(value) }));
|
---|
67 | }
|
---|
68 |
|
---|
69 | static Ref<CSSCustomPropertyValue> createSyntaxImage(const AtomString& name, Ref<StyleImage>&& value)
|
---|
70 | {
|
---|
71 | return adoptRef(*new CSSCustomPropertyValue(name, { WTFMove(value) }));
|
---|
72 | }
|
---|
73 |
|
---|
74 | static Ref<CSSCustomPropertyValue> create(const CSSCustomPropertyValue& other)
|
---|
75 | {
|
---|
76 | return adoptRef(*new CSSCustomPropertyValue(other));
|
---|
77 | }
|
---|
78 |
|
---|
79 | String customCSSText() const;
|
---|
80 |
|
---|
81 | const AtomString& name() const { return m_name; }
|
---|
82 | bool isResolved() const { return !std::holds_alternative<Ref<CSSVariableReferenceValue>>(m_value); }
|
---|
83 | bool isUnset() const { return std::holds_alternative<CSSValueID>(m_value) && std::get<CSSValueID>(m_value) == CSSValueUnset; }
|
---|
84 | bool isInvalid() const { return std::holds_alternative<CSSValueID>(m_value) && std::get<CSSValueID>(m_value) == CSSValueInvalid; }
|
---|
85 |
|
---|
86 | const VariantValue& value() const { return m_value; }
|
---|
87 |
|
---|
88 | Vector<CSSParserToken> tokens() const;
|
---|
89 | bool equals(const CSSCustomPropertyValue&) const;
|
---|
90 |
|
---|
91 | private:
|
---|
92 | CSSCustomPropertyValue(const AtomString& name, VariantValue&& value)
|
---|
93 | : CSSValue(CustomPropertyClass)
|
---|
94 | , m_name(name)
|
---|
95 | , m_value(WTFMove(value))
|
---|
96 | {
|
---|
97 | }
|
---|
98 |
|
---|
99 | CSSCustomPropertyValue(const CSSCustomPropertyValue& other)
|
---|
100 | : CSSValue(CustomPropertyClass)
|
---|
101 | , m_name(other.m_name)
|
---|
102 | , m_value(other.m_value)
|
---|
103 | , m_stringValue(other.m_stringValue)
|
---|
104 | {
|
---|
105 | }
|
---|
106 |
|
---|
107 | const AtomString m_name;
|
---|
108 | const VariantValue m_value;
|
---|
109 | mutable String m_stringValue;
|
---|
110 | };
|
---|
111 |
|
---|
112 | } // namespace WebCore
|
---|
113 |
|
---|
114 | SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSCustomPropertyValue, isCustomPropertyValue())
|
---|