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

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

Issue 1602833002: No pseudo elements in SelectorChecker::Mode QueryingRules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-pseudoelm-check-2-20160118
Patch Set: CORE_EXPORT for unit test in component build Created 4 years, 11 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
108 m_usesDeepCombinatorOrShadowPseudo = false; 108 m_usesDeepCombinatorOrShadowPseudo = false;
109 m_needsUpdatedDistribution = false; 109 m_needsUpdatedDistribution = false;
110 m_selectors.reserveInitialCapacity(selectorCount); 110 m_selectors.reserveInitialCapacity(selectorCount);
111 unsigned index = 0; 111 unsigned index = 0;
112 for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector), ++index) { 112 for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector)) {
113 if (selector->matchesPseudoElement())
114 continue;
esprehn 2016/01/29 02:42:17 why is it safe not to increment index here? That m
rune 2016/01/29 09:53:20 Ouch, that's not correct. Will fix.
rune 2016/01/29 10:58:43 Done.
113 m_selectors.uncheckedAppend(selector); 115 m_selectors.uncheckedAppend(selector);
114 m_usesDeepCombinatorOrShadowPseudo |= selectorList.selectorUsesDeepCombi natorOrShadowPseudo(index); 116 m_usesDeepCombinatorOrShadowPseudo |= selectorList.selectorUsesDeepCombi natorOrShadowPseudo(index);
115 m_needsUpdatedDistribution |= selectorList.selectorNeedsUpdatedDistribut ion(index); 117 m_needsUpdatedDistribution |= selectorList.selectorNeedsUpdatedDistribut ion(index);
118 ++index;
116 } 119 }
117 } 120 }
118 121
119 inline bool SelectorDataList::selectorMatches(const CSSSelector& selector, Eleme nt& element, const ContainerNode& rootNode) const 122 inline bool SelectorDataList::selectorMatches(const CSSSelector& selector, Eleme nt& element, const ContainerNode& rootNode) const
120 { 123 {
121 SelectorChecker selectorChecker(SelectorChecker::QueryingRules); 124 SelectorChecker selectorChecker(SelectorChecker::QueryingRules);
122 SelectorChecker::SelectorCheckingContext selectorCheckingContext(&element, S electorChecker::VisitedMatchDisabled); 125 SelectorChecker::SelectorCheckingContext selectorCheckingContext(&element, S electorChecker::VisitedMatchDisabled);
123 selectorCheckingContext.selector = &selector; 126 selectorCheckingContext.selector = &selector;
124 selectorCheckingContext.scope = &rootNode; 127 selectorCheckingContext.scope = &rootNode;
125 return selectorChecker.match(selectorCheckingContext); 128 return selectorChecker.match(selectorCheckingContext);
126 } 129 }
127 130
128 bool SelectorDataList::matches(Element& targetElement) const 131 bool SelectorDataList::matches(Element& targetElement) const
129 { 132 {
130 if (m_needsUpdatedDistribution) 133 if (m_needsUpdatedDistribution)
131 targetElement.updateDistribution(); 134 targetElement.updateDistribution();
132 135
133 unsigned selectorCount = m_selectors.size(); 136 unsigned selectorCount = m_selectors.size();
134 for (unsigned i = 0; i < selectorCount; ++i) { 137 for (unsigned i = 0; i < selectorCount; ++i) {
135 if (selectorMatches(*m_selectors[i], targetElement, targetElement)) 138 if (selectorMatches(*m_selectors[i], targetElement, targetElement))
136 return true; 139 return true;
137 } 140 }
138 141
139 return false; 142 return false;
140 } 143 }
141 144
142 Element* SelectorDataList::closest(Element& targetElement) const 145 Element* SelectorDataList::closest(Element& targetElement) const
143 { 146 {
147 unsigned selectorCount = m_selectors.size();
148 if (!selectorCount)
149 return nullptr;
150
144 if (m_needsUpdatedDistribution) 151 if (m_needsUpdatedDistribution)
145 targetElement.updateDistribution(); 152 targetElement.updateDistribution();
146 153
147 unsigned selectorCount = m_selectors.size();
148 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) { 154 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) {
149 for (unsigned i = 0; i < selectorCount; ++i) { 155 for (unsigned i = 0; i < selectorCount; ++i) {
150 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) ) 156 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) )
151 return currentElement; 157 return currentElement;
152 } 158 }
153 } 159 }
154 return nullptr; 160 return nullptr;
155 } 161 }
156 162
157 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const 163 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 return selector; 450 return selector;
445 if (selector->relation() != CSSSelector::SubSelector) 451 if (selector->relation() != CSSSelector::SubSelector)
446 break; 452 break;
447 } 453 }
448 return nullptr; 454 return nullptr;
449 } 455 }
450 456
451 template <typename SelectorQueryTrait> 457 template <typename SelectorQueryTrait>
452 void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr ait::OutputType& output) const 458 void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr ait::OutputType& output) const
453 { 459 {
460 if (!m_selectors.size())
461 return;
462
454 if (!canUseFastQuery(rootNode)) { 463 if (!canUseFastQuery(rootNode)) {
455 if (m_needsUpdatedDistribution) 464 if (m_needsUpdatedDistribution)
456 rootNode.updateDistribution(); 465 rootNode.updateDistribution();
457 if (m_usesDeepCombinatorOrShadowPseudo) { 466 if (m_usesDeepCombinatorOrShadowPseudo) {
458 executeSlowTraversingShadowTree<SelectorQueryTrait>(rootNode, output ); 467 executeSlowTraversingShadowTree<SelectorQueryTrait>(rootNode, output );
459 } else { 468 } else {
460 executeSlow<SelectorQueryTrait>(rootNode, output); 469 executeSlow<SelectorQueryTrait>(rootNode, output);
461 } 470 }
462 return; 471 return;
463 } 472 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 575
567 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get(); 576 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get();
568 } 577 }
569 578
570 void SelectorQueryCache::invalidate() 579 void SelectorQueryCache::invalidate()
571 { 580 {
572 m_entries.clear(); 581 m_entries.clear();
573 } 582 }
574 583
575 } 584 }
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