| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 template <ClassElementListBehavior onlyRoots> | 63 template <ClassElementListBehavior onlyRoots> |
| 64 class ClassElementList { | 64 class ClassElementList { |
| 65 public: | 65 public: |
| 66 ClassElementList(ContainerNode& rootNode, const AtomicString& className) | 66 ClassElementList(ContainerNode& rootNode, const AtomicString& className) |
| 67 : m_className(className) | 67 : m_className(className) |
| 68 , m_rootNode(rootNode) | 68 , m_rootNode(rootNode) |
| 69 , m_currentElement(nextInternal(ElementTraversal::firstWithin(rootNode))
) { } | 69 , m_currentElement(nextInternal(ElementTraversal::firstWithin(rootNode))
) { } |
| 70 | 70 |
| 71 bool isEmpty() const { return !m_currentElement; } | 71 bool isEmpty() const { return !m_currentElement; } |
| 72 | 72 |
| 73 Node* next() | 73 Element* next() |
| 74 { | 74 { |
| 75 Node* current = m_currentElement; | 75 Element* current = m_currentElement; |
| 76 ASSERT(current); | 76 ASSERT(current); |
| 77 if (onlyRoots) | 77 if (onlyRoots) |
| 78 m_currentElement = nextInternal(ElementTraversal::nextSkippingChildr
en(*m_currentElement, &m_rootNode)); | 78 m_currentElement = nextInternal(ElementTraversal::nextSkippingChildr
en(*m_currentElement, &m_rootNode)); |
| 79 else | 79 else |
| 80 m_currentElement = nextInternal(ElementTraversal::next(*m_currentEle
ment, &m_rootNode)); | 80 m_currentElement = nextInternal(ElementTraversal::next(*m_currentEle
ment, &m_rootNode)); |
| 81 return current; | 81 return current; |
| 82 } | 82 } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 Element* nextInternal(Element* element) | 85 Element* nextInternal(Element* element) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (selector->relation() == CSSSelector::DirectAdjacent || selector->rel
ation() == CSSSelector::IndirectAdjacent) | 254 if (selector->relation() == CSSSelector::DirectAdjacent || selector->rel
ation() == CSSSelector::IndirectAdjacent) |
| 255 startFromParent = true; | 255 startFromParent = true; |
| 256 else | 256 else |
| 257 startFromParent = false; | 257 startFromParent = false; |
| 258 } | 258 } |
| 259 | 259 |
| 260 executeForTraverseRoot<SelectorQueryTrait>(m_selectors[0], &rootNode, DoesNo
tMatchTraverseRoots, rootNode, output); | 260 executeForTraverseRoot<SelectorQueryTrait>(m_selectors[0], &rootNode, DoesNo
tMatchTraverseRoots, rootNode, output); |
| 261 } | 261 } |
| 262 | 262 |
| 263 template <typename SelectorQueryTrait> | 263 template <typename SelectorQueryTrait> |
| 264 void SelectorDataList::executeForTraverseRoot(const SelectorData& selector, Node
* traverseRoot, MatchTraverseRootState matchTraverseRoot, ContainerNode& rootNod
e, typename SelectorQueryTrait::OutputType& output) const | 264 void SelectorDataList::executeForTraverseRoot(const SelectorData& selector, Cont
ainerNode* traverseRoot, MatchTraverseRootState matchTraverseRoot, ContainerNode
& rootNode, typename SelectorQueryTrait::OutputType& output) const |
| 265 { | 265 { |
| 266 if (!traverseRoot) | 266 if (!traverseRoot) |
| 267 return; | 267 return; |
| 268 | 268 |
| 269 if (matchTraverseRoot) { | 269 if (matchTraverseRoot) { |
| 270 if (selectorMatches(selector, toElement(*traverseRoot), rootNode)) | 270 if (selectorMatches(selector, toElement(*traverseRoot), rootNode)) |
| 271 SelectorQueryTrait::appendElement(output, toElement(*traverseRoot)); | 271 SelectorQueryTrait::appendElement(output, toElement(*traverseRoot)); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 | 274 |
| 275 for (Element* element = ElementTraversal::firstWithin(*traverseRoot); elemen
t; element = ElementTraversal::next(*element, traverseRoot)) { | 275 for (Element* element = ElementTraversal::firstWithin(*traverseRoot); elemen
t; element = ElementTraversal::next(*element, traverseRoot)) { |
| 276 if (selectorMatches(selector, *element, rootNode)) { | 276 if (selectorMatches(selector, *element, rootNode)) { |
| 277 SelectorQueryTrait::appendElement(output, *element); | 277 SelectorQueryTrait::appendElement(output, *element); |
| 278 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 278 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 template <typename SelectorQueryTrait, typename SimpleNodeListType> | 284 template <typename SelectorQueryTrait, typename SimpleElementListType> |
| 285 void SelectorDataList::executeForTraverseRoots(const SelectorData& selector, Sim
pleNodeListType& traverseRoots, MatchTraverseRootState matchTraverseRoots, Conta
inerNode& rootNode, typename SelectorQueryTrait::OutputType& output) const | 285 void SelectorDataList::executeForTraverseRoots(const SelectorData& selector, Sim
pleElementListType& traverseRoots, MatchTraverseRootState matchTraverseRoots, Co
ntainerNode& rootNode, typename SelectorQueryTrait::OutputType& output) const |
| 286 { | 286 { |
| 287 if (traverseRoots.isEmpty()) | 287 if (traverseRoots.isEmpty()) |
| 288 return; | 288 return; |
| 289 | 289 |
| 290 if (matchTraverseRoots) { | 290 if (matchTraverseRoots) { |
| 291 while (!traverseRoots.isEmpty()) { | 291 while (!traverseRoots.isEmpty()) { |
| 292 Node& node = *traverseRoots.next(); | 292 Element& element = *traverseRoots.next(); |
| 293 Element& element = toElement(node); | |
| 294 if (selectorMatches(selector, element, rootNode)) { | 293 if (selectorMatches(selector, element, rootNode)) { |
| 295 SelectorQueryTrait::appendElement(output, element); | 294 SelectorQueryTrait::appendElement(output, element); |
| 296 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 295 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
| 297 return; | 296 return; |
| 298 } | 297 } |
| 299 } | 298 } |
| 300 return; | 299 return; |
| 301 } | 300 } |
| 302 | 301 |
| 303 while (!traverseRoots.isEmpty()) { | 302 while (!traverseRoots.isEmpty()) { |
| 304 Node* traverseRoot = traverseRoots.next(); | 303 Element& traverseRoot = *traverseRoots.next(); |
| 305 ASSERT(traverseRoot); | 304 for (Element* element = ElementTraversal::firstWithin(traverseRoot); ele
ment; element = ElementTraversal::next(*element, &traverseRoot)) { |
| 306 for (Element* element = ElementTraversal::firstWithin(*traverseRoot); el
ement; element = ElementTraversal::next(*element, traverseRoot)) { | |
| 307 if (selectorMatches(selector, *element, rootNode)) { | 305 if (selectorMatches(selector, *element, rootNode)) { |
| 308 SelectorQueryTrait::appendElement(output, *element); | 306 SelectorQueryTrait::appendElement(output, *element); |
| 309 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 307 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
| 310 return; | 308 return; |
| 311 } | 309 } |
| 312 } | 310 } |
| 313 } | 311 } |
| 314 } | 312 } |
| 315 | 313 |
| 316 template <typename SelectorQueryTrait> | 314 template <typename SelectorQueryTrait> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 m_entries.add(selectors, selectorQuery.release()); | 444 m_entries.add(selectors, selectorQuery.release()); |
| 447 return rawSelectorQuery; | 445 return rawSelectorQuery; |
| 448 } | 446 } |
| 449 | 447 |
| 450 void SelectorQueryCache::invalidate() | 448 void SelectorQueryCache::invalidate() |
| 451 { | 449 { |
| 452 m_entries.clear(); | 450 m_entries.clear(); |
| 453 } | 451 } |
| 454 | 452 |
| 455 } | 453 } |
| OLD | NEW |