~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/css/CSSParser.h

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the DOM implementation for KDE.
 
3
 *
 
4
 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
 
5
 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
 
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., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#ifndef CSSParser_h
 
24
#define CSSParser_h
 
25
 
 
26
#include "AtomicString.h"
 
27
#include "Color.h"
 
28
#include "MediaQuery.h"
 
29
#include <wtf/HashSet.h>
 
30
#include <wtf/Vector.h>
 
31
 
 
32
namespace WebCore {
 
33
 
 
34
    class CSSMutableStyleDeclaration;
 
35
    class CSSPrimitiveValue;
 
36
    class CSSProperty;
 
37
    class CSSRule;
 
38
    class CSSRuleList;
 
39
    class CSSSelector;
 
40
    class CSSStyleSheet;
 
41
    class CSSValue;
 
42
    class CSSValueList;
 
43
    class Document;
 
44
    class MediaList;
 
45
    class MediaList;
 
46
    class MediaQueryExp;
 
47
    class StyleBase;
 
48
    class StyleList;
 
49
    struct Function;
 
50
 
 
51
    struct ParseString {
 
52
        UChar* characters;
 
53
        int length;
 
54
 
 
55
        void lower();
 
56
    };
 
57
 
 
58
    struct Value {
 
59
        int id;
 
60
        bool isInt;
 
61
        union {
 
62
            double fValue;
 
63
            int iValue;
 
64
            ParseString string;
 
65
            Function* function;
 
66
        };
 
67
        enum {
 
68
            Operator = 0x100000,
 
69
            Function = 0x100001,
 
70
            Q_EMS    = 0x100002
 
71
        };
 
72
        int unit;
 
73
    };
 
74
 
 
75
    DeprecatedString deprecatedString(const ParseString&);
 
76
 
 
77
    static inline String domString(const ParseString& ps)
 
78
    {
 
79
        return String(ps.characters, ps.length);
 
80
    }
 
81
 
 
82
    static inline AtomicString atomicString(const ParseString& ps)
 
83
    {
 
84
        return AtomicString(ps.characters, ps.length);
 
85
    }
 
86
 
 
87
    class ValueList {
 
88
    public:
 
89
        ValueList() : m_current(0) { }
 
90
        ~ValueList();
 
91
 
 
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(); }
 
96
 
 
97
        Value* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
 
98
        void deleteValueAt(unsigned i) { m_values.remove(i); }
 
99
 
 
100
    private:
 
101
        Vector<Value, 16> m_values;
 
102
        unsigned m_current;
 
103
    };
 
104
 
 
105
    struct Function {
 
106
        ParseString name;
 
107
        ValueList* args;
 
108
 
 
109
        ~Function() { delete args; }
 
110
    };
 
111
 
 
112
    class CSSParser {
 
113
    public:
 
114
        CSSParser(bool strictParsing = true);
 
115
        ~CSSParser();
 
116
 
 
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&);
 
124
 
 
125
        static CSSParser* current() { return currentParser; }
 
126
 
 
127
        Document* document() const;
 
128
 
 
129
        void addProperty(int propId, PassRefPtr<CSSValue>, bool important);
 
130
        void rollbackLastProperties(int num);
 
131
        bool hasProperties() const { return numParsedProperties > 0; }
 
132
 
 
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);
 
137
 
 
138
        CSSValue* parseBackgroundColor();
 
139
        CSSValue* parseBackgroundImage();
 
140
        CSSValue* parseBackgroundPositionXY(bool& xFound, bool& yFound);
 
141
        void parseBackgroundPosition(CSSValue*&, CSSValue*&);
 
142
        CSSValue* parseBackgroundSize();
 
143
        
 
144
        bool parseBackgroundProperty(int propId, int& propId1, int& propId2, CSSValue*&, CSSValue*&);
 
145
        bool parseBackgroundShorthand(bool important);
 
146
 
 
147
        void addBackgroundValue(CSSValue*& lval, CSSValue* rval);
 
148
 
 
149
        bool parseDashboardRegions(int propId, bool important);
 
150
 
 
151
        bool parseShape(int propId, bool important);
 
152
 
 
153
        bool parseFont(bool important);
 
154
        CSSValueList* parseFontFamily();
 
155
 
 
156
        bool parseCounter(int propId, int defaultValue, bool important);
 
157
        PassRefPtr<CSSValue> parseCounterContent(ValueList* args, bool counters);
 
158
 
 
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);
 
163
 
 
164
        static bool parseColor(const String&, RGBA32& rgb, bool strict);
 
165
 
 
166
#if ENABLE(SVG)
 
167
        bool parseSVGValue(int propId, bool important);
 
168
        CSSValue* parseSVGPaint();
 
169
        CSSValue* parseSVGColor();
 
170
        CSSValue* parseSVGStrokeDasharray();
 
171
#endif
 
172
 
 
173
        // CSS3 Parsing Routines (for properties specific to CSS3)
 
174
        bool parseShadow(int propId, bool important);
 
175
        bool parseBorderImage(int propId, bool important);
 
176
 
 
177
        int yyparse();
 
178
 
 
179
        CSSSelector* createFloatingSelector();
 
180
        CSSSelector* sinkFloatingSelector(CSSSelector*);
 
181
 
 
182
        ValueList* createFloatingValueList();
 
183
        ValueList* sinkFloatingValueList(ValueList*);
 
184
 
 
185
        Function* createFloatingFunction();
 
186
        Function* sinkFloatingFunction(Function*);
 
187
 
 
188
        Value& sinkFloatingValue(Value&);
 
189
 
 
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*);
 
196
 
 
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*);
 
203
 
 
204
    public:
 
205
        bool strict;
 
206
        bool important;
 
207
        int id;
 
208
        StyleList* styleElement;
 
209
        RefPtr<CSSRule> rule;
 
210
        MediaQuery* mediaQuery;
 
211
        ValueList* valueList;
 
212
        CSSProperty** parsedProperties;
 
213
        int numParsedProperties;
 
214
        int maxParsedProperties;
 
215
 
 
216
        int m_inParseShorthand;
 
217
        int m_currentShorthand;
 
218
        bool m_implicitShorthand;
 
219
 
 
220
        AtomicString defaultNamespace;
 
221
 
 
222
        static CSSParser* currentParser;
 
223
 
 
224
        // tokenizer methods and data
 
225
    public:
 
226
        int lex(void* yylval);
 
227
        int token() { return yyTok; }
 
228
        UChar* text(int* length);
 
229
        int lex();
 
230
        
 
231
    private:
 
232
        void clearProperties();
 
233
 
 
234
        void setupParser(const char* prefix, const String&, const char* suffix);
 
235
 
 
236
        bool inShorthand() const { return m_inParseShorthand; }
 
237
 
 
238
        void checkForOrphanedUnits();
 
239
        
 
240
        UChar* data;
 
241
        UChar* yytext;
 
242
        UChar* yy_c_buf_p;
 
243
        UChar yy_hold_char;
 
244
        int yy_last_accepting_state;
 
245
        UChar* yy_last_accepting_cpos;
 
246
        int yyleng;
 
247
        int yyTok;
 
248
        int yy_start;
 
249
 
 
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;
 
255
 
 
256
        MediaQuery* m_floatingMediaQuery;
 
257
        MediaQueryExp* m_floatingMediaQueryExp;
 
258
        Vector<MediaQueryExp*>* m_floatingMediaQueryExpList;
 
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(Value*, Units, bool strict);
 
280
    };
 
281
 
 
282
} // namespace WebCore
 
283
 
 
284
#endif // CSSParser_h