#pragma once
#include "CSSDeferredParser.h"
#include "CSSParser.h"
#include "CSSParserTokenRange.h"
#include "CSSPropertyNames.h"
#include "StyleRule.h"
#include <memory>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class CSSParserObserver;
class CSSParserObserverWrapper;
class CSSSelectorList;
class CSSTokenizer;
class StyleRuleKeyframe;
class StyleRule;
class StyleRuleBase;
class StyleRuleCharset;
class StyleRuleFontFace;
class StyleRuleImport;
class StyleRuleKeyframes;
class StyleRuleMedia;
class StyleRuleNamespace;
class StyleRulePage;
class StyleRuleSupports;
class StyleRuleViewport;
class StyleSheetContents;
class ImmutableStyleProperties;
class Element;
class MutableStyleProperties;
class CSSParserImpl {
WTF_MAKE_NONCOPYABLE(CSSParserImpl);
public:
CSSParserImpl(const CSSParserContext&, const String&, StyleSheetContents* = nullptr, CSSParserObserverWrapper* = nullptr, CSSParser::RuleParsing = CSSParser::RuleParsing::Normal);
enum AllowedRulesType {
AllowCharsetRules,
AllowImportRules,
AllowNamespaceRules,
RegularRules,
KeyframeRules,
ApplyRules, NoRules, };
static CSSParser::ParseResult parseValue(MutableStyleProperties*, CSSPropertyID, const String&, bool important, const CSSParserContext&);
static CSSParser::ParseResult parseCustomPropertyValue(MutableStyleProperties*, const AtomString& propertyName, const String&, bool important, const CSSParserContext&);
static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, const Element*);
static bool parseDeclarationList(MutableStyleProperties*, const String&, const CSSParserContext&);
static RefPtr<StyleRuleBase> parseRule(const String&, const CSSParserContext&, StyleSheetContents*, AllowedRulesType);
static void parseStyleSheet(const String&, const CSSParserContext&, StyleSheetContents*, CSSParser::RuleParsing);
static CSSSelectorList parsePageSelector(CSSParserTokenRange, StyleSheetContents*);
static Vector<double> parseKeyframeKeyList(const String&);
bool supportsDeclaration(CSSParserTokenRange&);
const CSSParserContext& context() const { return m_context; }
static void parseDeclarationListForInspector(const String&, const CSSParserContext&, CSSParserObserver&);
static void parseStyleSheetForInspector(const String&, const CSSParserContext&, StyleSheetContents*, CSSParserObserver&);
static Ref<ImmutableStyleProperties> parseDeferredDeclaration(CSSParserTokenRange, const CSSParserContext&, StyleSheetContents*);
static void parseDeferredRuleList(CSSParserTokenRange, CSSDeferredParser&, Vector<RefPtr<StyleRuleBase>>&);
static void parseDeferredKeyframeList(CSSParserTokenRange, CSSDeferredParser&, StyleRuleKeyframes&);
CSSTokenizer* tokenizer() const { return m_tokenizer.get(); };
CSSDeferredParser* deferredParser() const { return m_deferredParser.get(); }
private:
CSSParserImpl(const CSSParserContext&, StyleSheetContents*);
CSSParserImpl(CSSDeferredParser&);
enum RuleListType {
TopLevelRuleList,
RegularRuleList,
KeyframesRuleList
};
template<typename T>
bool consumeRuleList(CSSParserTokenRange, RuleListType, T callback);
RefPtr<StyleRuleBase> consumeAtRule(CSSParserTokenRange&, AllowedRulesType);
RefPtr<StyleRuleBase> consumeQualifiedRule(CSSParserTokenRange&, AllowedRulesType);
static RefPtr<StyleRuleCharset> consumeCharsetRule(CSSParserTokenRange prelude);
RefPtr<StyleRuleImport> consumeImportRule(CSSParserTokenRange prelude);
RefPtr<StyleRuleNamespace> consumeNamespaceRule(CSSParserTokenRange prelude);
RefPtr<StyleRuleMedia> consumeMediaRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRuleSupports> consumeSupportsRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRuleViewport> consumeViewportRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRuleFontFace> consumeFontFaceRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRuleKeyframes> consumeKeyframesRule(bool webkitPrefixed, CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRulePage> consumePageRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRuleKeyframe> consumeKeyframeStyleRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
RefPtr<StyleRule> consumeStyleRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
void consumeDeclarationList(CSSParserTokenRange, StyleRuleType);
void consumeDeclaration(CSSParserTokenRange, StyleRuleType);
void consumeDeclarationValue(CSSParserTokenRange, CSSPropertyID, bool important, StyleRuleType);
void consumeCustomPropertyValue(CSSParserTokenRange, const AtomString& propertyName, bool important);
bool isPropertyRuntimeDisabled(CSSPropertyID) const;
static Vector<double> consumeKeyframeKeyList(CSSParserTokenRange);
Ref<DeferredStyleProperties> createDeferredStyleProperties(const CSSParserTokenRange& propertyRange);
void adoptTokenizerEscapedStrings();
ParsedPropertyVector m_parsedProperties;
const CSSParserContext& m_context;
RefPtr<StyleSheetContents> m_styleSheet;
RefPtr<CSSDeferredParser> m_deferredParser;
std::unique_ptr<CSSTokenizer> m_tokenizer;
CSSParserObserverWrapper* m_observerWrapper { nullptr };
};
}