Chromium Code Reviews| 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" |
| 11 #include "core/css/CSSPendingSubstitutionValue.h" | |
| 11 #include "core/css/CSSUnsetValue.h" | 12 #include "core/css/CSSUnsetValue.h" |
| 13 #include "core/css/CSSValuePool.h" | |
| 12 #include "core/css/CSSVariableData.h" | 14 #include "core/css/CSSVariableData.h" |
| 13 #include "core/css/CSSVariableReferenceValue.h" | 15 #include "core/css/CSSVariableReferenceValue.h" |
| 14 #include "core/css/parser/CSSParserToken.h" | 16 #include "core/css/parser/CSSParserToken.h" |
| 15 #include "core/css/parser/CSSParserTokenRange.h" | 17 #include "core/css/parser/CSSParserTokenRange.h" |
| 16 #include "core/css/parser/CSSPropertyParser.h" | 18 #include "core/css/parser/CSSPropertyParser.h" |
| 17 #include "core/css/resolver/StyleBuilder.h" | 19 #include "core/css/resolver/StyleBuilder.h" |
| 18 #include "core/css/resolver/StyleResolverState.h" | 20 #include "core/css/resolver/StyleResolverState.h" |
| 19 #include "core/style/StyleVariableData.h" | 21 #include "core/style/StyleVariableData.h" |
| 20 #include "wtf/Vector.h" | 22 #include "wtf/Vector.h" |
| 21 | 23 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 CSSVariableResolver resolver(styleVariableData); | 138 CSSVariableResolver resolver(styleVariableData); |
| 137 Vector<CSSParserToken> tokens; | 139 Vector<CSSParserToken> tokens; |
| 138 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens) ) | 140 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens) ) |
| 139 return CSSUnsetValue::create(); | 141 return CSSUnsetValue::create(); |
| 140 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS ParserContext()); | 142 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS ParserContext()); |
| 141 if (!result) | 143 if (!result) |
| 142 return CSSUnsetValue::create(); | 144 return CSSUnsetValue::create(); |
| 143 return result; | 145 return result; |
| 144 } | 146 } |
| 145 | 147 |
| 146 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState& state, CSSPropertyID id, const CSSVariableReferenceValue& value) | 148 const CSSValue* CSSVariableResolver::resolveVariableReferences(StyleResolverStat e& state, CSSPropertyID id, const CSSVariableReferenceValue& value) |
| 147 { | 149 { |
| 150 // Longhand variable references follow this path. | |
|
Timothy Loh
2016/06/22 00:06:12
Longhand -> Non-shorthand
Andy Mutton
2016/06/24 04:53:26
Done.
| |
| 148 CSSVariableResolver resolver(state.style()->variables()); | 151 CSSVariableResolver resolver(state.style()->variables()); |
| 149 | 152 |
| 150 Vector<CSSParserToken> tokens; | 153 Vector<CSSParserToken> tokens; |
| 151 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)) { | 154 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)) { |
| 152 CSSParserContext context(HTMLStandardMode, 0); | 155 CSSParserContext context(HTMLStandardMode, 0); |
| 153 | 156 |
| 154 HeapVector<CSSProperty, 256> parsedProperties; | 157 CSSValue* value = CSSPropertyParser::parseSingleValue(id, CSSParserToken Range(tokens), context); |
| 155 | 158 if (value) { |
|
Timothy Loh
2016/06/22 00:06:11
Braces { } are not required in Blink for single-li
Andy Mutton
2016/06/24 04:53:26
I prefer keeping, but I also don't really care abo
| |
| 156 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV alue | 159 return value; |
| 157 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens) , context, parsedProperties, StyleRule::RuleType::Style)) { | |
| 158 unsigned parsedPropertiesCount = parsedProperties.size(); | |
| 159 for (unsigned i = 0; i < parsedPropertiesCount; ++i) | |
| 160 StyleBuilder::applyProperty(parsedProperties[i].id(), state, *pa rsedProperties[i].value()); | |
| 161 return; | |
| 162 } | 160 } |
| 163 } | 161 } |
| 164 | 162 |
| 165 CSSUnsetValue* unset = CSSUnsetValue::create(); | 163 return CSSUnsetValue::create(); |
| 166 if (isShorthandProperty(id)) { | 164 } |
| 167 StylePropertyShorthand shorthand = shorthandForProperty(id); | 165 |
| 168 for (unsigned i = 0; i < shorthand.length(); i++) | 166 const CSSValue* CSSVariableResolver::resolvePendingSubstitutions(StyleResolverSt ate& state, CSSPropertyID id, const CSSPendingSubstitutionValue& pendingValue) |
| 169 StyleBuilder::applyProperty(shorthand.properties()[i], state, *unset ); | 167 { |
| 170 return; | 168 // Longhands from shorthand references follow this path. |
| 169 const CSSValue* value = state.cssValueForLonghandPropertyId(id); | |
| 170 if (!value) { | |
| 171 // Property cache is unset. Let's fill it. | |
| 172 CSSVariableReferenceValue* shorthandValue = pendingValue.shorthandValue( ); | |
| 173 CSSPropertyID shorthandPropertyId = pendingValue.shorthandPropertyId(); | |
| 174 | |
| 175 CSSVariableResolver resolver(state.style()->variables()); | |
| 176 | |
| 177 Vector<CSSParserToken> tokens; | |
| 178 if (resolver.resolveTokenRange(shorthandValue->variableDataValue()->toke ns(), tokens)) { | |
| 179 CSSParserContext context(HTMLStandardMode, 0); | |
| 180 | |
| 181 HeapVector<CSSProperty, 256> parsedProperties; | |
| 182 | |
| 183 if (CSSPropertyParser::parseValue(shorthandPropertyId, false, CSSPar serTokenRange(tokens), context, parsedProperties, StyleRule::RuleType::Style)) { | |
| 184 unsigned parsedPropertiesCount = parsedProperties.size(); | |
| 185 for (unsigned i = 0; i < parsedPropertiesCount; ++i) { | |
| 186 state.setCssValueForLonghandPropertyId(parsedProperties[i].i d(), parsedProperties[i].value()); | |
| 187 } | |
| 188 } | |
| 189 } | |
| 190 value = state.cssValueForLonghandPropertyId(id); | |
| 171 } | 191 } |
| 172 | 192 |
| 173 StyleBuilder::applyProperty(id, state, *unset); | 193 if (value) { |
| 194 return value; | |
| 195 } | |
| 196 | |
| 197 return CSSUnsetValue::create(); | |
| 174 } | 198 } |
| 175 | 199 |
| 200 | |
| 176 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable s) | 201 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable s) |
| 177 { | 202 { |
| 178 if (!variables) | 203 if (!variables) |
| 179 return; | 204 return; |
| 180 | 205 |
| 181 CSSVariableResolver resolver(variables); | 206 CSSVariableResolver resolver(variables); |
| 182 for (auto& variable : variables->m_data) { | 207 for (auto& variable : variables->m_data) { |
| 183 if (variable.value && variable.value->needsVariableResolution()) | 208 if (variable.value && variable.value->needsVariableResolution()) |
| 184 variable.value = resolver.resolveCustomProperty(variable.key, *varia ble.value); | 209 variable.value = resolver.resolveCustomProperty(variable.key, *varia ble.value); |
| 185 } | 210 } |
| 186 } | 211 } |
| 187 | 212 |
| 188 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) | 213 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) |
| 189 : m_styleVariableData(styleVariableData) | 214 : m_styleVariableData(styleVariableData) |
| 190 { | 215 { |
| 191 } | 216 } |
| 192 | 217 |
| 193 } // namespace blink | 218 } // namespace blink |
| OLD | NEW |