]> git.saurik.com Git - iphone-api.git/blob - WebCore/CSSParser.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / CSSParser.h
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
22 #ifndef CSSParser_h
23 #define CSSParser_h
24
25 #include "AtomicString.h"
26 #include "Color.h"
27 #include "CSSParserValues.h"
28 #include "CSSSelectorList.h"
29 #include "MediaQuery.h"
30 #include <wtf/HashSet.h>
31 #include <wtf/Vector.h>
32
33 namespace WebCore {
34
35 class CSSMutableStyleDeclaration;
36 class CSSPrimitiveValue;
37 class CSSProperty;
38 class CSSRule;
39 class CSSRuleList;
40 class CSSSelector;
41 class CSSStyleSheet;
42 class CSSValue;
43 class CSSValueList;
44 class CSSVariablesDeclaration;
45 class Document;
46 class MediaList;
47 class MediaQueryExp;
48 class StyleBase;
49 class StyleList;
50 class WebKitCSSKeyframeRule;
51 class WebKitCSSKeyframesRule;
52
53 class CSSParser {
54 public:
55 CSSParser(bool strictParsing = true);
56 ~CSSParser();
57
58 void parseSheet(CSSStyleSheet*, const String&);
59 PassRefPtr<CSSRule> parseRule(CSSStyleSheet*, const String&);
60 PassRefPtr<CSSRule> parseKeyframeRule(CSSStyleSheet*, const String&);
61 bool parseValue(CSSMutableStyleDeclaration*, int propId, const String&, bool important);
62 static bool parseColor(RGBA32& color, const String&, bool strict = false);
63 bool parseColor(CSSMutableStyleDeclaration*, const String&);
64 bool parseDeclaration(CSSMutableStyleDeclaration*, const String&);
65 bool parseMediaQuery(MediaList*, const String&);
66
67 Document* document() const;
68
69 void addProperty(int propId, PassRefPtr<CSSValue>, bool important);
70 void rollbackLastProperties(int num);
71 bool hasProperties() const { return m_numParsedProperties > 0; }
72
73 bool parseValue(int propId, bool important);
74 bool parseShorthand(int propId, const int* properties, int numProperties, bool important);
75 bool parse4Values(int propId, const int* properties, bool important);
76 bool parseContent(int propId, bool important);
77
78 PassRefPtr<CSSValue> parseBackgroundColor();
79
80 bool parseFillImage(RefPtr<CSSValue>&);
81 PassRefPtr<CSSValue> parseFillPositionXY(bool& xFound, bool& yFound);
82 void parseFillPosition(RefPtr<CSSValue>&, RefPtr<CSSValue>&);
83 PassRefPtr<CSSValue> parseFillSize();
84
85 bool parseFillProperty(int propId, int& propId1, int& propId2, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
86 bool parseFillShorthand(int propId, const int* properties, int numProperties, bool important);
87
88 void addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval);
89
90 void addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval);
91
92 PassRefPtr<CSSValue> parseAnimationDelay();
93 PassRefPtr<CSSValue> parseAnimationDirection();
94 PassRefPtr<CSSValue> parseAnimationDuration();
95 PassRefPtr<CSSValue> parseAnimationIterationCount();
96 PassRefPtr<CSSValue> parseAnimationName();
97 PassRefPtr<CSSValue> parseAnimationPlayState();
98 PassRefPtr<CSSValue> parseAnimationProperty();
99 PassRefPtr<CSSValue> parseAnimationTimingFunction();
100
101 void parseTransformOriginShorthand(RefPtr<CSSValue>&, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
102 bool parseTimingFunctionValue(CSSParserValueList*& args, double& result);
103 bool parseAnimationProperty(int propId, RefPtr<CSSValue>&);
104 bool parseTransitionShorthand(bool important);
105 bool parseAnimationShorthand(bool important);
106
107 bool parseDashboardRegions(int propId, bool important);
108
109 bool parseShape(int propId, bool important);
110
111 bool parseFont(bool important);
112 PassRefPtr<CSSValueList> parseFontFamily();
113
114 bool parseCounter(int propId, int defaultValue, bool important);
115 PassRefPtr<CSSValue> parseCounterContent(CSSParserValueList* args, bool counters);
116
117 bool parseColorParameters(CSSParserValue*, int* colorValues, bool parseAlpha);
118 bool parseHSLParameters(CSSParserValue*, double* colorValues, bool parseAlpha);
119 PassRefPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = 0);
120 bool parseColorFromValue(CSSParserValue*, RGBA32&, bool = false);
121 void parseSelector(const String&, Document* doc, CSSSelectorList&);
122
123 static bool parseColor(const String&, RGBA32& rgb, bool strict);
124
125 bool parseFontStyle(bool important);
126 bool parseFontVariant(bool important);
127 bool parseFontWeight(bool important);
128 bool parseFontFaceSrc();
129 bool parseFontFaceUnicodeRange();
130
131 #if ENABLE(SVG)
132 bool parseSVGValue(int propId, bool important);
133 PassRefPtr<CSSValue> parseSVGPaint();
134 PassRefPtr<CSSValue> parseSVGColor();
135 PassRefPtr<CSSValue> parseSVGStrokeDasharray();
136 #endif
137
138 // CSS3 Parsing Routines (for properties specific to CSS3)
139 bool parseShadow(int propId, bool important);
140 bool parseBorderImage(int propId, bool important, RefPtr<CSSValue>&);
141
142 bool parseReflect(int propId, bool important);
143
144 // Image generators
145 bool parseCanvas(RefPtr<CSSValue>&);
146 bool parseGradient(RefPtr<CSSValue>&);
147
148 PassRefPtr<CSSValueList> parseTransform();
149 bool parseTransformOrigin(int propId, int& propId1, int& propId2, int& propId3, RefPtr<CSSValue>&, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
150 bool parsePerspectiveOrigin(int propId, int& propId1, int& propId, RefPtr<CSSValue>&, RefPtr<CSSValue>&);
151 bool parseVariable(CSSVariablesDeclaration*, const String& variableName, const String& variableValue);
152 void parsePropertyWithResolvedVariables(int propId, bool important, CSSMutableStyleDeclaration*, CSSParserValueList*);
153
154 int yyparse();
155
156 CSSSelector* createFloatingSelector();
157 CSSSelector* sinkFloatingSelector(CSSSelector*);
158
159 CSSParserValueList* createFloatingValueList();
160 CSSParserValueList* sinkFloatingValueList(CSSParserValueList*);
161
162 CSSParserFunction* createFloatingFunction();
163 CSSParserFunction* sinkFloatingFunction(CSSParserFunction*);
164
165 CSSParserValue& sinkFloatingValue(CSSParserValue&);
166
167 MediaList* createMediaList();
168 CSSRule* createCharsetRule(const CSSParserString&);
169 CSSRule* createImportRule(const CSSParserString&, MediaList*);
170 WebKitCSSKeyframeRule* createKeyframeRule(CSSParserValueList*);
171 WebKitCSSKeyframesRule* createKeyframesRule();
172 CSSRule* createMediaRule(MediaList*, CSSRuleList*);
173 CSSRuleList* createRuleList();
174 CSSRule* createStyleRule(Vector<CSSSelector*>* selectors);
175 CSSRule* createFontFaceRule();
176 CSSRule* createVariablesRule(MediaList*, bool variablesKeyword);
177
178 MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
179 MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*);
180 Vector<MediaQueryExp*>* createFloatingMediaQueryExpList();
181 Vector<MediaQueryExp*>* sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
182 MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, Vector<MediaQueryExp*>*);
183 MediaQuery* createFloatingMediaQuery(Vector<MediaQueryExp*>*);
184 MediaQuery* sinkFloatingMediaQuery(MediaQuery*);
185
186 bool addVariable(const CSSParserString&, CSSParserValueList*);
187 bool addVariableDeclarationBlock(const CSSParserString&);
188 bool checkForVariables(CSSParserValueList*);
189 void addUnresolvedProperty(int propId, bool important);
190
191 Vector<CSSSelector*>* reusableSelectorVector() { return &m_reusableSelectorVector; }
192
193 public:
194 bool m_strict;
195 bool m_important;
196 int m_id;
197 CSSStyleSheet* m_styleSheet;
198 RefPtr<CSSRule> m_rule;
199 RefPtr<CSSRule> m_keyframe;
200 MediaQuery* m_mediaQuery;
201 CSSParserValueList* m_valueList;
202 CSSProperty** m_parsedProperties;
203 CSSSelectorList* m_selectorListForParseSelector;
204 unsigned m_numParsedProperties;
205 unsigned m_maxParsedProperties;
206
207 int m_inParseShorthand;
208 int m_currentShorthand;
209 bool m_implicitShorthand;
210
211 bool m_hasFontFaceOnlyValues;
212
213 Vector<String> m_variableNames;
214 Vector<RefPtr<CSSValue> > m_variableValues;
215
216 AtomicString m_defaultNamespace;
217
218 // tokenizer methods and data
219 public:
220 int lex(void* yylval);
221 int token() { return yyTok; }
222 UChar* text(int* length);
223 int lex();
224
225 private:
226 void clearProperties();
227
228 void setupParser(const char* prefix, const String&, const char* suffix);
229
230 bool inShorthand() const { return m_inParseShorthand; }
231
232 void checkForOrphanedUnits();
233
234 void clearVariables();
235
236 void deleteFontFaceOnlyValues();
237
238 UChar* m_data;
239 UChar* yytext;
240 UChar* yy_c_buf_p;
241 UChar yy_hold_char;
242 int yy_last_accepting_state;
243 UChar* yy_last_accepting_cpos;
244 int yyleng;
245 int yyTok;
246 int yy_start;
247
248 Vector<RefPtr<StyleBase> > m_parsedStyleObjects;
249 Vector<RefPtr<CSSRuleList> > m_parsedRuleLists;
250 HashSet<CSSSelector*> m_floatingSelectors;
251 HashSet<CSSParserValueList*> m_floatingValueLists;
252 HashSet<CSSParserFunction*> m_floatingFunctions;
253
254 MediaQuery* m_floatingMediaQuery;
255 MediaQueryExp* m_floatingMediaQueryExp;
256 Vector<MediaQueryExp*>* m_floatingMediaQueryExpList;
257
258 Vector<CSSSelector*> m_reusableSelectorVector;
259
260 // defines units allowed for a certain property, used in parseUnit
261 enum Units {
262 FUnknown = 0x0000,
263 FInteger = 0x0001,
264 FNumber = 0x0002, // Real Numbers
265 FPercent = 0x0004,
266 FLength = 0x0008,
267 FAngle = 0x0010,
268 FTime = 0x0020,
269 FFrequency = 0x0040,
270 FRelative = 0x0100,
271 FNonNeg = 0x0200
272 };
273
274 friend inline Units operator|(Units a, Units b)
275 {
276 return static_cast<Units>(static_cast<unsigned>(a) | static_cast<unsigned>(b));
277 }
278
279 static bool validUnit(CSSParserValue*, Units, bool strict);
280
281 friend class TransformOperationInfo;
282 };
283
284 int cssPropertyID(const CSSParserString&);
285 int cssPropertyID(const String&);
286 int cssValueKeywordID(const CSSParserString&);
287
288 class ShorthandScope {
289 public:
290 ShorthandScope(CSSParser* parser, int propId) : m_parser(parser)
291 {
292 if (!(m_parser->m_inParseShorthand++))
293 m_parser->m_currentShorthand = propId;
294 }
295 ~ShorthandScope()
296 {
297 if (!(--m_parser->m_inParseShorthand))
298 m_parser->m_currentShorthand = 0;
299 }
300
301 private:
302 CSSParser* m_parser;
303 };
304
305 } // namespace WebCore
306
307 #endif // CSSParser_h