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/parser/CSSVariableParser.h" | 5 #include "core/css/parser/CSSVariableParser.h" |
6 | 6 |
7 #include "core/css/CSSCustomPropertyDeclaration.h" | 7 #include "core/css/CSSCustomPropertyDeclaration.h" |
8 #include "core/css/parser/CSSParserTokenRange.h" | 8 #include "core/css/parser/CSSParserTokenRange.h" |
9 #include "core/css/parser/CSSParserValues.h" | 9 #include "core/css/parser/CSSParserValues.h" |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 bool CSSVariableParser::isValidVariableName(const String& string) | 22 bool CSSVariableParser::isValidVariableName(const String& string) |
23 { | 23 { |
24 return string.length() >= 2 && string[0] == '-' && string[1] == '-'; | 24 return string.length() >= 2 && string[0] == '-' && string[1] == '-'; |
25 } | 25 } |
26 | 26 |
27 bool isValidVariableReference(CSSParserTokenRange); | 27 bool isValidVariableReference(CSSParserTokenRange); |
28 | 28 |
29 bool classifyBlock(CSSParserTokenRange range, bool& hasReferences, bool isTopLev
elBlock = true) | 29 bool classifyBlock(CSSParserTokenRange range, bool& hasReferences, bool isTopLev
elBlock = true) |
30 { | 30 { |
31 while (!range.atEnd()) { | 31 while (!range.atEnd()) { |
32 if (range.peek().blockType() == CSSParserToken::BlockStart) { | 32 if (range.peek().getBlockType() == CSSParserToken::BlockStart) { |
33 const CSSParserToken& token = range.peek(); | 33 const CSSParserToken& token = range.peek(); |
34 CSSParserTokenRange block = range.consumeBlock(); | 34 CSSParserTokenRange block = range.consumeBlock(); |
35 if (token.functionId() == CSSValueVar) { | 35 if (token.functionId() == CSSValueVar) { |
36 if (!isValidVariableReference(block)) | 36 if (!isValidVariableReference(block)) |
37 return false; // Bail if any references are invalid | 37 return false; // Bail if any references are invalid |
38 hasReferences = true; | 38 hasReferences = true; |
39 continue; | 39 continue; |
40 } | 40 } |
41 if (!classifyBlock(block, hasReferences, false)) | 41 if (!classifyBlock(block, hasReferences, false)) |
42 return false; | 42 return false; |
43 continue; | 43 continue; |
44 } | 44 } |
45 | 45 |
46 ASSERT(range.peek().blockType() != CSSParserToken::BlockEnd); | 46 ASSERT(range.peek().getBlockType() != CSSParserToken::BlockEnd); |
47 | 47 |
48 const CSSParserToken& token = range.consume(); | 48 const CSSParserToken& token = range.consume(); |
49 switch (token.type()) { | 49 switch (token.type()) { |
50 case DelimiterToken: { | 50 case DelimiterToken: { |
51 if (token.delimiter() == '!' && isTopLevelBlock) | 51 if (token.delimiter() == '!' && isTopLevelBlock) |
52 return false; | 52 return false; |
53 break; | 53 break; |
54 } | 54 } |
55 case RightParenthesisToken: | 55 case RightParenthesisToken: |
56 case RightBraceToken: | 56 case RightBraceToken: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 CSSValueID type = classifyVariableRange(range, hasReferences); | 118 CSSValueID type = classifyVariableRange(range, hasReferences); |
119 | 119 |
120 if (type == CSSValueInvalid) | 120 if (type == CSSValueInvalid) |
121 return nullptr; | 121 return nullptr; |
122 if (type == CSSValueInternalVariableValue) | 122 if (type == CSSValueInternalVariableValue) |
123 return CSSCustomPropertyDeclaration::create(variableName, CSSVariableDat
a::create(range, hasReferences)); | 123 return CSSCustomPropertyDeclaration::create(variableName, CSSVariableDat
a::create(range, hasReferences)); |
124 return CSSCustomPropertyDeclaration::create(variableName, type); | 124 return CSSCustomPropertyDeclaration::create(variableName, type); |
125 } | 125 } |
126 | 126 |
127 } // namespace blink | 127 } // namespace blink |
OLD | NEW |