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/CSSKeyframesRule.h" | 8 #include "core/css/CSSKeyframesRule.h" |
9 #include "core/css/CSSStyleSheet.h" | 9 #include "core/css/CSSStyleSheet.h" |
10 #include "core/css/StylePropertySet.h" | 10 #include "core/css/StylePropertySet.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 StyleRule::Type ruleType = StyleRule::Style; | 42 StyleRule::Type ruleType = StyleRule::Style; |
43 if (declaration->cssParserMode() == CSSViewportRuleMode) | 43 if (declaration->cssParserMode() == CSSViewportRuleMode) |
44 ruleType = StyleRule::Viewport; | 44 ruleType = StyleRule::Viewport; |
45 CSSTokenizer::Scope scope(string); | 45 CSSTokenizer::Scope scope(string); |
46 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor
tant, ruleType); | 46 parser.consumeDeclarationValue(scope.tokenRange(), unresolvedProperty, impor
tant, ruleType); |
47 if (parser.m_parsedProperties.isEmpty()) | 47 if (parser.m_parsedProperties.isEmpty()) |
48 return false; | 48 return false; |
49 return declaration->addParsedProperties(parser.m_parsedProperties); | 49 return declaration->addParsedProperties(parser.m_parsedProperties); |
50 } | 50 } |
51 | 51 |
52 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 Vector<CSSProperty, 25
6>& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<num
CSSProperties>& seenProperties) |
53 { | 53 { |
54 // 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. |
55 for (size_t i = input.size(); i--; ) { | 55 for (size_t i = input.size(); i--; ) { |
56 const CSSProperty& property = input[i]; | 56 const CSSProperty& property = input[i]; |
57 if (property.isImportant() != important) | 57 if (property.isImportant() != important) |
58 continue; | 58 continue; |
59 const unsigned propertyIDIndex = property.id() - firstCSSProperty; | 59 const unsigned propertyIDIndex = property.id() - firstCSSProperty; |
60 if (seenProperties.get(propertyIDIndex)) | 60 if (seenProperties.get(propertyIDIndex)) |
61 continue; | 61 continue; |
62 seenProperties.set(propertyIDIndex); | 62 seenProperties.set(propertyIDIndex); |
63 output[--unusedEntries] = property; | 63 output[--unusedEntries] = property; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet(
WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) | 67 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet(
Vector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) |
68 { | 68 { |
69 BitArray<numCSSProperties> seenProperties; | 69 BitArray<numCSSProperties> seenProperties; |
70 size_t unusedEntries = parsedProperties.size(); | 70 size_t unusedEntries = parsedProperties.size(); |
71 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); | 71 Vector<CSSProperty, 256> results(unusedEntries); |
72 | 72 |
73 filterProperties(true, parsedProperties, results, unusedEntries, seenPropert
ies); | 73 filterProperties(true, parsedProperties, results, unusedEntries, seenPropert
ies); |
74 filterProperties(false, parsedProperties, results, unusedEntries, seenProper
ties); | 74 filterProperties(false, parsedProperties, results, unusedEntries, seenProper
ties); |
75 | 75 |
76 RefPtrWillBeRawPtr<ImmutableStylePropertySet> result = ImmutableStylePropert
ySet::create(results.data() + unusedEntries, results.size() - unusedEntries, mod
e); | 76 RefPtrWillBeRawPtr<ImmutableStylePropertySet> result = ImmutableStylePropert
ySet::create(results.data() + unusedEntries, results.size() - unusedEntries, mod
e); |
77 parsedProperties.clear(); | 77 parsedProperties.clear(); |
78 return result.release(); | 78 return result.release(); |
79 } | 79 } |
80 | 80 |
81 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParserImpl::parseInlineStyl
eDeclaration(const String& string, Element* element) | 81 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParserImpl::parseInlineStyl
eDeclaration(const String& string, Element* element) |
(...skipping 14 matching lines...) Expand all Loading... |
96 StyleRule::Type ruleType = StyleRule::Style; | 96 StyleRule::Type ruleType = StyleRule::Style; |
97 if (declaration->cssParserMode() == CSSViewportRuleMode) | 97 if (declaration->cssParserMode() == CSSViewportRuleMode) |
98 ruleType = StyleRule::Viewport; | 98 ruleType = StyleRule::Viewport; |
99 CSSTokenizer::Scope scope(string); | 99 CSSTokenizer::Scope scope(string); |
100 parser.consumeDeclarationList(scope.tokenRange(), ruleType); | 100 parser.consumeDeclarationList(scope.tokenRange(), ruleType); |
101 if (parser.m_parsedProperties.isEmpty()) | 101 if (parser.m_parsedProperties.isEmpty()) |
102 return false; | 102 return false; |
103 | 103 |
104 BitArray<numCSSProperties> seenProperties; | 104 BitArray<numCSSProperties> seenProperties; |
105 size_t unusedEntries = parser.m_parsedProperties.size(); | 105 size_t unusedEntries = parser.m_parsedProperties.size(); |
106 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); | 106 Vector<CSSProperty, 256> results(unusedEntries); |
107 filterProperties(true, parser.m_parsedProperties, results, unusedEntries, se
enProperties); | 107 filterProperties(true, parser.m_parsedProperties, results, unusedEntries, se
enProperties); |
108 filterProperties(false, parser.m_parsedProperties, results, unusedEntries, s
eenProperties); | 108 filterProperties(false, parser.m_parsedProperties, results, unusedEntries, s
eenProperties); |
109 if (unusedEntries) | 109 if (unusedEntries) |
110 results.remove(0, unusedEntries); | 110 results.remove(0, unusedEntries); |
111 return declaration->addParsedProperties(results); | 111 return declaration->addParsedProperties(results); |
112 } | 112 } |
113 | 113 |
114 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::parseRule(const String& str
ing, const CSSParserContext& context, StyleSheetContents* styleSheet, AllowedRul
esType allowedRules) | 114 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::parseRule(const String& str
ing, const CSSParserContext& context, StyleSheetContents* styleSheet, AllowedRul
esType allowedRules) |
115 { | 115 { |
116 CSSParserImpl parser(context, styleSheet); | 116 CSSParserImpl parser(context, styleSheet); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 else | 729 else |
730 return nullptr; // Parser error, invalid value in keyframe selector | 730 return nullptr; // Parser error, invalid value in keyframe selector |
731 if (range.atEnd()) | 731 if (range.atEnd()) |
732 return result.release(); | 732 return result.release(); |
733 if (range.consume().type() != CommaToken) | 733 if (range.consume().type() != CommaToken) |
734 return nullptr; // Parser error | 734 return nullptr; // Parser error |
735 } | 735 } |
736 } | 736 } |
737 | 737 |
738 } // namespace blink | 738 } // namespace blink |
OLD | NEW |