0
|
1 |
/*
|
|
2 |
* Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
|
|
3 |
* 1999 Waldo Bastian (bastian@kde.org)
|
|
4 |
* 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch)
|
|
5 |
* 2001-2003 Dirk Mueller (mueller@kde.org)
|
|
6 |
* Copyright (C) 2002, 2006, 2007, 2008 Apple Inc. All rights reserved.
|
|
7 |
* Copyright (C) 2008 David Smith (catfish.man@gmail.com)
|
|
8 |
*
|
|
9 |
* This library is free software; you can redistribute it and/or
|
|
10 |
* modify it under the terms of the GNU Library General Public
|
|
11 |
* License as published by the Free Software Foundation; either
|
|
12 |
* version 2 of the License, or (at your option) any later version.
|
|
13 |
*
|
|
14 |
* This library is distributed in the hope that it will be useful,
|
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 |
* Library General Public License for more details.
|
|
18 |
*
|
|
19 |
* You should have received a copy of the GNU Library General Public License
|
|
20 |
* along with this library; see the file COPYING.LIB. If not, write to
|
|
21 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
22 |
* Boston, MA 02110-1301, USA.
|
|
23 |
*/
|
|
24 |
|
|
25 |
#include "config.h"
|
|
26 |
#include "CSSSelector.h"
|
|
27 |
|
|
28 |
#include "wtf/Assertions.h"
|
|
29 |
#include "HTMLNames.h"
|
|
30 |
|
|
31 |
#include <wtf/StdLibExtras.h>
|
|
32 |
|
|
33 |
namespace WebCore {
|
|
34 |
|
|
35 |
using namespace HTMLNames;
|
|
36 |
|
|
37 |
unsigned int CSSSelector::specificity()
|
|
38 |
{
|
|
39 |
// FIXME: Pseudo-elements and pseudo-classes do not have the same specificity. This function
|
|
40 |
// isn't quite correct.
|
|
41 |
int s = (m_tag.localName() == starAtom ? 0 : 1);
|
|
42 |
switch (m_match) {
|
|
43 |
case Id:
|
|
44 |
s += 0x10000;
|
|
45 |
break;
|
|
46 |
case Exact:
|
|
47 |
case Class:
|
|
48 |
case Set:
|
|
49 |
case List:
|
|
50 |
case Hyphen:
|
|
51 |
case PseudoClass:
|
|
52 |
case PseudoElement:
|
|
53 |
case Contain:
|
|
54 |
case Begin:
|
|
55 |
case End:
|
|
56 |
s += 0x100;
|
|
57 |
case None:
|
|
58 |
break;
|
|
59 |
}
|
|
60 |
|
|
61 |
if (CSSSelector* tagHistory = this->tagHistory())
|
|
62 |
s += tagHistory->specificity();
|
|
63 |
|
|
64 |
// make sure it doesn't overflow
|
|
65 |
return s & 0xffffff;
|
|
66 |
}
|
|
67 |
|
|
68 |
void CSSSelector::extractPseudoType() const
|
|
69 |
{
|
|
70 |
if (m_match != PseudoClass && m_match != PseudoElement)
|
|
71 |
return;
|
|
72 |
|
|
73 |
DEFINE_STATIC_LOCAL(AtomicString, active, ("active"));
|
|
74 |
DEFINE_STATIC_LOCAL(AtomicString, after, ("after"));
|
|
75 |
DEFINE_STATIC_LOCAL(AtomicString, anyLink, ("-webkit-any-link"));
|
|
76 |
DEFINE_STATIC_LOCAL(AtomicString, autofill, ("-webkit-autofill"));
|
|
77 |
DEFINE_STATIC_LOCAL(AtomicString, before, ("before"));
|
|
78 |
DEFINE_STATIC_LOCAL(AtomicString, checked, ("checked"));
|
|
79 |
DEFINE_STATIC_LOCAL(AtomicString, fileUploadButton, ("-webkit-file-upload-button"));
|
|
80 |
DEFINE_STATIC_LOCAL(AtomicString, defaultString, ("default"));
|
|
81 |
DEFINE_STATIC_LOCAL(AtomicString, disabled, ("disabled"));
|
|
82 |
DEFINE_STATIC_LOCAL(AtomicString, readOnly, ("read-only"));
|
|
83 |
DEFINE_STATIC_LOCAL(AtomicString, readWrite, ("read-write"));
|
|
84 |
DEFINE_STATIC_LOCAL(AtomicString, valid, ("valid"));
|
|
85 |
DEFINE_STATIC_LOCAL(AtomicString, invalid, ("invalid"));
|
|
86 |
DEFINE_STATIC_LOCAL(AtomicString, drag, ("-webkit-drag"));
|
|
87 |
DEFINE_STATIC_LOCAL(AtomicString, dragAlias, ("-khtml-drag")); // was documented with this name in Apple documentation, so keep an alia
|
|
88 |
DEFINE_STATIC_LOCAL(AtomicString, empty, ("empty"));
|
|
89 |
DEFINE_STATIC_LOCAL(AtomicString, enabled, ("enabled"));
|
|
90 |
DEFINE_STATIC_LOCAL(AtomicString, firstChild, ("first-child"));
|
|
91 |
DEFINE_STATIC_LOCAL(AtomicString, firstLetter, ("first-letter"));
|
|
92 |
DEFINE_STATIC_LOCAL(AtomicString, firstLine, ("first-line"));
|
|
93 |
DEFINE_STATIC_LOCAL(AtomicString, firstOfType, ("first-of-type"));
|
|
94 |
DEFINE_STATIC_LOCAL(AtomicString, fullPageMedia, ("-webkit-full-page-media"));
|
|
95 |
DEFINE_STATIC_LOCAL(AtomicString, nthChild, ("nth-child("));
|
|
96 |
DEFINE_STATIC_LOCAL(AtomicString, nthOfType, ("nth-of-type("));
|
|
97 |
DEFINE_STATIC_LOCAL(AtomicString, nthLastChild, ("nth-last-child("));
|
|
98 |
DEFINE_STATIC_LOCAL(AtomicString, nthLastOfType, ("nth-last-of-type("));
|
|
99 |
DEFINE_STATIC_LOCAL(AtomicString, focus, ("focus"));
|
|
100 |
DEFINE_STATIC_LOCAL(AtomicString, hover, ("hover"));
|
|
101 |
DEFINE_STATIC_LOCAL(AtomicString, indeterminate, ("indeterminate"));
|
|
102 |
#if ENABLE(DATALIST)
|
|
103 |
DEFINE_STATIC_LOCAL(AtomicString, inputListButton, ("-webkit-input-list-button"));
|
|
104 |
#endif
|
|
105 |
DEFINE_STATIC_LOCAL(AtomicString, inputPlaceholder, ("-webkit-input-placeholder"));
|
|
106 |
DEFINE_STATIC_LOCAL(AtomicString, lastChild, ("last-child"));
|
|
107 |
DEFINE_STATIC_LOCAL(AtomicString, lastOfType, ("last-of-type"));
|
|
108 |
DEFINE_STATIC_LOCAL(AtomicString, link, ("link"));
|
|
109 |
DEFINE_STATIC_LOCAL(AtomicString, lang, ("lang("));
|
|
110 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsPanel, ("-webkit-media-controls-panel"));
|
|
111 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsMuteButton, ("-webkit-media-controls-mute-button"));
|
|
112 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsPlayButton, ("-webkit-media-controls-play-button"));
|
|
113 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsTimeline, ("-webkit-media-controls-timeline"));
|
|
114 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsVolumeSlider, ("-webkit-media-controls-volume-slider"));
|
|
115 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsSeekBackButton, ("-webkit-media-controls-seek-back-button"));
|
|
116 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsSeekForwardButton, ("-webkit-media-controls-seek-forward-button"));
|
|
117 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsRewindButton, ("-webkit-media-controls-rewind-button"));
|
|
118 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsReturnToRealtimeButton, ("-webkit-media-controls-return-to-realtime-button"));
|
|
119 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsStatusDisplay, ("-webkit-media-controls-status-display"));
|
|
120 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsFullscreenButton, ("-webkit-media-controls-fullscreen-button"));
|
|
121 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsTimelineContainer, ("-webkit-media-controls-timeline-container"));
|
|
122 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsVolumeSliderContainer, ("-webkit-media-controls-volume-slider-container"));
|
|
123 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsCurrentTimeDisplay, ("-webkit-media-controls-current-time-display"));
|
|
124 |
DEFINE_STATIC_LOCAL(AtomicString, mediaControlsTimeRemainingDisplay, ("-webkit-media-controls-time-remaining-display"));
|
|
125 |
DEFINE_STATIC_LOCAL(AtomicString, notStr, ("not("));
|
|
126 |
DEFINE_STATIC_LOCAL(AtomicString, onlyChild, ("only-child"));
|
|
127 |
DEFINE_STATIC_LOCAL(AtomicString, onlyOfType, ("only-of-type"));
|
|
128 |
DEFINE_STATIC_LOCAL(AtomicString, optional, ("optional"));
|
|
129 |
DEFINE_STATIC_LOCAL(AtomicString, required, ("required"));
|
|
130 |
DEFINE_STATIC_LOCAL(AtomicString, resizer, ("-webkit-resizer"));
|
|
131 |
DEFINE_STATIC_LOCAL(AtomicString, root, ("root"));
|
|
132 |
DEFINE_STATIC_LOCAL(AtomicString, scrollbar, ("-webkit-scrollbar"));
|
|
133 |
DEFINE_STATIC_LOCAL(AtomicString, scrollbarButton, ("-webkit-scrollbar-button"));
|
|
134 |
DEFINE_STATIC_LOCAL(AtomicString, scrollbarCorner, ("-webkit-scrollbar-corner"));
|
|
135 |
DEFINE_STATIC_LOCAL(AtomicString, scrollbarThumb, ("-webkit-scrollbar-thumb"));
|
|
136 |
DEFINE_STATIC_LOCAL(AtomicString, scrollbarTrack, ("-webkit-scrollbar-track"));
|
|
137 |
DEFINE_STATIC_LOCAL(AtomicString, scrollbarTrackPiece, ("-webkit-scrollbar-track-piece"));
|
|
138 |
DEFINE_STATIC_LOCAL(AtomicString, searchCancelButton, ("-webkit-search-cancel-button"));
|
|
139 |
DEFINE_STATIC_LOCAL(AtomicString, searchDecoration, ("-webkit-search-decoration"));
|
|
140 |
DEFINE_STATIC_LOCAL(AtomicString, searchResultsDecoration, ("-webkit-search-results-decoration"));
|
|
141 |
DEFINE_STATIC_LOCAL(AtomicString, searchResultsButton, ("-webkit-search-results-button"));
|
|
142 |
DEFINE_STATIC_LOCAL(AtomicString, selection, ("selection"));
|
|
143 |
DEFINE_STATIC_LOCAL(AtomicString, sliderThumb, ("-webkit-slider-thumb"));
|
|
144 |
DEFINE_STATIC_LOCAL(AtomicString, target, ("target"));
|
|
145 |
DEFINE_STATIC_LOCAL(AtomicString, visited, ("visited"));
|
|
146 |
DEFINE_STATIC_LOCAL(AtomicString, windowInactive, ("window-inactive"));
|
|
147 |
DEFINE_STATIC_LOCAL(AtomicString, decrement, ("decrement"));
|
|
148 |
DEFINE_STATIC_LOCAL(AtomicString, increment, ("increment"));
|
|
149 |
DEFINE_STATIC_LOCAL(AtomicString, start, ("start"));
|
|
150 |
DEFINE_STATIC_LOCAL(AtomicString, end, ("end"));
|
|
151 |
DEFINE_STATIC_LOCAL(AtomicString, horizontal, ("horizontal"));
|
|
152 |
DEFINE_STATIC_LOCAL(AtomicString, vertical, ("vertical"));
|
|
153 |
DEFINE_STATIC_LOCAL(AtomicString, doubleButton, ("double-button"));
|
|
154 |
DEFINE_STATIC_LOCAL(AtomicString, singleButton, ("single-button"));
|
|
155 |
DEFINE_STATIC_LOCAL(AtomicString, noButton, ("no-button"));
|
|
156 |
DEFINE_STATIC_LOCAL(AtomicString, cornerPresent, ("corner-present"));
|
|
157 |
|
|
158 |
bool element = false; // pseudo-element
|
|
159 |
bool compat = false; // single colon compatbility mode
|
|
160 |
|
|
161 |
m_pseudoType = PseudoUnknown;
|
|
162 |
if (m_value == active)
|
|
163 |
m_pseudoType = PseudoActive;
|
|
164 |
else if (m_value == after) {
|
|
165 |
m_pseudoType = PseudoAfter;
|
|
166 |
element = true;
|
|
167 |
compat = true;
|
|
168 |
} else if (m_value == anyLink)
|
|
169 |
m_pseudoType = PseudoAnyLink;
|
|
170 |
else if (m_value == autofill)
|
|
171 |
m_pseudoType = PseudoAutofill;
|
|
172 |
else if (m_value == before) {
|
|
173 |
m_pseudoType = PseudoBefore;
|
|
174 |
element = true;
|
|
175 |
compat = true;
|
|
176 |
} else if (m_value == checked)
|
|
177 |
m_pseudoType = PseudoChecked;
|
|
178 |
else if (m_value == fileUploadButton) {
|
|
179 |
m_pseudoType = PseudoFileUploadButton;
|
|
180 |
element = true;
|
|
181 |
} else if (m_value == defaultString)
|
|
182 |
m_pseudoType = PseudoDefault;
|
|
183 |
else if (m_value == disabled)
|
|
184 |
m_pseudoType = PseudoDisabled;
|
|
185 |
else if (m_value == readOnly)
|
|
186 |
m_pseudoType = PseudoReadOnly;
|
|
187 |
else if (m_value == readWrite)
|
|
188 |
m_pseudoType = PseudoReadWrite;
|
|
189 |
else if (m_value == valid)
|
|
190 |
m_pseudoType = PseudoValid;
|
|
191 |
else if (m_value == invalid)
|
|
192 |
m_pseudoType = PseudoInvalid;
|
|
193 |
else if (m_value == drag || m_value == dragAlias)
|
|
194 |
m_pseudoType = PseudoDrag;
|
|
195 |
else if (m_value == enabled)
|
|
196 |
m_pseudoType = PseudoEnabled;
|
|
197 |
else if (m_value == empty)
|
|
198 |
m_pseudoType = PseudoEmpty;
|
|
199 |
else if (m_value == firstChild)
|
|
200 |
m_pseudoType = PseudoFirstChild;
|
|
201 |
else if (m_value == fullPageMedia)
|
|
202 |
m_pseudoType = PseudoFullPageMedia;
|
|
203 |
else
|
|
204 |
#if ENABLE(DATALIST)
|
|
205 |
if (m_value == inputListButton) {
|
|
206 |
m_pseudoType = PseudoInputListButton;
|
|
207 |
element = true;
|
|
208 |
} else
|
|
209 |
#endif
|
|
210 |
if (m_value == inputPlaceholder) {
|
|
211 |
m_pseudoType = PseudoInputPlaceholder;
|
|
212 |
element = true;
|
|
213 |
} else if (m_value == lastChild)
|
|
214 |
m_pseudoType = PseudoLastChild;
|
|
215 |
else if (m_value == lastOfType)
|
|
216 |
m_pseudoType = PseudoLastOfType;
|
|
217 |
else if (m_value == onlyChild)
|
|
218 |
m_pseudoType = PseudoOnlyChild;
|
|
219 |
else if (m_value == onlyOfType)
|
|
220 |
m_pseudoType = PseudoOnlyOfType;
|
|
221 |
else if (m_value == firstLetter) {
|
|
222 |
m_pseudoType = PseudoFirstLetter;
|
|
223 |
element = true;
|
|
224 |
compat = true;
|
|
225 |
} else if (m_value == firstLine) {
|
|
226 |
m_pseudoType = PseudoFirstLine;
|
|
227 |
element = true;
|
|
228 |
compat = true;
|
|
229 |
} else if (m_value == firstOfType)
|
|
230 |
m_pseudoType = PseudoFirstOfType;
|
|
231 |
else if (m_value == focus)
|
|
232 |
m_pseudoType = PseudoFocus;
|
|
233 |
else if (m_value == hover)
|
|
234 |
m_pseudoType = PseudoHover;
|
|
235 |
else if (m_value == indeterminate)
|
|
236 |
m_pseudoType = PseudoIndeterminate;
|
|
237 |
else if (m_value == link)
|
|
238 |
m_pseudoType = PseudoLink;
|
|
239 |
else if (m_value == lang)
|
|
240 |
m_pseudoType = PseudoLang;
|
|
241 |
else if (m_value == mediaControlsPanel) {
|
|
242 |
m_pseudoType = PseudoMediaControlsPanel;
|
|
243 |
element = true;
|
|
244 |
} else if (m_value == mediaControlsMuteButton) {
|
|
245 |
m_pseudoType = PseudoMediaControlsMuteButton;
|
|
246 |
element = true;
|
|
247 |
} else if (m_value == mediaControlsPlayButton) {
|
|
248 |
m_pseudoType = PseudoMediaControlsPlayButton;
|
|
249 |
element = true;
|
|
250 |
} else if (m_value == mediaControlsCurrentTimeDisplay) {
|
|
251 |
m_pseudoType = PseudoMediaControlsCurrentTimeDisplay;
|
|
252 |
element = true;
|
|
253 |
} else if (m_value == mediaControlsTimeRemainingDisplay) {
|
|
254 |
m_pseudoType = PseudoMediaControlsTimeRemainingDisplay;
|
|
255 |
element = true;
|
|
256 |
} else if (m_value == mediaControlsTimeline) {
|
|
257 |
m_pseudoType = PseudoMediaControlsTimeline;
|
|
258 |
element = true;
|
|
259 |
} else if (m_value == mediaControlsVolumeSlider) {
|
|
260 |
m_pseudoType = PseudoMediaControlsVolumeSlider;
|
|
261 |
element = true;
|
|
262 |
} else if (m_value == mediaControlsSeekBackButton) {
|
|
263 |
m_pseudoType = PseudoMediaControlsSeekBackButton;
|
|
264 |
element = true;
|
|
265 |
} else if (m_value == mediaControlsSeekForwardButton) {
|
|
266 |
m_pseudoType = PseudoMediaControlsSeekForwardButton;
|
|
267 |
element = true;
|
|
268 |
} else if (m_value == mediaControlsRewindButton) {
|
|
269 |
m_pseudoType = PseudoMediaControlsRewindButton;
|
|
270 |
element = true;
|
|
271 |
} else if (m_value == mediaControlsReturnToRealtimeButton) {
|
|
272 |
m_pseudoType = PseudoMediaControlsReturnToRealtimeButton;
|
|
273 |
element = true;
|
|
274 |
} else if (m_value == mediaControlsStatusDisplay) {
|
|
275 |
m_pseudoType = PseudoMediaControlsStatusDisplay;
|
|
276 |
element = true;
|
|
277 |
} else if (m_value == mediaControlsFullscreenButton) {
|
|
278 |
m_pseudoType = PseudoMediaControlsFullscreenButton;
|
|
279 |
element = true;
|
|
280 |
} else if (m_value == mediaControlsTimelineContainer) {
|
|
281 |
m_pseudoType = PseudoMediaControlsTimelineContainer;
|
|
282 |
element = true;
|
|
283 |
} else if (m_value == mediaControlsVolumeSliderContainer) {
|
|
284 |
m_pseudoType = PseudoMediaControlsVolumeSliderContainer;
|
|
285 |
element = true;
|
|
286 |
} else if (m_value == notStr)
|
|
287 |
m_pseudoType = PseudoNot;
|
|
288 |
else if (m_value == nthChild)
|
|
289 |
m_pseudoType = PseudoNthChild;
|
|
290 |
else if (m_value == nthOfType)
|
|
291 |
m_pseudoType = PseudoNthOfType;
|
|
292 |
else if (m_value == nthLastChild)
|
|
293 |
m_pseudoType = PseudoNthLastChild;
|
|
294 |
else if (m_value == nthLastOfType)
|
|
295 |
m_pseudoType = PseudoNthLastOfType;
|
|
296 |
else if (m_value == root)
|
|
297 |
m_pseudoType = PseudoRoot;
|
|
298 |
else if (m_value == windowInactive)
|
|
299 |
m_pseudoType = PseudoWindowInactive;
|
|
300 |
else if (m_value == decrement)
|
|
301 |
m_pseudoType = PseudoDecrement;
|
|
302 |
else if (m_value == increment)
|
|
303 |
m_pseudoType = PseudoIncrement;
|
|
304 |
else if (m_value == start)
|
|
305 |
m_pseudoType = PseudoStart;
|
|
306 |
else if (m_value == end)
|
|
307 |
m_pseudoType = PseudoEnd;
|
|
308 |
else if (m_value == horizontal)
|
|
309 |
m_pseudoType = PseudoHorizontal;
|
|
310 |
else if (m_value == vertical)
|
|
311 |
m_pseudoType = PseudoVertical;
|
|
312 |
else if (m_value == doubleButton)
|
|
313 |
m_pseudoType = PseudoDoubleButton;
|
|
314 |
else if (m_value == singleButton)
|
|
315 |
m_pseudoType = PseudoSingleButton;
|
|
316 |
else if (m_value == noButton)
|
|
317 |
m_pseudoType = PseudoNoButton;
|
|
318 |
else if (m_value == optional)
|
|
319 |
m_pseudoType = PseudoOptional;
|
|
320 |
else if (m_value == required)
|
|
321 |
m_pseudoType = PseudoRequired;
|
|
322 |
else if (m_value == scrollbarCorner) {
|
|
323 |
element = true;
|
|
324 |
m_pseudoType = PseudoScrollbarCorner;
|
|
325 |
} else if (m_value == resizer) {
|
|
326 |
element = true;
|
|
327 |
m_pseudoType = PseudoResizer;
|
|
328 |
} else if (m_value == scrollbar) {
|
|
329 |
element = true;
|
|
330 |
m_pseudoType = PseudoScrollbar;
|
|
331 |
} else if (m_value == scrollbarButton) {
|
|
332 |
element = true;
|
|
333 |
m_pseudoType = PseudoScrollbarButton;
|
|
334 |
} else if (m_value == scrollbarCorner) {
|
|
335 |
element = true;
|
|
336 |
m_pseudoType = PseudoScrollbarCorner;
|
|
337 |
} else if (m_value == scrollbarThumb) {
|
|
338 |
element = true;
|
|
339 |
m_pseudoType = PseudoScrollbarThumb;
|
|
340 |
} else if (m_value == scrollbarTrack) {
|
|
341 |
element = true;
|
|
342 |
m_pseudoType = PseudoScrollbarTrack;
|
|
343 |
} else if (m_value == scrollbarTrackPiece) {
|
|
344 |
element = true;
|
|
345 |
m_pseudoType = PseudoScrollbarTrackPiece;
|
|
346 |
} else if (m_value == cornerPresent)
|
|
347 |
m_pseudoType = PseudoCornerPresent;
|
|
348 |
else if (m_value == searchCancelButton) {
|
|
349 |
m_pseudoType = PseudoSearchCancelButton;
|
|
350 |
element = true;
|
|
351 |
} else if (m_value == searchDecoration) {
|
|
352 |
m_pseudoType = PseudoSearchDecoration;
|
|
353 |
element = true;
|
|
354 |
} else if (m_value == searchResultsDecoration) {
|
|
355 |
m_pseudoType = PseudoSearchResultsDecoration;
|
|
356 |
element = true;
|
|
357 |
} else if (m_value == searchResultsButton) {
|
|
358 |
m_pseudoType = PseudoSearchResultsButton;
|
|
359 |
element = true;
|
|
360 |
} else if (m_value == selection) {
|
|
361 |
m_pseudoType = PseudoSelection;
|
|
362 |
element = true;
|
|
363 |
} else if (m_value == sliderThumb) {
|
|
364 |
m_pseudoType = PseudoSliderThumb;
|
|
365 |
element = true;
|
|
366 |
} else if (m_value == target)
|
|
367 |
m_pseudoType = PseudoTarget;
|
|
368 |
else if (m_value == visited)
|
|
369 |
m_pseudoType = PseudoVisited;
|
|
370 |
|
|
371 |
if (m_match == PseudoClass && element) {
|
|
372 |
if (!compat)
|
|
373 |
m_pseudoType = PseudoUnknown;
|
|
374 |
else
|
|
375 |
m_match = PseudoElement;
|
|
376 |
} else if (m_match == PseudoElement && !element)
|
|
377 |
m_pseudoType = PseudoUnknown;
|
|
378 |
}
|
|
379 |
|
|
380 |
bool CSSSelector::operator==(const CSSSelector& other)
|
|
381 |
{
|
|
382 |
const CSSSelector* sel1 = this;
|
|
383 |
const CSSSelector* sel2 = &other;
|
|
384 |
|
|
385 |
while (sel1 && sel2) {
|
|
386 |
if (sel1->m_tag != sel2->m_tag || sel1->attribute() != sel2->attribute() ||
|
|
387 |
sel1->relation() != sel2->relation() || sel1->m_match != sel2->m_match ||
|
|
388 |
sel1->m_value != sel2->m_value ||
|
|
389 |
sel1->pseudoType() != sel2->pseudoType() ||
|
|
390 |
sel1->argument() != sel2->argument())
|
|
391 |
return false;
|
|
392 |
sel1 = sel1->tagHistory();
|
|
393 |
sel2 = sel2->tagHistory();
|
|
394 |
}
|
|
395 |
|
|
396 |
if (sel1 || sel2)
|
|
397 |
return false;
|
|
398 |
|
|
399 |
return true;
|
|
400 |
}
|
|
401 |
|
|
402 |
String CSSSelector::selectorText() const
|
|
403 |
{
|
|
404 |
String str = "";
|
|
405 |
|
|
406 |
const AtomicString& prefix = m_tag.prefix();
|
|
407 |
const AtomicString& localName = m_tag.localName();
|
|
408 |
if (m_match == CSSSelector::None || !prefix.isNull() || localName != starAtom) {
|
|
409 |
if (prefix.isNull())
|
|
410 |
str = localName;
|
|
411 |
else
|
|
412 |
str = prefix + "|" + localName;
|
|
413 |
}
|
|
414 |
|
|
415 |
const CSSSelector* cs = this;
|
|
416 |
while (true) {
|
|
417 |
if (cs->m_match == CSSSelector::Id) {
|
|
418 |
str += "#";
|
|
419 |
str += cs->m_value;
|
|
420 |
} else if (cs->m_match == CSSSelector::Class) {
|
|
421 |
str += ".";
|
|
422 |
str += cs->m_value;
|
|
423 |
} else if (cs->m_match == CSSSelector::PseudoClass) {
|
|
424 |
str += ":";
|
|
425 |
str += cs->m_value;
|
|
426 |
if (cs->pseudoType() == PseudoNot) {
|
|
427 |
if (CSSSelector* subSel = cs->simpleSelector())
|
|
428 |
str += subSel->selectorText();
|
|
429 |
str += ")";
|
|
430 |
} else if (cs->pseudoType() == PseudoLang
|
|
431 |
|| cs->pseudoType() == PseudoNthChild
|
|
432 |
|| cs->pseudoType() == PseudoNthLastChild
|
|
433 |
|| cs->pseudoType() == PseudoNthOfType
|
|
434 |
|| cs->pseudoType() == PseudoNthLastOfType) {
|
|
435 |
str += cs->argument();
|
|
436 |
str += ")";
|
|
437 |
}
|
|
438 |
} else if (cs->m_match == CSSSelector::PseudoElement) {
|
|
439 |
str += "::";
|
|
440 |
str += cs->m_value;
|
|
441 |
} else if (cs->hasAttribute()) {
|
|
442 |
str += "[";
|
|
443 |
const AtomicString& prefix = cs->attribute().prefix();
|
|
444 |
if (!prefix.isNull())
|
|
445 |
str += prefix + "|";
|
|
446 |
str += cs->attribute().localName();
|
|
447 |
switch (cs->m_match) {
|
|
448 |
case CSSSelector::Exact:
|
|
449 |
str += "=";
|
|
450 |
break;
|
|
451 |
case CSSSelector::Set:
|
|
452 |
// set has no operator or value, just the attrName
|
|
453 |
str += "]";
|
|
454 |
break;
|
|
455 |
case CSSSelector::List:
|
|
456 |
str += "~=";
|
|
457 |
break;
|
|
458 |
case CSSSelector::Hyphen:
|
|
459 |
str += "|=";
|
|
460 |
break;
|
|
461 |
case CSSSelector::Begin:
|
|
462 |
str += "^=";
|
|
463 |
break;
|
|
464 |
case CSSSelector::End:
|
|
465 |
str += "$=";
|
|
466 |
break;
|
|
467 |
case CSSSelector::Contain:
|
|
468 |
str += "*=";
|
|
469 |
break;
|
|
470 |
default:
|
|
471 |
break;
|
|
472 |
}
|
|
473 |
if (cs->m_match != CSSSelector::Set) {
|
|
474 |
str += "\"";
|
|
475 |
str += cs->m_value;
|
|
476 |
str += "\"]";
|
|
477 |
}
|
|
478 |
}
|
|
479 |
if (cs->relation() != CSSSelector::SubSelector || !cs->tagHistory())
|
|
480 |
break;
|
|
481 |
cs = cs->tagHistory();
|
|
482 |
}
|
|
483 |
|
|
484 |
if (CSSSelector* tagHistory = cs->tagHistory()) {
|
|
485 |
String tagHistoryText = tagHistory->selectorText();
|
|
486 |
if (cs->relation() == CSSSelector::DirectAdjacent)
|
|
487 |
str = tagHistoryText + " + " + str;
|
|
488 |
else if (cs->relation() == CSSSelector::IndirectAdjacent)
|
|
489 |
str = tagHistoryText + " ~ " + str;
|
|
490 |
else if (cs->relation() == CSSSelector::Child)
|
|
491 |
str = tagHistoryText + " > " + str;
|
|
492 |
else
|
|
493 |
// Descendant
|
|
494 |
str = tagHistoryText + " " + str;
|
|
495 |
}
|
|
496 |
|
|
497 |
return str;
|
|
498 |
}
|
|
499 |
|
|
500 |
void CSSSelector::setTagHistory(CSSSelector* tagHistory)
|
|
501 |
{
|
|
502 |
if (m_hasRareData)
|
|
503 |
m_data.m_rareData->m_tagHistory.set(tagHistory);
|
|
504 |
else
|
|
505 |
m_data.m_tagHistory = tagHistory;
|
|
506 |
}
|
|
507 |
|
|
508 |
const QualifiedName& CSSSelector::attribute() const
|
|
509 |
{
|
|
510 |
switch (m_match) {
|
|
511 |
case Id:
|
|
512 |
return idAttr;
|
|
513 |
case Class:
|
|
514 |
return classAttr;
|
|
515 |
default:
|
|
516 |
return m_hasRareData ? m_data.m_rareData->m_attribute : anyQName();
|
|
517 |
}
|
|
518 |
}
|
|
519 |
|
|
520 |
void CSSSelector::setAttribute(const QualifiedName& value)
|
|
521 |
{
|
|
522 |
createRareData();
|
|
523 |
m_data.m_rareData->m_attribute = value;
|
|
524 |
}
|
|
525 |
|
|
526 |
void CSSSelector::setArgument(const AtomicString& value)
|
|
527 |
{
|
|
528 |
createRareData();
|
|
529 |
m_data.m_rareData->m_argument = value;
|
|
530 |
}
|
|
531 |
|
|
532 |
void CSSSelector::setSimpleSelector(CSSSelector* value)
|
|
533 |
{
|
|
534 |
createRareData();
|
|
535 |
m_data.m_rareData->m_simpleSelector.set(value);
|
|
536 |
}
|
|
537 |
|
|
538 |
bool CSSSelector::parseNth()
|
|
539 |
{
|
|
540 |
if (!m_hasRareData)
|
|
541 |
return false;
|
|
542 |
if (m_parsedNth)
|
|
543 |
return true;
|
|
544 |
m_parsedNth = m_data.m_rareData->parseNth();
|
|
545 |
return m_parsedNth;
|
|
546 |
}
|
|
547 |
|
|
548 |
bool CSSSelector::matchNth(int count)
|
|
549 |
{
|
|
550 |
ASSERT(m_hasRareData);
|
|
551 |
return m_data.m_rareData->matchNth(count);
|
|
552 |
}
|
|
553 |
|
|
554 |
// a helper function for parsing nth-arguments
|
|
555 |
bool CSSSelector::RareData::parseNth()
|
|
556 |
{
|
|
557 |
const String& argument = m_argument;
|
|
558 |
|
|
559 |
if (argument.isEmpty())
|
|
560 |
return false;
|
|
561 |
|
|
562 |
m_a = 0;
|
|
563 |
m_b = 0;
|
|
564 |
if (argument == "odd") {
|
|
565 |
m_a = 2;
|
|
566 |
m_b = 1;
|
|
567 |
} else if (argument == "even") {
|
|
568 |
m_a = 2;
|
|
569 |
m_b = 0;
|
|
570 |
} else {
|
|
571 |
int n = argument.find('n');
|
|
572 |
if (n != -1) {
|
|
573 |
if (argument[0] == '-') {
|
|
574 |
if (n == 1)
|
|
575 |
m_a = -1; // -n == -1n
|
|
576 |
else
|
|
577 |
m_a = argument.substring(0, n).toInt();
|
|
578 |
} else if (!n)
|
|
579 |
m_a = 1; // n == 1n
|
|
580 |
else
|
|
581 |
m_a = argument.substring(0, n).toInt();
|
|
582 |
|
|
583 |
int p = argument.find('+', n);
|
|
584 |
if (p != -1)
|
|
585 |
m_b = argument.substring(p + 1, argument.length() - p - 1).toInt();
|
|
586 |
else {
|
|
587 |
p = argument.find('-', n);
|
|
588 |
m_b = -argument.substring(p + 1, argument.length() - p - 1).toInt();
|
|
589 |
}
|
|
590 |
} else
|
|
591 |
m_b = argument.toInt();
|
|
592 |
}
|
|
593 |
return true;
|
|
594 |
}
|
|
595 |
|
|
596 |
// a helper function for checking nth-arguments
|
|
597 |
bool CSSSelector::RareData::matchNth(int count)
|
|
598 |
{
|
|
599 |
if (!m_a)
|
|
600 |
return count == m_b;
|
|
601 |
else if (m_a > 0) {
|
|
602 |
if (count < m_b)
|
|
603 |
return false;
|
|
604 |
return (count - m_b) % m_a == 0;
|
|
605 |
} else {
|
|
606 |
if (count > m_b)
|
|
607 |
return false;
|
|
608 |
return (m_b - count) % (-m_a) == 0;
|
|
609 |
}
|
|
610 |
}
|
|
611 |
|
|
612 |
} // namespace WebCore
|