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

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

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Missing file :( Created 5 years, 4 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 | Annotate | Revision Log
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/CSSCustomVariableValue.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/CSSParserValues.h" 18 #include "core/css/parser/CSSParserValues.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 18 matching lines...) Expand all
50 } 52 }
51 53
52 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties) 54 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties)
53 { 55 {
54 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. 56 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
55 for (size_t i = input.size(); i--; ) { 57 for (size_t i = input.size(); i--; ) {
56 const CSSProperty& property = input[i]; 58 const CSSProperty& property = input[i];
57 if (property.isImportant() != important) 59 if (property.isImportant() != important)
58 continue; 60 continue;
59 const unsigned propertyIDIndex = property.id() - firstCSSProperty; 61 const unsigned propertyIDIndex = property.id() - firstCSSProperty;
60 if (seenProperties.get(propertyIDIndex)) 62 if (seenProperties.get(propertyIDIndex) && property.id() != CSSPropertyV ariable)
61 continue; 63 continue;
62 seenProperties.set(propertyIDIndex); 64 seenProperties.set(propertyIDIndex);
63 output[--unusedEntries] = property; 65 output[--unusedEntries] = property;
64 } 66 }
65 } 67 }
66 68
67 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) 69 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode)
68 { 70 {
69 BitArray<numCSSProperties> seenProperties; 71 BitArray<numCSSProperties> seenProperties;
70 size_t unusedEntries = parsedProperties.size(); 72 size_t unusedEntries = parsedProperties.size();
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 m_observerWrapper->yieldCommentsBefore(range); 663 m_observerWrapper->yieldCommentsBefore(range);
662 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange)); 664 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange));
663 } 665 }
664 } 666 }
665 667
666 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) 668 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType)
667 { 669 {
668 CSSParserTokenRange rangeCopy = range; // For inspector callbacks 670 CSSParserTokenRange rangeCopy = range; // For inspector callbacks
669 671
670 ASSERT(range.peek().type() == IdentToken); 672 ASSERT(range.peek().type() == IdentToken);
671 CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseA sUnresolvedCSSPropertyID(); 673 CSSParserToken token = range.consumeIncludingWhitespace();
674 CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID();
672 if (range.consume().type() != ColonToken) 675 if (range.consume().type() != ColonToken)
673 return; // Parse error 676 return; // Parse error
674 677
675 bool important = false; 678 bool important = false;
676 const CSSParserToken* declarationValueEnd = range.end(); 679 const CSSParserToken* declarationValueEnd = range.end();
677 const CSSParserToken* last = range.end() - 1; 680 const CSSParserToken* last = range.end() - 1;
678 while (last->type() == WhitespaceToken) 681 while (last->type() == WhitespaceToken)
679 --last; 682 --last;
683
680 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { 684 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) {
681 --last; 685 --last;
682 while (last->type() == WhitespaceToken) 686 while (last->type() == WhitespaceToken)
683 --last; 687 --last;
684 if (last->type() == DelimiterToken && last->delimiter() == '!') { 688 if (last->type() == DelimiterToken && last->delimiter() == '!') {
685 important = true; 689 important = true;
686 declarationValueEnd = last; 690 declarationValueEnd = last;
687 } 691 }
688 } 692 }
693 if (unresolvedProperty == CSSPropertyVariable) {
694 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
695 AtomicString variableName = token.value();
696 consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declar ationValueEnd), variableName, important);
697 return;
698 }
689 699
690 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes)) 700 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes))
691 return; 701 return;
692 702
693 if (m_observerWrapper && ruleType == StyleRule::Style) { 703 if (m_observerWrapper && ruleType == StyleRule::Style) {
694 size_t propertiesCount = m_parsedProperties.size(); 704 size_t propertiesCount = m_parsedProperties.size();
695 if (unresolvedProperty != CSSPropertyInvalid) 705 if (unresolvedProperty != CSSPropertyInvalid)
696 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType); 706 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType);
697 m_observerWrapper->observer().observeProperty( 707 m_observerWrapper->observer().observeProperty(
698 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy), 708 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy),
699 important, m_parsedProperties.size() != propertiesCount); 709 important, m_parsedProperties.size() != propertiesCount);
700 return; 710 return;
701 } 711 }
702 712
703 if (unresolvedProperty == CSSPropertyInvalid) 713 if (unresolvedProperty == CSSPropertyInvalid)
704 return; 714 return;
705 715
706 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType); 716 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType);
707 } 717 }
708 718
719 void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, c onst AtomicString& variableName, bool important)
720 {
721 switch (CSSVariableParser::parseVariableDefinition(range)) {
alancutter (OOO until 2018) 2015/08/05 08:01:43 parseVariableDefinition() could just return a CSSC
722 case CSSVariableParser::Invalid:
723 return;
724 case CSSVariableParser::Variable:
725 m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
726 CSSCustomVariableValue::create(variableName, CSSVariableData::create (range, false)), important));
727 return;
728 case CSSVariableParser::VariableWithReferences:
729 m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
730 CSSCustomVariableValue::create(variableName, CSSVariableData::create (range, true)), important));
731 return;
732 case CSSVariableParser::Initial:
733 m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
734 CSSCustomVariableValue::create(variableName, CSSValueInitial), impor tant));
735 return;
736 case CSSVariableParser::Inherit:
737 m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
738 CSSCustomVariableValue::create(variableName, CSSValueInherit), impor tant));
739 return;
740 case CSSVariableParser::Unset:
741 m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
742 CSSCustomVariableValue::create(variableName, CSSValueUnset), importa nt));
743 return;
744 }
745 }
746
709 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType) 747 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType)
710 { 748 {
711 CSSParserValueList valueList(range); 749 CSSParserValueList valueList(range);
712 if (!valueList.size()) 750 if (!valueList.size())
713 return; // Parser error 751 return; // Parser error
714 CSSPropertyParser::parseValue(unresolvedProperty, important, &valueList, m_c ontext, m_parsedProperties, ruleType); 752 CSSPropertyParser::parseValue(unresolvedProperty, important, &valueList, m_c ontext, m_parsedProperties, ruleType);
715 } 753 }
716 754
717 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) 755 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range)
718 { 756 {
(...skipping 10 matching lines...) Expand all
729 else 767 else
730 return nullptr; // Parser error, invalid value in keyframe selector 768 return nullptr; // Parser error, invalid value in keyframe selector
731 if (range.atEnd()) 769 if (range.atEnd())
732 return result.release(); 770 return result.release();
733 if (range.consume().type() != CommaToken) 771 if (range.consume().type() != CommaToken)
734 return nullptr; // Parser error 772 return nullptr; // Parser error
735 } 773 }
736 } 774 }
737 775
738 } // namespace blink 776 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698