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, size_t& unused
Entries, BitArray<numCSSProperties>& 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(
WillBeHeapVector<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 WillBeHeapVector<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 |
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); |
87 CSSParserImpl parser(context, document.elementSheet().contents()); | 88 CSSParserImpl parser(context, document.elementSheet().contents()); |
88 CSSTokenizer::Scope scope(string); | 89 CSSTokenizer::Scope scope(string); |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 else | 733 else |
733 return nullptr; // Parser error, invalid value in keyframe selector | 734 return nullptr; // Parser error, invalid value in keyframe selector |
734 if (range.atEnd()) | 735 if (range.atEnd()) |
735 return result.release(); | 736 return result.release(); |
736 if (range.consume().type() != CommaToken) | 737 if (range.consume().type() != CommaToken) |
737 return nullptr; // Parser error | 738 return nullptr; // Parser error |
738 } | 739 } |
739 } | 740 } |
740 | 741 |
741 } // namespace blink | 742 } // namespace blink |
OLD | NEW |