OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * 1999 Waldo Bastian (bastian@kde.org) | 3 * 1999 Waldo Bastian (bastian@kde.org) |
4 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. | 4 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 BottomRightMarginBox, | 232 BottomRightMarginBox, |
233 BottomRightCornerMarginBox, | 233 BottomRightCornerMarginBox, |
234 LeftTopMarginBox, | 234 LeftTopMarginBox, |
235 LeftMiddleMarginBox, | 235 LeftMiddleMarginBox, |
236 LeftBottomMarginBox, | 236 LeftBottomMarginBox, |
237 RightTopMarginBox, | 237 RightTopMarginBox, |
238 RightMiddleMarginBox, | 238 RightMiddleMarginBox, |
239 RightBottomMarginBox, | 239 RightBottomMarginBox, |
240 }; | 240 }; |
241 | 241 |
| 242 enum AttributeMatchType { |
| 243 CaseSensitive, |
| 244 CaseInsensitive, |
| 245 }; |
| 246 |
242 PseudoType pseudoType() const | 247 PseudoType pseudoType() const |
243 { | 248 { |
244 if (m_pseudoType == PseudoNotParsed) | 249 if (m_pseudoType == PseudoNotParsed) |
245 extractPseudoType(); | 250 extractPseudoType(); |
246 return static_cast<PseudoType>(m_pseudoType); | 251 return static_cast<PseudoType>(m_pseudoType); |
247 } | 252 } |
248 | 253 |
249 static PseudoType parsePseudoType(const AtomicString&); | 254 static PseudoType parsePseudoType(const AtomicString&); |
250 static PseudoId pseudoId(PseudoType); | 255 static PseudoId pseudoId(PseudoType); |
251 | 256 |
252 // Selectors are kept in an array by CSSSelectorList. The next component
of the selector is | 257 // Selectors are kept in an array by CSSSelectorList. The next component
of the selector is |
253 // the next item in the array. | 258 // the next item in the array. |
254 const CSSSelector* tagHistory() const { return m_isLastInTagHistory ? 0
: const_cast<CSSSelector*>(this + 1); } | 259 const CSSSelector* tagHistory() const { return m_isLastInTagHistory ? 0
: const_cast<CSSSelector*>(this + 1); } |
255 | 260 |
256 const QualifiedName& tagQName() const; | 261 const QualifiedName& tagQName() const; |
257 const AtomicString& value() const; | 262 const AtomicString& value() const; |
258 | 263 |
259 // WARNING: Use of QualifiedName by attribute() is a lie. | 264 // WARNING: Use of QualifiedName by attribute() is a lie. |
260 // attribute() will return a QualifiedName with prefix and namespaceURI | 265 // attribute() will return a QualifiedName with prefix and namespaceURI |
261 // set to starAtom to mean "matches any namespace". Be very careful | 266 // set to starAtom to mean "matches any namespace". Be very careful |
262 // how you use the returned QualifiedName. | 267 // how you use the returned QualifiedName. |
263 // http://www.w3.org/TR/css3-selectors/#attrnmsp | 268 // http://www.w3.org/TR/css3-selectors/#attrnmsp |
264 const QualifiedName& attribute() const; | 269 const QualifiedName& attribute() const; |
| 270 AttributeMatchType attributeMatchType() const; |
265 // Returns the argument of a parameterized selector. For example, nth-ch
ild(2) would have an argument of 2. | 271 // Returns the argument of a parameterized selector. For example, nth-ch
ild(2) would have an argument of 2. |
266 const AtomicString& argument() const { return m_hasRareData ? m_data.m_r
areData->m_argument : nullAtom; } | 272 const AtomicString& argument() const { return m_hasRareData ? m_data.m_r
areData->m_argument : nullAtom; } |
267 const CSSSelectorList* selectorList() const { return m_hasRareData ? m_d
ata.m_rareData->m_selectorList.get() : 0; } | 273 const CSSSelectorList* selectorList() const { return m_hasRareData ? m_d
ata.m_rareData->m_selectorList.get() : 0; } |
268 | 274 |
269 #ifndef NDEBUG | 275 #ifndef NDEBUG |
270 void show() const; | 276 void show() const; |
271 void show(int indent) const; | 277 void show(int indent) const; |
272 #endif | 278 #endif |
273 | 279 |
274 void setValue(const AtomicString&); | 280 void setValue(const AtomicString&); |
275 void setAttribute(const QualifiedName&); | 281 void setAttribute(const QualifiedName&, AttributeMatchType); |
276 void setArgument(const AtomicString&); | 282 void setArgument(const AtomicString&); |
277 void setSelectorList(PassOwnPtr<CSSSelectorList>); | 283 void setSelectorList(PassOwnPtr<CSSSelectorList>); |
278 void setMatchUserAgentOnly(); | 284 void setMatchUserAgentOnly(); |
279 | 285 |
280 bool parseNth() const; | 286 bool parseNth() const; |
281 bool matchNth(int count) const; | 287 bool matchNth(int count) const; |
282 | 288 |
283 bool matchesPseudoElement() const; | 289 bool matchesPseudoElement() const; |
284 bool isCustomPseudoElement() const; | 290 bool isCustomPseudoElement() const; |
285 bool isDirectAdjacentSelector() const { return m_relation == DirectAdjac
ent; } | 291 bool isDirectAdjacentSelector() const { return m_relation == DirectAdjac
ent; } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 343 |
338 // Hide. | 344 // Hide. |
339 CSSSelector& operator=(const CSSSelector&); | 345 CSSSelector& operator=(const CSSSelector&); |
340 | 346 |
341 struct RareData : public RefCounted<RareData> { | 347 struct RareData : public RefCounted<RareData> { |
342 static PassRefPtr<RareData> create(const AtomicString& value) { retu
rn adoptRef(new RareData(value)); } | 348 static PassRefPtr<RareData> create(const AtomicString& value) { retu
rn adoptRef(new RareData(value)); } |
343 ~RareData(); | 349 ~RareData(); |
344 | 350 |
345 bool parseNth(); | 351 bool parseNth(); |
346 bool matchNth(int count); | 352 bool matchNth(int count); |
| 353 int nthAValue() const { return m_bits.m_nth.m_a; } |
| 354 void setNthAValue(int nthA) { m_bits.m_nth.m_a = nthA; } |
| 355 int nthBValue() const { return m_bits.m_nth.m_b; } |
| 356 void setNthBValue(int nthB) { m_bits.m_nth.m_b = nthB; } |
347 | 357 |
348 AtomicString m_value; | 358 AtomicString m_value; |
349 int m_a; // Used for :nth-* | 359 union { |
350 int m_b; // Used for :nth-* | 360 struct { |
| 361 int m_a; // Used for :nth-* |
| 362 int m_b; // Used for :nth-* |
| 363 } m_nth; |
| 364 AttributeMatchType m_attributeMatchType; // used for attribute s
elector (with value) |
| 365 } m_bits; |
351 QualifiedName m_attribute; // used for attribute selector | 366 QualifiedName m_attribute; // used for attribute selector |
352 AtomicString m_argument; // Used for :contains, :lang, :nth-* | 367 AtomicString m_argument; // Used for :contains, :lang, :nth-* |
353 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and
:not | 368 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and
:not |
354 | 369 |
355 private: | 370 private: |
356 RareData(const AtomicString& value); | 371 RareData(const AtomicString& value); |
357 }; | 372 }; |
358 void createRareData(); | 373 void createRareData(); |
359 | 374 |
360 union DataUnion { | 375 union DataUnion { |
361 DataUnion() : m_value(0) { } | 376 DataUnion() : m_value(0) { } |
362 StringImpl* m_value; | 377 StringImpl* m_value; |
363 QualifiedName::QualifiedNameImpl* m_tagQName; | 378 QualifiedName::QualifiedNameImpl* m_tagQName; |
364 RareData* m_rareData; | 379 RareData* m_rareData; |
365 } m_data; | 380 } m_data; |
366 }; | 381 }; |
367 | 382 |
368 inline const QualifiedName& CSSSelector::attribute() const | 383 inline const QualifiedName& CSSSelector::attribute() const |
369 { | 384 { |
370 ASSERT(isAttributeSelector()); | 385 ASSERT(isAttributeSelector()); |
371 ASSERT(m_hasRareData); | 386 ASSERT(m_hasRareData); |
372 return m_data.m_rareData->m_attribute; | 387 return m_data.m_rareData->m_attribute; |
373 } | 388 } |
374 | 389 |
| 390 inline CSSSelector::AttributeMatchType CSSSelector::attributeMatchType() const |
| 391 { |
| 392 ASSERT(isAttributeSelector()); |
| 393 ASSERT(m_hasRareData); |
| 394 return m_data.m_rareData->m_bits.m_attributeMatchType; |
| 395 } |
| 396 |
375 inline bool CSSSelector::matchesPseudoElement() const | 397 inline bool CSSSelector::matchesPseudoElement() const |
376 { | 398 { |
377 if (m_pseudoType == PseudoUnknown) | 399 if (m_pseudoType == PseudoUnknown) |
378 extractPseudoType(); | 400 extractPseudoType(); |
379 return m_match == PseudoElement; | 401 return m_match == PseudoElement; |
380 } | 402 } |
381 | 403 |
382 inline bool CSSSelector::isCustomPseudoElement() const | 404 inline bool CSSSelector::isCustomPseudoElement() const |
383 { | 405 { |
384 return m_match == PseudoElement && (m_pseudoType == PseudoUserAgentCustomEle
ment || m_pseudoType == PseudoWebKitCustomElement); | 406 return m_match == PseudoElement && (m_pseudoType == PseudoUserAgentCustomEle
ment || m_pseudoType == PseudoWebKitCustomElement); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 if (m_hasRareData) | 535 if (m_hasRareData) |
514 return m_data.m_rareData->m_value; | 536 return m_data.m_rareData->m_value; |
515 // AtomicString is really just a StringImpl* so the cast below is safe. | 537 // AtomicString is really just a StringImpl* so the cast below is safe. |
516 // FIXME: Perhaps call sites could be changed to accept StringImpl? | 538 // FIXME: Perhaps call sites could be changed to accept StringImpl? |
517 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); | 539 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); |
518 } | 540 } |
519 | 541 |
520 } // namespace blink | 542 } // namespace blink |
521 | 543 |
522 #endif // CSSSelector_h | 544 #endif // CSSSelector_h |
OLD | NEW |