]> git.saurik.com Git - iphone-api.git/blob - WebCore/CSSSelector.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / CSSSelector.h
1 /*
2 * This file is part of the CSS implementation for KDE.
3 *
4 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
5 * 1999 Waldo Bastian (bastian@kde.org)
6 * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #ifndef CSSSelector_h
25 #define CSSSelector_h
26
27 #include "QualifiedName.h"
28 #include <wtf/Noncopyable.h>
29 #include <wtf/OwnPtr.h>
30
31 namespace WebCore {
32
33 // this class represents a selector for a StyleRule
34 class CSSSelector : Noncopyable {
35 public:
36 CSSSelector()
37 : m_tag(anyQName())
38 , m_relation(Descendant)
39 , m_match(None)
40 , m_pseudoType(PseudoNotParsed)
41 , m_parsedNth(false)
42 , m_isLastInSelectorList(false)
43 , m_hasRareData(false)
44 {
45 }
46
47 CSSSelector(const QualifiedName& qName)
48 : m_tag(qName)
49 , m_relation(Descendant)
50 , m_match(None)
51 , m_pseudoType(PseudoNotParsed)
52 , m_parsedNth(false)
53 , m_isLastInSelectorList(false)
54 , m_hasRareData(false)
55 {
56 }
57
58 ~CSSSelector()
59 {
60 if (m_hasRareData)
61 delete m_data.m_rareData;
62 else
63 delete m_data.m_tagHistory;
64 }
65
66 /**
67 * Re-create selector text from selector's data
68 */
69 String selectorText() const;
70
71 // checks if the 2 selectors (including sub selectors) agree.
72 bool operator==(const CSSSelector&);
73
74 // tag == -1 means apply to all elements (Selector = *)
75
76 unsigned specificity();
77
78 /* how the attribute value has to match.... Default is Exact */
79 enum Match {
80 None = 0,
81 Id,
82 Class,
83 Exact,
84 Set,
85 List,
86 Hyphen,
87 PseudoClass,
88 PseudoElement,
89 Contain, // css3: E[foo*="bar"]
90 Begin, // css3: E[foo^="bar"]
91 End // css3: E[foo$="bar"]
92 };
93
94 enum Relation {
95 Descendant = 0,
96 Child,
97 DirectAdjacent,
98 IndirectAdjacent,
99 SubSelector
100 };
101
102 enum PseudoType {
103 PseudoNotParsed = 0,
104 PseudoUnknown,
105 PseudoEmpty,
106 PseudoFirstChild,
107 PseudoFirstOfType,
108 PseudoLastChild,
109 PseudoLastOfType,
110 PseudoOnlyChild,
111 PseudoOnlyOfType,
112 PseudoFirstLine,
113 PseudoFirstLetter,
114 PseudoNthChild,
115 PseudoNthOfType,
116 PseudoNthLastChild,
117 PseudoNthLastOfType,
118 PseudoLink,
119 PseudoVisited,
120 PseudoAnyLink,
121 PseudoAutofill,
122 PseudoHover,
123 PseudoDrag,
124 PseudoFocus,
125 PseudoActive,
126 PseudoChecked,
127 PseudoEnabled,
128 PseudoFullPageMedia,
129 PseudoDisabled,
130 PseudoInputPlaceholder,
131 PseudoReadOnly,
132 PseudoReadWrite,
133 PseudoIndeterminate,
134 PseudoTarget,
135 PseudoBefore,
136 PseudoAfter,
137 PseudoLang,
138 PseudoNot,
139 PseudoResizer,
140 PseudoRoot,
141 PseudoScrollbar,
142 PseudoScrollbarBack,
143 PseudoScrollbarButton,
144 PseudoScrollbarCorner,
145 PseudoScrollbarForward,
146 PseudoScrollbarThumb,
147 PseudoScrollbarTrack,
148 PseudoScrollbarTrackPiece,
149 PseudoWindowInactive,
150 PseudoCornerPresent,
151 PseudoDecrement,
152 PseudoIncrement,
153 PseudoHorizontal,
154 PseudoVertical,
155 PseudoStart,
156 PseudoEnd,
157 PseudoDoubleButton,
158 PseudoSingleButton,
159 PseudoNoButton,
160 PseudoSelection,
161 PseudoFileUploadButton,
162 PseudoSliderThumb,
163 PseudoSearchCancelButton,
164 PseudoSearchDecoration,
165 PseudoSearchResultsDecoration,
166 PseudoSearchResultsButton,
167 PseudoMediaControlsPanel,
168 PseudoMediaControlsMuteButton,
169 PseudoMediaControlsPlayButton,
170 PseudoMediaControlsTimelineContainer,
171 PseudoMediaControlsCurrentTimeDisplay,
172 PseudoMediaControlsTimeRemainingDisplay,
173 PseudoMediaControlsTimeline,
174 PseudoMediaControlsSeekBackButton,
175 PseudoMediaControlsSeekForwardButton,
176 PseudoMediaControlsFullscreenButton
177 };
178
179 PseudoType pseudoType() const
180 {
181 if (m_pseudoType == PseudoNotParsed)
182 extractPseudoType();
183 return static_cast<PseudoType>(m_pseudoType);
184 }
185
186 CSSSelector* tagHistory() const { return m_hasRareData ? m_data.m_rareData->m_tagHistory.get() : m_data.m_tagHistory; }
187 void setTagHistory(CSSSelector* tagHistory);
188
189 bool hasTag() const { return m_tag != anyQName(); }
190 bool hasAttribute() const { return m_match == Id || m_match == Class || (m_hasRareData && m_data.m_rareData->m_attribute != anyQName()); }
191
192 const QualifiedName& attribute() const;
193 const AtomicString& argument() const { return m_hasRareData ? m_data.m_rareData->m_argument : nullAtom; }
194 CSSSelector* simpleSelector() const { return m_hasRareData ? m_data.m_rareData->m_simpleSelector.get() : 0; }
195
196 void setAttribute(const QualifiedName& value);
197 void setArgument(const AtomicString& value);
198 void setSimpleSelector(CSSSelector* value);
199
200 bool parseNth();
201 bool matchNth(int count);
202
203 Relation relation() const { return static_cast<Relation>(m_relation); }
204
205 bool isLastInSelectorList() const { return m_isLastInSelectorList; }
206 void setLastInSelectorList() { m_isLastInSelectorList = true; }
207
208 mutable AtomicString m_value;
209 QualifiedName m_tag;
210
211 unsigned m_relation : 3; // enum Relation
212 mutable unsigned m_match : 4; // enum Match
213 mutable unsigned m_pseudoType : 8; // PseudoType
214
215 private:
216 bool m_parsedNth : 1; // Used for :nth-*
217 bool m_isLastInSelectorList : 1;
218 bool m_hasRareData : 1;
219
220 void extractPseudoType() const;
221
222 struct RareData {
223 RareData(CSSSelector* tagHistory)
224 : m_tagHistory(tagHistory)
225 , m_simpleSelector(0)
226 , m_attribute(anyQName())
227 , m_argument(nullAtom)
228 , m_a(0)
229 , m_b(0)
230 {
231 }
232
233 bool parseNth();
234 bool matchNth(int count);
235
236 OwnPtr<CSSSelector> m_tagHistory;
237 OwnPtr<CSSSelector> m_simpleSelector; // Used for :not.
238 QualifiedName m_attribute; // used for attribute selector
239 AtomicString m_argument; // Used for :contains, :lang and :nth-*
240 int m_a; // Used for :nth-*
241 int m_b; // Used for :nth-*
242 };
243
244 void createRareData()
245 {
246 if (m_hasRareData)
247 return;
248 m_data.m_rareData = new RareData(m_data.m_tagHistory);
249 m_hasRareData = true;
250 }
251
252 union DataUnion {
253 DataUnion() : m_tagHistory(0) { }
254 CSSSelector* m_tagHistory;
255 RareData* m_rareData;
256 } m_data;
257 };
258
259 } // namespace WebCore
260
261 #endif // CSSSelector_h