| 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/parser/CSSVariableParser.h" | 6 #include "core/css/parser/CSSVariableParser.h" |
| 7 | 7 |
| 8 #include "core/css/CSSCustomPropertyDeclaration.h" | 8 #include "core/css/CSSCustomPropertyDeclaration.h" |
| 9 #include "core/css/parser/CSSParserTokenRange.h" | 9 #include "core/css/parser/CSSParserTokenRange.h" |
| 10 #include "core/css/parser/CSSParserValues.h" | 10 #include "core/css/parser/CSSParserValues.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 bool CSSVariableParser::isValidVariableName(const CSSParserToken& token) | 14 bool CSSVariableParser::isValidVariableName(const CSSParserToken& token) |
| 15 { | 15 { |
| 16 if (token.type() != IdentToken) | 16 if (token.type() != IdentToken) |
| 17 return false; | 17 return false; |
| 18 | 18 |
| 19 CSSParserString value = token.value(); | 19 CSSParserString value = token.value(); |
| 20 return value.length() >= 2 && value[0] == '-' && value[1] == '-'; | 20 return value.length() >= 2 && value[0] == '-' && value[1] == '-'; |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool CSSVariableParser::isValidVariableName(const String& string) |
| 24 { |
| 25 return string.length() >= 2 && string[0] == '-' && string[1] == '-'; |
| 26 } |
| 27 |
| 23 bool isValidVariableReference(CSSParserTokenRange); | 28 bool isValidVariableReference(CSSParserTokenRange); |
| 24 | 29 |
| 25 bool classifyBlock(CSSParserTokenRange range, bool& hasReferences, bool isTopLev
elBlock = true) | 30 bool classifyBlock(CSSParserTokenRange range, bool& hasReferences, bool isTopLev
elBlock = true) |
| 26 { | 31 { |
| 27 while (!range.atEnd()) { | 32 while (!range.atEnd()) { |
| 28 if (range.peek().blockType() == CSSParserToken::BlockStart) { | 33 if (range.peek().blockType() == CSSParserToken::BlockStart) { |
| 29 const CSSParserToken& token = range.peek(); | 34 const CSSParserToken& token = range.peek(); |
| 30 CSSParserTokenRange block = range.consumeBlock(); | 35 CSSParserTokenRange block = range.consumeBlock(); |
| 31 if (token.functionId() == CSSValueVar) { | 36 if (token.functionId() == CSSValueVar) { |
| 32 if (!isValidVariableReference(block)) | 37 if (!isValidVariableReference(block)) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 CSSValueID type = classifyVariableRange(range, hasReferences); | 119 CSSValueID type = classifyVariableRange(range, hasReferences); |
| 115 | 120 |
| 116 if (type == CSSValueInvalid) | 121 if (type == CSSValueInvalid) |
| 117 return nullptr; | 122 return nullptr; |
| 118 if (type == CSSValueInternalVariableValue) | 123 if (type == CSSValueInternalVariableValue) |
| 119 return CSSCustomPropertyDeclaration::create(variableName, CSSVariableDat
a::create(range, hasReferences)); | 124 return CSSCustomPropertyDeclaration::create(variableName, CSSVariableDat
a::create(range, hasReferences)); |
| 120 return CSSCustomPropertyDeclaration::create(variableName, type); | 125 return CSSCustomPropertyDeclaration::create(variableName, type); |
| 121 } | 126 } |
| 122 | 127 |
| 123 } // namespace blink | 128 } // namespace blink |
| OLD | NEW |