Chromium Code Reviews| 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/CSSCustomPropertyDeclaration.h" | |
| 8 #include "core/css/CSSKeyframesRule.h" | 9 #include "core/css/CSSKeyframesRule.h" |
| 9 #include "core/css/CSSStyleSheet.h" | 10 #include "core/css/CSSStyleSheet.h" |
| 10 #include "core/css/StylePropertySet.h" | 11 #include "core/css/StylePropertySet.h" |
| 11 #include "core/css/StyleRuleImport.h" | 12 #include "core/css/StyleRuleImport.h" |
| 12 #include "core/css/StyleRuleKeyframe.h" | 13 #include "core/css/StyleRuleKeyframe.h" |
| 13 #include "core/css/StyleRuleNamespace.h" | 14 #include "core/css/StyleRuleNamespace.h" |
| 14 #include "core/css/StyleSheetContents.h" | 15 #include "core/css/StyleSheetContents.h" |
| 15 #include "core/css/parser/CSSParserObserver.h" | 16 #include "core/css/parser/CSSParserObserver.h" |
| 16 #include "core/css/parser/CSSParserObserverWrapper.h" | 17 #include "core/css/parser/CSSParserObserverWrapper.h" |
| 17 #include "core/css/parser/CSSParserSelector.h" | 18 #include "core/css/parser/CSSParserSelector.h" |
| 18 #include "core/css/parser/CSSPropertyParser.h" | 19 #include "core/css/parser/CSSPropertyParser.h" |
| 19 #include "core/css/parser/CSSSelectorParser.h" | 20 #include "core/css/parser/CSSSelectorParser.h" |
| 20 #include "core/css/parser/CSSSupportsParser.h" | 21 #include "core/css/parser/CSSSupportsParser.h" |
| 21 #include "core/css/parser/CSSTokenizer.h" | 22 #include "core/css/parser/CSSTokenizer.h" |
| 23 #include "core/css/parser/CSSVariableParser.h" | |
| 22 #include "core/css/parser/MediaQueryParser.h" | 24 #include "core/css/parser/MediaQueryParser.h" |
| 23 #include "core/dom/Document.h" | 25 #include "core/dom/Document.h" |
| 24 #include "core/dom/Element.h" | 26 #include "core/dom/Element.h" |
| 25 #include "core/frame/UseCounter.h" | 27 #include "core/frame/UseCounter.h" |
| 26 #include "platform/TraceEvent.h" | 28 #include "platform/TraceEvent.h" |
| 27 #include "wtf/BitArray.h" | 29 #include "wtf/BitArray.h" |
| 28 | 30 |
| 29 namespace blink { | 31 namespace blink { |
| 30 | 32 |
| 31 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet) | 33 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 48 return declaration->addParsedProperties(parser.m_parsedProperties); | 50 return declaration->addParsedProperties(parser.m_parsedProperties); |
| 49 } | 51 } |
| 50 | 52 |
| 51 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) |
| 52 { | 54 { |
| 53 // 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. |
| 54 for (size_t i = input.size(); i--; ) { | 56 for (size_t i = input.size(); i--; ) { |
| 55 const CSSProperty& property = input[i]; | 57 const CSSProperty& property = input[i]; |
| 56 if (property.isImportant() != important) | 58 if (property.isImportant() != important) |
| 57 continue; | 59 continue; |
| 58 const unsigned propertyIDIndex = property.id() - firstCSSProperty; | 60 // CSSPropertyVariable is asserted to be one number before the firstCSSP roperty. We need to include it here. |
|
Timothy Loh
2015/10/15 03:43:47
Not sure this is right, doesn't this make the last
| |
| 59 if (seenProperties.get(propertyIDIndex)) | 61 const unsigned propertyIDIndex = property.id(); |
| 62 if (property.id() != CSSPropertyVariable && seenProperties.get(propertyI DIndex)) | |
| 60 continue; | 63 continue; |
| 61 seenProperties.set(propertyIDIndex); | 64 seenProperties.set(propertyIDIndex); |
| 62 output[--unusedEntries] = property; | 65 output[--unusedEntries] = property; |
| 63 } | 66 } |
| 64 } | 67 } |
| 65 | 68 |
| 66 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) | 69 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) |
| 67 { | 70 { |
| 68 BitArray<numCSSProperties> seenProperties; | 71 BitArray<numCSSProperties> seenProperties; |
| 69 size_t unusedEntries = parsedProperties.size(); | 72 size_t unusedEntries = parsedProperties.size(); |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 m_observerWrapper->yieldCommentsBefore(range); | 661 m_observerWrapper->yieldCommentsBefore(range); |
| 659 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange)); | 662 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange)); |
| 660 } | 663 } |
| 661 } | 664 } |
| 662 | 665 |
| 663 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) | 666 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) |
| 664 { | 667 { |
| 665 CSSParserTokenRange rangeCopy = range; // For inspector callbacks | 668 CSSParserTokenRange rangeCopy = range; // For inspector callbacks |
| 666 | 669 |
| 667 ASSERT(range.peek().type() == IdentToken); | 670 ASSERT(range.peek().type() == IdentToken); |
| 668 CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseA sUnresolvedCSSPropertyID(); | 671 const CSSParserToken& token = range.consumeIncludingWhitespace(); |
| 672 CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); | |
| 669 if (range.consume().type() != ColonToken) | 673 if (range.consume().type() != ColonToken) |
| 670 return; // Parse error | 674 return; // Parse error |
| 671 | 675 |
| 672 bool important = false; | 676 bool important = false; |
| 673 const CSSParserToken* declarationValueEnd = range.end(); | 677 const CSSParserToken* declarationValueEnd = range.end(); |
| 674 const CSSParserToken* last = range.end() - 1; | 678 const CSSParserToken* last = range.end() - 1; |
| 675 while (last->type() == WhitespaceToken) | 679 while (last->type() == WhitespaceToken) |
| 676 --last; | 680 --last; |
| 677 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { | 681 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { |
| 678 --last; | 682 --last; |
| 679 while (last->type() == WhitespaceToken) | 683 while (last->type() == WhitespaceToken) |
| 680 --last; | 684 --last; |
| 681 if (last->type() == DelimiterToken && last->delimiter() == '!') { | 685 if (last->type() == DelimiterToken && last->delimiter() == '!') { |
| 682 important = true; | 686 important = true; |
| 683 declarationValueEnd = last; | 687 declarationValueEnd = last; |
| 684 } | 688 } |
| 685 } | 689 } |
| 690 if (RuntimeEnabledFeatures::cssVariablesEnabled() && unresolvedProperty == C SSPropertyInvalid && CSSVariableParser::isValidVariableName(token)) { | |
| 691 AtomicString variableName = token.value(); | |
| 692 consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declar ationValueEnd), variableName, important); | |
| 693 return; | |
| 694 } | |
| 686 | 695 |
| 687 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes)) | 696 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes)) |
| 688 return; | 697 return; |
| 689 | 698 |
| 690 if (m_observerWrapper && ruleType == StyleRule::Style) { | 699 if (m_observerWrapper && ruleType == StyleRule::Style) { |
| 691 size_t propertiesCount = m_parsedProperties.size(); | 700 size_t propertiesCount = m_parsedProperties.size(); |
| 692 if (unresolvedProperty != CSSPropertyInvalid) | 701 if (unresolvedProperty != CSSPropertyInvalid) |
| 693 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType); | 702 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType); |
| 694 m_observerWrapper->observer().observeProperty( | 703 m_observerWrapper->observer().observeProperty( |
| 695 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy), | 704 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy), |
| 696 important, m_parsedProperties.size() != propertiesCount); | 705 important, m_parsedProperties.size() != propertiesCount); |
| 697 return; | 706 return; |
| 698 } | 707 } |
| 699 | 708 |
| 700 if (unresolvedProperty == CSSPropertyInvalid) | 709 if (unresolvedProperty == CSSPropertyInvalid) |
| 701 return; | 710 return; |
| 702 | 711 |
| 703 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType); | 712 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType); |
| 704 } | 713 } |
| 705 | 714 |
| 715 void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, c onst AtomicString& variableName, bool important) | |
| 716 { | |
| 717 if (RefPtrWillBeRawPtr<CSSCustomPropertyDeclaration> value = CSSVariablePars er::parseDeclarationValue(variableName, range)) | |
| 718 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, value.release (), important)); | |
| 719 } | |
| 720 | |
| 706 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType) | 721 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType) |
| 707 { | 722 { |
| 708 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex t, m_parsedProperties, ruleType); | 723 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex t, m_parsedProperties, ruleType); |
| 709 } | 724 } |
| 710 | 725 |
| 711 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) | 726 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) |
| 712 { | 727 { |
| 713 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); | 728 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); |
| 714 while (true) { | 729 while (true) { |
| 715 range.consumeWhitespace(); | 730 range.consumeWhitespace(); |
| 716 const CSSParserToken& token = range.consumeIncludingWhitespace(); | 731 const CSSParserToken& token = range.consumeIncludingWhitespace(); |
| 717 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100) | 732 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100) |
| 718 result->append(token.numericValue() / 100); | 733 result->append(token.numericValue() / 100); |
| 719 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om")) | 734 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om")) |
| 720 result->append(0); | 735 result->append(0); |
| 721 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to ")) | 736 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to ")) |
| 722 result->append(1); | 737 result->append(1); |
| 723 else | 738 else |
| 724 return nullptr; // Parser error, invalid value in keyframe selector | 739 return nullptr; // Parser error, invalid value in keyframe selector |
| 725 if (range.atEnd()) | 740 if (range.atEnd()) |
| 726 return result.release(); | 741 return result.release(); |
| 727 if (range.consume().type() != CommaToken) | 742 if (range.consume().type() != CommaToken) |
| 728 return nullptr; // Parser error | 743 return nullptr; // Parser error |
| 729 } | 744 } |
| 730 } | 745 } |
| 731 | 746 |
| 732 } // namespace blink | 747 } // namespace blink |
| OLD | NEW |