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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 typedef Element* OutputType; 43 typedef Element* OutputType;
44 static const bool shouldOnlyMatchFirstElement = true; 44 static const bool shouldOnlyMatchFirstElement = true;
45 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element ) 45 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element )
46 { 46 {
47 ASSERT(!output); 47 ASSERT(!output);
48 output = &element; 48 output = &element;
49 } 49 }
50 }; 50 };
51 51
52 struct AllElementsSelectorQueryTrait { 52 struct AllElementsSelectorQueryTrait {
53 typedef WillBeHeapVector<RefPtrWillBeMember<Element>> OutputType; 53 typedef HeapVector<Member<Element>> OutputType;
54 static const bool shouldOnlyMatchFirstElement = false; 54 static const bool shouldOnlyMatchFirstElement = false;
55 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element ) 55 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element )
56 { 56 {
57 output.append(&element); 57 output.append(&element);
58 } 58 }
59 }; 59 };
60 60
61 enum ClassElementListBehavior { AllElements, OnlyRoots }; 61 enum ClassElementListBehavior { AllElements, OnlyRoots };
62 62
63 template <ClassElementListBehavior onlyRoots> 63 template <ClassElementListBehavior onlyRoots>
(...skipping 22 matching lines...) Expand all
86 Element* nextInternal(Element* element) 86 Element* nextInternal(Element* element)
87 { 87 {
88 for (; element; element = ElementTraversal::next(*element, m_rootNode)) { 88 for (; element; element = ElementTraversal::next(*element, m_rootNode)) {
89 if (element->hasClass() && element->classNames().contains(m_classNam e)) 89 if (element->hasClass() && element->classNames().contains(m_classNam e))
90 return element; 90 return element;
91 } 91 }
92 return nullptr; 92 return nullptr;
93 } 93 }
94 94
95 const AtomicString& m_className; 95 const AtomicString& m_className;
96 RawPtrWillBeMember<ContainerNode> m_rootNode; 96 Member<ContainerNode> m_rootNode;
97 RawPtrWillBeMember<Element> m_currentElement; 97 Member<Element> m_currentElement;
98 }; 98 };
99 99
100 void SelectorDataList::initialize(const CSSSelectorList& selectorList) 100 void SelectorDataList::initialize(const CSSSelectorList& selectorList)
101 { 101 {
102 ASSERT(m_selectors.isEmpty()); 102 ASSERT(m_selectors.isEmpty());
103 103
104 unsigned selectorCount = 0; 104 unsigned selectorCount = 0;
105 for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector)) 105 for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector))
106 selectorCount++; 106 selectorCount++;
107 107
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) { 155 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) {
156 for (unsigned i = 0; i < selectorCount; ++i) { 156 for (unsigned i = 0; i < selectorCount; ++i) {
157 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) ) 157 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) )
158 return currentElement; 158 return currentElement;
159 } 159 }
160 } 160 }
161 return nullptr; 161 return nullptr;
162 } 162 }
163 163
164 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const 164 RawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNode& rootNode) co nst
165 { 165 {
166 WillBeHeapVector<RefPtrWillBeMember<Element>> result; 166 HeapVector<Member<Element>> result;
167 execute<AllElementsSelectorQueryTrait>(rootNode, result); 167 execute<AllElementsSelectorQueryTrait>(rootNode, result);
168 return StaticElementList::adopt(result); 168 return StaticElementList::adopt(result);
169 } 169 }
170 170
171 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root Node) const 171 RawPtr<Element> SelectorDataList::queryFirst(ContainerNode& rootNode) const
172 { 172 {
173 Element* matchedElement = nullptr; 173 Element* matchedElement = nullptr;
174 execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement); 174 execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement);
175 return matchedElement; 175 return matchedElement;
176 } 176 }
177 177
178 template <typename SelectorQueryTrait> 178 template <typename SelectorQueryTrait>
179 void SelectorDataList::collectElementsByClassName(ContainerNode& rootNode, const AtomicString& className, typename SelectorQueryTrait::OutputType& output) cons t 179 void SelectorDataList::collectElementsByClassName(ContainerNode& rootNode, const AtomicString& className, typename SelectorQueryTrait::OutputType& output) cons t
180 { 180 {
181 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { 181 for (Element& element : ElementTraversal::descendantsOf(rootNode)) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 ASSERT(m_selectors.size() == 1); 475 ASSERT(m_selectors.size() == 1);
476 476
477 const CSSSelector& selector = *m_selectors[0]; 477 const CSSSelector& selector = *m_selectors[0];
478 const CSSSelector& firstSelector = selector; 478 const CSSSelector& firstSelector = selector;
479 479
480 // Fast path for querySelector*('#id'), querySelector*('tag#id'). 480 // Fast path for querySelector*('#id'), querySelector*('tag#id').
481 if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) { 481 if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) {
482 const AtomicString& idToMatch = idSelector->value(); 482 const AtomicString& idToMatch = idSelector->value();
483 if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) { 483 if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) {
484 const WillBeHeapVector<RawPtrWillBeMember<Element>>& elements = root Node.treeScope().getAllElementsById(idToMatch); 484 const HeapVector<Member<Element>>& elements = rootNode.treeScope().g etAllElementsById(idToMatch);
485 size_t count = elements.size(); 485 size_t count = elements.size();
486 for (size_t i = 0; i < count; ++i) { 486 for (size_t i = 0; i < count; ++i) {
487 Element& element = *elements[i]; 487 Element& element = *elements[i];
488 if (!(isTreeScopeRoot(rootNode) || element.isDescendantOf(&rootN ode))) 488 if (!(isTreeScopeRoot(rootNode) || element.isDescendantOf(&rootN ode)))
489 continue; 489 continue;
490 if (selectorMatches(selector, element, rootNode)) { 490 if (selectorMatches(selector, element, rootNode)) {
491 SelectorQueryTrait::appendElement(output, element); 491 SelectorQueryTrait::appendElement(output, element);
492 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) 492 if (SelectorQueryTrait::shouldOnlyMatchFirstElement)
493 return; 493 return;
494 } 494 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 bool SelectorQuery::matches(Element& element) const 534 bool SelectorQuery::matches(Element& element) const
535 { 535 {
536 return m_selectors.matches(element); 536 return m_selectors.matches(element);
537 } 537 }
538 538
539 Element* SelectorQuery::closest(Element& element) const 539 Element* SelectorQuery::closest(Element& element) const
540 { 540 {
541 return m_selectors.closest(element); 541 return m_selectors.closest(element);
542 } 542 }
543 543
544 PassRefPtrWillBeRawPtr<StaticElementList> SelectorQuery::queryAll(ContainerNode& rootNode) const 544 RawPtr<StaticElementList> SelectorQuery::queryAll(ContainerNode& rootNode) const
545 { 545 {
546 return m_selectors.queryAll(rootNode); 546 return m_selectors.queryAll(rootNode);
547 } 547 }
548 548
549 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod e) const 549 RawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNode) const
550 { 550 {
551 return m_selectors.queryFirst(rootNode); 551 return m_selectors.queryFirst(rootNode);
552 } 552 }
553 553
554 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu ment& document, ExceptionState& exceptionState) 554 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu ment& document, ExceptionState& exceptionState)
555 { 555 {
556 HashMap<AtomicString, OwnPtr<SelectorQuery>>::iterator it = m_entries.find(s electors); 556 HashMap<AtomicString, OwnPtr<SelectorQuery>>::iterator it = m_entries.find(s electors);
557 if (it != m_entries.end()) 557 if (it != m_entries.end())
558 return it->value.get(); 558 return it->value.get();
559 559
(...skipping 10 matching lines...) Expand all
570 570
571 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get(); 571 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get();
572 } 572 }
573 573
574 void SelectorQueryCache::invalidate() 574 void SelectorQueryCache::invalidate()
575 { 575 {
576 m_entries.clear(); 576 m_entries.clear();
577 } 577 }
578 578
579 } // namespace blink 579 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.h ('k') | third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698