2
* This file is part of the DOM implementation for KDE.
4
* Copyright (C) 2003 Lars Knoll (knoll@kde.org)
5
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
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.
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.
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., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
26
#include "AtomicString.h"
28
#include "MediaQuery.h"
29
#include <wtf/HashSet.h>
30
#include <wtf/Vector.h>
34
class CSSMutableStyleDeclaration;
35
class CSSPrimitiveValue;
75
DeprecatedString deprecatedString(const ParseString&);
77
static inline String domString(const ParseString& ps)
79
return String(ps.characters, ps.length);
82
static inline AtomicString atomicString(const ParseString& ps)
84
return AtomicString(ps.characters, ps.length);
89
ValueList() : m_current(0) { }
92
void addValue(const Value& v) { m_values.append(v); }
93
unsigned size() const { return m_values.size(); }
94
Value* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
95
Value* next() { ++m_current; return current(); }
97
Value* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
98
void deleteValueAt(unsigned i) { m_values.remove(i); }
101
Vector<Value, 16> m_values;
109
~Function() { delete args; }
114
CSSParser(bool strictParsing = true);
117
void parseSheet(CSSStyleSheet*, const String&);
118
PassRefPtr<CSSRule> parseRule(CSSStyleSheet*, const String&);
119
bool parseValue(CSSMutableStyleDeclaration*, int propId, const String&, bool important);
120
static RGBA32 parseColor(const String&, bool strict = false);
121
bool parseColor(CSSMutableStyleDeclaration*, const String&);
122
bool parseDeclaration(CSSMutableStyleDeclaration*, const String&);
123
bool parseMediaQuery(MediaList*, const String&);
125
static CSSParser* current() { return currentParser; }
127
Document* document() const;
129
void addProperty(int propId, PassRefPtr<CSSValue>, bool important);
130
void rollbackLastProperties(int num);
131
bool hasProperties() const { return numParsedProperties > 0; }
133
bool parseValue(int propId, bool important);
134
bool parseShorthand(int propId, const int* properties, int numProperties, bool important);
135
bool parse4Values(int propId, const int* properties, bool important);
136
bool parseContent(int propId, bool important);
138
CSSValue* parseBackgroundColor();
139
CSSValue* parseBackgroundImage();
140
CSSValue* parseBackgroundPositionXY(bool& xFound, bool& yFound);
141
void parseBackgroundPosition(CSSValue*&, CSSValue*&);
142
CSSValue* parseBackgroundSize();
144
bool parseBackgroundProperty(int propId, int& propId1, int& propId2, CSSValue*&, CSSValue*&);
145
bool parseBackgroundShorthand(bool important);
147
void addBackgroundValue(CSSValue*& lval, CSSValue* rval);
149
bool parseDashboardRegions(int propId, bool important);
151
bool parseShape(int propId, bool important);
153
bool parseFont(bool important);
154
CSSValueList* parseFontFamily();
156
bool parseCounter(int propId, int defaultValue, bool important);
157
PassRefPtr<CSSValue> parseCounterContent(ValueList* args, bool counters);
159
bool parseColorParameters(Value*, int* colorValues, bool parseAlpha);
160
bool parseHSLParameters(Value*, double* colorValues, bool parseAlpha);
161
CSSPrimitiveValue* parseColor(Value* = 0);
162
bool parseColorFromValue(Value*, RGBA32&, bool = false);
164
static bool parseColor(const String&, RGBA32& rgb, bool strict);
167
bool parseSVGValue(int propId, bool important);
168
CSSValue* parseSVGPaint();
169
CSSValue* parseSVGColor();
170
CSSValue* parseSVGStrokeDasharray();
173
// CSS3 Parsing Routines (for properties specific to CSS3)
174
bool parseShadow(int propId, bool important);
175
bool parseBorderImage(int propId, bool important);
179
CSSSelector* createFloatingSelector();
180
CSSSelector* sinkFloatingSelector(CSSSelector*);
182
ValueList* createFloatingValueList();
183
ValueList* sinkFloatingValueList(ValueList*);
185
Function* createFloatingFunction();
186
Function* sinkFloatingFunction(Function*);
188
Value& sinkFloatingValue(Value&);
190
MediaList* createMediaList();
191
CSSRule* createCharsetRule(const ParseString&);
192
CSSRule* createImportRule(const ParseString&, MediaList*);
193
CSSRule* createMediaRule(MediaList*, CSSRuleList*);
194
CSSRuleList* createRuleList();
195
CSSRule* createStyleRule(CSSSelector*);
197
MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, ValueList*);
198
MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*);
199
Vector<MediaQueryExp*>* createFloatingMediaQueryExpList();
200
Vector<MediaQueryExp*>* sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
201
MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, Vector<MediaQueryExp*>*);
202
MediaQuery* sinkFloatingMediaQuery(MediaQuery*);
208
StyleList* styleElement;
209
RefPtr<CSSRule> rule;
210
MediaQuery* mediaQuery;
211
ValueList* valueList;
212
CSSProperty** parsedProperties;
213
int numParsedProperties;
214
int maxParsedProperties;
216
int m_inParseShorthand;
217
int m_currentShorthand;
218
bool m_implicitShorthand;
220
AtomicString defaultNamespace;
222
static CSSParser* currentParser;
224
// tokenizer methods and data
226
int lex(void* yylval);
227
int token() { return yyTok; }
228
UChar* text(int* length);
232
void clearProperties();
234
void setupParser(const char* prefix, const String&, const char* suffix);
236
bool inShorthand() const { return m_inParseShorthand; }
238
void checkForOrphanedUnits();
244
int yy_last_accepting_state;
245
UChar* yy_last_accepting_cpos;
250
Vector<RefPtr<StyleBase> > m_parsedStyleObjects;
251
Vector<RefPtr<CSSRuleList> > m_parsedRuleLists;
252
HashSet<CSSSelector*> m_floatingSelectors;
253
HashSet<ValueList*> m_floatingValueLists;
254
HashSet<Function*> m_floatingFunctions;
256
MediaQuery* m_floatingMediaQuery;
257
MediaQueryExp* m_floatingMediaQueryExp;
258
Vector<MediaQueryExp*>* m_floatingMediaQueryExpList;
260
// defines units allowed for a certain property, used in parseUnit
264
FNumber = 0x0002, // Real Numbers
274
friend inline Units operator|(Units a, Units b)
276
return static_cast<Units>(static_cast<unsigned>(a) | static_cast<unsigned>(b));
279
static bool validUnit(Value*, Units, bool strict);
282
} // namespace WebCore
284
#endif // CSSParser_h