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

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

Issue 751023002: Use SubSelector as relation on left-most selector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: SubSelector is not a combinator Created 6 years 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
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 30 matching lines...) Expand all
41 // http://www.w3.org/TR/css3-selectors/#simple-selectors-dfn). The tagHistor y() method returns the next 41 // http://www.w3.org/TR/css3-selectors/#simple-selectors-dfn). The tagHistor y() method returns the next
42 // simple selector in the list. The relation() method returns the relationsh ip of the current simple selector to 42 // simple selector in the list. The relation() method returns the relationsh ip of the current simple selector to
43 // the one in tagHistory(). For example, the CSS selector .a.b #c is represe nted as: 43 // the one in tagHistory(). For example, the CSS selector .a.b #c is represe nted as:
44 // 44 //
45 // selectorText(): .a.b #c 45 // selectorText(): .a.b #c
46 // --> (relation == Descendant) 46 // --> (relation == Descendant)
47 // selectorText(): .a.b 47 // selectorText(): .a.b
48 // --> (relation == SubSelector) 48 // --> (relation == SubSelector)
49 // selectorText(): .b 49 // selectorText(): .b
50 // 50 //
51 // Note that currently a bare selector such as ".a" has a relation() of Desc endant. This is a bug - instead the relation should be
52 // "None".
53 //
54 // The order of tagHistory() varies depending on the situation. 51 // The order of tagHistory() varies depending on the situation.
55 // * Relations using combinators (http://www.w3.org/TR/css3-selectors/#combi nators), such as descendant, sibling, etc., are parsed 52 // * Relations using combinators (http://www.w3.org/TR/css3-selectors/#combi nators), such as descendant, sibling, etc., are parsed
56 // right-to-left (in the example above, this is why .c is earlier in the t agHistory() chain than .a.b). 53 // right-to-left (in the example above, this is why .c is earlier in the t agHistory() chain than .a.b).
57 // * SubSelector relations are parsed left-to-right in most cases (such as t he .a.b example above); a counter-example is the 54 // * SubSelector relations are parsed left-to-right in most cases (such as t he .a.b example above); a counter-example is the
58 // ::content pseudo-element. Most (all?) other pseudo elements and pseudo classes are parsed left-to-right. 55 // ::content pseudo-element. Most (all?) other pseudo elements and pseudo classes are parsed left-to-right.
59 // * ShadowPseudo relations are parsed right-to-left. Example: summary::-web kit-details-marker is parsed as: 56 // * ShadowPseudo relations are parsed right-to-left. Example: summary::-web kit-details-marker is parsed as:
60 // selectorText(): summary::-webkit-details-marker 57 // selectorText(): summary::-webkit-details-marker
61 // --> (relation == ShadowPseudo) 58 // --> (relation == ShadowPseudo)
62 // selectorText(): summary 59 // selectorText(): summary
63 // 60 //
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool operator==(const CSSSelector&) const; 96 bool operator==(const CSSSelector&) const;
100 97
101 // tag == -1 means apply to all elements (Selector = *) 98 // tag == -1 means apply to all elements (Selector = *)
102 99
103 // http://www.w3.org/TR/css3-selectors/#specificity 100 // http://www.w3.org/TR/css3-selectors/#specificity
104 // We use 256 as the base of the specificity number system. 101 // We use 256 as the base of the specificity number system.
105 unsigned specificity() const; 102 unsigned specificity() const;
106 103
107 /* how the attribute value has to match.... Default is Exact */ 104 /* how the attribute value has to match.... Default is Exact */
108 enum Match { 105 enum Match {
109 Unknown = 0, 106 Unknown,
110 Tag, // Example: div 107 Tag, // Example: div
111 Id, // Example: #id 108 Id, // Example: #id
112 Class, // example: .class 109 Class, // example: .class
113 PseudoClass, // Example: :nth-child(2) 110 PseudoClass, // Example: :nth-child(2)
114 PseudoElement, // Example: ::first-line 111 PseudoElement, // Example: ::first-line
115 PagePseudoClass, // ?? 112 PagePseudoClass, // ??
116 AttributeExact, // Example: E[foo="bar"] 113 AttributeExact, // Example: E[foo="bar"]
117 AttributeSet, // Example: E[foo] 114 AttributeSet, // Example: E[foo]
118 AttributeHyphen, // Example: E[foo|="bar"] 115 AttributeHyphen, // Example: E[foo|="bar"]
119 AttributeList, // Example: E[foo~="bar"] 116 AttributeList, // Example: E[foo~="bar"]
120 AttributeContain, // css3: E[foo*="bar"] 117 AttributeContain, // css3: E[foo*="bar"]
121 AttributeBegin, // css3: E[foo^="bar"] 118 AttributeBegin, // css3: E[foo^="bar"]
122 AttributeEnd, // css3: E[foo$="bar"] 119 AttributeEnd, // css3: E[foo$="bar"]
123 FirstAttributeSelectorMatch = AttributeExact, 120 FirstAttributeSelectorMatch = AttributeExact,
124 }; 121 };
125 122
126 enum Relation { 123 enum Relation {
127 Descendant = 0, // "Space" combinator 124 SubSelector, // No combinator
125 Descendant, // "Space" combinator
128 Child, // > combinator 126 Child, // > combinator
129 DirectAdjacent, // + combinator 127 DirectAdjacent, // + combinator
130 IndirectAdjacent, // ~ combinator 128 IndirectAdjacent, // ~ combinator
131 SubSelector, // "No space" combinator
132 ShadowPseudo, // Special case of shadow DOM pseudo elements / shadow pseudo element 129 ShadowPseudo, // Special case of shadow DOM pseudo elements / shadow pseudo element
133 ShadowDeep // /deep/ combinator 130 ShadowDeep // /deep/ combinator
134 }; 131 };
135 132
136 enum PseudoType { 133 enum PseudoType {
137 PseudoNotParsed = 0, 134 PseudoNotParsed,
138 PseudoUnknown, 135 PseudoUnknown,
139 PseudoEmpty, 136 PseudoEmpty,
140 PseudoFirstChild, 137 PseudoFirstChild,
141 PseudoFirstOfType, 138 PseudoFirstOfType,
142 PseudoLastChild, 139 PseudoLastChild,
143 PseudoLastOfType, 140 PseudoLastOfType,
144 PseudoOnlyChild, 141 PseudoOnlyChild,
145 PseudoOnlyOfType, 142 PseudoOnlyOfType,
146 PseudoFirstLine, 143 PseudoFirstLine,
147 PseudoFirstLetter, 144 PseudoFirstLetter,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 bool isDirectAdjacentSelector() const { return m_relation == DirectAdjac ent; } 286 bool isDirectAdjacentSelector() const { return m_relation == DirectAdjac ent; }
290 bool isAdjacentSelector() const { return m_relation == DirectAdjacent || m_relation == IndirectAdjacent; } 287 bool isAdjacentSelector() const { return m_relation == DirectAdjacent || m_relation == IndirectAdjacent; }
291 bool isShadowSelector() const { return m_relation == ShadowPseudo || m_r elation == ShadowDeep; } 288 bool isShadowSelector() const { return m_relation == ShadowPseudo || m_r elation == ShadowDeep; }
292 bool isSiblingSelector() const; 289 bool isSiblingSelector() const;
293 bool isAttributeSelector() const; 290 bool isAttributeSelector() const;
294 bool isContentPseudoElement() const; 291 bool isContentPseudoElement() const;
295 bool isShadowPseudoElement() const; 292 bool isShadowPseudoElement() const;
296 bool isHostPseudoClass() const; 293 bool isHostPseudoClass() const;
297 bool isTreeBoundaryCrossing() const; 294 bool isTreeBoundaryCrossing() const;
298 bool isInsertionPointCrossing() const; 295 bool isInsertionPointCrossing() const;
299 // FIXME: selectors with no tagHistory() get a relation() of Descendant (and sometimes even SubSelector). It should instead be
300 // None.
301 Relation relation() const { return static_cast<Relation>(m_relation); } 296 Relation relation() const { return static_cast<Relation>(m_relation); }
302 void setRelation(Relation relation) 297 void setRelation(Relation relation)
303 { 298 {
304 m_relation = relation; 299 m_relation = relation;
305 ASSERT(static_cast<Relation>(m_relation) == relation); // using a bi tfield. 300 ASSERT(static_cast<Relation>(m_relation) == relation); // using a bi tfield.
306 } 301 }
307 302
308 Match match() const { return static_cast<Match>(m_match); } 303 Match match() const { return static_cast<Match>(m_match); }
309 void setMatch(Match match) 304 void setMatch(Match match)
310 { 305 {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 m_data.m_rareData->m_value = value; 460 m_data.m_rareData->m_value = value;
466 return; 461 return;
467 } 462 }
468 if (m_data.m_value) 463 if (m_data.m_value)
469 m_data.m_value->deref(); 464 m_data.m_value->deref();
470 m_data.m_value = value.impl(); 465 m_data.m_value = value.impl();
471 m_data.m_value->ref(); 466 m_data.m_value->ref();
472 } 467 }
473 468
474 inline CSSSelector::CSSSelector() 469 inline CSSSelector::CSSSelector()
475 : m_relation(Descendant) 470 : m_relation(SubSelector)
476 , m_match(Unknown) 471 , m_match(Unknown)
477 , m_pseudoType(PseudoNotParsed) 472 , m_pseudoType(PseudoNotParsed)
478 , m_parsedNth(false) 473 , m_parsedNth(false)
479 , m_isLastInSelectorList(false) 474 , m_isLastInSelectorList(false)
480 , m_isLastInTagHistory(true) 475 , m_isLastInTagHistory(true)
481 , m_hasRareData(false) 476 , m_hasRareData(false)
482 , m_isForPage(false) 477 , m_isForPage(false)
483 , m_tagIsForNamespaceRule(false) 478 , m_tagIsForNamespaceRule(false)
484 , m_relationIsAffectedByPseudoContent(false) 479 , m_relationIsAffectedByPseudoContent(false)
485 { 480 {
486 } 481 }
487 482
488 inline CSSSelector::CSSSelector(const QualifiedName& tagQName, bool tagIsForName spaceRule) 483 inline CSSSelector::CSSSelector(const QualifiedName& tagQName, bool tagIsForName spaceRule)
489 : m_relation(Descendant) 484 : m_relation(SubSelector)
490 , m_match(Tag) 485 , m_match(Tag)
491 , m_pseudoType(PseudoNotParsed) 486 , m_pseudoType(PseudoNotParsed)
492 , m_parsedNth(false) 487 , m_parsedNth(false)
493 , m_isLastInSelectorList(false) 488 , m_isLastInSelectorList(false)
494 , m_isLastInTagHistory(true) 489 , m_isLastInTagHistory(true)
495 , m_hasRareData(false) 490 , m_hasRareData(false)
496 , m_isForPage(false) 491 , m_isForPage(false)
497 , m_tagIsForNamespaceRule(tagIsForNamespaceRule) 492 , m_tagIsForNamespaceRule(tagIsForNamespaceRule)
498 , m_relationIsAffectedByPseudoContent(false) 493 , m_relationIsAffectedByPseudoContent(false)
499 { 494 {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if (m_hasRareData) 542 if (m_hasRareData)
548 return m_data.m_rareData->m_value; 543 return m_data.m_rareData->m_value;
549 // AtomicString is really just a StringImpl* so the cast below is safe. 544 // AtomicString is really just a StringImpl* so the cast below is safe.
550 // FIXME: Perhaps call sites could be changed to accept StringImpl? 545 // FIXME: Perhaps call sites could be changed to accept StringImpl?
551 return *reinterpret_cast<const AtomicString*>(&m_data.m_value); 546 return *reinterpret_cast<const AtomicString*>(&m_data.m_value);
552 } 547 }
553 548
554 } // namespace blink 549 } // namespace blink
555 550
556 #endif // CSSSelector_h 551 #endif // CSSSelector_h
OLDNEW
« no previous file with comments | « LayoutTests/fast/css/invalidation/sub-selector-adjacent-cancellation-expected.txt ('k') | Source/core/css/RuleFeature.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698