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 WillBeHeapVector<CSSPr operty, 256>& input, WillBeHeapVector<CSSProperty, 256>& output, BitArray<numCSS Properties>& 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.append(property); |
64 } | 64 } |
65 output.reverse(); | |
65 } | 66 } |
66 | 67 |
67 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) | 68 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> createStylePropertySet( WillBeHeapVector<CSSProperty, 256>& parsedProperties, CSSParserMode mode) |
68 { | 69 { |
69 BitArray<numCSSProperties> seenProperties; | 70 BitArray<numCSSProperties> seenProperties; |
70 size_t unusedEntries = parsedProperties.size(); | 71 WillBeHeapVector<CSSProperty, 256> results; |
71 WillBeHeapVector<CSSProperty, 256> results(unusedEntries); | 72 results.reserveCapacity(parsedProperties.size()); |
Timothy Loh
2015/06/02 00:42:04
reserveInitialCapacity
sashab
2015/06/05 06:16:30
Done.
| |
72 | 73 |
73 filterProperties(true, parsedProperties, results, unusedEntries, seenPropert ies); | 74 filterProperties(true, parsedProperties, results, seenProperties); |
74 filterProperties(false, parsedProperties, results, unusedEntries, seenProper ties); | 75 filterProperties(false, parsedProperties, results, seenProperties); |
75 | 76 |
76 RefPtrWillBeRawPtr<ImmutableStylePropertySet> result = ImmutableStylePropert ySet::create(results.data() + unusedEntries, results.size() - unusedEntries, mod e); | 77 RefPtrWillBeRawPtr<ImmutableStylePropertySet> result = ImmutableStylePropert ySet::create(results.data(), results.size(), mode); |
77 parsedProperties.clear(); | 78 parsedProperties.clear(); |
78 return result.release(); | 79 return result.release(); |
79 } | 80 } |
80 | 81 |
81 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParserImpl::parseInlineStyl eDeclaration(const String& string, Element* element) | 82 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParserImpl::parseInlineStyl eDeclaration(const String& string, Element* element) |
82 { | 83 { |
83 Document& document = element->document(); | 84 Document& document = element->document(); |
84 CSSParserContext context = CSSParserContext(document.elementSheet().contents ()->parserContext(), UseCounter::getFrom(&document)); | 85 CSSParserContext context = CSSParserContext(document.elementSheet().contents ()->parserContext(), UseCounter::getFrom(&document)); |
85 CSSParserMode mode = element->isHTMLElement() && !document.inQuirksMode() ? HTMLStandardMode : HTMLQuirksMode; | 86 CSSParserMode mode = element->isHTMLElement() && !document.inQuirksMode() ? HTMLStandardMode : HTMLQuirksMode; |
86 context.setMode(mode); | 87 context.setMode(mode); |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 else | 719 else |
719 return nullptr; // Parser error, invalid value in keyframe selector | 720 return nullptr; // Parser error, invalid value in keyframe selector |
720 if (range.atEnd()) | 721 if (range.atEnd()) |
721 return result.release(); | 722 return result.release(); |
722 if (range.consume().type() != CommaToken) | 723 if (range.consume().type() != CommaToken) |
723 return nullptr; // Parser error | 724 return nullptr; // Parser error |
724 } | 725 } |
725 } | 726 } |
726 | 727 |
727 } // namespace blink | 728 } // namespace blink |
OLD | NEW |