| 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 "core/css/parser/CSSParserImpl.h" | 5 #include "core/css/parser/CSSParserImpl.h" |
| 6 | 6 |
| 7 #include "core/css/CSSCustomIdentValue.h" | 7 #include "core/css/CSSCustomIdentValue.h" |
| 8 #include "core/css/CSSCustomPropertyDeclaration.h" | 8 #include "core/css/CSSCustomPropertyDeclaration.h" |
| 9 #include "core/css/CSSKeyframesRule.h" | 9 #include "core/css/CSSKeyframesRule.h" |
| 10 #include "core/css/CSSStyleSheet.h" | 10 #include "core/css/CSSStyleSheet.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 321 |
| 322 return createStylePropertySet(parser.m_parsedProperties, HTMLStandardMode); | 322 return createStylePropertySet(parser.m_parsedProperties, HTMLStandardMode); |
| 323 } | 323 } |
| 324 | 324 |
| 325 std::unique_ptr<Vector<double>> CSSParserImpl::parseKeyframeKeyList( | 325 std::unique_ptr<Vector<double>> CSSParserImpl::parseKeyframeKeyList( |
| 326 const String& keyList) { | 326 const String& keyList) { |
| 327 return consumeKeyframeKeyList(CSSTokenizer(keyList).tokenRange()); | 327 return consumeKeyframeKeyList(CSSTokenizer(keyList).tokenRange()); |
| 328 } | 328 } |
| 329 | 329 |
| 330 bool CSSParserImpl::supportsDeclaration(CSSParserTokenRange& range) { | 330 bool CSSParserImpl::supportsDeclaration(CSSParserTokenRange& range) { |
| 331 ASSERT(m_parsedProperties.isEmpty()); | 331 DCHECK(m_parsedProperties.isEmpty()); |
| 332 consumeDeclaration(range, StyleRule::Style); | 332 consumeDeclaration(range, StyleRule::Style); |
| 333 bool result = !m_parsedProperties.isEmpty(); | 333 bool result = !m_parsedProperties.isEmpty(); |
| 334 m_parsedProperties.clear(); | 334 m_parsedProperties.clear(); |
| 335 return result; | 335 return result; |
| 336 } | 336 } |
| 337 | 337 |
| 338 void CSSParserImpl::parseDeclarationListForInspector( | 338 void CSSParserImpl::parseDeclarationListForInspector( |
| 339 const String& declaration, | 339 const String& declaration, |
| 340 const CSSParserContext* context, | 340 const CSSParserContext* context, |
| 341 CSSParserObserver& observer) { | 341 CSSParserObserver& observer) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 parser.consumeDeclarationList(std::move(block), StyleRule::Style); | 373 parser.consumeDeclarationList(std::move(block), StyleRule::Style); |
| 374 return createStylePropertySet(parser.m_parsedProperties, context->mode()); | 374 return createStylePropertySet(parser.m_parsedProperties, context->mode()); |
| 375 } | 375 } |
| 376 | 376 |
| 377 static CSSParserImpl::AllowedRulesType computeNewAllowedRules( | 377 static CSSParserImpl::AllowedRulesType computeNewAllowedRules( |
| 378 CSSParserImpl::AllowedRulesType allowedRules, | 378 CSSParserImpl::AllowedRulesType allowedRules, |
| 379 StyleRuleBase* rule) { | 379 StyleRuleBase* rule) { |
| 380 if (!rule || allowedRules == CSSParserImpl::KeyframeRules || | 380 if (!rule || allowedRules == CSSParserImpl::KeyframeRules || |
| 381 allowedRules == CSSParserImpl::NoRules) | 381 allowedRules == CSSParserImpl::NoRules) |
| 382 return allowedRules; | 382 return allowedRules; |
| 383 ASSERT(allowedRules <= CSSParserImpl::RegularRules); | 383 DCHECK_LE(allowedRules, CSSParserImpl::RegularRules); |
| 384 if (rule->isCharsetRule() || rule->isImportRule()) | 384 if (rule->isCharsetRule() || rule->isImportRule()) |
| 385 return CSSParserImpl::AllowImportRules; | 385 return CSSParserImpl::AllowImportRules; |
| 386 if (rule->isNamespaceRule()) | 386 if (rule->isNamespaceRule()) |
| 387 return CSSParserImpl::AllowNamespaceRules; | 387 return CSSParserImpl::AllowNamespaceRules; |
| 388 return CSSParserImpl::RegularRules; | 388 return CSSParserImpl::RegularRules; |
| 389 } | 389 } |
| 390 | 390 |
| 391 template <typename T> | 391 template <typename T> |
| 392 bool CSSParserImpl::consumeRuleList(CSSParserTokenRange range, | 392 bool CSSParserImpl::consumeRuleList(CSSParserTokenRange range, |
| 393 RuleListType ruleListType, | 393 RuleListType ruleListType, |
| 394 const T callback) { | 394 const T callback) { |
| 395 AllowedRulesType allowedRules = RegularRules; | 395 AllowedRulesType allowedRules = RegularRules; |
| 396 switch (ruleListType) { | 396 switch (ruleListType) { |
| 397 case TopLevelRuleList: | 397 case TopLevelRuleList: |
| 398 allowedRules = AllowCharsetRules; | 398 allowedRules = AllowCharsetRules; |
| 399 break; | 399 break; |
| 400 case RegularRuleList: | 400 case RegularRuleList: |
| 401 allowedRules = RegularRules; | 401 allowedRules = RegularRules; |
| 402 break; | 402 break; |
| 403 case KeyframesRuleList: | 403 case KeyframesRuleList: |
| 404 allowedRules = KeyframeRules; | 404 allowedRules = KeyframeRules; |
| 405 break; | 405 break; |
| 406 default: | 406 default: |
| 407 ASSERT_NOT_REACHED(); | 407 NOTREACHED(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 bool seenRule = false; | 410 bool seenRule = false; |
| 411 bool firstRuleValid = false; | 411 bool firstRuleValid = false; |
| 412 while (!range.atEnd()) { | 412 while (!range.atEnd()) { |
| 413 StyleRuleBase* rule; | 413 StyleRuleBase* rule; |
| 414 switch (range.peek().type()) { | 414 switch (range.peek().type()) { |
| 415 case WhitespaceToken: | 415 case WhitespaceToken: |
| 416 range.consumeWhitespace(); | 416 range.consumeWhitespace(); |
| 417 continue; | 417 continue; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 437 allowedRules = computeNewAllowedRules(allowedRules, rule); | 437 allowedRules = computeNewAllowedRules(allowedRules, rule); |
| 438 callback(rule); | 438 callback(rule); |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 | 441 |
| 442 return firstRuleValid; | 442 return firstRuleValid; |
| 443 } | 443 } |
| 444 | 444 |
| 445 StyleRuleBase* CSSParserImpl::consumeAtRule(CSSParserTokenRange& range, | 445 StyleRuleBase* CSSParserImpl::consumeAtRule(CSSParserTokenRange& range, |
| 446 AllowedRulesType allowedRules) { | 446 AllowedRulesType allowedRules) { |
| 447 ASSERT(range.peek().type() == AtKeywordToken); | 447 DCHECK_EQ(range.peek().type(), AtKeywordToken); |
| 448 const StringView name = range.consumeIncludingWhitespace().value(); | 448 const StringView name = range.consumeIncludingWhitespace().value(); |
| 449 const CSSParserToken* preludeStart = &range.peek(); | 449 const CSSParserToken* preludeStart = &range.peek(); |
| 450 while (!range.atEnd() && range.peek().type() != LeftBraceToken && | 450 while (!range.atEnd() && range.peek().type() != LeftBraceToken && |
| 451 range.peek().type() != SemicolonToken) | 451 range.peek().type() != SemicolonToken) |
| 452 range.consumeComponentValue(); | 452 range.consumeComponentValue(); |
| 453 | 453 |
| 454 CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); | 454 CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); |
| 455 CSSAtRuleID id = cssAtRuleID(name); | 455 CSSAtRuleID id = cssAtRuleID(name); |
| 456 if (id != CSSAtRuleInvalid && m_context->isUseCounterRecordingEnabled()) | 456 if (id != CSSAtRuleInvalid && m_context->isUseCounterRecordingEnabled()) |
| 457 countAtRule(m_context, id); | 457 countAtRule(m_context, id); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 471 return nullptr; // Parse error, unrecognised at-rule without block | 471 return nullptr; // Parse error, unrecognised at-rule without block |
| 472 } | 472 } |
| 473 | 473 |
| 474 CSSParserTokenRange block = range.consumeBlock(); | 474 CSSParserTokenRange block = range.consumeBlock(); |
| 475 if (allowedRules == KeyframeRules) | 475 if (allowedRules == KeyframeRules) |
| 476 return nullptr; // Parse error, no at-rules supported inside @keyframes | 476 return nullptr; // Parse error, no at-rules supported inside @keyframes |
| 477 if (allowedRules == NoRules || allowedRules == ApplyRules) | 477 if (allowedRules == NoRules || allowedRules == ApplyRules) |
| 478 return nullptr; // Parse error, no at-rules with blocks supported inside | 478 return nullptr; // Parse error, no at-rules with blocks supported inside |
| 479 // declaration lists | 479 // declaration lists |
| 480 | 480 |
| 481 ASSERT(allowedRules <= RegularRules); | 481 DCHECK_LE(allowedRules, RegularRules); |
| 482 | 482 |
| 483 switch (id) { | 483 switch (id) { |
| 484 case CSSAtRuleMedia: | 484 case CSSAtRuleMedia: |
| 485 return consumeMediaRule(prelude, block); | 485 return consumeMediaRule(prelude, block); |
| 486 case CSSAtRuleSupports: | 486 case CSSAtRuleSupports: |
| 487 return consumeSupportsRule(prelude, block); | 487 return consumeSupportsRule(prelude, block); |
| 488 case CSSAtRuleViewport: | 488 case CSSAtRuleViewport: |
| 489 return consumeViewportRule(prelude, block); | 489 return consumeViewportRule(prelude, block); |
| 490 case CSSAtRuleFontFace: | 490 case CSSAtRuleFontFace: |
| 491 return consumeFontFaceRule(prelude, block); | 491 return consumeFontFaceRule(prelude, block); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 511 return nullptr; // Parse error, EOF instead of qualified rule block | 511 return nullptr; // Parse error, EOF instead of qualified rule block |
| 512 | 512 |
| 513 CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); | 513 CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); |
| 514 CSSParserTokenRange block = range.consumeBlock(); | 514 CSSParserTokenRange block = range.consumeBlock(); |
| 515 | 515 |
| 516 if (allowedRules <= RegularRules) | 516 if (allowedRules <= RegularRules) |
| 517 return consumeStyleRule(prelude, block); | 517 return consumeStyleRule(prelude, block); |
| 518 if (allowedRules == KeyframeRules) | 518 if (allowedRules == KeyframeRules) |
| 519 return consumeKeyframeStyleRule(prelude, block); | 519 return consumeKeyframeStyleRule(prelude, block); |
| 520 | 520 |
| 521 ASSERT_NOT_REACHED(); | 521 NOTREACHED(); |
| 522 return nullptr; | 522 return nullptr; |
| 523 } | 523 } |
| 524 | 524 |
| 525 // This may still consume tokens if it fails | 525 // This may still consume tokens if it fails |
| 526 static AtomicString consumeStringOrURI(CSSParserTokenRange& range) { | 526 static AtomicString consumeStringOrURI(CSSParserTokenRange& range) { |
| 527 const CSSParserToken& token = range.peek(); | 527 const CSSParserToken& token = range.peek(); |
| 528 | 528 |
| 529 if (token.type() == StringToken || token.type() == UrlToken) | 529 if (token.type() == StringToken || token.type() == UrlToken) |
| 530 return range.consumeIncludingWhitespace().value().toAtomicString(); | 530 return range.consumeIncludingWhitespace().value().toAtomicString(); |
| 531 | 531 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 } | 743 } |
| 744 | 744 |
| 745 consumeDeclarationList(block, StyleRule::Style); | 745 consumeDeclarationList(block, StyleRule::Style); |
| 746 | 746 |
| 747 return StyleRulePage::create( | 747 return StyleRulePage::create( |
| 748 std::move(selectorList), | 748 std::move(selectorList), |
| 749 createStylePropertySet(m_parsedProperties, m_context->mode())); | 749 createStylePropertySet(m_parsedProperties, m_context->mode())); |
| 750 } | 750 } |
| 751 | 751 |
| 752 void CSSParserImpl::consumeApplyRule(CSSParserTokenRange prelude) { | 752 void CSSParserImpl::consumeApplyRule(CSSParserTokenRange prelude) { |
| 753 ASSERT(RuntimeEnabledFeatures::cssApplyAtRulesEnabled()); | 753 DCHECK(RuntimeEnabledFeatures::cssApplyAtRulesEnabled()); |
| 754 | 754 |
| 755 const CSSParserToken& ident = prelude.consumeIncludingWhitespace(); | 755 const CSSParserToken& ident = prelude.consumeIncludingWhitespace(); |
| 756 if (!prelude.atEnd() || !CSSVariableParser::isValidVariableName(ident)) | 756 if (!prelude.atEnd() || !CSSVariableParser::isValidVariableName(ident)) |
| 757 return; // Parse error, expected a single custom property name | 757 return; // Parse error, expected a single custom property name |
| 758 m_parsedProperties.push_back(CSSProperty( | 758 m_parsedProperties.push_back(CSSProperty( |
| 759 CSSPropertyApplyAtRule, | 759 CSSPropertyApplyAtRule, |
| 760 *CSSCustomIdentValue::create(ident.value().toAtomicString()))); | 760 *CSSCustomIdentValue::create(ident.value().toAtomicString()))); |
| 761 } | 761 } |
| 762 | 762 |
| 763 StyleRuleKeyframe* CSSParserImpl::consumeKeyframeStyleRule( | 763 StyleRuleKeyframe* CSSParserImpl::consumeKeyframeStyleRule( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 821 } |
| 822 consumeDeclarationList(block, StyleRule::Style); | 822 consumeDeclarationList(block, StyleRule::Style); |
| 823 | 823 |
| 824 return StyleRule::create( | 824 return StyleRule::create( |
| 825 std::move(selectorList), | 825 std::move(selectorList), |
| 826 createStylePropertySet(m_parsedProperties, m_context->mode())); | 826 createStylePropertySet(m_parsedProperties, m_context->mode())); |
| 827 } | 827 } |
| 828 | 828 |
| 829 void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, | 829 void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, |
| 830 StyleRule::RuleType ruleType) { | 830 StyleRule::RuleType ruleType) { |
| 831 ASSERT(m_parsedProperties.isEmpty()); | 831 DCHECK(m_parsedProperties.isEmpty()); |
| 832 | 832 |
| 833 bool useObserver = m_observerWrapper && (ruleType == StyleRule::Style || | 833 bool useObserver = m_observerWrapper && (ruleType == StyleRule::Style || |
| 834 ruleType == StyleRule::Keyframe); | 834 ruleType == StyleRule::Keyframe); |
| 835 if (useObserver) { | 835 if (useObserver) { |
| 836 m_observerWrapper->observer().startRuleBody( | 836 m_observerWrapper->observer().startRuleBody( |
| 837 m_observerWrapper->previousTokenStartOffset(range)); | 837 m_observerWrapper->previousTokenStartOffset(range)); |
| 838 m_observerWrapper->skipCommentsBefore(range, true); | 838 m_observerWrapper->skipCommentsBefore(range, true); |
| 839 } | 839 } |
| 840 | 840 |
| 841 while (!range.atEnd()) { | 841 while (!range.atEnd()) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 m_observerWrapper->yieldCommentsBefore(range); | 882 m_observerWrapper->yieldCommentsBefore(range); |
| 883 m_observerWrapper->observer().endRuleBody( | 883 m_observerWrapper->observer().endRuleBody( |
| 884 m_observerWrapper->endOffset(range)); | 884 m_observerWrapper->endOffset(range)); |
| 885 } | 885 } |
| 886 } | 886 } |
| 887 | 887 |
| 888 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, | 888 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, |
| 889 StyleRule::RuleType ruleType) { | 889 StyleRule::RuleType ruleType) { |
| 890 CSSParserTokenRange rangeCopy = range; // For inspector callbacks | 890 CSSParserTokenRange rangeCopy = range; // For inspector callbacks |
| 891 | 891 |
| 892 ASSERT(range.peek().type() == IdentToken); | 892 DCHECK_EQ(range.peek().type(), IdentToken); |
| 893 const CSSParserToken& token = range.consumeIncludingWhitespace(); | 893 const CSSParserToken& token = range.consumeIncludingWhitespace(); |
| 894 CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); | 894 CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); |
| 895 if (range.consume().type() != ColonToken) | 895 if (range.consume().type() != ColonToken) |
| 896 return; // Parse error | 896 return; // Parse error |
| 897 | 897 |
| 898 bool important = false; | 898 bool important = false; |
| 899 const CSSParserToken* declarationValueEnd = range.end(); | 899 const CSSParserToken* declarationValueEnd = range.end(); |
| 900 const CSSParserToken* last = range.end() - 1; | 900 const CSSParserToken* last = range.end() - 1; |
| 901 while (last->type() == WhitespaceToken) | 901 while (last->type() == WhitespaceToken) |
| 902 --last; | 902 --last; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 else | 981 else |
| 982 return nullptr; // Parser error, invalid value in keyframe selector | 982 return nullptr; // Parser error, invalid value in keyframe selector |
| 983 if (range.atEnd()) | 983 if (range.atEnd()) |
| 984 return result; | 984 return result; |
| 985 if (range.consume().type() != CommaToken) | 985 if (range.consume().type() != CommaToken) |
| 986 return nullptr; // Parser error | 986 return nullptr; // Parser error |
| 987 } | 987 } |
| 988 } | 988 } |
| 989 | 989 |
| 990 } // namespace blink | 990 } // namespace blink |
| OLD | NEW |