/* * Copyright (C) 2003 Lars Knoll (knoll@kde.org) * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. * Copyright (C) 2008 Eric Seidel * Copyright (C) 2009 - 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef SKY_ENGINE_CORE_CSS_PARSER_BISONCSSPARSER_H_ #define SKY_ENGINE_CORE_CSS_PARSER_BISONCSSPARSER_H_ #include "gen/sky/core/CSSPropertyNames.h" #include "gen/sky/core/CSSValueKeywords.h" #include "sky/engine/core/css/CSSCalculationValue.h" #include "sky/engine/core/css/CSSFilterValue.h" #include "sky/engine/core/css/CSSGradientValue.h" #include "sky/engine/core/css/CSSProperty.h" #include "sky/engine/core/css/CSSPropertySourceData.h" #include "sky/engine/core/css/CSSSelector.h" #include "sky/engine/core/css/StylePropertySet.h" #include "sky/engine/core/css/parser/CSSParserMode.h" #include "sky/engine/core/css/parser/CSSParserObserver.h" #include "sky/engine/core/css/parser/CSSParserValues.h" #include "sky/engine/core/css/parser/CSSPropertyParser.h" #include "sky/engine/core/css/parser/CSSTokenizer.h" #include "sky/engine/platform/graphics/Color.h" #include "sky/engine/wtf/HashSet.h" #include "sky/engine/wtf/OwnPtr.h" #include "sky/engine/wtf/Vector.h" #include "sky/engine/wtf/text/AtomicString.h" #include "sky/engine/wtf/text/TextPosition.h" namespace blink { class AnimationParseContext; class CSSBasicShape; class CSSBasicShapeInset; class CSSBorderImageSliceValue; class CSSPrimitiveValue; class CSSSelectorList; class CSSValue; class CSSValueList; class Document; class Element; class ImmutableStylePropertySet; class MutableStylePropertySet; class StyleColor; class StylePropertyShorthand; class StyleRuleBase; class StyleSheetContents; // FIXME: This class is shared with CSSTokenizer so should we rename it to CSSSourceLocation? struct CSSParserLocation { unsigned offset; unsigned lineNumber; CSSParserString token; }; class BisonCSSParser { STACK_ALLOCATED(); friend inline int cssyylex(void*, BisonCSSParser*); public: explicit BisonCSSParser(const CSSParserContext&); ~BisonCSSParser(); void rollbackLastProperties(int num); void setCurrentProperty(CSSPropertyID); void parseSheet(StyleSheetContents*, const String&); PassRefPtr parseRule(StyleSheetContents*, const String&); bool parseSupportsCondition(const String&); static bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, CSSParserMode, StyleSheetContents*); static bool parseColor(RGBA32& color, const String&, bool strict = false); static StyleColor colorFromRGBColorString(const String&); static bool parseSystemColor(RGBA32& color, const String&); static PassRefPtr parseFontFaceValue(const AtomicString&); static PassRefPtr parseAnimationTimingFunctionValue(const String&); bool parseDeclaration(MutableStylePropertySet*, const String&, CSSParserObserver*, StyleSheetContents* contextStyleSheet); static PassRefPtr parseInlineStyleDeclaration(const String&, Element*); bool parseAttributeMatchType(CSSSelector::AttributeMatchType&, const String&); static bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, const Document&); bool parseValue(CSSPropertyID); void parseSelector(const String&, CSSSelectorList&); CSSParserSelector* createFloatingSelector(); CSSParserSelector* createFloatingSelectorWithTagName(const QualifiedName&); PassOwnPtr sinkFloatingSelector(CSSParserSelector*); Vector >* createFloatingSelectorVector(); PassOwnPtr > > sinkFloatingSelectorVector(Vector >*); CSSParserValueList* createFloatingValueList(); PassOwnPtr sinkFloatingValueList(CSSParserValueList*); CSSParserFunction* createFloatingFunction(); CSSParserFunction* createFloatingFunction(const CSSParserString& name, PassOwnPtr args); PassOwnPtr sinkFloatingFunction(CSSParserFunction*); CSSParserValue& sinkFloatingValue(CSSParserValue&); typedef Vector > RuleList; RuleList* createRuleList(); RuleList* appendRule(RuleList*, StyleRuleBase*); StyleRuleBase* createStyleRule(Vector >* selectors); StyleRuleBase* createFontFaceRule(); StyleRuleBase* createSupportsRule(bool conditionIsSupported, RuleList*); void markSupportsRuleHeaderStart(); void markSupportsRuleHeaderEnd(); PassRefPtr popSupportsRuleData(); StyleRuleBase* createHostRule(RuleList* rules); void startDeclarationsForMarginBox(); void endDeclarationsForMarginBox(); CSSParserSelector* rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector*, bool isNamespacePlaceholder = false); CSSParserSelector* rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector*); CSSParserSelector* rewriteSpecifiers(CSSParserSelector*, CSSParserSelector*); CSSParserSelector* rewriteSpecifiersForShadowDistributed(CSSParserSelector* specifiers, CSSParserSelector* distributedPseudoElementSelector); void invalidBlockHit() { } Vector >* reusableSelectorVector() { return &m_reusableSelectorVector; } void clearProperties(); PassRefPtr createStylePropertySet(); CSSParserContext m_context; CSSPropertyID m_id; RawPtr m_styleSheet; RefPtr m_rule; OwnPtr m_valueList; bool m_supportsCondition; Vector m_parsedProperties; CSSSelectorList* m_selectorListForParseSelector; unsigned m_numParsedPropertiesBeforeMarginBox; bool m_hadSyntacticallyValidCSSRule; bool m_ignoreErrors; AtomicString m_defaultNamespace; // tokenizer methods and data CSSParserObserver* m_observer; // Local functions which just call into CSSParserObserver if non-null. void startRule(); void endRule(bool valid); void startRuleHeader(CSSRuleSourceData::Type); void endRuleHeader(); void startSelector(); void endSelector(); void startRuleBody(); void startProperty(); void endProperty(bool isPropertyParsed, CSSParserError = NoCSSError); void startEndUnknownRule(); void endInvalidRuleHeader(); void reportError(const CSSParserLocation&, CSSParserError = GeneralCSSError) { } void setLocationLabel(const CSSParserLocation& location) { m_locationLabel = location; } const CSSParserLocation& lastLocationLabel() const { return m_locationLabel; } void tokenToLowerCase(CSSParserString& token); CSSParserLocation currentLocation() { return m_tokenizer.currentLocation(); } private: inline void ensureLineEndings(); void setStyleSheet(StyleSheetContents* styleSheet) { m_styleSheet = styleSheet; } bool inViewport() const { return m_inViewport; } void recheckAtKeyword(const UChar* str, int len); template inline void setupParser(const char (&prefix)[prefixLength], const String& string, const char (&suffix)[suffixLength]) { setupParser(prefix, prefixLength - 1, string, suffix, suffixLength - 1); } void setupParser(const char* prefix, unsigned prefixLength, const String&, const char* suffix, unsigned suffixLength); bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, StyleSheetContents* contextStyleSheet); PassRefPtr parseDeclaration(const String&, StyleSheetContents* contextStyleSheet); bool parseColor(const String&); const String* m_source; TextPosition m_startPosition; CSSRuleSourceData::Type m_ruleHeaderType; unsigned m_ruleHeaderStartOffset; int m_ruleHeaderStartLineNumber; OwnPtr > m_lineEndings; bool m_ruleHasHeader; bool m_allowImportRules; bool m_allowNamespaceDeclarations; bool m_inViewport; CSSParserLocation m_locationLabel; Vector > m_parsedRules; Vector > m_parsedRuleLists; Vector m_floatingSelectors; Vector >*> m_floatingSelectorVectors; Vector m_floatingValueLists; Vector m_floatingFunctions; Vector > m_reusableSelectorVector; OwnPtr m_supportsRuleDataStack; CSSTokenizer m_tokenizer; friend class TransformOperationInfo; friend class FilterOperationInfo; }; inline int cssyylex(void* yylval, BisonCSSParser* parser) { return parser->m_tokenizer.lex(yylval); } bool isValidNthToken(const CSSParserString&); } // namespace blink #endif // SKY_ENGINE_CORE_CSS_PARSER_BISONCSSPARSER_H_