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

Side by Side Diff: Source/core/dom/SelectorQuery.cpp

Issue 465483002: Merge NamedNodesCollection and StaticNodeList classes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 4 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
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | Source/core/dom/StaticNodeList.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 typedef Element* OutputType; 44 typedef Element* OutputType;
45 static const bool shouldOnlyMatchFirstElement = true; 45 static const bool shouldOnlyMatchFirstElement = true;
46 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element ) 46 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element )
47 { 47 {
48 ASSERT(!output); 48 ASSERT(!output);
49 output = &element; 49 output = &element;
50 } 50 }
51 }; 51 };
52 52
53 struct AllElementsSelectorQueryTrait { 53 struct AllElementsSelectorQueryTrait {
54 typedef WillBeHeapVector<RefPtrWillBeMember<Node> > OutputType; 54 typedef WillBeHeapVector<RefPtrWillBeMember<Element> > OutputType;
55 static const bool shouldOnlyMatchFirstElement = false; 55 static const bool shouldOnlyMatchFirstElement = false;
56 ALWAYS_INLINE static void appendElement(OutputType& output, Node& element) 56 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element )
57 { 57 {
58 output.append(&element); 58 output.append(&element);
59 } 59 }
60 }; 60 };
61 61
62 enum ClassElementListBehavior { AllElements, OnlyRoots }; 62 enum ClassElementListBehavior { AllElements, OnlyRoots };
63 63
64 template <ClassElementListBehavior onlyRoots> 64 template <ClassElementListBehavior onlyRoots>
65 class ClassElementList { 65 class ClassElementList {
66 STACK_ALLOCATED(); 66 STACK_ALLOCATED();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 { 129 {
130 unsigned selectorCount = m_selectors.size(); 130 unsigned selectorCount = m_selectors.size();
131 for (unsigned i = 0; i < selectorCount; ++i) { 131 for (unsigned i = 0; i < selectorCount; ++i) {
132 if (selectorMatches(*m_selectors[i], targetElement, targetElement)) 132 if (selectorMatches(*m_selectors[i], targetElement, targetElement))
133 return true; 133 return true;
134 } 134 }
135 135
136 return false; 136 return false;
137 } 137 }
138 138
139 PassRefPtrWillBeRawPtr<StaticNodeList> SelectorDataList::queryAll(ContainerNode& rootNode) const 139 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const
140 { 140 {
141 WillBeHeapVector<RefPtrWillBeMember<Node> > result; 141 WillBeHeapVector<RefPtrWillBeMember<Element> > result;
142 execute<AllElementsSelectorQueryTrait>(rootNode, result); 142 execute<AllElementsSelectorQueryTrait>(rootNode, result);
143 return StaticNodeList::adopt(result); 143 return StaticElementList::adopt(result);
144 } 144 }
145 145
146 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root Node) const 146 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root Node) const
147 { 147 {
148 Element* matchedElement = 0; 148 Element* matchedElement = 0;
149 execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement); 149 execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement);
150 return matchedElement; 150 return matchedElement;
151 } 151 }
152 152
153 template <typename SelectorQueryTrait> 153 template <typename SelectorQueryTrait>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 { 475 {
476 m_selectorList.adopt(selectorList); 476 m_selectorList.adopt(selectorList);
477 m_selectors.initialize(m_selectorList); 477 m_selectors.initialize(m_selectorList);
478 } 478 }
479 479
480 bool SelectorQuery::matches(Element& element) const 480 bool SelectorQuery::matches(Element& element) const
481 { 481 {
482 return m_selectors.matches(element); 482 return m_selectors.matches(element);
483 } 483 }
484 484
485 PassRefPtrWillBeRawPtr<StaticNodeList> SelectorQuery::queryAll(ContainerNode& ro otNode) const 485 PassRefPtrWillBeRawPtr<StaticElementList> SelectorQuery::queryAll(ContainerNode& rootNode) const
486 { 486 {
487 return m_selectors.queryAll(rootNode); 487 return m_selectors.queryAll(rootNode);
488 } 488 }
489 489
490 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod e) const 490 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod e) const
491 { 491 {
492 return m_selectors.queryFirst(rootNode); 492 return m_selectors.queryFirst(rootNode);
493 } 493 }
494 494
495 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu ment& document, ExceptionState& exceptionState) 495 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu ment& document, ExceptionState& exceptionState)
(...skipping 23 matching lines...) Expand all
519 519
520 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa lue->value.get(); 520 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa lue->value.get();
521 } 521 }
522 522
523 void SelectorQueryCache::invalidate() 523 void SelectorQueryCache::invalidate()
524 { 524 {
525 m_entries.clear(); 525 m_entries.clear();
526 } 526 }
527 527
528 } 528 }
OLDNEW
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | Source/core/dom/StaticNodeList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698