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/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, const String& base String, StyleSheetContents* styleSheet) |
| 32 : m_context(context) | 34 : m_context(context) |
| 33 , m_defaultNamespace(starAtom) | 35 , m_defaultNamespace(starAtom) |
| 34 , m_styleSheet(styleSheet) | 36 , m_styleSheet(styleSheet) |
| 35 , m_observerWrapper(nullptr) | 37 , m_observerWrapper(nullptr) |
| 38 , m_baseString(baseString) | |
| 36 { | 39 { |
| 37 } | 40 } |
| 38 | 41 |
| 39 bool CSSParserImpl::parseValue(MutableStylePropertySet* declaration, CSSProperty ID unresolvedProperty, const String& string, bool important, const CSSParserCont ext& context) | 42 bool CSSParserImpl::parseValue(MutableStylePropertySet* declaration, CSSProperty ID unresolvedProperty, const String& string, bool important, const CSSParserCont ext& context) |
| 40 { | 43 { |
| 41 CSSParserImpl parser(context); | 44 CSSParserImpl parser(context, string); |
| 42 StyleRule::Type ruleType = StyleRule::Style; | 45 StyleRule::Type ruleType = StyleRule::Style; |
| 43 if (declaration->cssParserMode() == CSSViewportRuleMode) | 46 if (declaration->cssParserMode() == CSSViewportRuleMode) |
| 44 ruleType = StyleRule::Viewport; | 47 ruleType = StyleRule::Viewport; |
| 45 CSSTokenizer::Scope scope(string); | 48 CSSTokenizer::Scope scope(string); |
| 46 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor tant, ruleType); | 49 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor tant, ruleType); |
| 47 if (parser.m_parsedProperties.isEmpty()) | 50 if (parser.m_parsedProperties.isEmpty()) |
| 48 return false; | 51 return false; |
| 49 return declaration->addParsedProperties(parser.m_parsedProperties); | 52 return declaration->addParsedProperties(parser.m_parsedProperties); |
| 50 } | 53 } |
| 51 | 54 |
| 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 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE ntries, BitArray<numCSSProperties>& seenProperties) |
| 53 { | 56 { |
| 54 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. | 57 // 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--; ) { | 58 for (size_t i = input.size(); i--; ) { |
| 56 const CSSProperty& property = input[i]; | 59 const CSSProperty& property = input[i]; |
| 57 if (property.isImportant() != important) | 60 if (property.isImportant() != important) |
| 58 continue; | 61 continue; |
| 59 const unsigned propertyIDIndex = property.id() - firstCSSProperty; | 62 const unsigned propertyIDIndex = property.id() - firstCSSProperty; |
| 60 if (seenProperties.get(propertyIDIndex)) | 63 if (seenProperties.get(propertyIDIndex) && property.id() != CSSPropertyV ariable) |
| 61 continue; | 64 continue; |
| 62 seenProperties.set(propertyIDIndex); | 65 seenProperties.set(propertyIDIndex); |
| 63 output[--unusedEntries] = property; | 66 output[--unusedEntries] = property; |
| 64 } | 67 } |
| 65 } | 68 } |
| 66 | 69 |
| 67 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) | 70 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) |
| 68 { | 71 { |
| 69 BitArray<numCSSProperties> seenProperties; | 72 BitArray<numCSSProperties> seenProperties; |
| 70 size_t unusedEntries = parsedProperties.size(); | 73 size_t unusedEntries = parsedProperties.size(); |
| 71 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); | 74 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); |
| 72 | 75 |
| 73 filterProperties(true, parsedProperties, results, unusedEntries, seenPropert ies); | 76 filterProperties(true, parsedProperties, results, unusedEntries, seenPropert ies); |
| 74 filterProperties(false, parsedProperties, results, unusedEntries, seenProper ties); | 77 filterProperties(false, parsedProperties, results, unusedEntries, seenProper ties); |
| 75 | 78 |
| 76 RefPtrWillBeRawPtr<ImmutableStylePropertySet> result = ImmutableStylePropert ySet::create(results.data() + unusedEntries, results.size() - unusedEntries, mod e); | 79 RefPtrWillBeRawPtr<ImmutableStylePropertySet> result = ImmutableStylePropert ySet::create(results.data() + unusedEntries, results.size() - unusedEntries, mod e); |
| 77 parsedProperties.clear(); | 80 parsedProperties.clear(); |
| 78 return result.release(); | 81 return result.release(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParserImpl::parseInlineStyl eDeclaration(const String& string, Element* element) | 84 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParserImpl::parseInlineStyl eDeclaration(const String& string, Element* element) |
| 82 { | 85 { |
| 83 Document& document = element->document(); | 86 Document& document = element->document(); |
| 84 CSSParserContext context = CSSParserContext(document.elementSheet().contents ()->parserContext(), UseCounter::getFrom(&document)); | 87 CSSParserContext context = CSSParserContext(document.elementSheet().contents ()->parserContext(), UseCounter::getFrom(&document)); |
| 85 CSSParserMode mode = element->isHTMLElement() && !document.inQuirksMode() ? HTMLStandardMode : HTMLQuirksMode; | 88 CSSParserMode mode = element->isHTMLElement() && !document.inQuirksMode() ? HTMLStandardMode : HTMLQuirksMode; |
| 86 context.setMode(mode); | 89 context.setMode(mode); |
| 87 CSSParserImpl parser(context, document.elementSheet().contents()); | 90 CSSParserImpl parser(context, string, document.elementSheet().contents()); |
| 88 CSSTokenizer::Scope scope(string); | 91 CSSTokenizer::Scope scope(string); |
| 89 parser.consumeDeclarationList(scope.tokenRange(), StyleRule::Style); | 92 parser.consumeDeclarationList(scope.tokenRange(), StyleRule::Style); |
| 90 return createStylePropertySet(parser.m_parsedProperties, mode); | 93 return createStylePropertySet(parser.m_parsedProperties, mode); |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool CSSParserImpl::parseDeclarationList(MutableStylePropertySet* declaration, c onst String& string, const CSSParserContext& context) | 96 bool CSSParserImpl::parseDeclarationList(MutableStylePropertySet* declaration, c onst String& string, const CSSParserContext& context) |
| 94 { | 97 { |
| 95 CSSParserImpl parser(context); | 98 CSSParserImpl parser(context, string); |
| 96 StyleRule::Type ruleType = StyleRule::Style; | 99 StyleRule::Type ruleType = StyleRule::Style; |
| 97 if (declaration->cssParserMode() == CSSViewportRuleMode) | 100 if (declaration->cssParserMode() == CSSViewportRuleMode) |
| 98 ruleType = StyleRule::Viewport; | 101 ruleType = StyleRule::Viewport; |
| 99 CSSTokenizer::Scope scope(string); | 102 CSSTokenizer::Scope scope(string); |
| 100 parser.consumeDeclarationList(scope.tokenRange(), ruleType); | 103 parser.consumeDeclarationList(scope.tokenRange(), ruleType); |
| 101 if (parser.m_parsedProperties.isEmpty()) | 104 if (parser.m_parsedProperties.isEmpty()) |
| 102 return false; | 105 return false; |
| 103 | 106 |
| 104 BitArray<numCSSProperties> seenProperties; | 107 BitArray<numCSSProperties> seenProperties; |
| 105 size_t unusedEntries = parser.m_parsedProperties.size(); | 108 size_t unusedEntries = parser.m_parsedProperties.size(); |
| 106 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); | 109 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); |
| 107 filterProperties(true, parser.m_parsedProperties, results, unusedEntries, se enProperties); | 110 filterProperties(true, parser.m_parsedProperties, results, unusedEntries, se enProperties); |
| 108 filterProperties(false, parser.m_parsedProperties, results, unusedEntries, s eenProperties); | 111 filterProperties(false, parser.m_parsedProperties, results, unusedEntries, s eenProperties); |
| 109 if (unusedEntries) | 112 if (unusedEntries) |
| 110 results.remove(0, unusedEntries); | 113 results.remove(0, unusedEntries); |
| 111 return declaration->addParsedProperties(results); | 114 return declaration->addParsedProperties(results); |
| 112 } | 115 } |
| 113 | 116 |
| 114 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::parseRule(const String& str ing, const CSSParserContext& context, StyleSheetContents* styleSheet, AllowedRul esType allowedRules) | 117 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::parseRule(const String& str ing, const CSSParserContext& context, StyleSheetContents* styleSheet, AllowedRul esType allowedRules) |
| 115 { | 118 { |
| 116 CSSParserImpl parser(context, styleSheet); | 119 CSSParserImpl parser(context, string, styleSheet); |
| 117 CSSTokenizer::Scope scope(string); | 120 CSSTokenizer::Scope scope(string); |
| 118 CSSParserTokenRange range = scope.tokenRange(); | 121 CSSParserTokenRange range = scope.tokenRange(); |
| 119 range.consumeWhitespace(); | 122 range.consumeWhitespace(); |
| 120 if (range.atEnd()) | 123 if (range.atEnd()) |
| 121 return nullptr; // Parse error, empty rule | 124 return nullptr; // Parse error, empty rule |
| 122 RefPtrWillBeRawPtr<StyleRuleBase> rule; | 125 RefPtrWillBeRawPtr<StyleRuleBase> rule; |
| 123 if (range.peek().type() == AtKeywordToken) | 126 if (range.peek().type() == AtKeywordToken) |
| 124 rule = parser.consumeAtRule(range, allowedRules); | 127 rule = parser.consumeAtRule(range, allowedRules); |
| 125 else | 128 else |
| 126 rule = parser.consumeQualifiedRule(range, allowedRules); | 129 rule = parser.consumeQualifiedRule(range, allowedRules); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 137 TRACE_EVENT_BEGIN2( | 140 TRACE_EVENT_BEGIN2( |
| 138 "blink,blink_style", "CSSParserImpl::parseStyleSheet", | 141 "blink,blink_style", "CSSParserImpl::parseStyleSheet", |
| 139 "baseUrl", context.baseURL().string().utf8(), | 142 "baseUrl", context.baseURL().string().utf8(), |
| 140 "mode", context.mode()); | 143 "mode", context.mode()); |
| 141 | 144 |
| 142 TRACE_EVENT_BEGIN0("blink,blink_style", "CSSParserImpl::parseStyleSheet.toke nize"); | 145 TRACE_EVENT_BEGIN0("blink,blink_style", "CSSParserImpl::parseStyleSheet.toke nize"); |
| 143 CSSTokenizer::Scope scope(string); | 146 CSSTokenizer::Scope scope(string); |
| 144 TRACE_EVENT_END0("blink,blink_style", "CSSParserImpl::parseStyleSheet.tokeni ze"); | 147 TRACE_EVENT_END0("blink,blink_style", "CSSParserImpl::parseStyleSheet.tokeni ze"); |
| 145 | 148 |
| 146 TRACE_EVENT_BEGIN0("blink,blink_style", "CSSParserImpl::parseStyleSheet.pars e"); | 149 TRACE_EVENT_BEGIN0("blink,blink_style", "CSSParserImpl::parseStyleSheet.pars e"); |
| 147 CSSParserImpl parser(context, styleSheet); | 150 CSSParserImpl parser(context, string, styleSheet); |
| 148 bool firstRuleValid = parser.consumeRuleList(scope.tokenRange(), TopLevelRul eList, [&styleSheet](PassRefPtrWillBeRawPtr<StyleRuleBase> rule) { | 151 bool firstRuleValid = parser.consumeRuleList(scope.tokenRange(), TopLevelRul eList, [&styleSheet](PassRefPtrWillBeRawPtr<StyleRuleBase> rule) { |
| 149 if (rule->isCharsetRule()) | 152 if (rule->isCharsetRule()) |
| 150 return; | 153 return; |
| 151 styleSheet->parserAppendRule(rule); | 154 styleSheet->parserAppendRule(rule); |
| 152 }); | 155 }); |
| 153 styleSheet->setHasSyntacticallyValidCSSHeader(firstRuleValid); | 156 styleSheet->setHasSyntacticallyValidCSSHeader(firstRuleValid); |
| 154 TRACE_EVENT_END0("blink,blink_style", "CSSParserImpl::parseStyleSheet.parse" ); | 157 TRACE_EVENT_END0("blink,blink_style", "CSSParserImpl::parseStyleSheet.parse" ); |
| 155 | 158 |
| 156 TRACE_EVENT_END2( | 159 TRACE_EVENT_END2( |
| 157 "blink,blink_style", "CSSParserImpl::parseStyleSheet", | 160 "blink,blink_style", "CSSParserImpl::parseStyleSheet", |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 168 { | 171 { |
| 169 ASSERT(m_parsedProperties.isEmpty()); | 172 ASSERT(m_parsedProperties.isEmpty()); |
| 170 consumeDeclaration(range, StyleRule::Style); | 173 consumeDeclaration(range, StyleRule::Style); |
| 171 bool result = !m_parsedProperties.isEmpty(); | 174 bool result = !m_parsedProperties.isEmpty(); |
| 172 m_parsedProperties.clear(); | 175 m_parsedProperties.clear(); |
| 173 return result; | 176 return result; |
| 174 } | 177 } |
| 175 | 178 |
| 176 void CSSParserImpl::parseDeclarationListForInspector(const String& declaration, const CSSParserContext& context, CSSParserObserver& observer) | 179 void CSSParserImpl::parseDeclarationListForInspector(const String& declaration, const CSSParserContext& context, CSSParserObserver& observer) |
| 177 { | 180 { |
| 178 CSSParserImpl parser(context); | 181 CSSParserImpl parser(context, declaration); |
| 179 CSSParserObserverWrapper wrapper(observer); | 182 CSSParserObserverWrapper wrapper(observer); |
| 180 parser.m_observerWrapper = &wrapper; | 183 parser.m_observerWrapper = &wrapper; |
| 181 CSSTokenizer::Scope scope(declaration, wrapper); | 184 CSSTokenizer::Scope scope(declaration, wrapper); |
| 182 observer.startRuleHeader(StyleRule::Style, 0); | 185 observer.startRuleHeader(StyleRule::Style, 0); |
| 183 observer.endRuleHeader(1); | 186 observer.endRuleHeader(1); |
| 184 parser.consumeDeclarationList(scope.tokenRange(), StyleRule::Style); | 187 parser.consumeDeclarationList(scope.tokenRange(), StyleRule::Style); |
| 185 } | 188 } |
| 186 | 189 |
| 187 void CSSParserImpl::parseStyleSheetForInspector(const String& string, const CSSP arserContext& context, StyleSheetContents* styleSheet, CSSParserObserver& observ er) | 190 void CSSParserImpl::parseStyleSheetForInspector(const String& string, const CSSP arserContext& context, StyleSheetContents* styleSheet, CSSParserObserver& observ er) |
| 188 { | 191 { |
| 189 CSSParserImpl parser(context, styleSheet); | 192 CSSParserImpl parser(context, string, styleSheet); |
| 190 CSSParserObserverWrapper wrapper(observer); | 193 CSSParserObserverWrapper wrapper(observer); |
| 191 parser.m_observerWrapper = &wrapper; | 194 parser.m_observerWrapper = &wrapper; |
| 192 CSSTokenizer::Scope scope(string, wrapper); | 195 CSSTokenizer::Scope scope(string, wrapper); |
| 193 bool firstRuleValid = parser.consumeRuleList(scope.tokenRange(), TopLevelRul eList, [&styleSheet](PassRefPtrWillBeRawPtr<StyleRuleBase> rule) { | 196 bool firstRuleValid = parser.consumeRuleList(scope.tokenRange(), TopLevelRul eList, [&styleSheet](PassRefPtrWillBeRawPtr<StyleRuleBase> rule) { |
| 194 if (rule->isCharsetRule()) | 197 if (rule->isCharsetRule()) |
| 195 return; | 198 return; |
| 196 styleSheet->parserAppendRule(rule); | 199 styleSheet->parserAppendRule(rule); |
| 197 }); | 200 }); |
| 198 styleSheet->setHasSyntacticallyValidCSSHeader(firstRuleValid); | 201 styleSheet->setHasSyntacticallyValidCSSHeader(firstRuleValid); |
| 199 } | 202 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 m_observerWrapper->yieldCommentsBefore(range); | 664 m_observerWrapper->yieldCommentsBefore(range); |
| 662 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange)); | 665 m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(r ange)); |
| 663 } | 666 } |
| 664 } | 667 } |
| 665 | 668 |
| 666 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) | 669 void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ e ruleType) |
| 667 { | 670 { |
| 668 CSSParserTokenRange rangeCopy = range; // For inspector callbacks | 671 CSSParserTokenRange rangeCopy = range; // For inspector callbacks |
| 669 | 672 |
| 670 ASSERT(range.peek().type() == IdentToken); | 673 ASSERT(range.peek().type() == IdentToken); |
| 671 CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseA sUnresolvedCSSPropertyID(); | 674 CSSParserToken token = range.consumeIncludingWhitespace(); |
| 675 CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); | |
| 672 if (range.consume().type() != ColonToken) | 676 if (range.consume().type() != ColonToken) |
| 673 return; // Parse error | 677 return; // Parse error |
| 674 | 678 |
| 675 bool important = false; | 679 bool important = false; |
| 676 const CSSParserToken* declarationValueEnd = range.end(); | 680 const CSSParserToken* declarationValueEnd = range.end(); |
| 677 const CSSParserToken* last = range.end() - 1; | 681 const CSSParserToken* last = range.end() - 1; |
| 678 while (last->type() == WhitespaceToken) | 682 while (last->type() == WhitespaceToken) |
| 679 --last; | 683 --last; |
| 684 | |
| 685 if (unresolvedProperty == CSSPropertyVariable) { | |
| 686 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled()); | |
| 687 AtomicString variableName = token.value(); | |
| 688 m_styleSheet->parserSetUsesVariables(true); | |
| 689 consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declar ationValueEnd), variableName); | |
| 690 return; | |
| 691 } | |
| 680 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { | 692 if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important") ) { |
| 681 --last; | 693 --last; |
| 682 while (last->type() == WhitespaceToken) | 694 while (last->type() == WhitespaceToken) |
| 683 --last; | 695 --last; |
| 684 if (last->type() == DelimiterToken && last->delimiter() == '!') { | 696 if (last->type() == DelimiterToken && last->delimiter() == '!') { |
| 685 important = true; | 697 important = true; |
| 686 declarationValueEnd = last; | 698 declarationValueEnd = last; |
| 687 } | 699 } |
| 688 } | 700 } |
| 689 | 701 |
| 690 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes)) | 702 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule:: Keyframes)) |
| 691 return; | 703 return; |
| 692 | 704 |
| 693 if (m_observerWrapper && ruleType == StyleRule::Style) { | 705 if (m_observerWrapper && ruleType == StyleRule::Style) { |
| 694 size_t propertiesCount = m_parsedProperties.size(); | 706 size_t propertiesCount = m_parsedProperties.size(); |
| 695 if (unresolvedProperty != CSSPropertyInvalid) | 707 if (unresolvedProperty != CSSPropertyInvalid) |
| 696 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType); | 708 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio nValueEnd), unresolvedProperty, important, ruleType); |
| 697 m_observerWrapper->observer().observeProperty( | 709 m_observerWrapper->observer().observeProperty( |
| 698 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy), | 710 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff set(rangeCopy), |
| 699 important, m_parsedProperties.size() != propertiesCount); | 711 important, m_parsedProperties.size() != propertiesCount); |
| 712 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationVal ueEnd), unresolvedProperty, important, ruleType); | |
|
Timothy Loh
2015/07/23 08:11:46
What's this line for?
| |
| 700 return; | 713 return; |
| 701 } | 714 } |
| 702 | 715 |
| 703 if (unresolvedProperty == CSSPropertyInvalid) | 716 if (unresolvedProperty == CSSPropertyInvalid) |
| 704 return; | 717 return; |
| 705 | 718 |
| 706 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType); | 719 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn d), unresolvedProperty, important, ruleType); |
| 707 } | 720 } |
| 708 | 721 |
| 722 void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, c onst AtomicString& variableName) | |
| 723 { | |
| 724 bool important; | |
| 725 switch (CSSVariableParser::parseVariableDefinition(range, important)) { | |
| 726 case CSSVariableParser::Invalid: | |
| 727 return; | |
| 728 case CSSVariableParser::Variable: | |
| 729 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, | |
| 730 CSSCustomVariableValue::create(variableName, CSSVariableData::create (range, m_baseString, false)), important)); | |
| 731 return; | |
| 732 case CSSVariableParser::VariableWithReferences: | |
| 733 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, | |
| 734 CSSCustomVariableValue::create(variableName, CSSVariableData::create (range, m_baseString, true)), important)); | |
| 735 return; | |
| 736 case CSSVariableParser::Initial: | |
| 737 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, | |
| 738 CSSCustomVariableValue::create(variableName, CSSValueInitial), impor tant)); | |
| 739 return; | |
| 740 case CSSVariableParser::Inherit: | |
| 741 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, | |
| 742 CSSCustomVariableValue::create(variableName, CSSValueInherit), impor tant)); | |
| 743 return; | |
| 744 case CSSVariableParser::Unset: | |
| 745 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, | |
| 746 CSSCustomVariableValue::create(variableName, CSSValueUnset), importa nt)); | |
| 747 return; | |
| 748 } | |
| 749 } | |
| 750 | |
| 709 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType) | 751 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper tyID unresolvedProperty, bool important, StyleRule::Type ruleType) |
| 710 { | 752 { |
| 711 bool usesRemUnits; | 753 bool usesRemUnits, usesVariables; |
| 712 CSSParserValueList valueList(range, usesRemUnits); | 754 CSSParserValueList valueList(range, m_baseString, usesRemUnits, usesVariable s); |
| 713 if (!valueList.size()) | 755 if (!valueList.size()) |
| 714 return; // Parser error | 756 return; // Parser error |
| 715 if (usesRemUnits && m_styleSheet) | 757 if (m_styleSheet) { |
| 716 m_styleSheet->parserSetUsesRemUnits(true); | 758 if (usesRemUnits) |
| 759 m_styleSheet->parserSetUsesRemUnits(true); | |
| 760 if (usesVariables) | |
| 761 m_styleSheet->parserSetUsesVariables(true); | |
| 762 } | |
| 717 CSSPropertyParser::parseValue(unresolvedProperty, important, &valueList, m_c ontext, m_parsedProperties, ruleType); | 763 CSSPropertyParser::parseValue(unresolvedProperty, important, &valueList, m_c ontext, m_parsedProperties, ruleType); |
| 718 } | 764 } |
| 719 | 765 |
| 720 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) | 766 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR ange range) |
| 721 { | 767 { |
| 722 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); | 768 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); |
| 723 while (true) { | 769 while (true) { |
| 724 range.consumeWhitespace(); | 770 range.consumeWhitespace(); |
| 725 const CSSParserToken& token = range.consumeIncludingWhitespace(); | 771 const CSSParserToken& token = range.consumeIncludingWhitespace(); |
| 726 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100) | 772 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke n.numericValue() <= 100) |
| 727 result->append(token.numericValue() / 100); | 773 result->append(token.numericValue() / 100); |
| 728 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om")) | 774 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("fr om")) |
| 729 result->append(0); | 775 result->append(0); |
| 730 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to ")) | 776 else if (token.type() == IdentToken && token.valueEqualsIgnoringCase("to ")) |
| 731 result->append(1); | 777 result->append(1); |
| 732 else | 778 else |
| 733 return nullptr; // Parser error, invalid value in keyframe selector | 779 return nullptr; // Parser error, invalid value in keyframe selector |
| 734 if (range.atEnd()) | 780 if (range.atEnd()) |
| 735 return result.release(); | 781 return result.release(); |
| 736 if (range.consume().type() != CommaToken) | 782 if (range.consume().type() != CommaToken) |
| 737 return nullptr; // Parser error | 783 return nullptr; // Parser error |
| 738 } | 784 } |
| 739 } | 785 } |
| 740 | 786 |
| 741 } // namespace blink | 787 } // namespace blink |
| OLD | NEW |