2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef CSSParserValues_h
22 #define CSSParserValues_h
24 #include "CSSSelector.h"
25 #include "CSSValueKeywords.h"
26 #include "CSSValueList.h"
27 #include <wtf/text/AtomicString.h>
28 #include <wtf/text/WTFString.h>
35 struct CSSParserString {
36 void init(LChar* characters, unsigned length)
38 m_data.characters8 = characters;
43 void init(UChar* characters, unsigned length)
45 m_data.characters16 = characters;
50 void init(const String& string)
52 m_length = string.length();
53 if (m_length && string.is8Bit()) {
54 m_data.characters8 = const_cast<LChar*>(string.characters8());
57 m_data.characters16 = const_cast<UChar*>(string.characters());
64 m_data.characters8 = 0;
69 bool is8Bit() const { return m_is8Bit; }
70 LChar* characters8() const { ASSERT(is8Bit()); return m_data.characters8; }
71 UChar* characters16() const { ASSERT(!is8Bit()); return m_data.characters16; }
72 template <typename CharacterType>
73 CharacterType* characters() const;
75 unsigned length() const { return m_length; }
76 void setLength(unsigned length) { m_length = length; }
80 UChar operator[](unsigned i)
82 ASSERT_WITH_SECURITY_IMPLICATION(i < m_length);
84 return m_data.characters8[i];
85 return m_data.characters16[i];
88 bool equalIgnoringCase(const char* str)
91 return WTF::equalIgnoringCase(str, characters8(), length());
92 return WTF::equalIgnoringCase(str, characters16(), length());
95 operator String() const { return is8Bit() ? String(m_data.characters8, m_length) : String(m_data.characters16, m_length); }
96 operator AtomicString() const { return is8Bit() ? AtomicString(m_data.characters8, m_length) : AtomicString(m_data.characters16, m_length); }
98 #if ENABLE(CSS_VARIABLES)
99 AtomicString substring(unsigned position, unsigned length) const;
110 struct CSSParserFunction;
112 struct CSSParserValue {
118 CSSParserString string;
119 CSSParserFunction* function;
129 PassRefPtr<CSSValue> createCSSValue();
132 class CSSParserValueList {
133 WTF_MAKE_FAST_ALLOCATED;
139 ~CSSParserValueList();
141 void addValue(const CSSParserValue&);
142 void insertValueAt(unsigned, const CSSParserValue&);
143 void deleteValueAt(unsigned);
144 void extend(CSSParserValueList&);
146 unsigned size() const { return m_values.size(); }
147 unsigned currentIndex() { return m_current; }
148 CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
149 CSSParserValue* next() { ++m_current; return current(); }
150 CSSParserValue* previous()
158 CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
160 void clear() { m_values.clear(); }
164 Vector<CSSParserValue, 4> m_values;
167 struct CSSParserFunction {
168 WTF_MAKE_FAST_ALLOCATED;
170 CSSParserString name;
171 OwnPtr<CSSParserValueList> args;
174 class CSSParserSelector {
175 WTF_MAKE_FAST_ALLOCATED;
178 explicit CSSParserSelector(const QualifiedName&);
179 ~CSSParserSelector();
181 PassOwnPtr<CSSSelector> releaseSelector() { return m_selector.release(); }
183 void setValue(const AtomicString& value) { m_selector->setValue(value); }
184 void setAttribute(const QualifiedName& value) { m_selector->setAttribute(value); }
185 void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
186 void setMatch(CSSSelector::Match value) { m_selector->m_match = value; }
187 void setRelation(CSSSelector::Relation value) { m_selector->m_relation = value; }
188 void setForPage() { m_selector->setForPage(); }
190 void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector);
192 CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
193 bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); }
195 bool isSimple() const;
196 bool hasShadowDescendant() const;
198 CSSParserSelector* tagHistory() const { return m_tagHistory.get(); }
199 void setTagHistory(PassOwnPtr<CSSParserSelector> selector) { m_tagHistory = selector; }
200 void clearTagHistory() { m_tagHistory.clear(); }
201 void insertTagHistory(CSSSelector::Relation before, PassOwnPtr<CSSParserSelector>, CSSSelector::Relation after);
202 void appendTagHistory(CSSSelector::Relation, PassOwnPtr<CSSParserSelector>);
203 void prependTagSelector(const QualifiedName&, bool tagIsForNamespaceRule = false);
206 OwnPtr<CSSSelector> m_selector;
207 OwnPtr<CSSParserSelector> m_tagHistory;
210 inline bool CSSParserSelector::hasShadowDescendant() const
212 return m_selector->relation() == CSSSelector::ShadowDescendant;