| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 for (const auto& selector : m_selectors) { | 125 for (const auto& selector : m_selectors) { |
| 126 if (selectorMatches(*selector, targetElement, targetElement)) | 126 if (selectorMatches(*selector, targetElement, targetElement)) |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 Element* SelectorQuery::closest(Element& targetElement) const { | 133 Element* SelectorQuery::closest(Element& targetElement) const { |
| 134 if (m_selectors.size() == 0) | 134 if (m_selectors.isEmpty()) |
| 135 return nullptr; | 135 return nullptr; |
| 136 if (m_needsUpdatedDistribution) | 136 if (m_needsUpdatedDistribution) |
| 137 targetElement.updateDistribution(); | 137 targetElement.updateDistribution(); |
| 138 | 138 |
| 139 for (Element* currentElement = &targetElement; currentElement; | 139 for (Element* currentElement = &targetElement; currentElement; |
| 140 currentElement = currentElement->parentElement()) { | 140 currentElement = currentElement->parentElement()) { |
| 141 for (const auto& selector : m_selectors) { | 141 for (const auto& selector : m_selectors) { |
| 142 if (selectorMatches(*selector, *currentElement, targetElement)) | 142 if (selectorMatches(*selector, *currentElement, targetElement)) |
| 143 return currentElement; | 143 return currentElement; |
| 144 } | 144 } |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 552 } |
| 553 | 553 |
| 554 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); | 554 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); |
| 555 } | 555 } |
| 556 | 556 |
| 557 std::unique_ptr<SelectorQuery> SelectorQuery::adopt( | 557 std::unique_ptr<SelectorQuery> SelectorQuery::adopt( |
| 558 CSSSelectorList selectorList) { | 558 CSSSelectorList selectorList) { |
| 559 return WTF::wrapUnique(new SelectorQuery(std::move(selectorList))); | 559 return WTF::wrapUnique(new SelectorQuery(std::move(selectorList))); |
| 560 } | 560 } |
| 561 | 561 |
| 562 SelectorQuery::SelectorQuery(CSSSelectorList selectorList) { | 562 SelectorQuery::SelectorQuery(CSSSelectorList selectorList) |
| 563 m_selectorList = std::move(selectorList); | 563 : m_selectorList(std::move(selectorList)), |
| 564 DCHECK(m_selectors.isEmpty()); | 564 m_usesDeepCombinatorOrShadowPseudo(false), |
| 565 | 565 m_needsUpdatedDistribution(false) { |
| 566 unsigned selectorCount = 0; | 566 m_selectors.reserveInitialCapacity(m_selectorList.computeLength()); |
| 567 for (const CSSSelector* selector = m_selectorList.first(); selector; | |
| 568 selector = CSSSelectorList::next(*selector)) | |
| 569 selectorCount++; | |
| 570 | |
| 571 m_usesDeepCombinatorOrShadowPseudo = false; | |
| 572 m_needsUpdatedDistribution = false; | |
| 573 m_selectors.reserveInitialCapacity(selectorCount); | |
| 574 for (const CSSSelector* selector = m_selectorList.first(); selector; | 567 for (const CSSSelector* selector = m_selectorList.first(); selector; |
| 575 selector = CSSSelectorList::next(*selector)) { | 568 selector = CSSSelectorList::next(*selector)) { |
| 576 if (selector->matchesPseudoElement()) | 569 if (selector->matchesPseudoElement()) |
| 577 continue; | 570 continue; |
| 578 m_selectors.uncheckedAppend(selector); | 571 m_selectors.uncheckedAppend(selector); |
| 579 m_usesDeepCombinatorOrShadowPseudo |= | 572 m_usesDeepCombinatorOrShadowPseudo |= |
| 580 selector->hasDeepCombinatorOrShadowPseudo(); | 573 selector->hasDeepCombinatorOrShadowPseudo(); |
| 581 m_needsUpdatedDistribution |= selector->needsUpdatedDistribution(); | 574 m_needsUpdatedDistribution |= selector->needsUpdatedDistribution(); |
| 582 } | 575 } |
| 583 } | 576 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 614 return m_entries | 607 return m_entries |
| 615 .insert(selectors, SelectorQuery::adopt(std::move(selectorList))) | 608 .insert(selectors, SelectorQuery::adopt(std::move(selectorList))) |
| 616 .storedValue->value.get(); | 609 .storedValue->value.get(); |
| 617 } | 610 } |
| 618 | 611 |
| 619 void SelectorQueryCache::invalidate() { | 612 void SelectorQueryCache::invalidate() { |
| 620 m_entries.clear(); | 613 m_entries.clear(); |
| 621 } | 614 } |
| 622 | 615 |
| 623 } // namespace blink | 616 } // namespace blink |
| OLD | NEW |