| 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/CSSValuePool.h" | 11 #include "core/css/CSSValuePool.h" |
| 12 #include "core/css/CSSVariableData.h" | 12 #include "core/css/CSSVariableData.h" |
| 13 #include "core/css/CSSVariableReferenceValue.h" | 13 #include "core/css/CSSVariableReferenceValue.h" |
| 14 #include "core/css/parser/CSSParserToken.h" | 14 #include "core/css/parser/CSSParserToken.h" |
| 15 #include "core/css/parser/CSSParserTokenRange.h" | 15 #include "core/css/parser/CSSParserTokenRange.h" |
| 16 #include "core/css/parser/CSSParserValues.h" | 16 #include "core/css/parser/CSSParserValues.h" |
| 17 #include "core/css/parser/CSSPropertyParser.h" | 17 #include "core/css/parser/CSSPropertyParser.h" |
| 18 #include "core/css/parser/CSSVariableParser.h" |
| 18 #include "core/css/resolver/StyleBuilder.h" | 19 #include "core/css/resolver/StyleBuilder.h" |
| 19 #include "core/css/resolver/StyleResolverState.h" | 20 #include "core/css/resolver/StyleResolverState.h" |
| 20 #include "core/style/StyleVariableData.h" | 21 #include "core/style/StyleVariableData.h" |
| 21 #include "wtf/Vector.h" | 22 #include "wtf/Vector.h" |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 bool CSSVariableResolver::resolveFallback(CSSParserTokenRange range, Vector<CSSP
arserToken>& result) | 26 bool CSSVariableResolver::resolveFallback(CSSParserTokenRange range, Vector<CSSP
arserToken>& result) |
| 26 { | 27 { |
| 27 if (range.atEnd()) | 28 if (range.atEnd()) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 CSSVariableData* variableData = valueForCustomProperty(variableName); | 81 CSSVariableData* variableData = valueForCustomProperty(variableName); |
| 81 if (!variableData) | 82 if (!variableData) |
| 82 return resolveFallback(range, result); | 83 return resolveFallback(range, result); |
| 83 | 84 |
| 84 result.appendVector(variableData->tokens()); | 85 result.appendVector(variableData->tokens()); |
| 85 Vector<CSSParserToken> trash; | 86 Vector<CSSParserToken> trash; |
| 86 resolveFallback(range, trash); | 87 resolveFallback(range, trash); |
| 87 return true; | 88 return true; |
| 88 } | 89 } |
| 89 | 90 |
| 91 void CSSVariableResolver::resolveApplyAtRule(CSSParserTokenRange& range, |
| 92 Vector<CSSParserToken>& result) |
| 93 { |
| 94 ASSERT(range.peek().type() == AtKeywordToken && range.peek().valueEqualsIgno
ringASCIICase("apply")); |
| 95 CSSParserTokenRange originalRange = range; |
| 96 |
| 97 range.consumeIncludingWhitespace(); |
| 98 const CSSParserToken& variableName = range.consumeIncludingWhitespace(); |
| 99 if (!CSSVariableParser::isValidVariableName(variableName) |
| 100 || !(range.atEnd() || range.peek().type() == SemicolonToken || range.pee
k().type() == RightBraceToken)) { |
| 101 range = originalRange; |
| 102 result.append(range.consume()); |
| 103 return; |
| 104 } |
| 105 if (range.peek().type() == SemicolonToken) |
| 106 range.consume(); |
| 107 |
| 108 CSSVariableData* variableData = valueForCustomProperty(variableName.value())
; |
| 109 if (!variableData) |
| 110 return; // Invalid custom property |
| 111 |
| 112 CSSParserTokenRange rule = variableData->tokenRange(); |
| 113 rule.consumeWhitespace(); |
| 114 if (rule.peek().type() != LeftBraceToken) |
| 115 return; |
| 116 CSSParserTokenRange ruleContents = rule.consumeBlock(); |
| 117 rule.consumeWhitespace(); |
| 118 if (!rule.atEnd()) |
| 119 return; |
| 120 |
| 121 result.appendRange(ruleContents.begin(), ruleContents.end()); |
| 122 } |
| 123 |
| 90 bool CSSVariableResolver::resolveTokenRange(CSSParserTokenRange range, | 124 bool CSSVariableResolver::resolveTokenRange(CSSParserTokenRange range, |
| 91 Vector<CSSParserToken>& result) | 125 Vector<CSSParserToken>& result) |
| 92 { | 126 { |
| 93 bool success = true; | 127 bool success = true; |
| 94 while (!range.atEnd()) { | 128 while (!range.atEnd()) { |
| 95 if (range.peek().functionId() == CSSValueVar) { | 129 if (range.peek().functionId() == CSSValueVar) { |
| 96 success &= resolveVariableReference(range.consumeBlock(), result); | 130 success &= resolveVariableReference(range.consumeBlock(), result); |
| 131 } else if (range.peek().type() == AtKeywordToken && range.peek().valueEq
ualsIgnoringASCIICase("apply") |
| 132 && RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { |
| 133 resolveApplyAtRule(range, result); |
| 97 } else { | 134 } else { |
| 98 result.append(range.consume()); | 135 result.append(range.consume()); |
| 99 } | 136 } |
| 100 } | 137 } |
| 101 return success; | 138 return success; |
| 102 } | 139 } |
| 103 | 140 |
| 104 PassRefPtrWillBeRawPtr<CSSValue> CSSVariableResolver::resolveVariableReferences(
StyleVariableData* styleVariableData, CSSPropertyID id, const CSSVariableReferen
ceValue& value) | 141 PassRefPtrWillBeRawPtr<CSSValue> CSSVariableResolver::resolveVariableReferences(
StyleVariableData* styleVariableData, CSSPropertyID id, const CSSVariableReferen
ceValue& value) |
| 105 { | 142 { |
| 106 ASSERT(!isShorthandProperty(id)); | 143 ASSERT(!isShorthandProperty(id)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); | 196 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); |
| 160 } | 197 } |
| 161 } | 198 } |
| 162 | 199 |
| 163 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) | 200 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) |
| 164 : m_styleVariableData(styleVariableData) | 201 : m_styleVariableData(styleVariableData) |
| 165 { | 202 { |
| 166 } | 203 } |
| 167 | 204 |
| 168 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |