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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 bool startFromParent = false; | 243 bool startFromParent = false; |
244 | 244 |
245 for (const CSSSelector* selector = m_selectors[0]; selector; | 245 for (const CSSSelector* selector = m_selectors[0]; selector; |
246 selector = selector->tagHistory()) { | 246 selector = selector->tagHistory()) { |
247 if (selector->match() == CSSSelector::Id && rootNode.isInTreeScope() && | 247 if (selector->match() == CSSSelector::Id && rootNode.isInTreeScope() && |
248 !rootNode.containingTreeScope().containsMultipleElementsWithId( | 248 !rootNode.containingTreeScope().containsMultipleElementsWithId( |
249 selector->value())) { | 249 selector->value())) { |
250 Element* element = | 250 Element* element = |
251 rootNode.containingTreeScope().getElementById(selector->value()); | 251 rootNode.containingTreeScope().getElementById(selector->value()); |
252 ContainerNode* adjustedNode = &rootNode; | 252 ContainerNode* adjustedNode = &rootNode; |
253 if (element && | 253 if (element && element->isDescendantOf(&rootNode)) |
254 (isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode))) | |
255 adjustedNode = element; | 254 adjustedNode = element; |
256 else if (!element || isRightmostSelector) | 255 else if (!element || isRightmostSelector) |
257 adjustedNode = nullptr; | 256 adjustedNode = nullptr; |
258 if (isRightmostSelector) { | 257 if (isRightmostSelector) { |
259 if (!adjustedNode) | 258 if (!adjustedNode) |
260 return; | 259 return; |
261 element = toElement(adjustedNode); | 260 element = toElement(adjustedNode); |
262 if (selectorMatches(*m_selectors[0], *element, rootNode)) | 261 if (selectorMatches(*m_selectors[0], *element, rootNode)) |
263 SelectorQueryTrait::appendElement(output, *element); | 262 SelectorQueryTrait::appendElement(output, *element); |
264 return; | 263 return; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 const CSSSelector& firstSelector = selector; | 501 const CSSSelector& firstSelector = selector; |
503 | 502 |
504 // Fast path for querySelector*('#id'), querySelector*('tag#id'), | 503 // Fast path for querySelector*('#id'), querySelector*('tag#id'), |
505 // querySelector*('tag[id=example]'). | 504 // querySelector*('tag[id=example]'). |
506 if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) { | 505 if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) { |
507 const AtomicString& idToMatch = idSelector->value(); | 506 const AtomicString& idToMatch = idSelector->value(); |
508 if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) { | 507 if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) { |
509 const HeapVector<Member<Element>>& elements = | 508 const HeapVector<Member<Element>>& elements = |
510 rootNode.treeScope().getAllElementsById(idToMatch); | 509 rootNode.treeScope().getAllElementsById(idToMatch); |
511 for (const auto& element : elements) { | 510 for (const auto& element : elements) { |
512 if (!(isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode))) | 511 if (!element->isDescendantOf(&rootNode)) |
513 continue; | 512 continue; |
514 if (selectorMatches(selector, *element, rootNode)) { | 513 if (selectorMatches(selector, *element, rootNode)) { |
515 SelectorQueryTrait::appendElement(output, *element); | 514 SelectorQueryTrait::appendElement(output, *element); |
516 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 515 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
517 return; | 516 return; |
518 } | 517 } |
519 } | 518 } |
520 return; | 519 return; |
521 } | 520 } |
522 Element* element = rootNode.treeScope().getElementById(idToMatch); | 521 Element* element = rootNode.treeScope().getElementById(idToMatch); |
523 if (!element || | 522 if (!element) |
524 !(isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode))) | 523 return; |
| 524 if (!element->isDescendantOf(&rootNode)) |
525 return; | 525 return; |
526 if (selectorMatches(selector, *element, rootNode)) | 526 if (selectorMatches(selector, *element, rootNode)) |
527 SelectorQueryTrait::appendElement(output, *element); | 527 SelectorQueryTrait::appendElement(output, *element); |
528 return; | 528 return; |
529 } | 529 } |
530 | 530 |
531 if (!firstSelector.tagHistory()) { | 531 if (!firstSelector.tagHistory()) { |
532 // Fast path for querySelector*('.foo'), and querySelector*('div'). | 532 // Fast path for querySelector*('.foo'), and querySelector*('div'). |
533 switch (firstSelector.match()) { | 533 switch (firstSelector.match()) { |
534 case CSSSelector::Class: | 534 case CSSSelector::Class: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 return m_entries | 607 return m_entries |
608 .insert(selectors, SelectorQuery::adopt(std::move(selectorList))) | 608 .insert(selectors, SelectorQuery::adopt(std::move(selectorList))) |
609 .storedValue->value.get(); | 609 .storedValue->value.get(); |
610 } | 610 } |
611 | 611 |
612 void SelectorQueryCache::invalidate() { | 612 void SelectorQueryCache::invalidate() { |
613 m_entries.clear(); | 613 m_entries.clear(); |
614 } | 614 } |
615 | 615 |
616 } // namespace blink | 616 } // namespace blink |
OLD | NEW |