diff -r 000000000000 -r 4f2f89ce4247 WebCore/css/CSSParser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WebCore/css/CSSParser.h Fri Sep 17 09:02:29 2010 +0300 @@ -0,0 +1,361 @@ +/* + * Copyright (C) 2003 Lars Knoll (knoll@kde.org) + * Copyright (C) 2004, 2005, 2006, 2008 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 CSSParser_h +#define CSSParser_h + +#include "AtomicString.h" +#include "Color.h" +#include "CSSParserValues.h" +#include "CSSSelectorList.h" +#include "MediaQuery.h" +#include +#include +#include + +namespace WebCore { + + class CSSMutableStyleDeclaration; + class CSSPrimitiveValue; + class CSSProperty; + class CSSRule; + class CSSRuleList; + class CSSSelector; + class CSSStyleRule; + class CSSStyleSheet; + class CSSValue; + class CSSValueList; + class CSSVariablesDeclaration; + class Document; + class MediaList; + class MediaQueryExp; + class StyleBase; + class StyleList; + class WebKitCSSKeyframeRule; + class WebKitCSSKeyframesRule; + + class CSSParser { + public: + typedef HashMap > StyleRuleRanges; + + CSSParser(bool strictParsing = true); + ~CSSParser(); + + void parseSheet(CSSStyleSheet*, const String&, int startLineNumber = 0, StyleRuleRanges* ruleRangeMap = 0); + PassRefPtr parseRule(CSSStyleSheet*, const String&); + PassRefPtr parseKeyframeRule(CSSStyleSheet*, const String&); + bool parseValue(CSSMutableStyleDeclaration*, int propId, const String&, bool important); + static bool parseColor(RGBA32& color, const String&, bool strict = false); + bool parseColor(CSSMutableStyleDeclaration*, const String&); + bool parseDeclaration(CSSMutableStyleDeclaration*, const String&); + bool parseMediaQuery(MediaList*, const String&); + + Document* document() const; + + void addProperty(int propId, PassRefPtr, bool important); + void rollbackLastProperties(int num); + bool hasProperties() const { return m_numParsedProperties > 0; } + + bool parseValue(int propId, bool important); + bool parseShorthand(int propId, const int* properties, int numProperties, bool important); + bool parse4Values(int propId, const int* properties, bool important); + bool parseContent(int propId, bool important); + + PassRefPtr parseAttr(CSSParserValueList* args); + + PassRefPtr parseBackgroundColor(); + + bool parseFillImage(RefPtr&); + PassRefPtr parseFillPositionXY(bool& xFound, bool& yFound); + void parseFillPosition(RefPtr&, RefPtr&); + void parseFillRepeat(RefPtr&, RefPtr&); + PassRefPtr parseFillSize(int propId, bool &allowComma); + + bool parseFillProperty(int propId, int& propId1, int& propId2, RefPtr&, RefPtr&); + bool parseFillShorthand(int propId, const int* properties, int numProperties, bool important); + + void addFillValue(RefPtr& lval, PassRefPtr rval); + + void addAnimationValue(RefPtr& lval, PassRefPtr rval); + + PassRefPtr parseAnimationDelay(); + PassRefPtr parseAnimationDirection(); + PassRefPtr parseAnimationDuration(); + PassRefPtr parseAnimationFillMode(); + PassRefPtr parseAnimationIterationCount(); + PassRefPtr parseAnimationName(); + PassRefPtr parseAnimationPlayState(); + PassRefPtr parseAnimationProperty(); + PassRefPtr parseAnimationTimingFunction(); + + void parseTransformOriginShorthand(RefPtr&, RefPtr&, RefPtr&); + bool parseTimingFunctionValue(CSSParserValueList*& args, double& result); + bool parseAnimationProperty(int propId, RefPtr&); + bool parseTransitionShorthand(bool important); + bool parseAnimationShorthand(bool important); + + bool parseDashboardRegions(int propId, bool important); + + bool parseShape(int propId, bool important); + + bool parseFont(bool important); + PassRefPtr parseFontFamily(); + + bool parseCounter(int propId, int defaultValue, bool important); + PassRefPtr parseCounterContent(CSSParserValueList* args, bool counters); + + bool parseColorParameters(CSSParserValue*, int* colorValues, bool parseAlpha); + bool parseHSLParameters(CSSParserValue*, double* colorValues, bool parseAlpha); + PassRefPtr parseColor(CSSParserValue* = 0); + bool parseColorFromValue(CSSParserValue*, RGBA32&); + void parseSelector(const String&, Document* doc, CSSSelectorList&); + + static bool parseColor(const String&, RGBA32& rgb, bool strict); + + bool parseFontStyle(bool important); + bool parseFontVariant(bool important); + bool parseFontWeight(bool important); + bool parseFontFaceSrc(); + bool parseFontFaceUnicodeRange(); + +#if ENABLE(SVG) + bool parseSVGValue(int propId, bool important); + PassRefPtr parseSVGPaint(); + PassRefPtr parseSVGColor(); + PassRefPtr parseSVGStrokeDasharray(); +#endif + +#if ENABLE(WCSS) + PassRefPtr parseWCSSInputProperty(); +#endif + + // CSS3 Parsing Routines (for properties specific to CSS3) + bool parseShadow(int propId, bool important); + bool parseBorderImage(int propId, bool important, RefPtr&); + bool parseBorderRadius(int propId, bool important); + + bool parseReflect(int propId, bool important); + + // Image generators + bool parseCanvas(RefPtr&); + bool parseGradient(RefPtr&); + + PassRefPtr parseTransform(); + bool parseTransformOrigin(int propId, int& propId1, int& propId2, int& propId3, RefPtr&, RefPtr&, RefPtr&); + bool parsePerspectiveOrigin(int propId, int& propId1, int& propId2, RefPtr&, RefPtr&); + bool parseVariable(CSSVariablesDeclaration*, const String& variableName, const String& variableValue); + void parsePropertyWithResolvedVariables(int propId, bool important, CSSMutableStyleDeclaration*, CSSParserValueList*); + + int yyparse(); + + CSSSelector* createFloatingSelector(); + CSSSelector* sinkFloatingSelector(CSSSelector*); + + CSSParserValueList* createFloatingValueList(); + CSSParserValueList* sinkFloatingValueList(CSSParserValueList*); + + CSSParserFunction* createFloatingFunction(); + CSSParserFunction* sinkFloatingFunction(CSSParserFunction*); + + CSSParserValue& sinkFloatingValue(CSSParserValue&); + + MediaList* createMediaList(); + CSSRule* createCharsetRule(const CSSParserString&); + CSSRule* createImportRule(const CSSParserString&, MediaList*); + WebKitCSSKeyframeRule* createKeyframeRule(CSSParserValueList*); + WebKitCSSKeyframesRule* createKeyframesRule(); + CSSRule* createMediaRule(MediaList*, CSSRuleList*); + CSSRuleList* createRuleList(); + CSSRule* createStyleRule(Vector* selectors); + CSSRule* createFontFaceRule(); + CSSRule* createVariablesRule(MediaList*, bool variablesKeyword); + CSSRule* createPageRule(CSSSelector* pageSelector); + CSSRule* createMarginAtRule(CSSSelector::MarginBoxType marginBox); + void startDeclarationsForMarginBox(); + void endDeclarationsForMarginBox(); + + MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*); + MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*); + Vector* createFloatingMediaQueryExpList(); + Vector* sinkFloatingMediaQueryExpList(Vector*); + MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, Vector*); + MediaQuery* createFloatingMediaQuery(Vector*); + MediaQuery* sinkFloatingMediaQuery(MediaQuery*); + + void addNamespace(const AtomicString& prefix, const AtomicString& uri); + + bool addVariable(const CSSParserString&, CSSParserValueList*); + bool addVariableDeclarationBlock(const CSSParserString&); + bool checkForVariables(CSSParserValueList*); + void addUnresolvedProperty(int propId, bool important); + void invalidBlockHit(); + + Vector* reusableSelectorVector() { return &m_reusableSelectorVector; } + + void updateLastSelectorLineAndPosition(); + + void clearProperties(); + + bool m_strict; + bool m_important; + int m_id; + CSSStyleSheet* m_styleSheet; + RefPtr m_rule; + RefPtr m_keyframe; + MediaQuery* m_mediaQuery; + CSSParserValueList* m_valueList; + CSSProperty** m_parsedProperties; + CSSSelectorList* m_selectorListForParseSelector; + unsigned m_numParsedProperties; + unsigned m_maxParsedProperties; + unsigned m_numParsedPropertiesBeforeMarginBox; + + int m_inParseShorthand; + int m_currentShorthand; + bool m_implicitShorthand; + + bool m_hasFontFaceOnlyValues; + bool m_hadSyntacticallyValidCSSRule; + + Vector m_variableNames; + Vector > m_variableValues; + + AtomicString m_defaultNamespace; + + // tokenizer methods and data + unsigned m_ruleBodyStartOffset; + unsigned m_ruleBodyEndOffset; + StyleRuleRanges* m_ruleRanges; + void markRuleBodyStart(); + void markRuleBodyEnd(); + void resetRuleBodyMarks() { m_ruleBodyStartOffset = m_ruleBodyEndOffset = 0; } + int lex(void* yylval); + int token() { return yyTok; } + UChar* text(int* length); + void countLines(); + int lex(); + + private: + void recheckAtKeyword(const UChar* str, int len); + + void setupParser(const char* prefix, const String&, const char* suffix); + + bool inShorthand() const { return m_inParseShorthand; } + + void checkForOrphanedUnits(); + + void clearVariables(); + + void deleteFontFaceOnlyValues(); + + enum SizeParameterType { + None, + Auto, + Length, + PageSize, + Orientation, + }; + + bool parsePage(int propId, bool important); + bool parseSize(int propId, bool important); + SizeParameterType parseSizeParameter(CSSValueList* parsedValues, CSSParserValue* value, SizeParameterType prevParamType); + + UChar* m_data; + UChar* yytext; + UChar* yy_c_buf_p; + UChar yy_hold_char; + int yy_last_accepting_state; + UChar* yy_last_accepting_cpos; + int yyleng; + int yyTok; + int yy_start; + int m_lineNumber; + int m_lastSelectorLineNumber; + + bool m_allowImportRules; + bool m_allowVariablesRules; + bool m_allowNamespaceDeclarations; + + Vector > m_parsedStyleObjects; + Vector > m_parsedRuleLists; + HashSet m_floatingSelectors; + HashSet m_floatingValueLists; + HashSet m_floatingFunctions; + + MediaQuery* m_floatingMediaQuery; + MediaQueryExp* m_floatingMediaQueryExp; + Vector* m_floatingMediaQueryExpList; + + Vector m_reusableSelectorVector; + + // defines units allowed for a certain property, used in parseUnit + enum Units { + FUnknown = 0x0000, + FInteger = 0x0001, + FNumber = 0x0002, // Real Numbers + FPercent = 0x0004, + FLength = 0x0008, + FAngle = 0x0010, + FTime = 0x0020, + FFrequency = 0x0040, + FRelative = 0x0100, + FNonNeg = 0x0200 + }; + + friend inline Units operator|(Units a, Units b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + + static bool validUnit(CSSParserValue*, Units, bool strict); + + friend class TransformOperationInfo; + }; + + int cssPropertyID(const CSSParserString&); + int cssPropertyID(const String&); + int cssValueKeywordID(const CSSParserString&); + + class ShorthandScope : public FastAllocBase { + public: + ShorthandScope(CSSParser* parser, int propId) : m_parser(parser) + { + if (!(m_parser->m_inParseShorthand++)) + m_parser->m_currentShorthand = propId; + } + ~ShorthandScope() + { + if (!(--m_parser->m_inParseShorthand)) + m_parser->m_currentShorthand = 0; + } + + private: + CSSParser* m_parser; + }; + + String quoteCSSString(const String&); + String quoteCSSStringIfNeeded(const String&); + String quoteCSSURLIfNeeded(const String&); + +} // namespace WebCore + +#endif // CSSParser_h