| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 m_styleVariableData->setVariable(name, newVariableData); | 48 m_styleVariableData->setVariable(name, newVariableData); |
| 49 return newVariableData.get(); | 49 return newVariableData.get(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 PassRefPtr<CSSVariableData> CSSVariableResolver::resolveCustomProperty(AtomicStr
ing name, const CSSVariableData& variableData) | 52 PassRefPtr<CSSVariableData> CSSVariableResolver::resolveCustomProperty(AtomicStr
ing name, const CSSVariableData& variableData) |
| 53 { | 53 { |
| 54 ASSERT(variableData.needsVariableResolution()); | 54 ASSERT(variableData.needsVariableResolution()); |
| 55 | 55 |
| 56 Vector<CSSParserToken> tokens; | 56 Vector<CSSParserToken> tokens; |
| 57 m_variablesSeen.add(name); | 57 m_variablesSeen.add(name); |
| 58 bool success = resolveTokenRange(variableData.tokens(), tokens); | 58 bool success = resolveTokenRange(variableData.tokenRange(), tokens); |
| 59 m_variablesSeen.remove(name); | 59 m_variablesSeen.remove(name); |
| 60 | 60 |
| 61 // The old variable data holds onto the backing string the new resolved CSSV
ariableData | 61 // The old variable data holds onto the backing string the new resolved CSSV
ariableData |
| 62 // relies on. Ensure it will live beyond us overwriting the RefPtr in StyleV
ariableData. | 62 // relies on. Ensure it will live beyond us overwriting the RefPtr in StyleV
ariableData. |
| 63 ASSERT(variableData.refCount() > 1); | 63 ASSERT(variableData.refCount() > 1); |
| 64 | 64 |
| 65 if (!success || !m_cycleStartPoints.isEmpty()) { | 65 if (!success || !m_cycleStartPoints.isEmpty()) { |
| 66 m_cycleStartPoints.remove(name); | 66 m_cycleStartPoints.remove(name); |
| 67 return nullptr; | 67 return nullptr; |
| 68 } | 68 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 return success; | 129 return success; |
| 130 } | 130 } |
| 131 | 131 |
| 132 CSSValue* CSSVariableResolver::resolveVariableReferences(StyleVariableData* styl
eVariableData, CSSPropertyID id, const CSSVariableReferenceValue& value) | 132 CSSValue* CSSVariableResolver::resolveVariableReferences(StyleVariableData* styl
eVariableData, CSSPropertyID id, const CSSVariableReferenceValue& value) |
| 133 { | 133 { |
| 134 ASSERT(!isShorthandProperty(id)); | 134 ASSERT(!isShorthandProperty(id)); |
| 135 | 135 |
| 136 CSSVariableResolver resolver(styleVariableData); | 136 CSSVariableResolver resolver(styleVariableData); |
| 137 Vector<CSSParserToken> tokens; | 137 Vector<CSSParserToken> tokens; |
| 138 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)
) | 138 if (!resolver.resolveTokenRange(value.variableDataValue()->tokenRange(), tok
ens)) |
| 139 return cssValuePool().createUnsetValue(); | 139 return cssValuePool().createUnsetValue(); |
| 140 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS
ParserContext()); | 140 CSSValue* result = CSSPropertyParser::parseSingleValue(id, CSSParserTokenRan
ge(tokens.begin(), tokens.end()), strictCSSParserContext()); |
| 141 if (!result) | 141 if (!result) |
| 142 return cssValuePool().createUnsetValue(); | 142 return cssValuePool().createUnsetValue(); |
| 143 return result; | 143 return result; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) | 146 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) |
| 147 { | 147 { |
| 148 CSSVariableResolver resolver(state.style()->variables()); | 148 CSSVariableResolver resolver(state.style()->variables()); |
| 149 | 149 |
| 150 Vector<CSSParserToken> tokens; | 150 Vector<CSSParserToken> tokens; |
| 151 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens))
{ | 151 if (resolver.resolveTokenRange(value.variableDataValue()->tokenRange(), toke
ns)) { |
| 152 CSSParserContext context(HTMLStandardMode, 0); | 152 CSSParserContext context(HTMLStandardMode, 0); |
| 153 | 153 |
| 154 HeapVector<CSSProperty, 256> parsedProperties; | 154 HeapVector<CSSProperty, 256> parsedProperties; |
| 155 | 155 |
| 156 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV
alue | 156 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV
alue |
| 157 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens)
, context, parsedProperties, StyleRule::RuleType::Style)) { | 157 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens.
begin(), tokens.end()), context, parsedProperties, StyleRule::RuleType::Style))
{ |
| 158 unsigned parsedPropertiesCount = parsedProperties.size(); | 158 unsigned parsedPropertiesCount = parsedProperties.size(); |
| 159 for (unsigned i = 0; i < parsedPropertiesCount; ++i) | 159 for (unsigned i = 0; i < parsedPropertiesCount; ++i) |
| 160 StyleBuilder::applyProperty(parsedProperties[i].id(), state, par
sedProperties[i].value()); | 160 StyleBuilder::applyProperty(parsedProperties[i].id(), state, par
sedProperties[i].value()); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 CSSUnsetValue* unset = cssValuePool().createUnsetValue(); | 165 CSSUnsetValue* unset = cssValuePool().createUnsetValue(); |
| 166 if (isShorthandProperty(id)) { | 166 if (isShorthandProperty(id)) { |
| 167 StylePropertyShorthand shorthand = shorthandForProperty(id); | 167 StylePropertyShorthand shorthand = shorthandForProperty(id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 184 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); | 184 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) | 188 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) |
| 189 : m_styleVariableData(styleVariableData) | 189 : m_styleVariableData(styleVariableData) |
| 190 { | 190 { |
| 191 } | 191 } |
| 192 | 192 |
| 193 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |