OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/cssom/CSSUnparsedValue.h" | 5 #include "core/css/cssom/CSSUnparsedValue.h" |
6 | 6 |
7 #include "core/css/cssom/CSSStyleVariableReferenceValue.h" | 7 #include "core/css/cssom/CSSStyleVariableReferenceValue.h" |
8 #include "core/css/parser/CSSTokenizer.h" | 8 #include "core/css/parser/CSSTokenizer.h" |
9 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
| 12 namespace cssom { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 class UnparsedValueIterationSource final : public ValueIterable<StringOrCSSVaria
bleReferenceValue>::IterationSource { | 16 class UnparsedValueIterationSource final : public ValueIterable<StringOrCSSVaria
bleReferenceValue>::IterationSource { |
16 public: | 17 public: |
17 explicit UnparsedValueIterationSource(CSSUnparsedValue* unparsedValue) | 18 explicit UnparsedValueIterationSource(CSSUnparsedValue* unparsedValue) |
18 : m_unparsedValue(unparsedValue) | 19 : m_unparsedValue(unparsedValue) |
19 { | 20 { |
20 } | 21 } |
21 | 22 |
22 bool next(ScriptState*, StringOrCSSVariableReferenceValue& value, ExceptionS
tate&) override | 23 bool next(blink::ScriptState*, StringOrCSSVariableReferenceValue& value, Exc
eptionState&) override |
23 { | 24 { |
24 if (m_index >= m_unparsedValue->size()) | 25 if (m_index >= m_unparsedValue->size()) |
25 return false; | 26 return false; |
26 value = m_unparsedValue->fragmentAtIndex(m_index); | 27 value = m_unparsedValue->fragmentAtIndex(m_index); |
27 return true; | 28 return true; |
28 } | 29 } |
29 | 30 |
30 DEFINE_INLINE_VIRTUAL_TRACE() | 31 DEFINE_INLINE_VIRTUAL_TRACE() |
31 { | 32 { |
32 visitor->trace(m_unparsedValue); | 33 visitor->trace(m_unparsedValue); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 range.consume().serialize(builder); | 75 range.consume().serialize(builder); |
75 } | 76 } |
76 } | 77 } |
77 if (!builder.isEmpty()) | 78 if (!builder.isEmpty()) |
78 fragments.append(StringOrCSSVariableReferenceValue::fromString(builder.t
oString())); | 79 fragments.append(StringOrCSSVariableReferenceValue::fromString(builder.t
oString())); |
79 return fragments; | 80 return fragments; |
80 } | 81 } |
81 | 82 |
82 } // namespace | 83 } // namespace |
83 | 84 |
84 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource* CSSUnparsedVa
lue::startIteration(ScriptState*, ExceptionState&) | 85 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource* CSSUnparsedVa
lue::startIteration(blink::ScriptState*, ExceptionState&) |
85 { | 86 { |
86 return new UnparsedValueIterationSource(this); | 87 return new UnparsedValueIterationSource(this); |
87 } | 88 } |
88 | 89 |
89 CSSUnparsedValue* CSSUnparsedValue::fromCSSValue(const CSSVariableReferenceValue
& cssVariableReferenceValue) | 90 CSSUnparsedValue* CSSUnparsedValue::fromCSSValue(const CSSVariableReferenceValue
& cssVariableReferenceValue) |
90 { | 91 { |
91 return CSSUnparsedValue::create(parserTokenRangeToFragments(cssVariableRefer
enceValue.variableDataValue()->tokenRange())); | 92 return CSSUnparsedValue::create(parserTokenRangeToFragments(cssVariableRefer
enceValue.variableDataValue()->tokenRange())); |
92 } | 93 } |
93 | 94 |
94 CSSValue* CSSUnparsedValue::toCSSValue() const | 95 CSSValue* CSSUnparsedValue::toCSSValue() const |
95 { | 96 { |
96 StringBuilder tokens; | 97 StringBuilder tokens; |
97 | 98 |
98 for (unsigned i = 0; i < m_fragments.size(); i++) { | 99 for (unsigned i = 0; i < m_fragments.size(); i++) { |
99 if (i) | 100 if (i) |
100 tokens.append("/**/"); | 101 tokens.append("/**/"); |
101 if (m_fragments[i].isString()) | 102 if (m_fragments[i].isString()) |
102 tokens.append(m_fragments[i].getAsString()); | 103 tokens.append(m_fragments[i].getAsString()); |
103 else if (m_fragments[i].isCSSVariableReferenceValue()) | 104 else if (m_fragments[i].isCSSVariableReferenceValue()) |
104 tokens.append(m_fragments[i].getAsCSSVariableReferenceValue()->varia
ble()); | 105 tokens.append(m_fragments[i].getAsCSSVariableReferenceValue()->varia
ble()); |
105 else | 106 else |
106 NOTREACHED(); | 107 NOTREACHED(); |
107 } | 108 } |
108 | 109 |
109 CSSTokenizer::Scope scope(tokens.toString()); | 110 CSSTokenizer::Scope scope(tokens.toString()); |
110 | 111 |
111 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token
Range())); | 112 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token
Range())); |
112 } | 113 } |
113 | 114 |
| 115 } // namespace cssom |
114 } // namespace blink | 116 } // namespace blink |
| 117 |
OLD | NEW |