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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { | 169 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { |
170 if (element.hasClass() && element.classNames().contains(className)) { | 170 if (element.hasClass() && element.classNames().contains(className)) { |
171 SelectorQueryTrait::appendElement(output, element); | 171 SelectorQueryTrait::appendElement(output, element); |
172 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 172 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
173 return; | 173 return; |
174 } | 174 } |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 template <typename SelectorQueryTrait> | 178 template <typename SelectorQueryTrait> |
179 void SelectorDataList::collectElementsByTagName(ContainerNode& rootNode, const Q
ualifiedName& tagName, typename SelectorQueryTrait::OutputType& output) const | 179 void SelectorDataList::collectElementsByTagName(ContainerNode& rootNode, const C
SSSelector& tagSelector, typename SelectorQueryTrait::OutputType& output) const |
180 { | 180 { |
181 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { | 181 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { |
182 if (SelectorChecker::tagMatches(element, tagName)) { | 182 if (SelectorChecker::tagMatches(element, tagSelector)) { |
183 SelectorQueryTrait::appendElement(output, element); | 183 SelectorQueryTrait::appendElement(output, element); |
184 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 184 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
185 return; | 185 return; |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 inline bool SelectorDataList::canUseFastQuery(const ContainerNode& rootNode) con
st | 190 inline bool SelectorDataList::canUseFastQuery(const ContainerNode& rootNode) con
st |
191 { | 191 { |
192 return m_selectors.size() == 1 && !m_crossesTreeBoundary && rootNode.inDocum
ent() && !rootNode.document().inQuirksMode(); | 192 return m_selectors.size() == 1 && !m_crossesTreeBoundary && rootNode.inDocum
ent() && !rootNode.document().inQuirksMode(); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 return; | 461 return; |
462 } | 462 } |
463 | 463 |
464 if (!firstSelector.tagHistory()) { | 464 if (!firstSelector.tagHistory()) { |
465 // Fast path for querySelector*('.foo'), and querySelector*('div'). | 465 // Fast path for querySelector*('.foo'), and querySelector*('div'). |
466 switch (firstSelector.match()) { | 466 switch (firstSelector.match()) { |
467 case CSSSelector::Class: | 467 case CSSSelector::Class: |
468 collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelect
or.value(), output); | 468 collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelect
or.value(), output); |
469 return; | 469 return; |
470 case CSSSelector::Tag: | 470 case CSSSelector::Tag: |
471 collectElementsByTagName<SelectorQueryTrait>(rootNode, firstSelector
.tagQName(), output); | 471 collectElementsByTagName<SelectorQueryTrait>(rootNode, firstSelector
, output); |
472 return; | 472 return; |
473 default: | 473 default: |
474 break; // If we need another fast path, add here. | 474 break; // If we need another fast path, add here. |
475 } | 475 } |
476 } | 476 } |
477 | 477 |
478 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); | 478 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); |
479 } | 479 } |
480 | 480 |
481 PassOwnPtr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList& selectorList) | 481 PassOwnPtr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList& selectorList) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 535 |
536 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); | 536 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); |
537 } | 537 } |
538 | 538 |
539 void SelectorQueryCache::invalidate() | 539 void SelectorQueryCache::invalidate() |
540 { | 540 { |
541 m_entries.clear(); | 541 m_entries.clear(); |
542 } | 542 } |
543 | 543 |
544 } | 544 } |
OLD | NEW |