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 #ifndef CSSParserImpl_h | 5 #ifndef CSSParserImpl_h |
6 #define CSSParserImpl_h | 6 #define CSSParserImpl_h |
7 | 7 |
8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
9 #include "core/css/CSSProperty.h" | 9 #include "core/css/CSSProperty.h" |
10 #include "core/css/CSSPropertySourceData.h" | 10 #include "core/css/CSSPropertySourceData.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 class StyleRuleSupports; | 34 class StyleRuleSupports; |
35 class StyleRuleViewport; | 35 class StyleRuleViewport; |
36 class StyleSheetContents; | 36 class StyleSheetContents; |
37 class Element; | 37 class Element; |
38 | 38 |
39 class CSSParserImpl { | 39 class CSSParserImpl { |
40 STACK_ALLOCATED(); | 40 STACK_ALLOCATED(); |
41 WTF_MAKE_NONCOPYABLE(CSSParserImpl); | 41 WTF_MAKE_NONCOPYABLE(CSSParserImpl); |
42 | 42 |
43 public: | 43 public: |
44 CSSParserImpl(const CSSParserContext&, StyleSheetContents* = nullptr); | 44 CSSParserImpl(const CSSParserContext*, StyleSheetContents* = nullptr); |
45 | 45 |
46 enum AllowedRulesType { | 46 enum AllowedRulesType { |
47 // As per css-syntax, css-cascade and css-namespaces, @charset rules | 47 // As per css-syntax, css-cascade and css-namespaces, @charset rules |
48 // must come first, followed by @import then @namespace. | 48 // must come first, followed by @import then @namespace. |
49 // AllowImportRules actually means we allow @import and any rules thay | 49 // AllowImportRules actually means we allow @import and any rules thay |
50 // may follow it, i.e. @namespace rules and regular rules. | 50 // may follow it, i.e. @namespace rules and regular rules. |
51 // AllowCharsetRules and AllowNamespaceRules behave similarly. | 51 // AllowCharsetRules and AllowNamespaceRules behave similarly. |
52 AllowCharsetRules, | 52 AllowCharsetRules, |
53 AllowImportRules, | 53 AllowImportRules, |
54 AllowNamespaceRules, | 54 AllowNamespaceRules, |
55 RegularRules, | 55 RegularRules, |
56 KeyframeRules, | 56 KeyframeRules, |
57 ApplyRules, // For @apply inside style rules | 57 ApplyRules, // For @apply inside style rules |
58 NoRules, // For parsing at-rules inside declaration lists | 58 NoRules, // For parsing at-rules inside declaration lists |
59 }; | 59 }; |
60 | 60 |
61 static MutableStylePropertySet::SetResult parseValue(MutableStylePropertySet*, | 61 static MutableStylePropertySet::SetResult parseValue(MutableStylePropertySet*, |
62 CSSPropertyID, | 62 CSSPropertyID, |
63 const String&, | 63 const String&, |
64 bool important, | 64 bool important, |
65 const CSSParserContext&); | 65 const CSSParserContext*); |
66 static MutableStylePropertySet::SetResult parseVariableValue( | 66 static MutableStylePropertySet::SetResult parseVariableValue( |
67 MutableStylePropertySet*, | 67 MutableStylePropertySet*, |
68 const AtomicString& propertyName, | 68 const AtomicString& propertyName, |
69 const PropertyRegistry*, | 69 const PropertyRegistry*, |
70 const String&, | 70 const String&, |
71 bool important, | 71 bool important, |
72 const CSSParserContext&, | 72 const CSSParserContext*, |
73 bool isAnimationTainted); | 73 bool isAnimationTainted); |
74 static ImmutableStylePropertySet* parseInlineStyleDeclaration(const String&, | 74 static ImmutableStylePropertySet* parseInlineStyleDeclaration(const String&, |
75 Element*); | 75 Element*); |
76 static bool parseDeclarationList(MutableStylePropertySet*, | 76 static bool parseDeclarationList(MutableStylePropertySet*, |
77 const String&, | 77 const String&, |
78 const CSSParserContext&); | 78 const CSSParserContext*); |
79 static StyleRuleBase* parseRule(const String&, | 79 static StyleRuleBase* parseRule(const String&, |
80 const CSSParserContext&, | 80 const CSSParserContext*, |
81 StyleSheetContents*, | 81 StyleSheetContents*, |
82 AllowedRulesType); | 82 AllowedRulesType); |
83 static void parseStyleSheet(const String&, | 83 static void parseStyleSheet(const String&, |
84 const CSSParserContext&, | 84 const CSSParserContext*, |
85 StyleSheetContents*, | 85 StyleSheetContents*, |
86 bool deferPropertyParsing = false); | 86 bool deferPropertyParsing = false); |
87 static CSSSelectorList parsePageSelector(CSSParserTokenRange, | 87 static CSSSelectorList parsePageSelector(CSSParserTokenRange, |
88 StyleSheetContents*); | 88 StyleSheetContents*); |
89 | 89 |
90 static ImmutableStylePropertySet* parseCustomPropertySet(CSSParserTokenRange); | 90 static ImmutableStylePropertySet* parseCustomPropertySet(CSSParserTokenRange); |
91 | 91 |
92 static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&); | 92 static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&); |
93 | 93 |
94 bool supportsDeclaration(CSSParserTokenRange&); | 94 bool supportsDeclaration(CSSParserTokenRange&); |
95 | 95 |
96 static void parseDeclarationListForInspector(const String&, | 96 static void parseDeclarationListForInspector(const String&, |
97 const CSSParserContext&, | 97 const CSSParserContext*, |
98 CSSParserObserver&); | 98 CSSParserObserver&); |
99 static void parseStyleSheetForInspector(const String&, | 99 static void parseStyleSheetForInspector(const String&, |
100 const CSSParserContext&, | 100 const CSSParserContext*, |
101 StyleSheetContents*, | 101 StyleSheetContents*, |
102 CSSParserObserver&); | 102 CSSParserObserver&); |
103 | 103 |
104 static StylePropertySet* parseDeclarationListForLazyStyle( | 104 static StylePropertySet* parseDeclarationListForLazyStyle( |
105 CSSParserTokenRange block, | 105 CSSParserTokenRange block, |
106 const CSSParserContext&); | 106 const CSSParserContext*); |
107 | 107 |
108 private: | 108 private: |
109 enum RuleListType { TopLevelRuleList, RegularRuleList, KeyframesRuleList }; | 109 enum RuleListType { TopLevelRuleList, RegularRuleList, KeyframesRuleList }; |
110 | 110 |
111 // Returns whether the first encountered rule was valid | 111 // Returns whether the first encountered rule was valid |
112 template <typename T> | 112 template <typename T> |
113 bool consumeRuleList(CSSParserTokenRange, RuleListType, T callback); | 113 bool consumeRuleList(CSSParserTokenRange, RuleListType, T callback); |
114 | 114 |
115 // These two functions update the range they're given | 115 // These two functions update the range they're given |
116 StyleRuleBase* consumeAtRule(CSSParserTokenRange&, AllowedRulesType); | 116 StyleRuleBase* consumeAtRule(CSSParserTokenRange&, AllowedRulesType); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 const AtomicString& propertyName, | 150 const AtomicString& propertyName, |
151 bool important, | 151 bool important, |
152 bool isAnimationTainted); | 152 bool isAnimationTainted); |
153 | 153 |
154 static std::unique_ptr<Vector<double>> consumeKeyframeKeyList( | 154 static std::unique_ptr<Vector<double>> consumeKeyframeKeyList( |
155 CSSParserTokenRange); | 155 CSSParserTokenRange); |
156 | 156 |
157 // FIXME: Can we build StylePropertySets directly? | 157 // FIXME: Can we build StylePropertySets directly? |
158 // FIXME: Investigate using a smaller inline buffer | 158 // FIXME: Investigate using a smaller inline buffer |
159 HeapVector<CSSProperty, 256> m_parsedProperties; | 159 HeapVector<CSSProperty, 256> m_parsedProperties; |
160 const CSSParserContext& m_context; | |
161 | 160 |
| 161 Member<const CSSParserContext> m_context; |
162 Member<StyleSheetContents> m_styleSheet; | 162 Member<StyleSheetContents> m_styleSheet; |
163 | 163 |
164 // For the inspector | 164 // For the inspector |
165 CSSParserObserverWrapper* m_observerWrapper; | 165 CSSParserObserverWrapper* m_observerWrapper; |
166 | 166 |
167 Member<CSSLazyParsingState> m_lazyState; | 167 Member<CSSLazyParsingState> m_lazyState; |
168 }; | 168 }; |
169 | 169 |
170 } // namespace blink | 170 } // namespace blink |
171 | 171 |
172 #endif // CSSParserImpl_h | 172 #endif // CSSParserImpl_h |
OLD | NEW |