| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/css/resolver/CSSVariableResolver.h" | 6 #include "core/css/resolver/CSSVariableResolver.h" |
| 7 | 7 |
| 8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
| 9 #include "core/CSSValueKeywords.h" | 9 #include "core/CSSValueKeywords.h" |
| 10 #include "core/StyleBuilderFunctions.h" | 10 #include "core/StyleBuilderFunctions.h" |
| 11 #include "core/StylePropertyShorthand.h" |
| 12 #include "core/css/CSSValuePool.h" |
| 11 #include "core/css/CSSVariableData.h" | 13 #include "core/css/CSSVariableData.h" |
| 12 #include "core/css/CSSVariableReferenceValue.h" | 14 #include "core/css/CSSVariableReferenceValue.h" |
| 13 #include "core/css/parser/CSSParserToken.h" | 15 #include "core/css/parser/CSSParserToken.h" |
| 14 #include "core/css/parser/CSSParserTokenRange.h" | 16 #include "core/css/parser/CSSParserTokenRange.h" |
| 15 #include "core/css/parser/CSSParserValues.h" | 17 #include "core/css/parser/CSSParserValues.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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 resolveVariableTokensRecursive(range.consumeBlock(), result, context
); | 104 resolveVariableTokensRecursive(range.consumeBlock(), result, context
); |
| 103 } | 105 } |
| 104 } | 106 } |
| 105 if (!context.success) | 107 if (!context.success) |
| 106 result.clear(); | 108 result.clear(); |
| 107 return; | 109 return; |
| 108 } | 110 } |
| 109 | 111 |
| 110 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) | 112 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) |
| 111 { | 113 { |
| 114 |
| 112 // TODO(leviw): This should be a stack | 115 // TODO(leviw): This should be a stack |
| 113 CSSVariableResolver resolver(state.style()->variables()); | 116 CSSVariableResolver resolver(state.style()->variables()); |
| 114 | 117 |
| 115 Vector<CSSParserToken> tokens; | 118 Vector<CSSParserToken> tokens; |
| 116 ResolutionState resolutionContext; | 119 ResolutionState resolutionContext; |
| 117 resolver.resolveVariableReferencesFromTokens(value.variableDataValue()->toke
ns(), tokens, resolutionContext); | 120 resolver.resolveVariableReferencesFromTokens(value.variableDataValue()->toke
ns(), tokens, resolutionContext); |
| 118 if (!resolutionContext.success) | 121 |
| 122 if (resolutionContext.success) { |
| 123 CSSParserContext context(HTMLStandardMode, 0); |
| 124 |
| 125 WillBeHeapVector<CSSProperty, 256> parsedProperties; |
| 126 |
| 127 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens)
, context, parsedProperties, StyleRule::Type::Style)) { |
| 128 unsigned parsedPropertiesCount = parsedProperties.size(); |
| 129 for (unsigned i = 0; i < parsedPropertiesCount; ++i) |
| 130 StyleBuilder::applyProperty(parsedProperties[i].id(), state, par
sedProperties[i].value()); |
| 131 return; |
| 132 } |
| 133 } |
| 134 |
| 135 RefPtrWillBeRawPtr<CSSUnsetValue> unset = cssValuePool().createUnsetValue(); |
| 136 if (isShorthandProperty(id)) { |
| 137 StylePropertyShorthand shorthand = shorthandForProperty(id); |
| 138 for (unsigned i = 0; i < shorthand.length(); i++) |
| 139 StyleBuilder::applyProperty(shorthand.properties()[i], state, unset.
get()); |
| 119 return; | 140 return; |
| 141 } |
| 120 | 142 |
| 121 CSSParserContext context(HTMLStandardMode, 0); | 143 StyleBuilder::applyProperty(id, state, unset.get()); |
| 122 | |
| 123 WillBeHeapVector<CSSProperty, 256> parsedProperties; | |
| 124 | |
| 125 CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens), contex
t, parsedProperties, StyleRule::Type::Style); | |
| 126 | |
| 127 unsigned parsedPropertiesCount = parsedProperties.size(); | |
| 128 for (unsigned i = 0; i < parsedPropertiesCount; ++i) | |
| 129 StyleBuilder::applyProperty(parsedProperties[i].id(), state, parsedPrope
rties[i].value()); | |
| 130 } | 144 } |
| 131 | 145 |
| 132 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable
s) | 146 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable
s) |
| 133 { | 147 { |
| 134 if (!variables) | 148 if (!variables) |
| 135 return; | 149 return; |
| 136 | 150 |
| 137 for (auto& variable : variables->m_data) { | 151 for (auto& variable : variables->m_data) { |
| 138 if (!variable.value->needsVariableResolution()) | 152 if (!variable.value->needsVariableResolution()) |
| 139 continue; | 153 continue; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 152 { | 166 { |
| 153 } | 167 } |
| 154 | 168 |
| 155 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData, A
tomicString& variable) | 169 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData, A
tomicString& variable) |
| 156 : m_styleVariableData(styleVariableData) | 170 : m_styleVariableData(styleVariableData) |
| 157 { | 171 { |
| 158 m_variablesSeen.add(variable); | 172 m_variablesSeen.add(variable); |
| 159 } | 173 } |
| 160 | 174 |
| 161 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |