/platform/external/webkit/WebCore/css/CSSParser.h

https://github.com/aharish/totoro-gb-opensource-update2 · C Header · 319 lines · 229 code · 66 blank · 24 comment · 2 complexity · 18388bc741e96bc745fe6cbec44cd3c9 MD5 · raw file

  1. /*
  2. * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
  4. * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this library; see the file COPYING.LIB. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef CSSParser_h
  22. #define CSSParser_h
  23. #include "AtomicString.h"
  24. #include "Color.h"
  25. #include "CSSParserValues.h"
  26. #include "CSSSelectorList.h"
  27. #include "MediaQuery.h"
  28. #include <wtf/HashSet.h>
  29. #include <wtf/Vector.h>
  30. namespace WebCore {
  31. class CSSMutableStyleDeclaration;
  32. class CSSPrimitiveValue;
  33. class CSSProperty;
  34. class CSSRule;
  35. class CSSRuleList;
  36. class CSSSelector;
  37. class CSSStyleSheet;
  38. class CSSValue;
  39. class CSSValueList;
  40. class CSSVariablesDeclaration;
  41. class Document;
  42. class MediaList;
  43. class MediaQueryExp;
  44. class StyleBase;
  45. class StyleList;
  46. class WebKitCSSKeyframeRule;
  47. class WebKitCSSKeyframesRule;
  48. class CSSParser {
  49. public:
  50. CSSParser(bool strictParsing = true);
  51. ~CSSParser();
  52. void parseSheet(CSSStyleSheet*, const String&);
  53. PassRefPtr<CSSRule> parseRule(CSSStyleSheet*, const String&);
  54. PassRefPtr<CSSRule> parseKeyframeRule(CSSStyleSheet*, const String&);
  55. bool parseValue(CSSMutableStyleDeclaration*, int propId, const String&, bool important);
  56. static bool parseColor(RGBA32& color, const String&, bool strict = false);
  57. bool parseColor(CSSMutableStyleDeclaration*, const String&);
  58. bool parseDeclaration(CSSMutableStyleDeclaration*, const String&);
  59. bool parseMediaQuery(MediaList*, const String&);
  60. Document* document() const;
  61. void addProperty(int propId, PassRefPtr<CSSValue>, bool important);
  62. void rollbackLastProperties(int num);
  63. bool hasProperties() const { return m_numParsedProperties > 0; }
  64. bool parseValue(int propId, bool important);
  65. bool parseShorthand(int propId, const int* properties, int numProperties, bool important);
  66. bool parse4Values(int propId, const int* properties, bool important);
  67. bool parseContent(int propId, bool important);
  68. PassRefPtr<CSSValue> parseAttr(CSSParserValueList* args);
  69. PassRefPtr<CSSValue> parseBackgroundColor();
  70. bool parseFillImage(RefPtr<CSSValue>&);
  71. PassRefPtr<CSSValue> parseFillPositionXY(bool& xFound, bool& yFound);
  72. void parseFillPosition(RefPtr<CSSValue>&, RefPtr<CSSValue>&);
  73. void parseFillRepeat(RefPtr<CSSValue>&, RefPtr<CSSValue>&);
  74. PassRefPtr<CSSValue> parseFillSize(int propId, bool &allowComma);
  75. bool parseFillProperty(int propId, int& propId1, int& propId2, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
  76. bool parseFillShorthand(int propId, const int* properties, int numProperties, bool important);
  77. void addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval);
  78. void addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval);
  79. PassRefPtr<CSSValue> parseAnimationDelay();
  80. PassRefPtr<CSSValue> parseAnimationDirection();
  81. PassRefPtr<CSSValue> parseAnimationDuration();
  82. PassRefPtr<CSSValue> parseAnimationIterationCount();
  83. PassRefPtr<CSSValue> parseAnimationName();
  84. PassRefPtr<CSSValue> parseAnimationPlayState();
  85. PassRefPtr<CSSValue> parseAnimationProperty();
  86. PassRefPtr<CSSValue> parseAnimationTimingFunction();
  87. void parseTransformOriginShorthand(RefPtr<CSSValue>&, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
  88. bool parseTimingFunctionValue(CSSParserValueList*& args, double& result);
  89. bool parseAnimationProperty(int propId, RefPtr<CSSValue>&);
  90. bool parseTransitionShorthand(bool important);
  91. bool parseAnimationShorthand(bool important);
  92. bool parseDashboardRegions(int propId, bool important);
  93. bool parseShape(int propId, bool important);
  94. bool parseFont(bool important);
  95. PassRefPtr<CSSValueList> parseFontFamily();
  96. bool parseCounter(int propId, int defaultValue, bool important);
  97. PassRefPtr<CSSValue> parseCounterContent(CSSParserValueList* args, bool counters);
  98. bool parseColorParameters(CSSParserValue*, int* colorValues, bool parseAlpha);
  99. bool parseHSLParameters(CSSParserValue*, double* colorValues, bool parseAlpha);
  100. PassRefPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = 0);
  101. bool parseColorFromValue(CSSParserValue*, RGBA32&, bool = false);
  102. void parseSelector(const String&, Document* doc, CSSSelectorList&);
  103. static bool parseColor(const String&, RGBA32& rgb, bool strict);
  104. bool parseFontStyle(bool important);
  105. bool parseFontVariant(bool important);
  106. bool parseFontWeight(bool important);
  107. bool parseFontFaceSrc();
  108. bool parseFontFaceUnicodeRange();
  109. #if ENABLE(SVG)
  110. bool parseSVGValue(int propId, bool important);
  111. PassRefPtr<CSSValue> parseSVGPaint();
  112. PassRefPtr<CSSValue> parseSVGColor();
  113. PassRefPtr<CSSValue> parseSVGStrokeDasharray();
  114. #endif
  115. // CSS3 Parsing Routines (for properties specific to CSS3)
  116. bool parseShadow(int propId, bool important);
  117. bool parseBorderImage(int propId, bool important, RefPtr<CSSValue>&);
  118. bool parseBorderRadius(int propId, bool important);
  119. bool parseReflect(int propId, bool important);
  120. // Image generators
  121. bool parseCanvas(RefPtr<CSSValue>&);
  122. bool parseGradient(RefPtr<CSSValue>&);
  123. PassRefPtr<CSSValueList> parseTransform();
  124. bool parseTransformOrigin(int propId, int& propId1, int& propId2, int& propId3, RefPtr<CSSValue>&, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
  125. bool parsePerspectiveOrigin(int propId, int& propId1, int& propId2, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
  126. bool parseVariable(CSSVariablesDeclaration*, const String& variableName, const String& variableValue);
  127. void parsePropertyWithResolvedVariables(int propId, bool important, CSSMutableStyleDeclaration*, CSSParserValueList*);
  128. int yyparse();
  129. CSSSelector* createFloatingSelector();
  130. CSSSelector* sinkFloatingSelector(CSSSelector*);
  131. CSSParserValueList* createFloatingValueList();
  132. CSSParserValueList* sinkFloatingValueList(CSSParserValueList*);
  133. CSSParserFunction* createFloatingFunction();
  134. CSSParserFunction* sinkFloatingFunction(CSSParserFunction*);
  135. CSSParserValue& sinkFloatingValue(CSSParserValue&);
  136. MediaList* createMediaList();
  137. CSSRule* createCharsetRule(const CSSParserString&);
  138. CSSRule* createImportRule(const CSSParserString&, MediaList*);
  139. WebKitCSSKeyframeRule* createKeyframeRule(CSSParserValueList*);
  140. WebKitCSSKeyframesRule* createKeyframesRule();
  141. CSSRule* createMediaRule(MediaList*, CSSRuleList*);
  142. CSSRuleList* createRuleList();
  143. CSSRule* createStyleRule(Vector<CSSSelector*>* selectors);
  144. CSSRule* createFontFaceRule();
  145. CSSRule* createVariablesRule(MediaList*, bool variablesKeyword);
  146. MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
  147. MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*);
  148. Vector<MediaQueryExp*>* createFloatingMediaQueryExpList();
  149. Vector<MediaQueryExp*>* sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
  150. MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, Vector<MediaQueryExp*>*);
  151. MediaQuery* createFloatingMediaQuery(Vector<MediaQueryExp*>*);
  152. MediaQuery* sinkFloatingMediaQuery(MediaQuery*);
  153. void addNamespace(const AtomicString& prefix, const AtomicString& uri);
  154. bool addVariable(const CSSParserString&, CSSParserValueList*);
  155. bool addVariableDeclarationBlock(const CSSParserString&);
  156. bool checkForVariables(CSSParserValueList*);
  157. void addUnresolvedProperty(int propId, bool important);
  158. void invalidBlockHit();
  159. Vector<CSSSelector*>* reusableSelectorVector() { return &m_reusableSelectorVector; }
  160. bool m_strict;
  161. bool m_important;
  162. int m_id;
  163. CSSStyleSheet* m_styleSheet;
  164. RefPtr<CSSRule> m_rule;
  165. RefPtr<CSSRule> m_keyframe;
  166. MediaQuery* m_mediaQuery;
  167. CSSParserValueList* m_valueList;
  168. CSSProperty** m_parsedProperties;
  169. CSSSelectorList* m_selectorListForParseSelector;
  170. unsigned m_numParsedProperties;
  171. unsigned m_maxParsedProperties;
  172. int m_inParseShorthand;
  173. int m_currentShorthand;
  174. bool m_implicitShorthand;
  175. bool m_hasFontFaceOnlyValues;
  176. bool m_hadSyntacticallyValidCSSRule;
  177. Vector<String> m_variableNames;
  178. Vector<RefPtr<CSSValue> > m_variableValues;
  179. AtomicString m_defaultNamespace;
  180. // tokenizer methods and data
  181. int lex(void* yylval);
  182. int token() { return yyTok; }
  183. UChar* text(int* length);
  184. int lex();
  185. private:
  186. void recheckAtKeyword(const UChar* str, int len);
  187. void clearProperties();
  188. void setupParser(const char* prefix, const String&, const char* suffix);
  189. bool inShorthand() const { return m_inParseShorthand; }
  190. void checkForOrphanedUnits();
  191. void clearVariables();
  192. void deleteFontFaceOnlyValues();
  193. UChar* m_data;
  194. UChar* yytext;
  195. UChar* yy_c_buf_p;
  196. UChar yy_hold_char;
  197. int yy_last_accepting_state;
  198. UChar* yy_last_accepting_cpos;
  199. int yyleng;
  200. int yyTok;
  201. int yy_start;
  202. bool m_allowImportRules;
  203. bool m_allowVariablesRules;
  204. bool m_allowNamespaceDeclarations;
  205. Vector<RefPtr<StyleBase> > m_parsedStyleObjects;
  206. Vector<RefPtr<CSSRuleList> > m_parsedRuleLists;
  207. HashSet<CSSSelector*> m_floatingSelectors;
  208. HashSet<CSSParserValueList*> m_floatingValueLists;
  209. HashSet<CSSParserFunction*> m_floatingFunctions;
  210. MediaQuery* m_floatingMediaQuery;
  211. MediaQueryExp* m_floatingMediaQueryExp;
  212. Vector<MediaQueryExp*>* m_floatingMediaQueryExpList;
  213. Vector<CSSSelector*> m_reusableSelectorVector;
  214. // defines units allowed for a certain property, used in parseUnit
  215. enum Units {
  216. FUnknown = 0x0000,
  217. FInteger = 0x0001,
  218. FNumber = 0x0002, // Real Numbers
  219. FPercent = 0x0004,
  220. FLength = 0x0008,
  221. FAngle = 0x0010,
  222. FTime = 0x0020,
  223. FFrequency = 0x0040,
  224. FRelative = 0x0100,
  225. FNonNeg = 0x0200
  226. };
  227. friend inline Units operator|(Units a, Units b)
  228. {
  229. return static_cast<Units>(static_cast<unsigned>(a) | static_cast<unsigned>(b));
  230. }
  231. static bool validUnit(CSSParserValue*, Units, bool strict);
  232. friend class TransformOperationInfo;
  233. };
  234. int cssPropertyID(const CSSParserString&);
  235. int cssPropertyID(const String&);
  236. int cssValueKeywordID(const CSSParserString&);
  237. class ShorthandScope : public FastAllocBase {
  238. public:
  239. ShorthandScope(CSSParser* parser, int propId) : m_parser(parser)
  240. {
  241. if (!(m_parser->m_inParseShorthand++))
  242. m_parser->m_currentShorthand = propId;
  243. }
  244. ~ShorthandScope()
  245. {
  246. if (!(--m_parser->m_inParseShorthand))
  247. m_parser->m_currentShorthand = 0;
  248. }
  249. private:
  250. CSSParser* m_parser;
  251. };
  252. } // namespace WebCore
  253. #endif // CSSParser_h