OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/resolver/CSSVariableResolver.h" | 5 #include "core/css/resolver/CSSVariableResolver.h" |
6 | 6 |
7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
8 #include "core/CSSValueKeywords.h" | 8 #include "core/CSSValueKeywords.h" |
9 #include "core/StyleBuilderFunctions.h" | 9 #include "core/StyleBuilderFunctions.h" |
10 #include "core/StylePropertyShorthand.h" | 10 #include "core/StylePropertyShorthand.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } else if (range.peek().type() == AtKeywordToken && range.peek().valueEq
ualsIgnoringASCIICase("apply") | 123 } else if (range.peek().type() == AtKeywordToken && range.peek().valueEq
ualsIgnoringASCIICase("apply") |
124 && RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { | 124 && RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { |
125 resolveApplyAtRule(range, result); | 125 resolveApplyAtRule(range, result); |
126 } else { | 126 } else { |
127 result.append(range.consume()); | 127 result.append(range.consume()); |
128 } | 128 } |
129 } | 129 } |
130 return success; | 130 return success; |
131 } | 131 } |
132 | 132 |
133 RawPtr<CSSValue> CSSVariableResolver::resolveVariableReferences(StyleVariableDat
a* styleVariableData, CSSPropertyID id, const CSSVariableReferenceValue& value) | 133 CSSValue* CSSVariableResolver::resolveVariableReferences(StyleVariableData* styl
eVariableData, CSSPropertyID id, const CSSVariableReferenceValue& value) |
134 { | 134 { |
135 ASSERT(!isShorthandProperty(id)); | 135 ASSERT(!isShorthandProperty(id)); |
136 | 136 |
137 CSSVariableResolver resolver(styleVariableData); | 137 CSSVariableResolver resolver(styleVariableData); |
138 Vector<CSSParserToken> tokens; | 138 Vector<CSSParserToken> tokens; |
139 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)
) | 139 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)
) |
140 return cssValuePool().createUnsetValue(); | 140 return cssValuePool().createUnsetValue(); |
141 RawPtr<CSSValue> result = CSSPropertyParser::parseSingleValue(id, tokens, st
rictCSSParserContext()); | 141 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS
ParserContext()); |
142 if (!result) | 142 if (!result) |
143 return cssValuePool().createUnsetValue(); | 143 return cssValuePool().createUnsetValue(); |
144 return result.release(); | 144 return result; |
145 } | 145 } |
146 | 146 |
147 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) | 147 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) |
148 { | 148 { |
149 CSSVariableResolver resolver(state.style()->variables()); | 149 CSSVariableResolver resolver(state.style()->variables()); |
150 | 150 |
151 Vector<CSSParserToken> tokens; | 151 Vector<CSSParserToken> tokens; |
152 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens))
{ | 152 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens))
{ |
153 CSSParserContext context(HTMLStandardMode, 0); | 153 CSSParserContext context(HTMLStandardMode, 0); |
154 | 154 |
155 HeapVector<CSSProperty, 256> parsedProperties; | 155 HeapVector<CSSProperty, 256> parsedProperties; |
156 | 156 |
157 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV
alue | 157 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV
alue |
158 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens)
, context, parsedProperties, StyleRule::RuleType::Style)) { | 158 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens)
, context, parsedProperties, StyleRule::RuleType::Style)) { |
159 unsigned parsedPropertiesCount = parsedProperties.size(); | 159 unsigned parsedPropertiesCount = parsedProperties.size(); |
160 for (unsigned i = 0; i < parsedPropertiesCount; ++i) | 160 for (unsigned i = 0; i < parsedPropertiesCount; ++i) |
161 StyleBuilder::applyProperty(parsedProperties[i].id(), state, par
sedProperties[i].value()); | 161 StyleBuilder::applyProperty(parsedProperties[i].id(), state, par
sedProperties[i].value()); |
162 return; | 162 return; |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 RawPtr<CSSUnsetValue> unset = cssValuePool().createUnsetValue(); | 166 CSSUnsetValue* unset = cssValuePool().createUnsetValue(); |
167 if (isShorthandProperty(id)) { | 167 if (isShorthandProperty(id)) { |
168 StylePropertyShorthand shorthand = shorthandForProperty(id); | 168 StylePropertyShorthand shorthand = shorthandForProperty(id); |
169 for (unsigned i = 0; i < shorthand.length(); i++) | 169 for (unsigned i = 0; i < shorthand.length(); i++) |
170 StyleBuilder::applyProperty(shorthand.properties()[i], state, unset.
get()); | 170 StyleBuilder::applyProperty(shorthand.properties()[i], state, unset)
; |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 StyleBuilder::applyProperty(id, state, unset.get()); | 174 StyleBuilder::applyProperty(id, state, unset); |
175 } | 175 } |
176 | 176 |
177 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable
s) | 177 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable
s) |
178 { | 178 { |
179 if (!variables) | 179 if (!variables) |
180 return; | 180 return; |
181 | 181 |
182 CSSVariableResolver resolver(variables); | 182 CSSVariableResolver resolver(variables); |
183 for (auto& variable : variables->m_data) { | 183 for (auto& variable : variables->m_data) { |
184 if (variable.value && variable.value->needsVariableResolution()) | 184 if (variable.value && variable.value->needsVariableResolution()) |
185 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); | 185 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) | 189 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) |
190 : m_styleVariableData(styleVariableData) | 190 : m_styleVariableData(styleVariableData) |
191 { | 191 { |
192 } | 192 } |
193 | 193 |
194 } // namespace blink | 194 } // namespace blink |
OLD | NEW |