OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/CSSParserImpl.h" | 6 #include "core/css/parser/CSSParserImpl.h" |
7 | 7 |
8 #include "core/css/CSSKeyframesRule.h" | 8 #include "core/css/CSSKeyframesRule.h" |
9 #include "core/css/CSSStyleSheet.h" | 9 #include "core/css/CSSStyleSheet.h" |
10 #include "core/css/StylePropertySet.h" | 10 #include "core/css/StylePropertySet.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 { | 141 { |
142 ASSERT(m_parsedProperties.isEmpty()); | 142 ASSERT(m_parsedProperties.isEmpty()); |
143 consumeDeclaration(range, StyleRule::Style); | 143 consumeDeclaration(range, StyleRule::Style); |
144 bool result = !m_parsedProperties.isEmpty(); | 144 bool result = !m_parsedProperties.isEmpty(); |
145 m_parsedProperties.clear(); | 145 m_parsedProperties.clear(); |
146 return result; | 146 return result; |
147 } | 147 } |
148 | 148 |
149 static CSSParserImpl::AllowedRulesType computeNewAllowedRules(CSSParserImpl::All
owedRulesType allowedRules, StyleRuleBase* rule) | 149 static CSSParserImpl::AllowedRulesType computeNewAllowedRules(CSSParserImpl::All
owedRulesType allowedRules, StyleRuleBase* rule) |
150 { | 150 { |
151 if (!rule || allowedRules == CSSParserImpl::KeyframeRules) | 151 if (!rule || allowedRules == CSSParserImpl::KeyframeRules || allowedRules ==
CSSParserImpl::NoRules) |
152 return allowedRules; | 152 return allowedRules; |
153 ASSERT(allowedRules <= CSSParserImpl::RegularRules); | 153 ASSERT(allowedRules <= CSSParserImpl::RegularRules); |
154 if (rule->isCharsetRule() || rule->isImportRule()) | 154 if (rule->isCharsetRule() || rule->isImportRule()) |
155 return CSSParserImpl::AllowImportRules; | 155 return CSSParserImpl::AllowImportRules; |
156 if (rule->isNamespaceRule()) | 156 if (rule->isNamespaceRule()) |
157 return CSSParserImpl::AllowNamespaceRules; | 157 return CSSParserImpl::AllowNamespaceRules; |
158 return CSSParserImpl::RegularRules; | 158 return CSSParserImpl::RegularRules; |
159 } | 159 } |
160 | 160 |
161 template<typename T> | 161 template<typename T> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (allowedRules <= AllowImportRules && name.equalIgnoringCase("import")
) | 228 if (allowedRules <= AllowImportRules && name.equalIgnoringCase("import")
) |
229 return consumeImportRule(prelude); | 229 return consumeImportRule(prelude); |
230 if (allowedRules <= AllowNamespaceRules && name.equalIgnoringCase("names
pace")) | 230 if (allowedRules <= AllowNamespaceRules && name.equalIgnoringCase("names
pace")) |
231 return consumeNamespaceRule(prelude); | 231 return consumeNamespaceRule(prelude); |
232 return nullptr; // Parse error, unrecognised at-rule without block | 232 return nullptr; // Parse error, unrecognised at-rule without block |
233 } | 233 } |
234 | 234 |
235 CSSParserTokenRange block = range.consumeBlock(); | 235 CSSParserTokenRange block = range.consumeBlock(); |
236 if (allowedRules == KeyframeRules) | 236 if (allowedRules == KeyframeRules) |
237 return nullptr; // Parse error, no at-rules supported inside @keyframes | 237 return nullptr; // Parse error, no at-rules supported inside @keyframes |
| 238 if (allowedRules == NoRules) |
| 239 return nullptr; // Parse error, no at-rules supported inside declaration
lists |
238 | 240 |
239 ASSERT(allowedRules <= RegularRules); | 241 ASSERT(allowedRules <= RegularRules); |
240 | 242 |
241 if (name.equalIgnoringCase("media")) | 243 if (name.equalIgnoringCase("media")) |
242 return consumeMediaRule(prelude, block); | 244 return consumeMediaRule(prelude, block); |
243 if (name.equalIgnoringCase("supports")) | 245 if (name.equalIgnoringCase("supports")) |
244 return consumeSupportsRule(prelude, block); | 246 return consumeSupportsRule(prelude, block); |
245 if (name.equalIgnoringCase("viewport")) | 247 if (name.equalIgnoringCase("viewport")) |
246 return consumeViewportRule(prelude, block); | 248 return consumeViewportRule(prelude, block); |
247 if (name.equalIgnoringCase("font-face")) | 249 if (name.equalIgnoringCase("font-face")) |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 case SemicolonToken: | 511 case SemicolonToken: |
510 range.consume(); | 512 range.consume(); |
511 break; | 513 break; |
512 case IdentToken: { | 514 case IdentToken: { |
513 const CSSParserToken* declarationStart = &range.peek(); | 515 const CSSParserToken* declarationStart = &range.peek(); |
514 while (!range.atEnd() && range.peek().type() != SemicolonToken) | 516 while (!range.atEnd() && range.peek().type() != SemicolonToken) |
515 range.consumeComponentValue(); | 517 range.consumeComponentValue(); |
516 consumeDeclaration(range.makeSubRange(declarationStart, &range.peek(
)), ruleType); | 518 consumeDeclaration(range.makeSubRange(declarationStart, &range.peek(
)), ruleType); |
517 break; | 519 break; |
518 } | 520 } |
519 default: // Parser error | 521 case AtKeywordToken: { |
520 // FIXME: The spec allows at-rules in a declaration list | 522 RefPtrWillBeRawPtr<StyleRuleBase> rule = consumeAtRule(range, NoRule
s); |
| 523 ASSERT(!rule); |
| 524 break; |
| 525 } |
| 526 default: // Parse error, unexpected token in declaration list |
521 while (!range.atEnd() && range.peek().type() != SemicolonToken) | 527 while (!range.atEnd() && range.peek().type() != SemicolonToken) |
522 range.consumeComponentValue(); | 528 range.consumeComponentValue(); |
523 break; | 529 break; |
524 } | 530 } |
525 } | 531 } |
526 } | 532 } |
527 | 533 |
528 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ
e ruleType) | 534 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ
e ruleType) |
529 { | 535 { |
530 ASSERT(range.peek().type() == IdentToken); | 536 ASSERT(range.peek().type() == IdentToken); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 else | 583 else |
578 return nullptr; // Parser error, invalid value in keyframe selector | 584 return nullptr; // Parser error, invalid value in keyframe selector |
579 if (range.atEnd()) | 585 if (range.atEnd()) |
580 return result.release(); | 586 return result.release(); |
581 if (range.consume().type() != CommaToken) | 587 if (range.consume().type() != CommaToken) |
582 return nullptr; // Parser error | 588 return nullptr; // Parser error |
583 } | 589 } |
584 } | 590 } |
585 | 591 |
586 } // namespace blink | 592 } // namespace blink |
OLD | NEW |