0
|
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 : public 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 |
PseudoDefault,
|
|
130 |
PseudoDisabled,
|
|
131 |
PseudoInputPlaceholder,
|
|
132 |
PseudoOptional,
|
|
133 |
PseudoRequired,
|
|
134 |
PseudoReadOnly,
|
|
135 |
PseudoReadWrite,
|
|
136 |
PseudoValid,
|
|
137 |
PseudoInvalid,
|
|
138 |
PseudoIndeterminate,
|
|
139 |
PseudoTarget,
|
|
140 |
PseudoBefore,
|
|
141 |
PseudoAfter,
|
|
142 |
PseudoLang,
|
|
143 |
PseudoNot,
|
|
144 |
PseudoResizer,
|
|
145 |
PseudoRoot,
|
|
146 |
PseudoScrollbar,
|
|
147 |
PseudoScrollbarBack,
|
|
148 |
PseudoScrollbarButton,
|
|
149 |
PseudoScrollbarCorner,
|
|
150 |
PseudoScrollbarForward,
|
|
151 |
PseudoScrollbarThumb,
|
|
152 |
PseudoScrollbarTrack,
|
|
153 |
PseudoScrollbarTrackPiece,
|
|
154 |
PseudoWindowInactive,
|
|
155 |
PseudoCornerPresent,
|
|
156 |
PseudoDecrement,
|
|
157 |
PseudoIncrement,
|
|
158 |
PseudoHorizontal,
|
|
159 |
PseudoVertical,
|
|
160 |
PseudoStart,
|
|
161 |
PseudoEnd,
|
|
162 |
PseudoDoubleButton,
|
|
163 |
PseudoSingleButton,
|
|
164 |
PseudoNoButton,
|
|
165 |
PseudoSelection,
|
|
166 |
PseudoFileUploadButton,
|
|
167 |
PseudoSliderThumb,
|
|
168 |
PseudoSearchCancelButton,
|
|
169 |
PseudoSearchDecoration,
|
|
170 |
PseudoSearchResultsDecoration,
|
|
171 |
PseudoSearchResultsButton,
|
|
172 |
PseudoMediaControlsPanel,
|
|
173 |
PseudoMediaControlsMuteButton,
|
|
174 |
PseudoMediaControlsPlayButton,
|
|
175 |
PseudoMediaControlsTimelineContainer,
|
|
176 |
PseudoMediaControlsVolumeSliderContainer,
|
|
177 |
PseudoMediaControlsCurrentTimeDisplay,
|
|
178 |
PseudoMediaControlsTimeRemainingDisplay,
|
|
179 |
PseudoMediaControlsTimeline,
|
|
180 |
PseudoMediaControlsVolumeSlider,
|
|
181 |
PseudoMediaControlsSeekBackButton,
|
|
182 |
PseudoMediaControlsSeekForwardButton,
|
|
183 |
PseudoMediaControlsRewindButton,
|
|
184 |
PseudoMediaControlsReturnToRealtimeButton,
|
|
185 |
PseudoMediaControlsStatusDisplay,
|
|
186 |
PseudoMediaControlsFullscreenButton,
|
|
187 |
PseudoInputListButton
|
|
188 |
};
|
|
189 |
|
|
190 |
PseudoType pseudoType() const
|
|
191 |
{
|
|
192 |
if (m_pseudoType == PseudoNotParsed)
|
|
193 |
extractPseudoType();
|
|
194 |
return static_cast<PseudoType>(m_pseudoType);
|
|
195 |
}
|
|
196 |
|
|
197 |
CSSSelector* tagHistory() const { return m_hasRareData ? m_data.m_rareData->m_tagHistory.get() : m_data.m_tagHistory; }
|
|
198 |
void setTagHistory(CSSSelector* tagHistory);
|
|
199 |
|
|
200 |
bool hasTag() const { return m_tag != anyQName(); }
|
|
201 |
bool hasAttribute() const { return m_match == Id || m_match == Class || (m_hasRareData && m_data.m_rareData->m_attribute != anyQName()); }
|
|
202 |
|
|
203 |
const QualifiedName& attribute() const;
|
|
204 |
const AtomicString& argument() const { return m_hasRareData ? m_data.m_rareData->m_argument : nullAtom; }
|
|
205 |
CSSSelector* simpleSelector() const { return m_hasRareData ? m_data.m_rareData->m_simpleSelector.get() : 0; }
|
|
206 |
|
|
207 |
void setAttribute(const QualifiedName& value);
|
|
208 |
void setArgument(const AtomicString& value);
|
|
209 |
void setSimpleSelector(CSSSelector* value);
|
|
210 |
|
|
211 |
bool parseNth();
|
|
212 |
bool matchNth(int count);
|
|
213 |
|
|
214 |
Relation relation() const { return static_cast<Relation>(m_relation); }
|
|
215 |
|
|
216 |
bool isLastInSelectorList() const { return m_isLastInSelectorList; }
|
|
217 |
void setLastInSelectorList() { m_isLastInSelectorList = true; }
|
|
218 |
|
|
219 |
mutable AtomicString m_value;
|
|
220 |
QualifiedName m_tag;
|
|
221 |
|
|
222 |
unsigned m_relation : 3; // enum Relation
|
|
223 |
mutable unsigned m_match : 4; // enum Match
|
|
224 |
mutable unsigned m_pseudoType : 8; // PseudoType
|
|
225 |
|
|
226 |
private:
|
|
227 |
bool m_parsedNth : 1; // Used for :nth-*
|
|
228 |
bool m_isLastInSelectorList : 1;
|
|
229 |
bool m_hasRareData : 1;
|
|
230 |
|
|
231 |
void extractPseudoType() const;
|
|
232 |
|
|
233 |
struct RareData {
|
|
234 |
RareData(CSSSelector* tagHistory)
|
|
235 |
: m_tagHistory(tagHistory)
|
|
236 |
, m_simpleSelector(0)
|
|
237 |
, m_attribute(anyQName())
|
|
238 |
, m_argument(nullAtom)
|
|
239 |
, m_a(0)
|
|
240 |
, m_b(0)
|
|
241 |
{
|
|
242 |
}
|
|
243 |
|
|
244 |
bool parseNth();
|
|
245 |
bool matchNth(int count);
|
|
246 |
|
|
247 |
OwnPtr<CSSSelector> m_tagHistory;
|
|
248 |
OwnPtr<CSSSelector> m_simpleSelector; // Used for :not.
|
|
249 |
QualifiedName m_attribute; // used for attribute selector
|
|
250 |
AtomicString m_argument; // Used for :contains, :lang and :nth-*
|
|
251 |
int m_a; // Used for :nth-*
|
|
252 |
int m_b; // Used for :nth-*
|
|
253 |
};
|
|
254 |
|
|
255 |
void createRareData()
|
|
256 |
{
|
|
257 |
if (m_hasRareData)
|
|
258 |
return;
|
|
259 |
m_data.m_rareData = new RareData(m_data.m_tagHistory);
|
|
260 |
m_hasRareData = true;
|
|
261 |
}
|
|
262 |
|
|
263 |
union DataUnion {
|
|
264 |
DataUnion() : m_tagHistory(0) { }
|
|
265 |
CSSSelector* m_tagHistory;
|
|
266 |
RareData* m_rareData;
|
|
267 |
} m_data;
|
|
268 |
};
|
|
269 |
|
|
270 |
} // namespace WebCore
|
|
271 |
|
|
272 |
#endif // CSSSelector_h
|