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 Bits { |
350 int m_b; // Used for :nth-* | 360 Bits() : m_nth() { } |
eseidel
2014/07/30 20:12:41
How does this initailize to zeros? Do structs hav
fs
2014/07/31 09:27:15
This boils down to "value-initialize" vs. "default
| |
361 struct { | |
362 int m_a; // Used for :nth-* | |
363 int m_b; // Used for :nth-* | |
364 } m_nth; | |
365 AttributeMatchType m_attributeMatchType; // used for attribute s elector (with value) | |
366 } m_bits; | |
351 QualifiedName m_attribute; // used for attribute selector | 367 QualifiedName m_attribute; // used for attribute selector |
352 AtomicString m_argument; // Used for :contains, :lang, :nth-* | 368 AtomicString m_argument; // Used for :contains, :lang, :nth-* |
353 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and :not | 369 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and :not |
354 | 370 |
355 private: | 371 private: |
356 RareData(const AtomicString& value); | 372 RareData(const AtomicString& value); |
357 }; | 373 }; |
358 void createRareData(); | 374 void createRareData(); |
359 | 375 |
360 union DataUnion { | 376 union DataUnion { |
361 DataUnion() : m_value(0) { } | 377 DataUnion() : m_value(0) { } |
362 StringImpl* m_value; | 378 StringImpl* m_value; |
363 QualifiedName::QualifiedNameImpl* m_tagQName; | 379 QualifiedName::QualifiedNameImpl* m_tagQName; |
364 RareData* m_rareData; | 380 RareData* m_rareData; |
365 } m_data; | 381 } m_data; |
366 }; | 382 }; |
367 | 383 |
368 inline const QualifiedName& CSSSelector::attribute() const | 384 inline const QualifiedName& CSSSelector::attribute() const |
369 { | 385 { |
370 ASSERT(isAttributeSelector()); | 386 ASSERT(isAttributeSelector()); |
371 ASSERT(m_hasRareData); | 387 ASSERT(m_hasRareData); |
372 return m_data.m_rareData->m_attribute; | 388 return m_data.m_rareData->m_attribute; |
373 } | 389 } |
374 | 390 |
391 inline CSSSelector::AttributeMatchType CSSSelector::attributeMatchType() const | |
392 { | |
393 ASSERT(isAttributeSelector()); | |
394 ASSERT(m_hasRareData); | |
395 return m_data.m_rareData->m_bits.m_attributeMatchType; | |
396 } | |
397 | |
375 inline bool CSSSelector::matchesPseudoElement() const | 398 inline bool CSSSelector::matchesPseudoElement() const |
376 { | 399 { |
377 if (m_pseudoType == PseudoUnknown) | 400 if (m_pseudoType == PseudoUnknown) |
378 extractPseudoType(); | 401 extractPseudoType(); |
379 return m_match == PseudoElement; | 402 return m_match == PseudoElement; |
380 } | 403 } |
381 | 404 |
382 inline bool CSSSelector::isCustomPseudoElement() const | 405 inline bool CSSSelector::isCustomPseudoElement() const |
383 { | 406 { |
384 return m_match == PseudoElement && (m_pseudoType == PseudoUserAgentCustomEle ment || m_pseudoType == PseudoWebKitCustomElement); | 407 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) | 536 if (m_hasRareData) |
514 return m_data.m_rareData->m_value; | 537 return m_data.m_rareData->m_value; |
515 // AtomicString is really just a StringImpl* so the cast below is safe. | 538 // AtomicString is really just a StringImpl* so the cast below is safe. |
516 // FIXME: Perhaps call sites could be changed to accept StringImpl? | 539 // FIXME: Perhaps call sites could be changed to accept StringImpl? |
517 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); | 540 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); |
518 } | 541 } |
519 | 542 |
520 } // namespace blink | 543 } // namespace blink |
521 | 544 |
522 #endif // CSSSelector_h | 545 #endif // CSSSelector_h |
OLD | NEW |