OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "core/dom/SelectorQuery.h" | 27 #include "core/dom/SelectorQuery.h" |
28 | 28 |
29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
30 #include "core/css/CSSParser.h" | 30 #include "core/css/CSSParser.h" |
31 #include "core/css/CSSSelectorList.h" | 31 #include "core/css/CSSSelectorList.h" |
32 #include "core/css/SelectorChecker.h" | 32 #include "core/css/SelectorChecker.h" |
33 #include "core/css/SelectorCheckerFastPath.h" | 33 #include "core/css/SelectorCheckerFastPath.h" |
34 #include "core/css/SiblingTraversalStrategies.h" | 34 #include "core/css/SiblingTraversalStrategies.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/ElementTraversal.h" | 36 #include "core/dom/ElementTraversal.h" |
37 #include "core/dom/Node.h" | |
38 #include "core/dom/StaticNodeList.h" | 37 #include "core/dom/StaticNodeList.h" |
39 | 38 |
40 namespace WebCore { | 39 namespace WebCore { |
41 | 40 |
42 class SimpleNodeList { | 41 class SimpleNodeList { |
43 public: | 42 public: |
44 virtual ~SimpleNodeList() { } | 43 virtual ~SimpleNodeList() { } |
45 virtual bool isEmpty() const = 0; | 44 virtual bool isEmpty() const = 0; |
46 virtual Node* next() = 0; | 45 virtual Node* next() = 0; |
47 }; | 46 }; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Vector<RefPtr<Node> > result; | 172 Vector<RefPtr<Node> > result; |
174 executeQueryAll(rootNode, result); | 173 executeQueryAll(rootNode, result); |
175 return StaticNodeList::adopt(result); | 174 return StaticNodeList::adopt(result); |
176 } | 175 } |
177 | 176 |
178 PassRefPtr<Element> SelectorDataList::queryFirst(Node& rootNode) const | 177 PassRefPtr<Element> SelectorDataList::queryFirst(Node& rootNode) const |
179 { | 178 { |
180 return executeQueryFirst(rootNode); | 179 return executeQueryFirst(rootNode); |
181 } | 180 } |
182 | 181 |
| 182 static inline bool isTreeScopeRoot(Node* node) |
| 183 { |
| 184 ASSERT(node); |
| 185 return node->isDocumentNode() || node->isShadowRoot(); |
| 186 } |
| 187 |
183 void SelectorDataList::collectElementsByClassName(Node& rootNode, const AtomicSt
ring& className, Vector<RefPtr<Node> >& traversalRoots) const | 188 void SelectorDataList::collectElementsByClassName(Node& rootNode, const AtomicSt
ring& className, Vector<RefPtr<Node> >& traversalRoots) const |
184 { | 189 { |
185 for (Element* element = ElementTraversal::firstWithin(rootNode); element; el
ement = ElementTraversal::next(*element, &rootNode)) { | 190 for (Element* element = ElementTraversal::firstWithin(rootNode); element; el
ement = ElementTraversal::next(*element, &rootNode)) { |
186 if (element->hasClass() && element->classNames().contains(className)) | 191 if (element->hasClass() && element->classNames().contains(className)) |
187 traversalRoots.append(element); | 192 traversalRoots.append(element); |
188 } | 193 } |
189 } | 194 } |
190 | 195 |
191 void SelectorDataList::collectElementsByTagName(Node& rootNode, const QualifiedN
ame& tagName, Vector<RefPtr<Node> >& traversalRoots) const | 196 void SelectorDataList::collectElementsByTagName(Node& rootNode, const QualifiedN
ame& tagName, Vector<RefPtr<Node> >& traversalRoots) const |
192 { | 197 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 ASSERT(m_selectors.size() == 1); | 251 ASSERT(m_selectors.size() == 1); |
247 ASSERT(m_selectors[0].selector); | 252 ASSERT(m_selectors[0].selector); |
248 | 253 |
249 bool isRightmostSelector = true; | 254 bool isRightmostSelector = true; |
250 bool startFromParent = false; | 255 bool startFromParent = false; |
251 | 256 |
252 for (const CSSSelector* selector = m_selectors[0].selector; selector; select
or = selector->tagHistory()) { | 257 for (const CSSSelector* selector = m_selectors[0].selector; selector; select
or = selector->tagHistory()) { |
253 if (selector->m_match == CSSSelector::Id && !rootNode.document().contain
sMultipleElementsWithId(selector->value())) { | 258 if (selector->m_match == CSSSelector::Id && !rootNode.document().contain
sMultipleElementsWithId(selector->value())) { |
254 Element* element = rootNode.treeScope().getElementById(selector->val
ue()); | 259 Element* element = rootNode.treeScope().getElementById(selector->val
ue()); |
255 Node* adjustedNode = &rootNode; | 260 Node* adjustedNode = &rootNode; |
256 if (element && (isTreeScopeRoot(rootNode) || element->isDescendantOf
(&rootNode))) | 261 if (element && (isTreeScopeRoot(&rootNode) || element->isDescendantO
f(&rootNode))) |
257 adjustedNode = element; | 262 adjustedNode = element; |
258 else if (!element || isRightmostSelector) | 263 else if (!element || isRightmostSelector) |
259 adjustedNode = 0; | 264 adjustedNode = 0; |
260 if (isRightmostSelector) { | 265 if (isRightmostSelector) { |
261 matchTraverseRoots = true; | 266 matchTraverseRoots = true; |
262 return adoptPtr(new SingleNodeList(adjustedNode)); | 267 return adoptPtr(new SingleNodeList(adjustedNode)); |
263 } | 268 } |
264 if (startFromParent && adjustedNode) | 269 if (startFromParent && adjustedNode) |
265 adjustedNode = adjustedNode->parentNode(); | 270 adjustedNode = adjustedNode->parentNode(); |
266 | 271 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 m_entries.add(selectors, selectorQuery.release()); | 526 m_entries.add(selectors, selectorQuery.release()); |
522 return rawSelectorQuery; | 527 return rawSelectorQuery; |
523 } | 528 } |
524 | 529 |
525 void SelectorQueryCache::invalidate() | 530 void SelectorQueryCache::invalidate() |
526 { | 531 { |
527 m_entries.clear(); | 532 m_entries.clear(); |
528 } | 533 } |
529 | 534 |
530 } | 535 } |
OLD | NEW |