Chromium Code Reviews| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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), ++index) { |
| 113 if (selector->matchesPseudoElement()) | |
| 114 continue; | |
| 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); |
| 116 } | 118 } |
| 117 } | 119 } |
| 118 | 120 |
| 119 inline bool SelectorDataList::selectorMatches(const CSSSelector& selector, Eleme nt& element, const ContainerNode& rootNode) const | 121 inline bool SelectorDataList::selectorMatches(const CSSSelector& selector, Eleme nt& element, const ContainerNode& rootNode) const |
| 120 { | 122 { |
| 121 SelectorChecker selectorChecker(SelectorChecker::QueryingRules); | 123 SelectorChecker selectorChecker(SelectorChecker::QueryingRules); |
| 122 SelectorChecker::SelectorCheckingContext selectorCheckingContext(&element, S electorChecker::VisitedMatchDisabled); | 124 SelectorChecker::SelectorCheckingContext selectorCheckingContext(&element, S electorChecker::VisitedMatchDisabled); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 134 for (unsigned i = 0; i < selectorCount; ++i) { | 136 for (unsigned i = 0; i < selectorCount; ++i) { |
| 135 if (selectorMatches(*m_selectors[i], targetElement, targetElement)) | 137 if (selectorMatches(*m_selectors[i], targetElement, targetElement)) |
| 136 return true; | 138 return true; |
| 137 } | 139 } |
| 138 | 140 |
| 139 return false; | 141 return false; |
| 140 } | 142 } |
| 141 | 143 |
| 142 Element* SelectorDataList::closest(Element& targetElement) const | 144 Element* SelectorDataList::closest(Element& targetElement) const |
| 143 { | 145 { |
| 146 unsigned selectorCount = m_selectors.size(); | |
| 147 if (!selectorCount) | |
| 148 return nullptr; | |
| 149 | |
| 144 if (m_needsUpdatedDistribution) | 150 if (m_needsUpdatedDistribution) |
| 145 targetElement.updateDistribution(); | 151 targetElement.updateDistribution(); |
| 146 | 152 |
| 147 unsigned selectorCount = m_selectors.size(); | |
| 148 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) { | 153 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) { |
| 149 for (unsigned i = 0; i < selectorCount; ++i) { | 154 for (unsigned i = 0; i < selectorCount; ++i) { |
| 150 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) ) | 155 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) ) |
| 151 return currentElement; | 156 return currentElement; |
| 152 } | 157 } |
| 153 } | 158 } |
| 154 return nullptr; | 159 return nullptr; |
| 155 } | 160 } |
| 156 | 161 |
| 157 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const | 162 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 return selector; | 449 return selector; |
| 445 if (selector->relation() != CSSSelector::SubSelector) | 450 if (selector->relation() != CSSSelector::SubSelector) |
| 446 break; | 451 break; |
| 447 } | 452 } |
| 448 return nullptr; | 453 return nullptr; |
| 449 } | 454 } |
| 450 | 455 |
| 451 template <typename SelectorQueryTrait> | 456 template <typename SelectorQueryTrait> |
| 452 void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr ait::OutputType& output) const | 457 void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr ait::OutputType& output) const |
| 453 { | 458 { |
| 459 if (!m_selectors.size()) | |
|
esprehn
2016/01/29 12:29:56
isEmpty() ?
rune
2016/01/29 12:43:13
Done.
| |
| 460 return; | |
| 461 | |
| 454 if (!canUseFastQuery(rootNode)) { | 462 if (!canUseFastQuery(rootNode)) { |
| 455 if (m_needsUpdatedDistribution) | 463 if (m_needsUpdatedDistribution) |
| 456 rootNode.updateDistribution(); | 464 rootNode.updateDistribution(); |
| 457 if (m_usesDeepCombinatorOrShadowPseudo) { | 465 if (m_usesDeepCombinatorOrShadowPseudo) { |
| 458 executeSlowTraversingShadowTree<SelectorQueryTrait>(rootNode, output ); | 466 executeSlowTraversingShadowTree<SelectorQueryTrait>(rootNode, output ); |
| 459 } else { | 467 } else { |
| 460 executeSlow<SelectorQueryTrait>(rootNode, output); | 468 executeSlow<SelectorQueryTrait>(rootNode, output); |
| 461 } | 469 } |
| 462 return; | 470 return; |
| 463 } | 471 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 | 568 |
| 561 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get(); | 569 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get(); |
| 562 } | 570 } |
| 563 | 571 |
| 564 void SelectorQueryCache::invalidate() | 572 void SelectorQueryCache::invalidate() |
| 565 { | 573 { |
| 566 m_entries.clear(); | 574 m_entries.clear(); |
| 567 } | 575 } |
| 568 | 576 |
| 569 } // namespace blink | 577 } // namespace blink |
| OLD | NEW |