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

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: legacyCaseSensitive->legacyCaseInsensitive; Extend tests. Created 6 years, 5 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AttributeFlags {
243 NoAttributeFlags,
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 AttributeFlags attributeFlags() 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&, unsigned flags);
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 isUnknownPseudoElement() const; 290 bool isUnknownPseudoElement() const;
285 bool isCustomPseudoElement() const; 291 bool isCustomPseudoElement() const;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 CSSSelector& operator=(const CSSSelector&); 346 CSSSelector& operator=(const CSSSelector&);
341 347
342 struct RareData : public RefCounted<RareData> { 348 struct RareData : public RefCounted<RareData> {
343 static PassRefPtr<RareData> create(const AtomicString& value) { retu rn adoptRef(new RareData(value)); } 349 static PassRefPtr<RareData> create(const AtomicString& value) { retu rn adoptRef(new RareData(value)); }
344 ~RareData(); 350 ~RareData();
345 351
346 bool parseNth(); 352 bool parseNth();
347 bool matchNth(int count); 353 bool matchNth(int count);
348 354
349 AtomicString m_value; 355 AtomicString m_value;
350 int m_a; // Used for :nth-* 356 union Bits {
eseidel 2014/07/29 15:43:22 I'm confused by these. It looks like this is a bi
fs 2014/07/29 17:14:32 The union is "reaction" to comments in https://cod
351 int m_b; // Used for :nth-* 357 Bits() : m_nth() { }
eseidel 2014/07/29 15:43:22 This doesn't do anything.
fs 2014/07/29 17:14:32 It initializes m_nth to zeros.
358 struct {
359 int m_a; // Used for :nth-*
360 int m_b; // Used for :nth-*
361 } m_nth;
362 unsigned m_attributeFlags; // used for attribute selector (with value)
363 } m_bits;
352 QualifiedName m_attribute; // used for attribute selector 364 QualifiedName m_attribute; // used for attribute selector
353 AtomicString m_argument; // Used for :contains, :lang, :nth-* 365 AtomicString m_argument; // Used for :contains, :lang, :nth-*
354 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and :not 366 OwnPtr<CSSSelectorList> m_selectorList; // Used for :-webkit-any and :not
355 367
356 private: 368 private:
357 RareData(const AtomicString& value); 369 RareData(const AtomicString& value);
358 }; 370 };
359 void createRareData(); 371 void createRareData();
360 372
361 union DataUnion { 373 union DataUnion {
362 DataUnion() : m_value(0) { } 374 DataUnion() : m_value(0) { }
363 StringImpl* m_value; 375 StringImpl* m_value;
364 QualifiedName::QualifiedNameImpl* m_tagQName; 376 QualifiedName::QualifiedNameImpl* m_tagQName;
365 RareData* m_rareData; 377 RareData* m_rareData;
366 } m_data; 378 } m_data;
367 }; 379 };
368 380
369 inline const QualifiedName& CSSSelector::attribute() const 381 inline const QualifiedName& CSSSelector::attribute() const
370 { 382 {
371 ASSERT(isAttributeSelector()); 383 ASSERT(isAttributeSelector());
372 ASSERT(m_hasRareData); 384 ASSERT(m_hasRareData);
373 return m_data.m_rareData->m_attribute; 385 return m_data.m_rareData->m_attribute;
374 } 386 }
375 387
388 inline CSSSelector::AttributeFlags CSSSelector::attributeFlags() const
389 {
390 ASSERT(isAttributeSelector());
391 ASSERT(m_hasRareData);
392 return static_cast<AttributeFlags>(m_data.m_rareData->m_bits.m_attributeFlag s);
393 }
394
376 inline bool CSSSelector::matchesPseudoElement() const 395 inline bool CSSSelector::matchesPseudoElement() const
377 { 396 {
378 if (m_pseudoType == PseudoUnknown) 397 if (m_pseudoType == PseudoUnknown)
379 extractPseudoType(); 398 extractPseudoType();
380 return m_match == PseudoElement; 399 return m_match == PseudoElement;
381 } 400 }
382 401
383 inline bool CSSSelector::isUnknownPseudoElement() const 402 inline bool CSSSelector::isUnknownPseudoElement() const
384 { 403 {
385 return m_match == PseudoElement && m_pseudoType == PseudoUnknown; 404 return m_match == PseudoElement && m_pseudoType == PseudoUnknown;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 if (m_hasRareData) 538 if (m_hasRareData)
520 return m_data.m_rareData->m_value; 539 return m_data.m_rareData->m_value;
521 // AtomicString is really just a StringImpl* so the cast below is safe. 540 // AtomicString is really just a StringImpl* so the cast below is safe.
522 // FIXME: Perhaps call sites could be changed to accept StringImpl? 541 // FIXME: Perhaps call sites could be changed to accept StringImpl?
523 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); 542 return *reinterpret_cast<const AtomicString*>(&m_data.m_value);
524 } 543 }
525 544
526 } // namespace blink 545 } // namespace blink
527 546
528 #endif // CSSSelector_h 547 #endif // CSSSelector_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698