initial import
[vuplus_webkit] / Source / WebCore / css / CSSParserValues.h
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
27 namespace WebCore {
28
29 class CSSValue;
30 class QualifiedName;
31
32 struct 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
42 struct CSSParserFunction;
43
44 struct 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
64 class CSSParserValueList {
65     WTF_MAKE_FAST_ALLOCATED;
66 public:
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     CSSParserValue* previous()
82     {
83         if (!m_current)
84             return 0;
85         --m_current;
86         return current();
87     }
88
89     CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
90         
91     void clear() { m_values.clear(); }
92
93 private:
94     unsigned m_current;
95     Vector<CSSParserValue, 4> m_values;
96 };
97
98 struct CSSParserFunction {
99     WTF_MAKE_FAST_ALLOCATED;
100 public:
101     CSSParserString name;
102     OwnPtr<CSSParserValueList> args;
103 };
104
105 class CSSParserSelector {
106     WTF_MAKE_FAST_ALLOCATED;
107 public:
108     CSSParserSelector();
109     ~CSSParserSelector();
110
111     PassOwnPtr<CSSSelector> releaseSelector() { return m_selector.release(); }
112     
113     void setTag(const QualifiedName& value) { m_selector->setTag(value); }
114     void setValue(const AtomicString& value) { m_selector->setValue(value); }
115     void setAttribute(const QualifiedName& value) { m_selector->setAttribute(value); }
116     void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
117     void setMatch(CSSSelector::Match value) { m_selector->m_match = value; }
118     void setRelation(CSSSelector::Relation value) { m_selector->m_relation = value; }
119     void setForPage() { m_selector->setForPage(); }
120
121     void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector);
122
123     CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
124     bool isUnknownPseudoElement() const { return m_selector->isUnknownPseudoElement(); }
125     bool isSimple() const { return !m_tagHistory && m_selector->isSimple(); }
126     bool hasShadowDescendant() const;
127
128     CSSParserSelector* tagHistory() const { return m_tagHistory.get(); }
129     void setTagHistory(PassOwnPtr<CSSParserSelector> selector) { m_tagHistory = selector; }
130     void insertTagHistory(CSSSelector::Relation before, PassOwnPtr<CSSParserSelector>, CSSSelector::Relation after);
131     void appendTagHistory(CSSSelector::Relation, PassOwnPtr<CSSParserSelector>);
132
133 private:
134     OwnPtr<CSSSelector> m_selector;
135     OwnPtr<CSSParserSelector> m_tagHistory;
136 };
137
138 inline bool CSSParserSelector::hasShadowDescendant() const
139 {
140     return m_selector->relation() == CSSSelector::ShadowDescendant;
141 }
142
143 }
144
145 #endif