| 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" |
| 11 #include "core/css/StylePropertySet.h" | 11 #include "core/css/StylePropertySet.h" |
| 12 #include "core/css/parser/CSSParserTokenRange.h" | 12 #include "core/css/parser/CSSParserTokenRange.h" |
| 13 #include "core/css/parser/CSSParserTokenStream.h" |
| 13 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
| 14 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
| 15 #include "wtf/text/WTFString.h" | 16 #include "wtf/text/WTFString.h" |
| 16 #include <memory> | 17 #include <memory> |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 class CSSLazyParsingState; | 21 class CSSLazyParsingState; |
| 21 class CSSParserContext; | 22 class CSSParserContext; |
| 22 class CSSParserObserver; | 23 class CSSParserObserver; |
| 23 class CSSParserObserverWrapper; | |
| 24 class StyleRule; | 24 class StyleRule; |
| 25 class StyleRuleBase; | 25 class StyleRuleBase; |
| 26 class StyleRuleCharset; | 26 class StyleRuleCharset; |
| 27 class StyleRuleFontFace; | 27 class StyleRuleFontFace; |
| 28 class StyleRuleImport; | 28 class StyleRuleImport; |
| 29 class StyleRuleKeyframe; | 29 class StyleRuleKeyframe; |
| 30 class StyleRuleKeyframes; | 30 class StyleRuleKeyframes; |
| 31 class StyleRuleMedia; | 31 class StyleRuleMedia; |
| 32 class StyleRuleNamespace; | 32 class StyleRuleNamespace; |
| 33 class StyleRulePage; | 33 class StyleRulePage; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // This will be removed when crbug.com/661854 is fixed. We need to use a |
| 92 // stream for parsing @apply blocks so we can correctly store custom |
| 93 // property values. |
| 94 void consumeDeclarationListForAtApply(CSSParserTokenRange); |
| 91 | 95 |
| 92 static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&); | 96 static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&); |
| 93 | 97 |
| 94 bool supportsDeclaration(CSSParserTokenRange&); | 98 bool supportsDeclaration(CSSParserTokenRange&); |
| 95 | 99 |
| 96 static void parseDeclarationListForInspector(const String&, | 100 static void parseDeclarationListForInspector(const String&, |
| 97 const CSSParserContext&, | 101 const CSSParserContext&, |
| 98 CSSParserObserver&); | 102 CSSParserObserver&); |
| 99 static void parseStyleSheetForInspector(const String&, | 103 static void parseStyleSheetForInspector(const String&, |
| 100 const CSSParserContext&, | 104 const CSSParserContext&, |
| 101 StyleSheetContents*, | 105 StyleSheetContents*, |
| 102 CSSParserObserver&); | 106 CSSParserObserver&); |
| 103 | 107 |
| 104 static StylePropertySet* parseDeclarationListForLazyStyle( | 108 static StylePropertySet* parseDeclarationListForLazyStyle( |
| 105 CSSParserTokenRange block, | 109 const String&, |
| 110 size_t startOffset, |
| 106 const CSSParserContext&); | 111 const CSSParserContext&); |
| 107 | 112 |
| 108 private: | 113 private: |
| 109 enum RuleListType { TopLevelRuleList, RegularRuleList, KeyframesRuleList }; | 114 enum RuleListType { TopLevelRuleList, RegularRuleList, KeyframesRuleList }; |
| 110 | 115 |
| 111 // Returns whether the first encountered rule was valid | 116 // Returns whether the first encountered rule was valid |
| 112 template <typename T> | 117 template <typename T> |
| 113 bool consumeRuleList(CSSParserTokenRange, RuleListType, T callback); | 118 bool consumeRuleList(CSSParserTokenStream&, RuleListType, T callback); |
| 114 | 119 |
| 115 // These two functions update the range they're given | 120 StyleRuleBase* consumeAtRule(CSSParserTokenStream&, AllowedRulesType); |
| 116 StyleRuleBase* consumeAtRule(CSSParserTokenRange&, AllowedRulesType); | 121 // The start offset is needed when we use a CSSParserObserver |
| 117 StyleRuleBase* consumeQualifiedRule(CSSParserTokenRange&, AllowedRulesType); | 122 StyleRuleBase* consumeQualifiedRule(CSSParserTokenStream&, |
| 123 AllowedRulesType, |
| 124 size_t startOffset = 0); |
| 118 | 125 |
| 119 static StyleRuleCharset* consumeCharsetRule(CSSParserTokenRange prelude); | 126 static StyleRuleCharset* consumeCharsetRule(CSSParserTokenRange prelude); |
| 120 StyleRuleImport* consumeImportRule(CSSParserTokenRange prelude); | 127 StyleRuleImport* consumeImportRule(CSSParserTokenRange prelude, |
| 128 size_t startOffset, |
| 129 size_t endOffset); |
| 121 StyleRuleNamespace* consumeNamespaceRule(CSSParserTokenRange prelude); | 130 StyleRuleNamespace* consumeNamespaceRule(CSSParserTokenRange prelude); |
| 131 // The prelude runs from preludeStartOffset to block.offset() - 1 |
| 122 StyleRuleMedia* consumeMediaRule(CSSParserTokenRange prelude, | 132 StyleRuleMedia* consumeMediaRule(CSSParserTokenRange prelude, |
| 123 CSSParserTokenRange block); | 133 CSSParserTokenStream& block, |
| 134 size_t preludeStartOffset); |
| 124 StyleRuleSupports* consumeSupportsRule(CSSParserTokenRange prelude, | 135 StyleRuleSupports* consumeSupportsRule(CSSParserTokenRange prelude, |
| 125 CSSParserTokenRange block); | 136 CSSParserTokenStream& block, |
| 137 size_t preludeStartOffset); |
| 126 StyleRuleViewport* consumeViewportRule(CSSParserTokenRange prelude, | 138 StyleRuleViewport* consumeViewportRule(CSSParserTokenRange prelude, |
| 127 CSSParserTokenRange block); | 139 CSSParserTokenStream& block, |
| 140 size_t preludeStartOffset); |
| 128 StyleRuleFontFace* consumeFontFaceRule(CSSParserTokenRange prelude, | 141 StyleRuleFontFace* consumeFontFaceRule(CSSParserTokenRange prelude, |
| 129 CSSParserTokenRange block); | 142 CSSParserTokenStream& block, |
| 143 size_t preludeStartOffset); |
| 130 StyleRuleKeyframes* consumeKeyframesRule(bool webkitPrefixed, | 144 StyleRuleKeyframes* consumeKeyframesRule(bool webkitPrefixed, |
| 131 CSSParserTokenRange prelude, | 145 CSSParserTokenRange prelude, |
| 132 CSSParserTokenRange block); | 146 CSSParserTokenStream& block, |
| 147 size_t preludeStartOffset); |
| 133 StyleRulePage* consumePageRule(CSSParserTokenRange prelude, | 148 StyleRulePage* consumePageRule(CSSParserTokenRange prelude, |
| 134 CSSParserTokenRange block); | 149 CSSParserTokenStream& block, |
| 150 size_t preludeStartOffset); |
| 135 // Updates m_parsedProperties | 151 // Updates m_parsedProperties |
| 136 void consumeApplyRule(CSSParserTokenRange prelude); | 152 void consumeApplyRule(CSSParserTokenRange prelude); |
| 137 | 153 |
| 138 StyleRuleKeyframe* consumeKeyframeStyleRule(CSSParserTokenRange prelude, | 154 StyleRuleKeyframe* consumeKeyframeStyleRule(CSSParserTokenRange prelude, |
| 139 CSSParserTokenRange block); | 155 CSSParserTokenStream& block, |
| 140 StyleRule* consumeStyleRule(CSSParserTokenRange prelude, | 156 size_t preludeStartOffset); |
| 141 CSSParserTokenRange block); | 157 StyleRule* consumeStyleRule(CSSParserTokenStream&, size_t startOffset); |
| 142 | 158 |
| 143 void consumeDeclarationList(CSSParserTokenRange, StyleRule::RuleType); | 159 void consumeDeclarationList(CSSParserTokenStream&, StyleRule::RuleType); |
| 144 void consumeDeclaration(CSSParserTokenRange, StyleRule::RuleType); | 160 void consumeDeclaration(CSSParserTokenStream&, |
| 161 StyleRule::RuleType, |
| 162 size_t declarationStartOffset); |
| 163 void consumeDeclaration(CSSParserTokenRange, |
| 164 StyleRule::RuleType, |
| 165 size_t declarationStartOffset, |
| 166 size_t declarationEndOffset); |
| 145 void consumeDeclarationValue(CSSParserTokenRange, | 167 void consumeDeclarationValue(CSSParserTokenRange, |
| 146 CSSPropertyID, | 168 CSSPropertyID, |
| 147 bool important, | 169 bool important, |
| 148 StyleRule::RuleType); | 170 StyleRule::RuleType); |
| 149 void consumeVariableValue(CSSParserTokenRange, | 171 void consumeVariableValue(CSSParserTokenRange, |
| 150 const AtomicString& propertyName, | 172 const AtomicString& propertyName, |
| 151 bool important, | 173 bool important, |
| 152 bool isAnimationTainted); | 174 bool isAnimationTainted); |
| 153 | 175 |
| 154 static std::unique_ptr<Vector<double>> consumeKeyframeKeyList( | 176 static std::unique_ptr<Vector<double>> consumeKeyframeKeyList( |
| 155 CSSParserTokenRange); | 177 CSSParserTokenRange); |
| 156 | 178 |
| 157 // FIXME: Can we build StylePropertySets directly? | 179 // FIXME: Can we build StylePropertySets directly? |
| 158 // FIXME: Investigate using a smaller inline buffer | 180 // FIXME: Investigate using a smaller inline buffer |
| 159 HeapVector<CSSProperty, 256> m_parsedProperties; | 181 HeapVector<CSSProperty, 256> m_parsedProperties; |
| 160 const CSSParserContext& m_context; | 182 const CSSParserContext& m_context; |
| 161 | 183 |
| 162 Member<StyleSheetContents> m_styleSheet; | 184 Member<StyleSheetContents> m_styleSheet; |
| 163 | 185 |
| 164 // For the inspector | 186 Member<CSSLazyParsingState> m_lazyState; |
| 165 CSSParserObserverWrapper* m_observerWrapper; | |
| 166 | 187 |
| 167 Member<CSSLazyParsingState> m_lazyState; | 188 CSSParserObserver* m_observer = nullptr; |
| 168 }; | 189 }; |
| 169 | 190 |
| 170 } // namespace blink | 191 } // namespace blink |
| 171 | 192 |
| 172 #endif // CSSParserImpl_h | 193 #endif // CSSParserImpl_h |
| OLD | NEW |