CSSParserValues.h revision ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb
1/*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB.  If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef CSSParserValues_h
22#define CSSParserValues_h
23
24#include <wtf/text/AtomicString.h>
25
26namespace WebCore {
27
28class CSSValue;
29
30struct CSSParserString {
31    UChar* characters;
32    int length;
33
34    void lower();
35
36    operator String() const { return String(characters, length); }
37    operator AtomicString() const { return AtomicString(characters, length); }
38};
39
40struct CSSParserFunction;
41
42struct CSSParserValue {
43    int id;
44    bool isInt;
45    union {
46        double fValue;
47        int iValue;
48        CSSParserString string;
49        CSSParserFunction* function;
50    };
51    enum {
52        Operator = 0x100000,
53        Function = 0x100001,
54        Q_EMS    = 0x100002
55    };
56    int unit;
57
58
59    PassRefPtr<CSSValue> createCSSValue();
60};
61
62class CSSParserValueList {
63    WTF_MAKE_FAST_ALLOCATED;
64public:
65    CSSParserValueList()
66        : m_current(0)
67    {
68    }
69    ~CSSParserValueList();
70
71    void addValue(const CSSParserValue&);
72    void deleteValueAt(unsigned);
73
74    unsigned size() const { return m_values.size(); }
75    CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
76    CSSParserValue* next() { ++m_current; return current(); }
77
78    CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
79
80    void clear() { m_values.clear(); }
81
82private:
83    unsigned m_current;
84    Vector<CSSParserValue, 4> m_values;
85};
86
87struct CSSParserFunction {
88    WTF_MAKE_FAST_ALLOCATED;
89public:
90    CSSParserString name;
91    OwnPtr<CSSParserValueList> args;
92};
93
94}
95
96#endif
97