Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: Source/core/css/parser/CSSParserImpl.cpp

Issue 1096963002: Make UseCounters work on aliased properties (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/parser/CSSParser.cpp ('k') | Source/core/css/parser/CSSParserToken.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 namespace blink { 29 namespace blink {
30 30
31 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet) 31 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet)
32 : m_context(context) 32 : m_context(context)
33 , m_defaultNamespace(starAtom) 33 , m_defaultNamespace(starAtom)
34 , m_styleSheet(styleSheet) 34 , m_styleSheet(styleSheet)
35 , m_observerWrapper(nullptr) 35 , m_observerWrapper(nullptr)
36 { 36 {
37 } 37 }
38 38
39 bool CSSParserImpl::parseValue(MutableStylePropertySet* declaration, CSSProperty ID propertyID, const String& string, bool important, const CSSParserContext& con text) 39 bool CSSParserImpl::parseValue(MutableStylePropertySet* declaration, CSSProperty ID unresolvedProperty, const String& string, bool important, const CSSParserCont ext& context)
40 { 40 {
41 CSSParserImpl parser(context); 41 CSSParserImpl parser(context);
42 StyleRule::Type ruleType = StyleRule::Style; 42 StyleRule::Type ruleType = StyleRule::Style;
43 if (declaration->cssParserMode() == CSSViewportRuleMode) 43 if (declaration->cssParserMode() == CSSViewportRuleMode)
44 ruleType = StyleRule::Viewport; 44 ruleType = StyleRule::Viewport;
45 CSSTokenizer::Scope scope(string); 45 CSSTokenizer::Scope scope(string);
46 parser.consumeDeclarationValue(scope.tokenRange(), propertyID, important, ru leType); 46 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor tant, ruleType);
47 if (parser.m_parsedProperties.isEmpty()) 47 if (parser.m_parsedProperties.isEmpty())
48 return false; 48 return false;
49 declaration->addParsedProperties(parser.m_parsedProperties); 49 declaration->addParsedProperties(parser.m_parsedProperties);
50 return true; 50 return true;
51 } 51 }
52 52
53 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties) 53 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties)
54 { 54 {
55 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. 55 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
56 for (size_t i = input.size(); i--; ) { 56 for (size_t i = input.size(); i--; ) {
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 m_observerWrapper->yieldCommentsBefore(range); 679 m_observerWrapper->yieldCommentsBefore(range);
680 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange), NoCSSError); 680 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange), NoCSSError);
681 } 681 }
682 } 682 }
683 683
684 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) 684 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType)
685 { 685 {
686 CSSParserTokenRange rangeCopy = range; // For inspector callbacks 686 CSSParserTokenRange rangeCopy = range; // For inspector callbacks
687 687
688 ASSERT(range.peek().type() == IdentToken); 688 ASSERT(range.peek().type() == IdentToken);
689 CSSPropertyID id = range.consumeIncludingWhitespace().parseAsCSSPropertyID() ; 689 CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseA sUnresolvedCSSPropertyID();
690 if (range.consume().type() != ColonToken) 690 if (range.consume().type() != ColonToken)
691 return; // Parse error 691 return; // Parse error
692 692
693 // FIXME: We shouldn't allow !important in @keyframes or @font-face 693 // FIXME: We shouldn't allow !important in @keyframes or @font-face
694 bool important = false; 694 bool important = false;
695 const CSSParserToken* declarationValueEnd = range.end(); 695 const CSSParserToken* declarationValueEnd = range.end();
696 const CSSParserToken* last = range.end() - 1; 696 const CSSParserToken* last = range.end() - 1;
697 while (last->type() == WhitespaceToken) 697 while (last->type() == WhitespaceToken)
698 --last; 698 --last;
699 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { 699 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) {
700 --last; 700 --last;
701 while (last->type() == WhitespaceToken) 701 while (last->type() == WhitespaceToken)
702 --last; 702 --last;
703 if (last->type() == DelimiterToken && last->delimiter() == '!') { 703 if (last->type() == DelimiterToken && last->delimiter() == '!') {
704 important = true; 704 important = true;
705 declarationValueEnd = last; 705 declarationValueEnd = last;
706 } 706 }
707 } 707 }
708 708
709 if (m_observerWrapper && ruleType == StyleRule::Style) { 709 if (m_observerWrapper && ruleType == StyleRule::Style) {
710 size_t propertiesCount = m_parsedProperties.size(); 710 size_t propertiesCount = m_parsedProperties.size();
711 if (id != CSSPropertyInvalid) 711 if (unresolvedProperty != CSSPropertyInvalid)
712 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), id, important, ruleType); 712 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType);
713 m_observerWrapper->observer().startProperty(m_observerWrapper->startOffs et(rangeCopy)); 713 m_observerWrapper->observer().startProperty(m_observerWrapper->startOffs et(rangeCopy));
714 m_observerWrapper->observer().endProperty(important, 714 m_observerWrapper->observer().endProperty(important,
715 m_parsedProperties.size() != propertiesCount, 715 m_parsedProperties.size() != propertiesCount,
716 m_observerWrapper->endOffset(rangeCopy), NoCSSError); 716 m_observerWrapper->endOffset(rangeCopy), NoCSSError);
717 return; 717 return;
718 } 718 }
719 719
720 if (id == CSSPropertyInvalid) 720 if (unresolvedProperty == CSSPropertyInvalid)
721 return; 721 return;
722 722
723 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), id, important, ruleType); 723 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType);
724 } 724 }
725 725
726 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID propertyID, bool important, StyleRule::Type ruleType) 726 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType)
727 { 727 {
728 bool usesRemUnits; 728 bool usesRemUnits;
729 CSSParserValueList valueList(range, usesRemUnits); 729 CSSParserValueList valueList(range, usesRemUnits);
730 if (!valueList.size()) 730 if (!valueList.size())
731 return; // Parser error 731 return; // Parser error
732 if (usesRemUnits && m_styleSheet) 732 if (usesRemUnits && m_styleSheet)
733 m_styleSheet->parserSetUsesRemUnits(true); 733 m_styleSheet->parserSetUsesRemUnits(true);
734 bool inViewport = ruleType == StyleRule::Viewport; 734 bool inViewport = ruleType == StyleRule::Viewport;
735 CSSPropertyParser::parseValue(propertyID, important, &valueList, m_context, inViewport, m_parsedProperties, ruleType); 735 CSSPropertyParser::parseValue(unresolvedProperty, important, &valueList, m_c ontext, inViewport, m_parsedProperties, ruleType);
736 } 736 }
737 737
738 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) 738 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range)
739 { 739 {
740 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); 740 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>);
741 while (true) { 741 while (true) {
742 range.consumeWhitespace(); 742 range.consumeWhitespace();
743 const CSSParserToken& token = range.consumeIncludingWhitespace(); 743 const CSSParserToken& token = range.consumeIncludingWhitespace();
744 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100) 744 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100)
745 result->append(token.numericValue() / 100); 745 result->append(token.numericValue() / 100);
746 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om")) 746 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om"))
747 result->append(0); 747 result->append(0);
748 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to ")) 748 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to "))
749 result->append(1); 749 result->append(1);
750 else 750 else
751 return nullptr; // Parser error, invalid value in keyframe selector 751 return nullptr; // Parser error, invalid value in keyframe selector
752 if (range.atEnd()) 752 if (range.atEnd())
753 return result.release(); 753 return result.release();
754 if (range.consume().type() != CommaToken) 754 if (range.consume().type() != CommaToken)
755 return nullptr; // Parser error 755 return nullptr; // Parser error
756 } 756 }
757 } 757 }
758 758
759 } // namespace blink 759 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSParser.cpp ('k') | Source/core/css/parser/CSSParserToken.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698