Home | History | Annotate | Download | only in css
      1 /*
      2  * Copyright (C) 2003 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
      4  * Copyright (C) 2008 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2009 - 2010  Torch Mobile (Beijing) Co. Ltd. All rights reserved.
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  */
     22 
     23 #ifndef CSSParser_h
     24 #define CSSParser_h
     25 
     26 #include "CSSPropertyNames.h"
     27 #include "CSSValueKeywords.h"
     28 #include "core/css/CSSCalculationValue.h"
     29 #include "core/css/CSSFilterValue.h"
     30 #include "core/css/CSSGradientValue.h"
     31 #include "core/css/CSSParserMode.h"
     32 #include "core/css/CSSParserValues.h"
     33 #include "core/css/CSSProperty.h"
     34 #include "core/css/CSSPropertySourceData.h"
     35 #include "core/css/CSSSelector.h"
     36 #include "core/css/MediaQuery.h"
     37 #include "core/page/UseCounter.h"
     38 #include "core/platform/graphics/Color.h"
     39 #include "wtf/HashSet.h"
     40 #include "wtf/OwnArrayPtr.h"
     41 #include "wtf/Vector.h"
     42 #include "wtf/text/AtomicString.h"
     43 #include "wtf/text/TextPosition.h"
     44 
     45 namespace WebCore {
     46 
     47 class AnimationParseContext;
     48 class CSSArrayFunctionValue;
     49 class CSSBorderImageSliceValue;
     50 class CSSMixFunctionValue;
     51 class CSSPrimitiveValue;
     52 class CSSSelectorList;
     53 class CSSShaderValue;
     54 class CSSValue;
     55 class CSSValueList;
     56 class CSSBasicShape;
     57 class Document;
     58 class Element;
     59 class ImmutableStylePropertySet;
     60 class MediaQueryExp;
     61 class MediaQuerySet;
     62 class MutableStylePropertySet;
     63 class StyleKeyframe;
     64 class StylePropertyShorthand;
     65 class StyleRuleBase;
     66 class StyleRuleKeyframes;
     67 class StyleKeyframe;
     68 class StyleSheetContents;
     69 
     70 struct CSSParserLocation {
     71     unsigned offset;
     72     unsigned lineNumber;
     73     CSSParserString token;
     74 };
     75 
     76 class CSSParser {
     77     friend inline int cssyylex(void*, CSSParser*);
     78 
     79 public:
     80     class SourceDataHandler;
     81     enum ErrorType {
     82         NoError,
     83         PropertyDeclarationError,
     84         InvalidPropertyValueError,
     85         InvalidPropertyError,
     86         InvalidSelectorError,
     87         InvalidSupportsConditionError,
     88         InvalidRuleError,
     89         InvalidMediaQueryError,
     90         InvalidKeyframeSelectorError,
     91         InvalidSelectorPseudoError,
     92         UnterminatedCommentError,
     93         GeneralError
     94     };
     95 
     96     CSSParser(const CSSParserContext&, UseCounter* = 0);
     97 
     98     ~CSSParser();
     99 
    100     void parseSheet(StyleSheetContents*, const String&, const TextPosition& startPosition = TextPosition::minimumPosition(), SourceDataHandler* = 0, bool = false);
    101     PassRefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
    102     PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
    103     bool parseSupportsCondition(const String&);
    104     static bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, bool important, CSSParserMode, StyleSheetContents*);
    105     static bool parseColor(RGBA32& color, const String&, bool strict = false);
    106     static bool parseSystemColor(RGBA32& color, const String&, Document*);
    107     static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
    108     PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, CSSParserValue*);
    109     bool parseDeclaration(MutableStylePropertySet*, const String&, SourceDataHandler*, StyleSheetContents* contextStyleSheet);
    110     static PassRefPtr<ImmutableStylePropertySet> parseInlineStyleDeclaration(const String&, Element*);
    111     PassRefPtr<MediaQuerySet> parseMediaQueryList(const String&);
    112 
    113     void addPropertyWithPrefixingVariant(CSSPropertyID, PassRefPtr<CSSValue>, bool important, bool implicit = false);
    114     void addProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important, bool implicit = false);
    115     void rollbackLastProperties(int num);
    116     bool hasProperties() const { return !m_parsedProperties.isEmpty(); }
    117     void addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr<CSSValue>, bool);
    118     void setCurrentProperty(CSSPropertyID);
    119 
    120     bool parseValue(CSSPropertyID, bool important);
    121     bool parseShorthand(CSSPropertyID, const StylePropertyShorthand&, bool important);
    122     bool parse4Values(CSSPropertyID, const CSSPropertyID* properties, bool important);
    123     bool parseContent(CSSPropertyID, bool important);
    124     bool parseQuotes(CSSPropertyID, bool important);
    125 
    126     static bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, bool important, Document*);
    127     void storeVariableDeclaration(const CSSParserString&, PassOwnPtr<CSSParserValueList>, bool important);
    128 
    129     PassRefPtr<CSSValue> parseAttr(CSSParserValueList* args);
    130 
    131     PassRefPtr<CSSValue> parseBackgroundColor();
    132 
    133     bool parseFillImage(CSSParserValueList*, RefPtr<CSSValue>&);
    134 
    135     enum FillPositionFlag { InvalidFillPosition = 0, AmbiguousFillPosition = 1, XFillPosition = 2, YFillPosition = 4 };
    136     enum FillPositionParsingMode { ResolveValuesAsPercent = 0, ResolveValuesAsKeyword = 1 };
    137     PassRefPtr<CSSPrimitiveValue> parseFillPositionComponent(CSSParserValueList*, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode = ResolveValuesAsPercent);
    138     PassRefPtr<CSSValue> parseFillPositionX(CSSParserValueList*);
    139     PassRefPtr<CSSValue> parseFillPositionY(CSSParserValueList*);
    140     void parse2ValuesFillPosition(CSSParserValueList*, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    141     bool isPotentialPositionValue(CSSParserValue*);
    142     void parseFillPosition(CSSParserValueList*, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    143     void parse3ValuesFillPosition(CSSParserValueList*, RefPtr<CSSValue>&, RefPtr<CSSValue>&, PassRefPtr<CSSPrimitiveValue>, PassRefPtr<CSSPrimitiveValue>);
    144     void parse4ValuesFillPosition(CSSParserValueList*, RefPtr<CSSValue>&, RefPtr<CSSValue>&, PassRefPtr<CSSPrimitiveValue>, PassRefPtr<CSSPrimitiveValue>);
    145 
    146     void parseFillRepeat(RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    147     PassRefPtr<CSSValue> parseFillSize(CSSPropertyID, bool &allowComma);
    148 
    149     bool parseFillProperty(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    150     bool parseFillShorthand(CSSPropertyID, const CSSPropertyID* properties, int numProperties, bool important);
    151 
    152     void addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval);
    153 
    154     void addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval);
    155 
    156     PassRefPtr<CSSValue> parseAnimationDelay();
    157     PassRefPtr<CSSValue> parseAnimationDirection();
    158     PassRefPtr<CSSValue> parseAnimationDuration();
    159     PassRefPtr<CSSValue> parseAnimationFillMode();
    160     PassRefPtr<CSSValue> parseAnimationIterationCount();
    161     PassRefPtr<CSSValue> parseAnimationName();
    162     PassRefPtr<CSSValue> parseAnimationPlayState();
    163     PassRefPtr<CSSValue> parseAnimationProperty(AnimationParseContext&);
    164     PassRefPtr<CSSValue> parseAnimationTimingFunction();
    165 
    166     bool parseTransformOriginShorthand(RefPtr<CSSValue>&, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    167     bool parseCubicBezierTimingFunctionValue(CSSParserValueList*& args, double& result);
    168     bool parseAnimationProperty(CSSPropertyID, RefPtr<CSSValue>&, AnimationParseContext&);
    169     bool parseTransitionShorthand(CSSPropertyID, bool important);
    170     bool parseAnimationShorthand(bool important);
    171 
    172     PassRefPtr<CSSValue> parseColumnWidth();
    173     PassRefPtr<CSSValue> parseColumnCount();
    174     bool parseColumnsShorthand(bool important);
    175 
    176     PassRefPtr<CSSValue> parseGridPosition();
    177     bool parseIntegerOrStringFromGridPosition(RefPtr<CSSPrimitiveValue>& numericValue, RefPtr<CSSPrimitiveValue>& gridLineName);
    178     bool parseGridItemPositionShorthand(CSSPropertyID, bool important);
    179     bool parseGridAreaShorthand(bool important);
    180     bool parseSingleGridAreaLonghand(RefPtr<CSSValue>&);
    181     bool parseGridTrackList(CSSPropertyID, bool important);
    182     bool parseGridTrackRepeatFunction(CSSValueList&);
    183     PassRefPtr<CSSPrimitiveValue> parseGridTrackSize(CSSParserValueList& inputList);
    184     PassRefPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue*);
    185     PassRefPtr<CSSValue> parseGridTemplate();
    186 
    187     bool parseClipShape(CSSPropertyID, bool important);
    188 
    189     bool parseBasicShape(CSSPropertyID, bool important);
    190     PassRefPtr<CSSBasicShape> parseBasicShapeRectangle(CSSParserValueList* args);
    191     PassRefPtr<CSSBasicShape> parseBasicShapeCircle(CSSParserValueList* args);
    192     PassRefPtr<CSSBasicShape> parseBasicShapeEllipse(CSSParserValueList* args);
    193     PassRefPtr<CSSBasicShape> parseBasicShapePolygon(CSSParserValueList* args);
    194     PassRefPtr<CSSBasicShape> parseBasicShapeInsetRectangle(CSSParserValueList* args);
    195 
    196     bool parseFont(bool important);
    197     PassRefPtr<CSSValueList> parseFontFamily();
    198 
    199     bool parseCounter(CSSPropertyID, int defaultValue, bool important);
    200     PassRefPtr<CSSValue> parseCounterContent(CSSParserValueList* args, bool counters);
    201 
    202     bool parseColorParameters(CSSParserValue*, int* colorValues, bool parseAlpha);
    203     bool parseHSLParameters(CSSParserValue*, double* colorValues, bool parseAlpha);
    204     PassRefPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = 0);
    205     bool parseColorFromValue(CSSParserValue*, RGBA32&);
    206     void parseSelector(const String&, CSSSelectorList&);
    207 
    208     template<typename StringType>
    209     static bool fastParseColor(RGBA32&, const StringType&, bool strict);
    210 
    211     bool parseLineHeight(bool important);
    212     bool parseFontSize(bool important);
    213     bool parseFontVariant(bool important);
    214     bool parseFontWeight(bool important);
    215     bool parseFontFaceSrc();
    216     bool parseFontFaceUnicodeRange();
    217 
    218     bool parseSVGValue(CSSPropertyID propId, bool important);
    219     PassRefPtr<CSSValue> parseSVGPaint();
    220     PassRefPtr<CSSValue> parseSVGColor();
    221     PassRefPtr<CSSValue> parseSVGStrokeDasharray();
    222 
    223     // CSS3 Parsing Routines (for properties specific to CSS3)
    224     PassRefPtr<CSSValueList> parseShadow(CSSParserValueList*, CSSPropertyID);
    225     bool parseBorderImage(CSSPropertyID, RefPtr<CSSValue>&, bool important = false);
    226     bool parseBorderImageRepeat(RefPtr<CSSValue>&);
    227     bool parseBorderImageSlice(CSSPropertyID, RefPtr<CSSBorderImageSliceValue>&);
    228     bool parseBorderImageWidth(RefPtr<CSSPrimitiveValue>&);
    229     bool parseBorderImageOutset(RefPtr<CSSPrimitiveValue>&);
    230     bool parseBorderRadius(CSSPropertyID, bool important);
    231 
    232     bool parseAspectRatio(bool important);
    233 
    234     bool parseReflect(CSSPropertyID, bool important);
    235 
    236     bool parseFlex(CSSParserValueList* args, bool important);
    237 
    238     // Image generators
    239     bool parseCanvas(CSSParserValueList*, RefPtr<CSSValue>&);
    240 
    241     bool parseDeprecatedGradient(CSSParserValueList*, RefPtr<CSSValue>&);
    242     bool parseDeprecatedLinearGradient(CSSParserValueList*, RefPtr<CSSValue>&, CSSGradientRepeat repeating);
    243     bool parseDeprecatedRadialGradient(CSSParserValueList*, RefPtr<CSSValue>&, CSSGradientRepeat repeating);
    244     bool parseLinearGradient(CSSParserValueList*, RefPtr<CSSValue>&, CSSGradientRepeat repeating);
    245     bool parseRadialGradient(CSSParserValueList*, RefPtr<CSSValue>&, CSSGradientRepeat repeating);
    246     bool parseGradientColorStops(CSSParserValueList*, CSSGradientValue*, bool expectComma);
    247 
    248     bool parseCrossfade(CSSParserValueList*, RefPtr<CSSValue>&);
    249 
    250     PassRefPtr<CSSValue> parseImageSet(CSSParserValueList*);
    251 
    252     PassRefPtr<CSSValueList> parseFilter();
    253     PassRefPtr<CSSFilterValue> parseBuiltinFilterArguments(CSSParserValueList*, CSSFilterValue::FilterOperationType);
    254     PassRefPtr<CSSMixFunctionValue> parseMixFunction(CSSParserValue*);
    255     PassRefPtr<CSSArrayFunctionValue> parseCustomFilterArrayFunction(CSSParserValue*);
    256     PassRefPtr<CSSValueList> parseCustomFilterTransform(CSSParserValueList*);
    257     PassRefPtr<CSSValueList> parseCustomFilterParameters(CSSParserValueList*);
    258     PassRefPtr<CSSFilterValue> parseCustomFilterFunctionWithAtRuleReferenceSyntax(CSSParserValue*);
    259     PassRefPtr<CSSFilterValue> parseCustomFilterFunctionWithInlineSyntax(CSSParserValue*);
    260     PassRefPtr<CSSFilterValue> parseCustomFilterFunction(CSSParserValue*);
    261     bool parseFilterRuleSrc();
    262     PassRefPtr<CSSShaderValue> parseFilterRuleSrcUriAndFormat(CSSParserValueList*);
    263 
    264     static bool isBlendMode(CSSValueID);
    265     static bool isCompositeOperator(CSSValueID);
    266 
    267     PassRefPtr<CSSValueList> parseTransform();
    268     PassRefPtr<CSSValue> parseTransformValue(CSSParserValue*);
    269     bool parseTransformOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, CSSPropertyID& propId3, RefPtr<CSSValue>&, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    270     bool parsePerspectiveOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2,  RefPtr<CSSValue>&, RefPtr<CSSValue>&);
    271 
    272     bool parseTextEmphasisStyle(bool important);
    273 
    274     void addTextDecorationProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important);
    275     bool parseTextDecoration(CSSPropertyID propId, bool important);
    276 #if ENABLE(CSS3_TEXT)
    277     bool parseTextUnderlinePosition(bool important);
    278 #endif // CSS3_TEXT
    279 
    280     PassRefPtr<CSSValue> parseTextIndent();
    281 
    282     bool parseLineBoxContain(bool important);
    283     bool parseCalculation(CSSParserValue*, CalculationPermittedValueRange);
    284 
    285     bool parseFontFeatureTag(CSSValueList*);
    286     bool parseFontFeatureSettings(bool important);
    287 
    288     bool parseFlowThread(const String& flowName);
    289     bool parseFlowThread(CSSPropertyID, bool important);
    290     bool parseRegionThread(CSSPropertyID, bool important);
    291 
    292     bool parseFontVariantLigatures(bool important);
    293 
    294     CSSParserSelector* createFloatingSelector();
    295     CSSParserSelector* createFloatingSelectorWithTagName(const QualifiedName&);
    296     PassOwnPtr<CSSParserSelector> sinkFloatingSelector(CSSParserSelector*);
    297 
    298     Vector<OwnPtr<CSSParserSelector> >* createFloatingSelectorVector();
    299     PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > sinkFloatingSelectorVector(Vector<OwnPtr<CSSParserSelector> >*);
    300 
    301     CSSParserValueList* createFloatingValueList();
    302     PassOwnPtr<CSSParserValueList> sinkFloatingValueList(CSSParserValueList*);
    303 
    304     CSSParserFunction* createFloatingFunction();
    305     CSSParserFunction* createFloatingFunction(const CSSParserString& name, PassOwnPtr<CSSParserValueList> args);
    306     PassOwnPtr<CSSParserFunction> sinkFloatingFunction(CSSParserFunction*);
    307 
    308     CSSParserValue& sinkFloatingValue(CSSParserValue&);
    309 
    310     MediaQuerySet* createMediaQuerySet();
    311     StyleRuleBase* createImportRule(const CSSParserString&, MediaQuerySet*);
    312     StyleKeyframe* createKeyframe(CSSParserValueList*);
    313     StyleRuleKeyframes* createKeyframesRule(const String&, PassOwnPtr<Vector<RefPtr<StyleKeyframe> > >);
    314 
    315     typedef Vector<RefPtr<StyleRuleBase> > RuleList;
    316     StyleRuleBase* createMediaRule(MediaQuerySet*, RuleList*);
    317     RuleList* createRuleList();
    318     StyleRuleBase* createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors);
    319     StyleRuleBase* createFontFaceRule();
    320     StyleRuleBase* createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
    321     StyleRuleBase* createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules);
    322     StyleRuleBase* createMarginAtRule(CSSSelector::MarginBoxType);
    323     StyleRuleBase* createSupportsRule(bool conditionIsSupported, RuleList*);
    324     void markSupportsRuleHeaderStart();
    325     void markSupportsRuleHeaderEnd();
    326     PassRefPtr<CSSRuleSourceData> popSupportsRuleData();
    327     StyleRuleBase* createHostRule(RuleList* rules);
    328     StyleRuleBase* createFilterRule(const CSSParserString&);
    329 
    330     void startDeclarationsForMarginBox();
    331     void endDeclarationsForMarginBox();
    332 
    333     MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
    334     PassOwnPtr<MediaQueryExp> sinkFloatingMediaQueryExp(MediaQueryExp*);
    335     Vector<OwnPtr<MediaQueryExp> >* createFloatingMediaQueryExpList();
    336     PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > sinkFloatingMediaQueryExpList(Vector<OwnPtr<MediaQueryExp> >*);
    337     MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > >);
    338     MediaQuery* createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > >);
    339     MediaQuery* createFloatingNotAllQuery();
    340     PassOwnPtr<MediaQuery> sinkFloatingMediaQuery(MediaQuery*);
    341 
    342     Vector<RefPtr<StyleKeyframe> >* createFloatingKeyframeVector();
    343     PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > sinkFloatingKeyframeVector(Vector<RefPtr<StyleKeyframe> >*);
    344 
    345     void addNamespace(const AtomicString& prefix, const AtomicString& uri);
    346     QualifiedName determineNameInNamespace(const AtomicString& prefix, const AtomicString& localName);
    347 
    348     CSSParserSelector* rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector*, bool isNamespacePlaceholder = false);
    349     CSSParserSelector* rewriteSpecifiersWithElementNameForCustomPseudoElement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule);
    350     CSSParserSelector* rewriteSpecifiersWithElementNameForContentPseudoElement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule);
    351     CSSParserSelector* rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector*);
    352     CSSParserSelector* rewriteSpecifiers(CSSParserSelector*, CSSParserSelector*);
    353     CSSParserSelector* rewriteSpecifiersForShadowDistributed(CSSParserSelector* specifiers, CSSParserSelector* distributedPseudoElementSelector);
    354 
    355     void invalidBlockHit();
    356 
    357     Vector<OwnPtr<CSSParserSelector> >* reusableSelectorVector() { return &m_reusableSelectorVector; }
    358 
    359     void setReusableRegionSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectors);
    360     Vector<OwnPtr<CSSParserSelector> >* reusableRegionSelectorVector() { return &m_reusableRegionSelectorVector; }
    361 
    362     void clearProperties();
    363 
    364     PassRefPtr<ImmutableStylePropertySet> createStylePropertySet();
    365 
    366     CSSParserContext m_context;
    367 
    368     bool m_important;
    369     CSSPropertyID m_id;
    370     StyleSheetContents* m_styleSheet;
    371     RefPtr<StyleRuleBase> m_rule;
    372     RefPtr<StyleKeyframe> m_keyframe;
    373     RefPtr<MediaQuerySet> m_mediaList;
    374     OwnPtr<CSSParserValueList> m_valueList;
    375     bool m_supportsCondition;
    376 
    377     typedef Vector<CSSProperty, 256> ParsedPropertyVector;
    378     ParsedPropertyVector m_parsedProperties;
    379     CSSSelectorList* m_selectorListForParseSelector;
    380 
    381     unsigned m_numParsedPropertiesBeforeMarginBox;
    382 
    383     int m_inParseShorthand;
    384     CSSPropertyID m_currentShorthand;
    385     bool m_implicitShorthand;
    386 
    387     bool m_hasFontFaceOnlyValues;
    388     bool m_hadSyntacticallyValidCSSRule;
    389     bool m_logErrors;
    390     bool m_ignoreErrors;
    391 
    392     bool m_inFilterRule;
    393 
    394     AtomicString m_defaultNamespace;
    395 
    396     // tokenizer methods and data
    397     size_t m_parsedTextPrefixLength;
    398     size_t m_parsedTextSuffixLength;
    399     SourceDataHandler* m_sourceDataHandler;
    400 
    401     void startRuleHeader(CSSRuleSourceData::Type);
    402     void endRuleHeader();
    403     void startSelector();
    404     void endSelector();
    405     void startRuleBody();
    406     void endRuleBody(bool discard = false);
    407     void startProperty();
    408     void endProperty(bool isImportantFound, bool isPropertyParsed, ErrorType = NoError);
    409     void startEndUnknownRule();
    410 
    411     void endInvalidRuleHeader();
    412     void reportError(const CSSParserLocation&, ErrorType = GeneralError);
    413     void resumeErrorLogging() { m_ignoreErrors = false; }
    414     void setLocationLabel(const CSSParserLocation& location) { m_locationLabel = location; }
    415     const CSSParserLocation& lastLocationLabel() const { return m_locationLabel; }
    416 
    417     inline int lex(void* yylval) { return (this->*m_lexFunc)(yylval); }
    418 
    419     int token() { return m_token; }
    420 
    421     void tokenToLowerCase(const CSSParserString& token);
    422 
    423     void markViewportRuleBodyStart() { m_inViewport = true; }
    424     void markViewportRuleBodyEnd() { m_inViewport = false; }
    425     StyleRuleBase* createViewportRule();
    426 
    427     PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*);
    428     PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*);
    429     PassRefPtr<CSSPrimitiveValue> createPrimitiveVariableNameValue(CSSParserValue*);
    430 
    431     static KURL completeURL(const CSSParserContext&, const String& url);
    432 
    433     CSSParserLocation currentLocation();
    434 
    435 private:
    436     enum PropertyType {
    437         PropertyExplicit,
    438         PropertyImplicit
    439     };
    440 
    441     class ImplicitScope {
    442         WTF_MAKE_NONCOPYABLE(ImplicitScope);
    443     public:
    444         ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType)
    445             : m_parser(parser)
    446         {
    447             m_parser->m_implicitShorthand = propertyType == CSSParser::PropertyImplicit;
    448         }
    449 
    450         ~ImplicitScope()
    451         {
    452             m_parser->m_implicitShorthand = false;
    453         }
    454 
    455     private:
    456         WebCore::CSSParser* m_parser;
    457     };
    458 
    459     bool is8BitSource() const { return m_is8BitSource; }
    460 
    461     template <typename SourceCharacterType>
    462     int realLex(void* yylval);
    463 
    464     UChar*& currentCharacter16();
    465 
    466     template <typename CharacterType>
    467     inline CharacterType*& currentCharacter();
    468 
    469     template <typename CharacterType>
    470     inline CharacterType* tokenStart();
    471 
    472     template <typename CharacterType>
    473     inline CharacterType* dataStart();
    474 
    475     template <typename CharacterType>
    476     inline void setTokenStart(CharacterType*);
    477 
    478     inline unsigned tokenStartOffset();
    479     inline UChar tokenStartChar();
    480 
    481     template <typename CharacterType>
    482     inline bool isIdentifierStart();
    483 
    484     inline void ensureLineEndings();
    485 
    486     template <typename CharacterType>
    487     inline CSSParserLocation tokenLocation();
    488 
    489     template <typename CharacterType>
    490     unsigned parseEscape(CharacterType*&);
    491     template <typename DestCharacterType>
    492     inline void UnicodeToChars(DestCharacterType*&, unsigned);
    493     template <typename SrcCharacterType, typename DestCharacterType>
    494     inline bool parseIdentifierInternal(SrcCharacterType*&, DestCharacterType*&, bool&);
    495 
    496     template <typename CharacterType>
    497     inline void parseIdentifier(CharacterType*&, CSSParserString&, bool&);
    498 
    499     template <typename SrcCharacterType, typename DestCharacterType>
    500     inline bool parseStringInternal(SrcCharacterType*&, DestCharacterType*&, UChar);
    501 
    502     template <typename CharacterType>
    503     inline void parseString(CharacterType*&, CSSParserString& resultString, UChar);
    504 
    505     template <typename CharacterType>
    506     inline bool findURI(CharacterType*& start, CharacterType*& end, UChar& quote);
    507 
    508     template <typename SrcCharacterType, typename DestCharacterType>
    509     inline bool parseURIInternal(SrcCharacterType*&, DestCharacterType*&, UChar quote);
    510 
    511     template <typename CharacterType>
    512     inline void parseURI(CSSParserString&);
    513     template <typename CharacterType>
    514     inline bool parseUnicodeRange();
    515     template <typename CharacterType>
    516     bool parseNthChild();
    517     template <typename CharacterType>
    518     bool parseNthChildExtra();
    519     template <typename CharacterType>
    520     inline bool detectFunctionTypeToken(int);
    521     template <typename CharacterType>
    522     inline void detectMediaQueryToken(int);
    523     template <typename CharacterType>
    524     inline void detectNumberToken(CharacterType*, int);
    525     template <typename CharacterType>
    526     inline void detectDashToken(int);
    527     template <typename CharacterType>
    528     inline void detectAtToken(int, bool);
    529     template <typename CharacterType>
    530     inline void detectSupportsToken(int);
    531     template <typename CharacterType>
    532     inline void detectCSSVariableDefinitionToken(int);
    533 
    534     void setStyleSheet(StyleSheetContents* styleSheet) { m_styleSheet = styleSheet; }
    535 
    536     inline bool inStrictMode() const { return m_context.mode == CSSStrictMode || m_context.mode == SVGAttributeMode; }
    537     inline bool inQuirksMode() const { return m_context.mode == CSSQuirksMode; }
    538 
    539     KURL completeURL(const String& url) const;
    540 
    541     void recheckAtKeyword(const UChar* str, int len);
    542 
    543     template<unsigned prefixLength, unsigned suffixLength>
    544     inline void setupParser(const char (&prefix)[prefixLength], const String& string, const char (&suffix)[suffixLength])
    545     {
    546         setupParser(prefix, prefixLength - 1, string, suffix, suffixLength - 1);
    547     }
    548     void setupParser(const char* prefix, unsigned prefixLength, const String&, const char* suffix, unsigned suffixLength);
    549     bool inShorthand() const { return m_inParseShorthand; }
    550 
    551     bool validWidthOrHeight(CSSParserValue*);
    552 
    553     void deleteFontFaceOnlyValues();
    554 
    555     bool isGeneratedImageValue(CSSParserValue*) const;
    556     bool parseGeneratedImage(CSSParserValueList*, RefPtr<CSSValue>&);
    557 
    558     bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, bool important, StyleSheetContents* contextStyleSheet);
    559     PassRefPtr<ImmutableStylePropertySet> parseDeclaration(const String&, StyleSheetContents* contextStyleSheet);
    560 
    561     enum SizeParameterType {
    562         None,
    563         Auto,
    564         Length,
    565         PageSize,
    566         Orientation,
    567     };
    568 
    569     bool parsePage(CSSPropertyID propId, bool important);
    570     bool parseSize(CSSPropertyID propId, bool important);
    571     SizeParameterType parseSizeParameter(CSSValueList* parsedValues, CSSParserValue* value, SizeParameterType prevParamType);
    572 
    573     bool parseFontFaceSrcURI(CSSValueList*);
    574     bool parseFontFaceSrcLocal(CSSValueList*);
    575 
    576     bool parseColor(const String&);
    577 
    578     enum ParsingMode {
    579         NormalMode,
    580         MediaQueryMode,
    581         SupportsMode,
    582         NthChildMode
    583     };
    584 
    585     ParsingMode m_parsingMode;
    586     bool m_is8BitSource;
    587     OwnArrayPtr<LChar> m_dataStart8;
    588     OwnArrayPtr<UChar> m_dataStart16;
    589     LChar* m_currentCharacter8;
    590     UChar* m_currentCharacter16;
    591     const String* m_source;
    592     union {
    593         LChar* ptr8;
    594         UChar* ptr16;
    595     } m_tokenStart;
    596     unsigned m_length;
    597     int m_token;
    598     TextPosition m_startPosition;
    599     int m_lineNumber;
    600     int m_tokenStartLineNumber;
    601     CSSRuleSourceData::Type m_ruleHeaderType;
    602     unsigned m_ruleHeaderStartOffset;
    603     int m_ruleHeaderStartLineNumber;
    604     OwnPtr<Vector<unsigned> > m_lineEndings;
    605 
    606     bool m_allowImportRules;
    607     bool m_allowNamespaceDeclarations;
    608 
    609     bool parseViewportProperty(CSSPropertyID propId, bool important);
    610     bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPropertyID second, bool important);
    611 
    612     bool inViewport() const { return m_inViewport; }
    613     bool m_inViewport;
    614 
    615     CSSParserLocation m_locationLabel;
    616 
    617     bool useLegacyBackgroundSizeShorthandBehavior() const;
    618 
    619     int (CSSParser::*m_lexFunc)(void*);
    620 
    621     Vector<RefPtr<StyleRuleBase> > m_parsedRules;
    622     Vector<RefPtr<StyleKeyframe> > m_parsedKeyframes;
    623     Vector<RefPtr<MediaQuerySet> > m_parsedMediaQuerySets;
    624     Vector<OwnPtr<RuleList> > m_parsedRuleLists;
    625     HashSet<CSSParserSelector*> m_floatingSelectors;
    626     HashSet<Vector<OwnPtr<CSSParserSelector> >*> m_floatingSelectorVectors;
    627     HashSet<CSSParserValueList*> m_floatingValueLists;
    628     HashSet<CSSParserFunction*> m_floatingFunctions;
    629 
    630     OwnPtr<MediaQuery> m_floatingMediaQuery;
    631     OwnPtr<MediaQueryExp> m_floatingMediaQueryExp;
    632     OwnPtr<Vector<OwnPtr<MediaQueryExp> > > m_floatingMediaQueryExpList;
    633 
    634     OwnPtr<Vector<RefPtr<StyleKeyframe> > > m_floatingKeyframeVector;
    635 
    636     Vector<OwnPtr<CSSParserSelector> > m_reusableSelectorVector;
    637     Vector<OwnPtr<CSSParserSelector> > m_reusableRegionSelectorVector;
    638 
    639     RefPtr<CSSCalcValue> m_parsedCalculation;
    640 
    641     OwnPtr<RuleSourceDataList> m_supportsRuleDataStack;
    642 
    643     // defines units allowed for a certain property, used in parseUnit
    644     enum Units {
    645         FUnknown = 0x0000,
    646         FInteger = 0x0001,
    647         FNumber = 0x0002, // Real Numbers
    648         FPercent = 0x0004,
    649         FLength = 0x0008,
    650         FAngle = 0x0010,
    651         FTime = 0x0020,
    652         FFrequency = 0x0040,
    653         FPositiveInteger = 0x0080,
    654         FRelative = 0x0100,
    655         FResolution = 0x0200,
    656         FNonNeg = 0x0400
    657     };
    658 
    659     friend inline Units operator|(Units a, Units b)
    660     {
    661         return static_cast<Units>(static_cast<unsigned>(a) | static_cast<unsigned>(b));
    662     }
    663 
    664     enum ReleaseParsedCalcValueCondition {
    665         ReleaseParsedCalcValue,
    666         DoNotReleaseParsedCalcValue
    667     };
    668 
    669     bool isLoggingErrors();
    670     void logError(const String& message, const CSSParserLocation&);
    671 
    672     bool validCalculationUnit(CSSParserValue*, Units, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
    673 
    674     bool shouldAcceptUnitLessValues(CSSParserValue*, Units, CSSParserMode);
    675 
    676     inline bool validUnit(CSSParserValue* value, Units unitflags, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue) { return validUnit(value, unitflags, m_context.mode, releaseCalc); }
    677     bool validUnit(CSSParserValue*, Units, CSSParserMode, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
    678 
    679     bool parseBorderImageQuad(Units, RefPtr<CSSPrimitiveValue>&);
    680     int colorIntFromValue(CSSParserValue*);
    681     double parsedDouble(CSSParserValue*, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
    682     bool isCalculation(CSSParserValue*);
    683 
    684     inline unsigned safeUserStringTokenOffset();
    685 
    686     UseCounter* m_useCounter;
    687 
    688     friend class TransformOperationInfo;
    689     friend class FilterOperationInfo;
    690 };
    691 
    692 CSSPropertyID cssPropertyID(const CSSParserString&);
    693 CSSPropertyID cssPropertyID(const String&);
    694 CSSValueID cssValueKeywordID(const CSSParserString&);
    695 
    696 class ShorthandScope {
    697     WTF_MAKE_FAST_ALLOCATED;
    698 public:
    699     ShorthandScope(CSSParser* parser, CSSPropertyID propId) : m_parser(parser)
    700     {
    701         if (!(m_parser->m_inParseShorthand++))
    702             m_parser->m_currentShorthand = propId;
    703     }
    704     ~ShorthandScope()
    705     {
    706         if (!(--m_parser->m_inParseShorthand))
    707             m_parser->m_currentShorthand = CSSPropertyInvalid;
    708     }
    709 
    710 private:
    711     CSSParser* m_parser;
    712 };
    713 
    714 class CSSParser::SourceDataHandler {
    715 public:
    716     virtual void startRuleHeader(CSSRuleSourceData::Type, unsigned offset) = 0;
    717     virtual void endRuleHeader(unsigned offset) = 0;
    718     virtual void startSelector(unsigned offset) = 0;
    719     virtual void endSelector(unsigned offset) = 0;
    720     virtual void startRuleBody(unsigned offset) = 0;
    721     virtual void endRuleBody(unsigned offset, bool error) = 0;
    722     virtual void startEndUnknownRule() = 0;
    723     virtual void startProperty(unsigned offset) = 0;
    724     virtual void endProperty(bool isImportant, bool isParsed, unsigned offset, CSSParser::ErrorType) = 0;
    725     virtual void startComment(unsigned offset) = 0;
    726     virtual void endComment(unsigned offset) = 0;
    727 };
    728 
    729 String quoteCSSString(const String&);
    730 String quoteCSSStringIfNeeded(const String&);
    731 String quoteCSSURLIfNeeded(const String&);
    732 
    733 bool isValidNthToken(const CSSParserString&);
    734 
    735 template <>
    736 inline void CSSParser::setTokenStart<LChar>(LChar* tokenStart)
    737 {
    738     m_tokenStart.ptr8 = tokenStart;
    739 }
    740 
    741 template <>
    742 inline void CSSParser::setTokenStart<UChar>(UChar* tokenStart)
    743 {
    744     m_tokenStart.ptr16 = tokenStart;
    745 }
    746 
    747 inline unsigned CSSParser::tokenStartOffset()
    748 {
    749     if (is8BitSource())
    750         return m_tokenStart.ptr8 - m_dataStart8.get();
    751     return m_tokenStart.ptr16 - m_dataStart16.get();
    752 }
    753 
    754 inline UChar CSSParser::tokenStartChar()
    755 {
    756     if (is8BitSource())
    757         return *m_tokenStart.ptr8;
    758     return *m_tokenStart.ptr16;
    759 }
    760 
    761 inline int cssyylex(void* yylval, CSSParser* parser)
    762 {
    763     return parser->lex(yylval);
    764 }
    765 
    766 } // namespace WebCore
    767 
    768 #endif // CSSParser_h
    769