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
StringCSSParserString38 operator String() const { return String(characters, length); }
AtomicStringCSSParserString39 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:
CSSParserValueList()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
size()78 unsigned size() const { return m_values.size(); }
current()79 CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
next()80 CSSParserValue* next() { ++m_current; return current(); }
81
valueAt(unsigned i)82 CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
83
clear()84 void clear() { m_values.clear(); }
85
86 private:
87 unsigned m_current;
88 Vector<CSSParserValue, 4> m_values;
89 };
90
91 struct CSSParserFunction {
92 WTF_MAKE_FAST_ALLOCATED;
93 public:
94 CSSParserString name;
95 OwnPtr<CSSParserValueList> args;
96 };
97
98 class CSSParserSelector {
99 WTF_MAKE_FAST_ALLOCATED;
100 public:
101 CSSParserSelector();
102 ~CSSParserSelector();
103
releaseSelector()104 PassOwnPtr<CSSSelector> releaseSelector() { return m_selector.release(); }
105
setTag(const QualifiedName & value)106 void setTag(const QualifiedName& value) { m_selector->setTag(value); }
setValue(const AtomicString & value)107 void setValue(const AtomicString& value) { m_selector->setValue(value); }
setAttribute(const QualifiedName & value)108 void setAttribute(const QualifiedName& value) { m_selector->setAttribute(value); }
setArgument(const AtomicString & value)109 void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
setMatch(CSSSelector::Match value)110 void setMatch(CSSSelector::Match value) { m_selector->m_match = value; }
setRelation(CSSSelector::Relation value)111 void setRelation(CSSSelector::Relation value) { m_selector->m_relation = value; }
setForPage()112 void setForPage() { m_selector->setForPage(); }
113
114 void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector);
115
pseudoType()116 CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
isUnknownPseudoElement()117 bool isUnknownPseudoElement() const { return m_selector->isUnknownPseudoElement(); }
isSimple()118 bool isSimple() const { return !m_tagHistory && m_selector->isSimple(); }
119 bool hasShadowDescendant() const;
120
tagHistory()121 CSSParserSelector* tagHistory() const { return m_tagHistory.get(); }
setTagHistory(PassOwnPtr<CSSParserSelector> selector)122 void setTagHistory(PassOwnPtr<CSSParserSelector> selector) { m_tagHistory = selector; }
123 void insertTagHistory(CSSSelector::Relation before, PassOwnPtr<CSSParserSelector>, CSSSelector::Relation after);
124 void appendTagHistory(CSSSelector::Relation, PassOwnPtr<CSSParserSelector>);
125
126 private:
127 OwnPtr<CSSSelector> m_selector;
128 OwnPtr<CSSParserSelector> m_tagHistory;
129 };
130
hasShadowDescendant()131 inline bool CSSParserSelector::hasShadowDescendant() const
132 {
133 return m_selector->relation() == CSSSelector::ShadowDescendant;
134 }
135
136 }
137
138 #endif
139