| 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/CSSCustomPropertyDeclaration.h" |
| 9 #include "core/css/CSSKeyframesRule.h" | 9 #include "core/css/CSSKeyframesRule.h" |
| 10 #include "core/css/CSSStyleSheet.h" | 10 #include "core/css/CSSStyleSheet.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 StyleRule::Type ruleType = StyleRule::Style; | 44 StyleRule::Type ruleType = StyleRule::Style; |
| 45 if (declaration->cssParserMode() == CSSViewportRuleMode) | 45 if (declaration->cssParserMode() == CSSViewportRuleMode) |
| 46 ruleType = StyleRule::Viewport; | 46 ruleType = StyleRule::Viewport; |
| 47 CSSTokenizer::Scope scope(string); | 47 CSSTokenizer::Scope scope(string); |
| 48 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor
tant, ruleType); | 48 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor
tant, ruleType); |
| 49 if (parser.m_parsedProperties.isEmpty()) | 49 if (parser.m_parsedProperties.isEmpty()) |
| 50 return false; | 50 return false; |
| 51 return declaration->addParsedProperties(parser.m_parsedProperties); | 51 return declaration->addParsedProperties(parser.m_parsedProperties); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool CSSParserImpl::parseVariableValue(MutableStylePropertySet* declaration, con
st AtomicString& propertyName, const String& value, bool important, const CSSPar
serContext& context) |
| 55 { |
| 56 CSSParserImpl parser(context); |
| 57 CSSTokenizer::Scope scope(value); |
| 58 parser.consumeVariableValue(scope.tokenRange(), propertyName, important); |
| 59 if (parser.m_parsedProperties.isEmpty()) |
| 60 return false; |
| 61 return declaration->addParsedProperties(parser.m_parsedProperties); |
| 62 } |
| 63 |
| 54 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr
operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE
ntries, BitArray<numCSSProperties>& seenProperties) | 64 static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr
operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, size_t& unusedE
ntries, BitArray<numCSSProperties>& seenProperties) |
| 55 { | 65 { |
| 56 // Add properties in reverse order so that highest priority definitions are
reached first. Duplicate definitions can then be ignored when found. | 66 // 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--; ) { | 67 for (size_t i = input.size(); i--; ) { |
| 58 const CSSProperty& property = input[i]; | 68 const CSSProperty& property = input[i]; |
| 59 if (property.isImportant() != important) | 69 if (property.isImportant() != important) |
| 60 continue; | 70 continue; |
| 61 const unsigned propertyIDIndex = property.id(); | 71 const unsigned propertyIDIndex = property.id(); |
| 62 // All custom properties use the same CSSPropertyID so we can't remove r
epeated definitions | 72 // All custom properties use the same CSSPropertyID so we can't remove r
epeated definitions |
| 63 if (property.id() != CSSPropertyVariable) { | 73 if (property.id() != CSSPropertyVariable) { |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 --last; | 701 --last; |
| 692 while (last->type() == WhitespaceToken) | 702 while (last->type() == WhitespaceToken) |
| 693 --last; | 703 --last; |
| 694 if (last->type() == DelimiterToken && last->delimiter() == '!') { | 704 if (last->type() == DelimiterToken && last->delimiter() == '!') { |
| 695 important = true; | 705 important = true; |
| 696 declarationValueEnd = last; | 706 declarationValueEnd = last; |
| 697 } | 707 } |
| 698 } | 708 } |
| 699 if (RuntimeEnabledFeatures::cssVariablesEnabled() && unresolvedProperty == C
SSPropertyInvalid && CSSVariableParser::isValidVariableName(token)) { | 709 if (RuntimeEnabledFeatures::cssVariablesEnabled() && unresolvedProperty == C
SSPropertyInvalid && CSSVariableParser::isValidVariableName(token)) { |
| 700 AtomicString variableName = token.value(); | 710 AtomicString variableName = token.value(); |
| 701 consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declar
ationValueEnd), variableName, important); | 711 consumeVariableValue(range.makeSubRange(&range.peek(), declarationValueE
nd), variableName, important); |
| 702 return; | 712 return; |
| 703 } | 713 } |
| 704 | 714 |
| 705 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule::
Keyframes)) | 715 if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule::
Keyframes)) |
| 706 return; | 716 return; |
| 707 | 717 |
| 708 if (m_observerWrapper && ruleType == StyleRule::Style) { | 718 if (m_observerWrapper && ruleType == StyleRule::Style) { |
| 709 size_t propertiesCount = m_parsedProperties.size(); | 719 size_t propertiesCount = m_parsedProperties.size(); |
| 710 if (unresolvedProperty != CSSPropertyInvalid) | 720 if (unresolvedProperty != CSSPropertyInvalid) |
| 711 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio
nValueEnd), unresolvedProperty, important, ruleType); | 721 consumeDeclarationValue(range.makeSubRange(&range.peek(), declaratio
nValueEnd), unresolvedProperty, important, ruleType); |
| 712 m_observerWrapper->observer().observeProperty( | 722 m_observerWrapper->observer().observeProperty( |
| 713 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff
set(rangeCopy), | 723 m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOff
set(rangeCopy), |
| 714 important, m_parsedProperties.size() != propertiesCount); | 724 important, m_parsedProperties.size() != propertiesCount); |
| 715 return; | 725 return; |
| 716 } | 726 } |
| 717 | 727 |
| 718 if (unresolvedProperty == CSSPropertyInvalid) | 728 if (unresolvedProperty == CSSPropertyInvalid) |
| 719 return; | 729 return; |
| 720 | 730 |
| 721 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn
d), unresolvedProperty, important, ruleType); | 731 consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEn
d), unresolvedProperty, important, ruleType); |
| 722 } | 732 } |
| 723 | 733 |
| 724 void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, c
onst AtomicString& variableName, bool important) | 734 void CSSParserImpl::consumeVariableValue(CSSParserTokenRange range, const Atomic
String& variableName, bool important) |
| 725 { | 735 { |
| 726 if (RefPtrWillBeRawPtr<CSSCustomPropertyDeclaration> value = CSSVariablePars
er::parseDeclarationValue(variableName, range)) | 736 if (RefPtrWillBeRawPtr<CSSCustomPropertyDeclaration> value = CSSVariablePars
er::parseDeclarationValue(variableName, range)) |
| 727 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, value.release
(), important)); | 737 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, value.release
(), important)); |
| 728 } | 738 } |
| 729 | 739 |
| 730 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper
tyID unresolvedProperty, bool important, StyleRule::Type ruleType) | 740 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper
tyID unresolvedProperty, bool important, StyleRule::Type ruleType) |
| 731 { | 741 { |
| 732 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex
t, m_parsedProperties, ruleType); | 742 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex
t, m_parsedProperties, ruleType); |
| 733 } | 743 } |
| 734 | 744 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 747 else | 757 else |
| 748 return nullptr; // Parser error, invalid value in keyframe selector | 758 return nullptr; // Parser error, invalid value in keyframe selector |
| 749 if (range.atEnd()) | 759 if (range.atEnd()) |
| 750 return result.release(); | 760 return result.release(); |
| 751 if (range.consume().type() != CommaToken) | 761 if (range.consume().type() != CommaToken) |
| 752 return nullptr; // Parser error | 762 return nullptr; // Parser error |
| 753 } | 763 } |
| 754 } | 764 } |
| 755 | 765 |
| 756 } // namespace blink | 766 } // namespace blink |
| OLD | NEW |