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 |
| 5 * reserved. |
5 * | 6 * |
6 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
10 * | 11 * |
11 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 15 * Library General Public License for more details. |
(...skipping 11 matching lines...) Expand all Loading... |
26 #include "core/dom/QualifiedName.h" | 27 #include "core/dom/QualifiedName.h" |
27 #include "core/style/ComputedStyleConstants.h" | 28 #include "core/style/ComputedStyleConstants.h" |
28 #include "wtf/RefCounted.h" | 29 #include "wtf/RefCounted.h" |
29 #include <memory> | 30 #include <memory> |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 class CSSSelectorList; | 33 class CSSSelectorList; |
33 | 34 |
34 // This class represents a selector for a StyleRule. | 35 // This class represents a selector for a StyleRule. |
35 | 36 |
36 // CSS selector representation is somewhat complicated and subtle. A representat
ive list of selectors is | 37 // CSS selector representation is somewhat complicated and subtle. A |
37 // in CSSSelectorTest; run it in a debug build to see useful debugging output. | 38 // representative list of selectors is in CSSSelectorTest; run it in a debug |
| 39 // build to see useful debugging output. |
38 // | 40 // |
39 // ** tagHistory() and relation(): | 41 // ** tagHistory() and relation(): |
40 // | 42 // |
41 // Selectors are represented as a linked list of simple selectors (defined more
or less according to | 43 // Selectors are represented as a linked list of simple selectors (defined more |
42 // http://www.w3.org/TR/css3-selectors/#simple-selectors-dfn). The tagHistory()
method returns the next | 44 // or less according to |
43 // simple selector in the list. The relation() method returns the relationship o
f the current simple selector to | 45 // http://www.w3.org/TR/css3-selectors/#simple-selectors-dfn). The tagHistory() |
44 // the one in tagHistory(). For example, the CSS selector .a.b #c is represented
as: | 46 // method returns the next simple selector in the list. The relation() method |
| 47 // returns the relationship of the current simple selector to the one in |
| 48 // tagHistory(). For example, the CSS selector .a.b #c is represented as: |
45 // | 49 // |
46 // selectorText(): .a.b #c | 50 // selectorText(): .a.b #c |
47 // --> (relation == Descendant) | 51 // --> (relation == Descendant) |
48 // selectorText(): .a.b | 52 // selectorText(): .a.b |
49 // --> (relation == SubSelector) | 53 // --> (relation == SubSelector) |
50 // selectorText(): .b | 54 // selectorText(): .b |
51 // | 55 // |
52 // The order of tagHistory() varies depending on the situation. | 56 // The order of tagHistory() varies depending on the situation. |
53 // * Relations using combinators (http://www.w3.org/TR/css3-selectors/#combinato
rs), such as descendant, sibling, etc., are parsed | 57 // * Relations using combinators |
54 // right-to-left (in the example above, this is why #c is earlier in the tagHi
story() chain than .a.b). | 58 // (http://www.w3.org/TR/css3-selectors/#combinators), such as descendant, |
55 // * SubSelector relations are parsed left-to-right in most cases (such as the .
a.b example above); a counter-example is the | 59 // sibling, etc., are parsed right-to-left (in the example above, this is why |
56 // ::content pseudo-element. Most (all?) other pseudo elements and pseudo clas
ses are parsed left-to-right. | 60 // #c is earlier in the tagHistory() chain than .a.b). |
57 // * ShadowPseudo relations are parsed right-to-left. Example: summary::-webkit-
details-marker is parsed as: | 61 // * SubSelector relations are parsed left-to-right in most cases (such as the |
58 // selectorText(): summary::-webkit-details-marker | 62 // .a.b example above); a counter-example is the |
59 // --> (relation == ShadowPseudo) | 63 // ::content pseudo-element. Most (all?) other pseudo elements and pseudo |
60 // selectorText(): summary | 64 // classes are parsed left-to-right. |
| 65 // * ShadowPseudo relations are parsed right-to-left. Example: |
| 66 // summary::-webkit-details-marker is parsed as: selectorText(): |
| 67 // summary::-webkit-details-marker --> (relation == ShadowPseudo) |
| 68 // selectorText(): summary |
61 // | 69 // |
62 // ** match(): | 70 // ** match(): |
63 // | 71 // |
64 // The match of the current simple selector tells us the type of selector, such
as class, id, tagname, or pseudo-class. | 72 // The match of the current simple selector tells us the type of selector, such |
65 // Inline comments in the Match enum give examples of when each type would occur
. | 73 // as class, id, tagname, or pseudo-class. Inline comments in the Match enum |
| 74 // give examples of when each type would occur. |
66 // | 75 // |
67 // ** value(), attribute(): | 76 // ** value(), attribute(): |
68 // | 77 // |
69 // value() tells you the value of the simple selector. For example, for class se
lectors, value() will tell you the class string, | 78 // value() tells you the value of the simple selector. For example, for class |
70 // and for id selectors it will tell you the id(). See below for the special cas
e of attribute selectors. | 79 // selectors, value() will tell you the class string, and for id selectors it |
| 80 // will tell you the id(). See below for the special case of attribute |
| 81 // selectors. |
71 // | 82 // |
72 // ** Attribute selectors. | 83 // ** Attribute selectors. |
73 // | 84 // |
74 // Attribute selectors return the attribute name in the attribute() method. The
value() method returns the value matched against | 85 // Attribute selectors return the attribute name in the attribute() method. The |
75 // in case of selectors like [attr="value"]. | 86 // value() method returns the value matched against in case of selectors like |
| 87 // [attr="value"]. |
76 // | 88 // |
77 class CORE_EXPORT CSSSelector { | 89 class CORE_EXPORT CSSSelector { |
78 USING_FAST_MALLOC_WITH_TYPE_NAME(blink::CSSSelector); | 90 USING_FAST_MALLOC_WITH_TYPE_NAME(blink::CSSSelector); |
79 | 91 |
80 public: | 92 public: |
81 CSSSelector(); | 93 CSSSelector(); |
82 CSSSelector(const CSSSelector&); | 94 CSSSelector(const CSSSelector&); |
83 explicit CSSSelector(const QualifiedName&, bool tagIsImplicit = false); | 95 explicit CSSSelector(const QualifiedName&, bool tagIsImplicit = false); |
84 | 96 |
85 ~CSSSelector(); | 97 ~CSSSelector(); |
(...skipping 24 matching lines...) Expand all Loading... |
110 AttributeEnd, // css3: E[foo$="bar"] | 122 AttributeEnd, // css3: E[foo$="bar"] |
111 FirstAttributeSelectorMatch = AttributeExact, | 123 FirstAttributeSelectorMatch = AttributeExact, |
112 }; | 124 }; |
113 | 125 |
114 enum RelationType { | 126 enum RelationType { |
115 SubSelector, // No combinator | 127 SubSelector, // No combinator |
116 Descendant, // "Space" combinator | 128 Descendant, // "Space" combinator |
117 Child, // > combinator | 129 Child, // > combinator |
118 DirectAdjacent, // + combinator | 130 DirectAdjacent, // + combinator |
119 IndirectAdjacent, // ~ combinator | 131 IndirectAdjacent, // ~ combinator |
120 ShadowPseudo, // Special case of shadow DOM pseudo elements / shadow pseudo
element | 132 // Special case of shadow DOM pseudo elements / shadow pseudo element |
| 133 ShadowPseudo, |
121 ShadowDeep, // /deep/ combinator | 134 ShadowDeep, // /deep/ combinator |
122 ShadowSlot // slotted to <slot> element | 135 ShadowSlot // slotted to <slot> element |
123 }; | 136 }; |
124 | 137 |
125 enum PseudoType { | 138 enum PseudoType { |
126 PseudoUnknown, | 139 PseudoUnknown, |
127 PseudoEmpty, | 140 PseudoEmpty, |
128 PseudoFirstChild, | 141 PseudoFirstChild, |
129 PseudoFirstOfType, | 142 PseudoFirstOfType, |
130 PseudoLastChild, | 143 PseudoLastChild, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 232 |
220 PseudoType getPseudoType() const { | 233 PseudoType getPseudoType() const { |
221 return static_cast<PseudoType>(m_pseudoType); | 234 return static_cast<PseudoType>(m_pseudoType); |
222 } | 235 } |
223 void updatePseudoType(const AtomicString&, bool hasArguments); | 236 void updatePseudoType(const AtomicString&, bool hasArguments); |
224 | 237 |
225 static PseudoType parsePseudoType(const AtomicString&, bool hasArguments); | 238 static PseudoType parsePseudoType(const AtomicString&, bool hasArguments); |
226 static PseudoId parsePseudoId(const String&); | 239 static PseudoId parsePseudoId(const String&); |
227 static PseudoId pseudoId(PseudoType); | 240 static PseudoId pseudoId(PseudoType); |
228 | 241 |
229 // Selectors are kept in an array by CSSSelectorList. The next component of th
e selector is | 242 // Selectors are kept in an array by CSSSelectorList. The next component of |
230 // the next item in the array. | 243 // the selector is the next item in the array. |
231 const CSSSelector* tagHistory() const { | 244 const CSSSelector* tagHistory() const { |
232 return m_isLastInTagHistory ? 0 : const_cast<CSSSelector*>(this + 1); | 245 return m_isLastInTagHistory ? 0 : const_cast<CSSSelector*>(this + 1); |
233 } | 246 } |
234 | 247 |
235 const QualifiedName& tagQName() const; | 248 const QualifiedName& tagQName() const; |
236 const AtomicString& value() const; | 249 const AtomicString& value() const; |
237 const AtomicString& serializingValue() const; | 250 const AtomicString& serializingValue() const; |
238 | 251 |
239 // WARNING: Use of QualifiedName by attribute() is a lie. | 252 // WARNING: Use of QualifiedName by attribute() is a lie. |
240 // attribute() will return a QualifiedName with prefix and namespaceURI | 253 // attribute() will return a QualifiedName with prefix and namespaceURI |
241 // set to starAtom to mean "matches any namespace". Be very careful | 254 // set to starAtom to mean "matches any namespace". Be very careful |
242 // how you use the returned QualifiedName. | 255 // how you use the returned QualifiedName. |
243 // http://www.w3.org/TR/css3-selectors/#attrnmsp | 256 // http://www.w3.org/TR/css3-selectors/#attrnmsp |
244 const QualifiedName& attribute() const; | 257 const QualifiedName& attribute() const; |
245 AttributeMatchType attributeMatch() const; | 258 AttributeMatchType attributeMatch() const; |
246 // Returns the argument of a parameterized selector. For example, :lang(en-US)
would have an argument of en-US. | 259 // Returns the argument of a parameterized selector. For example, :lang(en-US) |
247 // Note that :nth-* selectors don't store an argument and just store the numbe
rs. | 260 // would have an argument of en-US. |
| 261 // Note that :nth-* selectors don't store an argument and just store the |
| 262 // numbers. |
248 const AtomicString& argument() const { | 263 const AtomicString& argument() const { |
249 return m_hasRareData ? m_data.m_rareData->m_argument : nullAtom; | 264 return m_hasRareData ? m_data.m_rareData->m_argument : nullAtom; |
250 } | 265 } |
251 const CSSSelectorList* selectorList() const { | 266 const CSSSelectorList* selectorList() const { |
252 return m_hasRareData ? m_data.m_rareData->m_selectorList.get() : nullptr; | 267 return m_hasRareData ? m_data.m_rareData->m_selectorList.get() : nullptr; |
253 } | 268 } |
254 | 269 |
255 #ifndef NDEBUG | 270 #ifndef NDEBUG |
256 void show() const; | 271 void show() const; |
257 void show(int indent) const; | 272 void show(int indent) const; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 533 } |
519 | 534 |
520 inline bool CSSSelector::isIdClassOrAttributeSelector() const { | 535 inline bool CSSSelector::isIdClassOrAttributeSelector() const { |
521 return isAttributeSelector() || match() == CSSSelector::Id || | 536 return isAttributeSelector() || match() == CSSSelector::Id || |
522 match() == CSSSelector::Class; | 537 match() == CSSSelector::Class; |
523 } | 538 } |
524 | 539 |
525 } // namespace blink | 540 } // namespace blink |
526 | 541 |
527 #endif // CSSSelector_h | 542 #endif // CSSSelector_h |
OLD | NEW |