Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/core/css/CSSSelector.h

Issue 330043003: Add support for case-insensitive attribute value selectors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make union w/ m_attributeFlags and nth-state; Return enum type. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 BottomRightMarginBox, 231 BottomRightMarginBox,
232 BottomRightCornerMarginBox, 232 BottomRightCornerMarginBox,
233 LeftTopMarginBox, 233 LeftTopMarginBox,
234 LeftMiddleMarginBox, 234 LeftMiddleMarginBox,
235 LeftBottomMarginBox, 235 LeftBottomMarginBox,
236 RightTopMarginBox, 236 RightTopMarginBox,
237 RightMiddleMarginBox, 237 RightMiddleMarginBox,
238 RightBottomMarginBox, 238 RightBottomMarginBox,
239 }; 239 };
240 240
241 enum AttributeFlags {
242 NoAttributeFlags,
243 CaseInsensitive,
244 };
245
241 PseudoType pseudoType() const 246 PseudoType pseudoType() const
242 { 247 {
243 if (m_pseudoType == PseudoNotParsed) 248 if (m_pseudoType == PseudoNotParsed)
244 extractPseudoType(); 249 extractPseudoType();
245 return static_cast<PseudoType>(m_pseudoType); 250 return static_cast<PseudoType>(m_pseudoType);
246 } 251 }
247 252
248 static PseudoType parsePseudoType(const AtomicString&); 253 static PseudoType parsePseudoType(const AtomicString&);
249 static PseudoId pseudoId(PseudoType); 254 static PseudoId pseudoId(PseudoType);
250 255
251 // Selectors are kept in an array by CSSSelectorList. The next component of the selector is 256 // Selectors are kept in an array by CSSSelectorList. The next component of the selector is
252 // the next item in the array. 257 // the next item in the array.
253 const CSSSelector* tagHistory() const { return m_isLastInTagHistory ? 0 : const_cast<CSSSelector*>(this + 1); } 258 const CSSSelector* tagHistory() const { return m_isLastInTagHistory ? 0 : const_cast<CSSSelector*>(this + 1); }
254 259
255 const QualifiedName& tagQName() const; 260 const QualifiedName& tagQName() const;
256 const AtomicString& value() const; 261 const AtomicString& value() const;
257 262
258 // WARNING: Use of QualifiedName by attribute() is a lie. 263 // WARNING: Use of QualifiedName by attribute() is a lie.
259 // attribute() will return a QualifiedName with prefix and namespaceURI 264 // attribute() will return a QualifiedName with prefix and namespaceURI
260 // set to starAtom to mean "matches any namespace". Be very careful 265 // set to starAtom to mean "matches any namespace". Be very careful
261 // how you use the returned QualifiedName. 266 // how you use the returned QualifiedName.
262 // http://www.w3.org/TR/css3-selectors/#attrnmsp 267 // http://www.w3.org/TR/css3-selectors/#attrnmsp
263 const QualifiedName& attribute() const; 268 const QualifiedName& attribute() const;
269 AttributeFlags attributeFlags() const;
264 // Returns the argument of a parameterized selector. For example, nth-ch ild(2) would have an argument of 2. 270 // Returns the argument of a parameterized selector. For example, nth-ch ild(2) would have an argument of 2.
265 const AtomicString& argument() const { return m_hasRareData ? m_data.m_r areData->m_argument : nullAtom; } 271 const AtomicString& argument() const { return m_hasRareData ? m_data.m_r areData->m_argument : nullAtom; }
266 const CSSSelectorList* selectorList() const { return m_hasRareData ? m_d ata.m_rareData->m_selectorList.get() : 0; } 272 const CSSSelectorList* selectorList() const { return m_hasRareData ? m_d ata.m_rareData->m_selectorList.get() : 0; }
267 273
268 #ifndef NDEBUG 274 #ifndef NDEBUG
269 void show() const; 275 void show() const;
270 void show(int indent) const; 276 void show(int indent) const;
271 #endif 277 #endif
272 278
273 void setValue(const AtomicString&); 279 void setValue(const AtomicString&);
274 void setAttribute(const QualifiedName&); 280 void setAttribute(const QualifiedName&, unsigned flags);
275 void setArgument(const AtomicString&); 281 void setArgument(const AtomicString&);
276 void setSelectorList(PassOwnPtr<CSSSelectorList>); 282 void setSelectorList(PassOwnPtr<CSSSelectorList>);
277 void setMatchUserAgentOnly(); 283 void setMatchUserAgentOnly();
278 284
279 bool parseNth() const; 285 bool parseNth() const;
280 bool matchNth(int count) const; 286 bool matchNth(int count) const;
281 287
282 bool matchesPseudoElement() const; 288 bool matchesPseudoElement() const;
283 bool isUnknownPseudoElement() const; 289 bool isUnknownPseudoElement() const;
284 bool isCustomPseudoElement() const; 290 bool isCustomPseudoElement() const;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
347 353
348 AtomicString m_value; 354 AtomicString m_value;
349 int m_a; // Used for :nth-* 355 union Bits {
350 int m_b; // Used for :nth-* 356 Bits() : m_nth() { }
357 struct {
358 int m_a; // Used for :nth-*
359 int m_b; // Used for :nth-*
360 } m_nth;
361 unsigned m_attributeFlags; // used for attribute selector (with value)
362 } m_bits;
351 QualifiedName m_attribute; // used for attribute selector 363 QualifiedName m_attribute; // used for attribute selector
352 AtomicString m_argument; // Used for :contains, :lang, :nth-* 364 AtomicString m_argument; // Used for :contains, :lang, :nth-*
353 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and :not 365 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and :not
354 366
355 private: 367 private:
356 RareData(const AtomicString& value); 368 RareData(const AtomicString& value);
357 }; 369 };
358 void createRareData(); 370 void createRareData();
359 371
360 union DataUnion { 372 union DataUnion {
361 DataUnion() : m_value(0) { } 373 DataUnion() : m_value(0) { }
362 StringImpl* m_value; 374 StringImpl* m_value;
363 QualifiedName::QualifiedNameImpl* m_tagQName; 375 QualifiedName::QualifiedNameImpl* m_tagQName;
364 RareData* m_rareData; 376 RareData* m_rareData;
365 } m_data; 377 } m_data;
366 }; 378 };
367 379
368 inline const QualifiedName& CSSSelector::attribute() const 380 inline const QualifiedName& CSSSelector::attribute() const
369 { 381 {
370 ASSERT(isAttributeSelector()); 382 ASSERT(isAttributeSelector());
371 ASSERT(m_hasRareData); 383 ASSERT(m_hasRareData);
372 return m_data.m_rareData->m_attribute; 384 return m_data.m_rareData->m_attribute;
373 } 385 }
374 386
387 inline CSSSelector::AttributeFlags CSSSelector::attributeFlags() const
388 {
389 ASSERT(isAttributeSelector());
390 ASSERT(m_hasRareData);
391 return static_cast<AttributeFlags>(m_data.m_rareData->m_bits.m_attributeFlag s);
392 }
393
375 inline bool CSSSelector::matchesPseudoElement() const 394 inline bool CSSSelector::matchesPseudoElement() const
376 { 395 {
377 if (m_pseudoType == PseudoUnknown) 396 if (m_pseudoType == PseudoUnknown)
378 extractPseudoType(); 397 extractPseudoType();
379 return m_match == PseudoElement; 398 return m_match == PseudoElement;
380 } 399 }
381 400
382 inline bool CSSSelector::isUnknownPseudoElement() const 401 inline bool CSSSelector::isUnknownPseudoElement() const
383 { 402 {
384 return m_match == PseudoElement && m_pseudoType == PseudoUnknown; 403 return m_match == PseudoElement && m_pseudoType == PseudoUnknown;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 if (m_hasRareData) 537 if (m_hasRareData)
519 return m_data.m_rareData->m_value; 538 return m_data.m_rareData->m_value;
520 // AtomicString is really just a StringImpl* so the cast below is safe. 539 // AtomicString is really just a StringImpl* so the cast below is safe.
521 // FIXME: Perhaps call sites could be changed to accept StringImpl? 540 // FIXME: Perhaps call sites could be changed to accept StringImpl?
522 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); 541 return *reinterpret_cast<const AtomicString*>(&m_data.m_value);
523 } 542 }
524 543
525 } // namespace WebCore 544 } // namespace WebCore
526 545
527 #endif // CSSSelector_h 546 #endif // CSSSelector_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698