2 * This file is part of the CSS implementation for KDE.
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.
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.
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.
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.
27 #include "QualifiedName.h"
28 #include <wtf/Noncopyable.h>
29 #include <wtf/OwnPtr.h>
33 // this class represents a selector for a StyleRule
34 class CSSSelector
: Noncopyable
{
38 , m_relation(Descendant
)
40 , m_pseudoType(PseudoNotParsed
)
42 , m_isLastInSelectorList(false)
43 , m_hasRareData(false)
47 CSSSelector(const QualifiedName
& qName
)
49 , m_relation(Descendant
)
51 , m_pseudoType(PseudoNotParsed
)
53 , m_isLastInSelectorList(false)
54 , m_hasRareData(false)
61 delete m_data
.m_rareData
;
63 delete m_data
.m_tagHistory
;
67 * Re-create selector text from selector's data
69 String
selectorText() const;
71 // checks if the 2 selectors (including sub selectors) agree.
72 bool operator==(const CSSSelector
&);
74 // tag == -1 means apply to all elements (Selector = *)
76 unsigned specificity();
78 /* how the attribute value has to match.... Default is Exact */
89 Contain
, // css3: E[foo*="bar"]
90 Begin
, // css3: E[foo^="bar"]
91 End
// css3: E[foo$="bar"]
130 PseudoInputPlaceholder
,
143 PseudoScrollbarButton
,
144 PseudoScrollbarCorner
,
145 PseudoScrollbarForward
,
146 PseudoScrollbarThumb
,
147 PseudoScrollbarTrack
,
148 PseudoScrollbarTrackPiece
,
149 PseudoWindowInactive
,
161 PseudoFileUploadButton
,
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
179 PseudoType
pseudoType() const
181 if (m_pseudoType
== PseudoNotParsed
)
183 return static_cast<PseudoType
>(m_pseudoType
);
186 CSSSelector
* tagHistory() const { return m_hasRareData
? m_data
.m_rareData
->m_tagHistory
.get() : m_data
.m_tagHistory
; }
187 void setTagHistory(CSSSelector
* tagHistory
);
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()); }
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; }
196 void setAttribute(const QualifiedName
& value
);
197 void setArgument(const AtomicString
& value
);
198 void setSimpleSelector(CSSSelector
* value
);
201 bool matchNth(int count
);
203 Relation
relation() const { return static_cast<Relation
>(m_relation
); }
205 bool isLastInSelectorList() const { return m_isLastInSelectorList
; }
206 void setLastInSelectorList() { m_isLastInSelectorList
= true; }
208 mutable AtomicString m_value
;
211 unsigned m_relation
: 3; // enum Relation
212 mutable unsigned m_match
: 4; // enum Match
213 mutable unsigned m_pseudoType
: 8; // PseudoType
216 bool m_parsedNth
: 1; // Used for :nth-*
217 bool m_isLastInSelectorList
: 1;
218 bool m_hasRareData
: 1;
220 void extractPseudoType() const;
223 RareData(CSSSelector
* tagHistory
)
224 : m_tagHistory(tagHistory
)
225 , m_simpleSelector(0)
226 , m_attribute(anyQName())
227 , m_argument(nullAtom
)
234 bool matchNth(int count
);
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-*
244 void createRareData()
248 m_data
.m_rareData
= new RareData(m_data
.m_tagHistory
);
249 m_hasRareData
= true;
253 DataUnion() : m_tagHistory(0) { }
254 CSSSelector
* m_tagHistory
;
255 RareData
* m_rareData
;
259 } // namespace WebCore
261 #endif // CSSSelector_h