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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // for selectors in html documents. Compare the upper case converted names | 198 // for selectors in html documents. Compare the upper case converted names |
199 // instead to allow matching SVG elements like foreignObject. | 199 // instead to allow matching SVG elements like foreignObject. |
200 if (!element.isHTMLElement() && element.document().isHTMLDocument()) | 200 if (!element.isHTMLElement() && element.document().isHTMLDocument()) |
201 return element.tagQName().localNameUpper() == tagName.localNameUpper(); | 201 return element.tagQName().localNameUpper() == tagName.localNameUpper(); |
202 return false; | 202 return false; |
203 } | 203 } |
204 | 204 |
205 template <typename SelectorQueryTrait> | 205 template <typename SelectorQueryTrait> |
206 void SelectorDataList::collectElementsByTagName(ContainerNode& rootNode, const Q
ualifiedName& tagName, typename SelectorQueryTrait::OutputType& output) const | 206 void SelectorDataList::collectElementsByTagName(ContainerNode& rootNode, const Q
ualifiedName& tagName, typename SelectorQueryTrait::OutputType& output) const |
207 { | 207 { |
| 208 DCHECK_EQ(tagName.namespaceURI(), starAtom); |
208 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { | 209 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { |
209 // querySelector*() doesn't allow namespaces and throws before it gets | |
210 // here so we can ignore them. | |
211 DCHECK_EQ(tagName.namespaceURI(), starAtom); | |
212 if (matchesTagName(tagName, element)) { | 210 if (matchesTagName(tagName, element)) { |
213 SelectorQueryTrait::appendElement(output, element); | 211 SelectorQueryTrait::appendElement(output, element); |
214 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 212 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
215 return; | 213 return; |
216 } | 214 } |
217 } | 215 } |
218 } | 216 } |
219 | 217 |
220 inline bool SelectorDataList::canUseFastQuery(const ContainerNode& rootNode) con
st | 218 inline bool SelectorDataList::canUseFastQuery(const ContainerNode& rootNode) con
st |
221 { | 219 { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 return; | 501 return; |
504 } | 502 } |
505 | 503 |
506 if (!firstSelector.tagHistory()) { | 504 if (!firstSelector.tagHistory()) { |
507 // Fast path for querySelector*('.foo'), and querySelector*('div'). | 505 // Fast path for querySelector*('.foo'), and querySelector*('div'). |
508 switch (firstSelector.match()) { | 506 switch (firstSelector.match()) { |
509 case CSSSelector::Class: | 507 case CSSSelector::Class: |
510 collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelect
or.value(), output); | 508 collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelect
or.value(), output); |
511 return; | 509 return; |
512 case CSSSelector::Tag: | 510 case CSSSelector::Tag: |
513 collectElementsByTagName<SelectorQueryTrait>(rootNode, firstSelector
.tagQName(), output); | 511 if (firstSelector.tagQName().namespaceURI() == starAtom) { |
514 return; | 512 collectElementsByTagName<SelectorQueryTrait>(rootNode, firstSele
ctor.tagQName(), output); |
| 513 return; |
| 514 } |
| 515 // querySelector*() doesn't allow namespace prefix resolution and |
| 516 // throws before we get here, but we still may have selectors for |
| 517 // elements without a namespace. |
| 518 DCHECK_EQ(firstSelector.tagQName().namespaceURI(), nullAtom); |
| 519 break; |
515 default: | 520 default: |
516 break; // If we need another fast path, add here. | 521 break; // If we need another fast path, add here. |
517 } | 522 } |
518 } | 523 } |
519 | 524 |
520 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); | 525 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); |
521 } | 526 } |
522 | 527 |
523 PassOwnPtr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList selectorList) | 528 PassOwnPtr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList selectorList) |
524 { | 529 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 | 575 |
571 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(); |
572 } | 577 } |
573 | 578 |
574 void SelectorQueryCache::invalidate() | 579 void SelectorQueryCache::invalidate() |
575 { | 580 { |
576 m_entries.clear(); | 581 m_entries.clear(); |
577 } | 582 } |
578 | 583 |
579 } // namespace blink | 584 } // namespace blink |
OLD | NEW |