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 "CSSSelector.h"
25#include <wtf/text/AtomicString.h>
26
27namespace WebCore {
28
29class CSSValue;
30class QualifiedName;
31
32struct CSSParserString {
33    UChar* characters;
34    int length;
35
36    void lower();
37
38    operator String() const { return String(characters, length); }
39    operator AtomicString() const { return AtomicString(characters, length); }
40};
41
42struct CSSParserFunction;
43
44struct CSSParserValue {
45    int id;
46    bool isInt;
47    union {
48        double fValue;
49        int iValue;
50        CSSParserString string;
51        CSSParserFunction* function;
52    };
53    enum {
54        Operator = 0x100000,
55        Function = 0x100001,
56        Q_EMS    = 0x100002
57    };
58    int unit;
59
60
61    PassRefPtr<CSSValue> createCSSValue();
62};
63
64class CSSParserValueList {
65    WTF_MAKE_FAST_ALLOCATED;
66public:
67    CSSParserValueList()
68        : m_current(0)
69    {
70    }
71    ~CSSParserValueList();
72
73    void addValue(const CSSParserValue&);
74    void insertValueAt(unsigned, const CSSParserValue&);
75    void deleteValueAt(unsigned);
76    void extend(CSSParserValueList&);
77
78    unsigned size() const { return m_values.size(); }
79    CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
80    CSSParserValue* next() { ++m_current; return current(); }
81
82    CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
83
84    void clear() { m_values.clear(); }
85
86private:
87    unsigned m_current;
88    Vector<CSSParserValue, 4> m_values;
89};
90
91struct CSSParserFunction {
92    WTF_MAKE_FAST_ALLOCATED;
93public:
94    CSSParserString name;
95    OwnPtr<CSSParserValueList> args;
96};
97
98class CSSParserSelector {
99    WTF_MAKE_FAST_ALLOCATED;
100public:
101    CSSParserSelector();
102    ~CSSParserSelector();
103
104    PassOwnPtr<CSSSelector> releaseSelector() { return m_selector.release(); }
105
106    void setTag(const QualifiedName& value) { m_selector->setTag(value); }
107    void setValue(const AtomicString& value) { m_selector->setValue(value); }
108    void setAttribute(const QualifiedName& value) { m_selector->setAttribute(value); }
109    void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
110    void setMatch(CSSSelector::Match value) { m_selector->m_match = value; }
111    void setRelation(CSSSelector::Relation value) { m_selector->m_relation = value; }
112    void setForPage() { m_selector->setForPage(); }
113
114    void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector);
115
116    CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
117    bool isUnknownPseudoElement() const { return m_selector->isUnknownPseudoElement(); }
118    bool isSimple() const { return !m_tagHistory && m_selector->isSimple(); }
119
120    CSSParserSelector* tagHistory() const { return m_tagHistory.get(); }
121    void setTagHistory(PassOwnPtr<CSSParserSelector> selector) { m_tagHistory = selector; }
122
123private:
124    OwnPtr<CSSSelector> m_selector;
125    OwnPtr<CSSParserSelector> m_tagHistory;
126};
127
128}
129
130#endif
131