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

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

Issue 1406993009: Revert "CSS Custom Properties (Variables)" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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/CSSCustomPropertyDeclaration.h"
9 #include "core/css/CSSKeyframesRule.h" 8 #include "core/css/CSSKeyframesRule.h"
10 #include "core/css/CSSStyleSheet.h" 9 #include "core/css/CSSStyleSheet.h"
11 #include "core/css/StylePropertySet.h" 10 #include "core/css/StylePropertySet.h"
12 #include "core/css/StyleRuleImport.h" 11 #include "core/css/StyleRuleImport.h"
13 #include "core/css/StyleRuleKeyframe.h" 12 #include "core/css/StyleRuleKeyframe.h"
14 #include "core/css/StyleRuleNamespace.h" 13 #include "core/css/StyleRuleNamespace.h"
15 #include "core/css/StyleSheetContents.h" 14 #include "core/css/StyleSheetContents.h"
16 #include "core/css/parser/CSSAtRuleID.h" 15 #include "core/css/parser/CSSAtRuleID.h"
17 #include "core/css/parser/CSSParserObserver.h" 16 #include "core/css/parser/CSSParserObserver.h"
18 #include "core/css/parser/CSSParserObserverWrapper.h" 17 #include "core/css/parser/CSSParserObserverWrapper.h"
19 #include "core/css/parser/CSSParserSelector.h" 18 #include "core/css/parser/CSSParserSelector.h"
20 #include "core/css/parser/CSSPropertyParser.h" 19 #include "core/css/parser/CSSPropertyParser.h"
21 #include "core/css/parser/CSSSelectorParser.h" 20 #include "core/css/parser/CSSSelectorParser.h"
22 #include "core/css/parser/CSSSupportsParser.h" 21 #include "core/css/parser/CSSSupportsParser.h"
23 #include "core/css/parser/CSSTokenizer.h" 22 #include "core/css/parser/CSSTokenizer.h"
24 #include "core/css/parser/CSSVariableParser.h"
25 #include "core/css/parser/MediaQueryParser.h" 23 #include "core/css/parser/MediaQueryParser.h"
26 #include "core/dom/Document.h" 24 #include "core/dom/Document.h"
27 #include "core/dom/Element.h" 25 #include "core/dom/Element.h"
28 #include "core/frame/UseCounter.h" 26 #include "core/frame/UseCounter.h"
29 #include "platform/TraceEvent.h" 27 #include "platform/TraceEvent.h"
30 #include "wtf/BitArray.h" 28 #include "wtf/BitArray.h"
31 29
32 namespace blink { 30 namespace blink {
33 31
34 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet) 32 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet)
(...skipping 16 matching lines...) Expand all
51 return declaration->addParsedProperties(parser.m_parsedProperties); 49 return declaration->addParsedProperties(parser.m_parsedProperties);
52 } 50 }
53 51
54 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties) 52 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties)
55 { 53 {
56 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. 54 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
57 for (size_t i = input.size(); i--; ) { 55 for (size_t i = input.size(); i--; ) {
58 const CSSProperty& property = input[i]; 56 const CSSProperty& property = input[i];
59 if (property.isImportant() != important) 57 if (property.isImportant() != important)
60 continue; 58 continue;
61 const unsigned propertyIDIndex = property.id(); 59 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
62 // All custom properties use the same CSSPropertyID so we can't remove r epeated definitions 60 if (seenProperties.get(propertyIDIndex))
63 if (property.id() != CSSPropertyVariable) { 61 continue;
64 if (seenProperties.get(propertyIDIndex)) 62 seenProperties.set(propertyIDIndex);
65 continue;
66 seenProperties.set(propertyIDIndex);
67 }
68 output[--unusedEntries] = property; 63 output[--unusedEntries] = property;
69 } 64 }
70 } 65 }
71 66
72 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) 67 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode)
73 { 68 {
74 BitArray<numCSSProperties> seenProperties; 69 BitArray<numCSSProperties> seenProperties;
75 size_t unusedEntries = parsedProperties.size(); 70 size_t unusedEntries = parsedProperties.size();
76 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); 71 WillBeHeapVector<CSSProperty, 256> results(unusedEntries);
77 72
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 m_observerWrapper->yieldCommentsBefore(range); 665 m_observerWrapper->yieldCommentsBefore(range);
671 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange)); 666 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange));
672 } 667 }
673 } 668 }
674 669
675 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) 670 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType)
676 { 671 {
677 CSSParserTokenRange rangeCopy = range; // For inspector callbacks 672 CSSParserTokenRange rangeCopy = range; // For inspector callbacks
678 673
679 ASSERT(range.peek().type() == IdentToken); 674 ASSERT(range.peek().type() == IdentToken);
680 const CSSParserToken& token = range.consumeIncludingWhitespace(); 675 CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseA sUnresolvedCSSPropertyID();
681 CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID();
682 if (range.consume().type() != ColonToken) 676 if (range.consume().type() != ColonToken)
683 return; // Parse error 677 return; // Parse error
684 678
685 bool important = false; 679 bool important = false;
686 const CSSParserToken* declarationValueEnd = range.end(); 680 const CSSParserToken* declarationValueEnd = range.end();
687 const CSSParserToken* last = range.end() - 1; 681 const CSSParserToken* last = range.end() - 1;
688 while (last->type() == WhitespaceToken) 682 while (last->type() == WhitespaceToken)
689 --last; 683 --last;
690 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { 684 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) {
691 --last; 685 --last;
692 while (last->type() == WhitespaceToken) 686 while (last->type() == WhitespaceToken)
693 --last; 687 --last;
694 if (last->type() == DelimiterToken && last->delimiter() == '!') { 688 if (last->type() == DelimiterToken && last->delimiter() == '!') {
695 important = true; 689 important = true;
696 declarationValueEnd = last; 690 declarationValueEnd = last;
697 } 691 }
698 } 692 }
699 if (RuntimeEnabledFeatures::cssVariablesEnabled() && unresolvedProperty == C SSPropertyInvalid && CSSVariableParser::isValidVariableName(token)) {
700 AtomicString variableName = token.value();
701 consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declar ationValueEnd), variableName, important);
702 return;
703 }
704 693
705 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes)) 694 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes))
706 return; 695 return;
707 696
708 if (m_observerWrapper && ruleType == StyleRule::Style) { 697 if (m_observerWrapper && ruleType == StyleRule::Style) {
709 size_t propertiesCount = m_parsedProperties.size(); 698 size_t propertiesCount = m_parsedProperties.size();
710 if (unresolvedProperty != CSSPropertyInvalid) 699 if (unresolvedProperty != CSSPropertyInvalid)
711 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType); 700 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType);
712 m_observerWrapper->observer().observeProperty( 701 m_observerWrapper->observer().observeProperty(
713 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy), 702 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy),
714 important, m_parsedProperties.size() != propertiesCount); 703 important, m_parsedProperties.size() != propertiesCount);
715 return; 704 return;
716 } 705 }
717 706
718 if (unresolvedProperty == CSSPropertyInvalid) 707 if (unresolvedProperty == CSSPropertyInvalid)
719 return; 708 return;
720 709
721 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType); 710 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType);
722 } 711 }
723 712
724 void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, c onst AtomicString& variableName, bool important)
725 {
726 if (RefPtrWillBeRawPtr<CSSCustomPropertyDeclaration> value = CSSVariablePars er::parseDeclarationValue(variableName, range))
727 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, value.release (), important));
728 }
729
730 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType) 713 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType)
731 { 714 {
732 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex t, m_parsedProperties, ruleType); 715 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex t, m_parsedProperties, ruleType);
733 } 716 }
734 717
735 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) 718 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range)
736 { 719 {
737 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); 720 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>);
738 while (true) { 721 while (true) {
739 range.consumeWhitespace(); 722 range.consumeWhitespace();
740 const CSSParserToken& token = range.consumeIncludingWhitespace(); 723 const CSSParserToken& token = range.consumeIncludingWhitespace();
741 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100) 724 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100)
742 result->append(token.numericValue() / 100); 725 result->append(token.numericValue() / 100);
743 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om")) 726 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om"))
744 result->append(0); 727 result->append(0);
745 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to ")) 728 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to "))
746 result->append(1); 729 result->append(1);
747 else 730 else
748 return nullptr; // Parser error, invalid value in keyframe selector 731 return nullptr; // Parser error, invalid value in keyframe selector
749 if (range.atEnd()) 732 if (range.atEnd())
750 return result.release(); 733 return result.release();
751 if (range.consume().type() != CommaToken) 734 if (range.consume().type() != CommaToken)
752 return nullptr; // Parser error 735 return nullptr; // Parser error
753 } 736 }
754 } 737 }
755 738
756 } // namespace blink 739 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSParserImpl.h ('k') | third_party/WebKit/Source/core/css/parser/CSSParserToken.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698