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

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

Issue 1885453002: Rename Node::treeScope() to Node::treeScopeOrDocument() Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 { 255 {
256 // We need to return the matches in document order. To use id lookup while t here is possiblity of multiple matches 256 // We need to return the matches in document order. To use id lookup while t here is possiblity of multiple matches
257 // we would need to sort the results. For now, just traverse the document in that case. 257 // we would need to sort the results. For now, just traverse the document in that case.
258 DCHECK_EQ(m_selectors.size(), 1u); 258 DCHECK_EQ(m_selectors.size(), 1u);
259 259
260 bool isRightmostSelector = true; 260 bool isRightmostSelector = true;
261 bool startFromParent = false; 261 bool startFromParent = false;
262 262
263 for (const CSSSelector* selector = m_selectors[0]; selector; selector = sele ctor->tagHistory()) { 263 for (const CSSSelector* selector = m_selectors[0]; selector; selector = sele ctor->tagHistory()) {
264 if (selector->match() == CSSSelector::Id && !rootNode.document().contain sMultipleElementsWithId(selector->value())) { 264 if (selector->match() == CSSSelector::Id && !rootNode.document().contain sMultipleElementsWithId(selector->value())) {
265 Element* element = rootNode.treeScope().getElementById(selector->val ue()); 265 Element* element = rootNode.treeScopeOrDocument().getElementById(sel ector->value());
266 ContainerNode* adjustedNode = &rootNode; 266 ContainerNode* adjustedNode = &rootNode;
267 if (element && (isTreeScopeRoot(rootNode) || element->isDescendantOf (&rootNode))) 267 if (element && (isTreeScopeRoot(rootNode) || element->isDescendantOf (&rootNode)))
268 adjustedNode = element; 268 adjustedNode = element;
269 else if (!element || isRightmostSelector) 269 else if (!element || isRightmostSelector)
270 adjustedNode = nullptr; 270 adjustedNode = nullptr;
271 if (isRightmostSelector) { 271 if (isRightmostSelector) {
272 executeForTraverseRoot<SelectorQueryTrait>(*m_selectors[0], adju stedNode, MatchesTraverseRoots, rootNode, output); 272 executeForTraverseRoot<SelectorQueryTrait>(*m_selectors[0], adju stedNode, MatchesTraverseRoots, rootNode, output);
273 return; 273 return;
274 } 274 }
275 275
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 473 }
474 474
475 DCHECK_EQ(m_selectors.size(), 1u); 475 DCHECK_EQ(m_selectors.size(), 1u);
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.treeScopeOrDocument().containsMultipleElementsWithId(idToMa tch)) {
484 const HeapVector<Member<Element>>& elements = rootNode.treeScope().g etAllElementsById(idToMatch); 484 const HeapVector<Member<Element>>& elements = rootNode.treeScopeOrDo cument().getAllElementsById(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 }
495 } 495 }
496 return; 496 return;
497 } 497 }
498 Element* element = rootNode.treeScope().getElementById(idToMatch); 498 Element* element = rootNode.treeScopeOrDocument().getElementById(idToMat ch);
499 if (!element || !(isTreeScopeRoot(rootNode) || element->isDescendantOf(& rootNode))) 499 if (!element || !(isTreeScopeRoot(rootNode) || element->isDescendantOf(& rootNode)))
500 return; 500 return;
501 if (selectorMatches(selector, *element, rootNode)) 501 if (selectorMatches(selector, *element, rootNode))
502 SelectorQueryTrait::appendElement(output, *element); 502 SelectorQueryTrait::appendElement(output, *element);
503 return; 503 return;
504 } 504 }
505 505
506 if (!firstSelector.tagHistory()) { 506 if (!firstSelector.tagHistory()) {
507 // Fast path for querySelector*('.foo'), and querySelector*('div'). 507 // Fast path for querySelector*('.foo'), and querySelector*('div').
508 switch (firstSelector.match()) { 508 switch (firstSelector.match()) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/PseudoElement.cpp ('k') | third_party/WebKit/Source/core/dom/StyleElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698