| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 typedef Element* OutputType; | 44 typedef Element* OutputType; |
| 45 static const bool shouldOnlyMatchFirstElement = true; | 45 static const bool shouldOnlyMatchFirstElement = true; |
| 46 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element
) | 46 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element
) |
| 47 { | 47 { |
| 48 ASSERT(!output); | 48 ASSERT(!output); |
| 49 output = &element; | 49 output = &element; |
| 50 } | 50 } |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 struct AllElementsSelectorQueryTrait { | 53 struct AllElementsSelectorQueryTrait { |
| 54 typedef WillBeHeapVector<RefPtrWillBeMember<Element> > OutputType; | 54 typedef WillBeHeapVector<RefPtrWillBeMember<Element>> OutputType; |
| 55 static const bool shouldOnlyMatchFirstElement = false; | 55 static const bool shouldOnlyMatchFirstElement = false; |
| 56 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element
) | 56 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element
) |
| 57 { | 57 { |
| 58 output.append(&element); | 58 output.append(&element); |
| 59 } | 59 } |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 enum ClassElementListBehavior { AllElements, OnlyRoots }; | 62 enum ClassElementListBehavior { AllElements, OnlyRoots }; |
| 63 | 63 |
| 64 template <ClassElementListBehavior onlyRoots> | 64 template <ClassElementListBehavior onlyRoots> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 for (unsigned i = 0; i < selectorCount; ++i) { | 143 for (unsigned i = 0; i < selectorCount; ++i) { |
| 144 if (selectorMatches(*m_selectors[i], *currentElement, targetElement)
) | 144 if (selectorMatches(*m_selectors[i], *currentElement, targetElement)
) |
| 145 return currentElement; | 145 return currentElement; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 return nullptr; | 148 return nullptr; |
| 149 } | 149 } |
| 150 | 150 |
| 151 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo
de& rootNode) const | 151 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo
de& rootNode) const |
| 152 { | 152 { |
| 153 WillBeHeapVector<RefPtrWillBeMember<Element> > result; | 153 WillBeHeapVector<RefPtrWillBeMember<Element>> result; |
| 154 execute<AllElementsSelectorQueryTrait>(rootNode, result); | 154 execute<AllElementsSelectorQueryTrait>(rootNode, result); |
| 155 return StaticElementList::adopt(result); | 155 return StaticElementList::adopt(result); |
| 156 } | 156 } |
| 157 | 157 |
| 158 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root
Node) const | 158 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root
Node) const |
| 159 { | 159 { |
| 160 Element* matchedElement = 0; | 160 Element* matchedElement = 0; |
| 161 execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement); | 161 execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement); |
| 162 return matchedElement; | 162 return matchedElement; |
| 163 } | 163 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 431 |
| 432 ASSERT(m_selectors.size() == 1); | 432 ASSERT(m_selectors.size() == 1); |
| 433 | 433 |
| 434 const CSSSelector& selector = *m_selectors[0]; | 434 const CSSSelector& selector = *m_selectors[0]; |
| 435 const CSSSelector& firstSelector = selector; | 435 const CSSSelector& firstSelector = selector; |
| 436 | 436 |
| 437 // Fast path for querySelector*('#id'), querySelector*('tag#id'). | 437 // Fast path for querySelector*('#id'), querySelector*('tag#id'). |
| 438 if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) { | 438 if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) { |
| 439 const AtomicString& idToMatch = idSelector->value(); | 439 const AtomicString& idToMatch = idSelector->value(); |
| 440 if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) { | 440 if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) { |
| 441 const WillBeHeapVector<RawPtrWillBeMember<Element> >& elements = roo
tNode.treeScope().getAllElementsById(idToMatch); | 441 const WillBeHeapVector<RawPtrWillBeMember<Element>>& elements = root
Node.treeScope().getAllElementsById(idToMatch); |
| 442 size_t count = elements.size(); | 442 size_t count = elements.size(); |
| 443 for (size_t i = 0; i < count; ++i) { | 443 for (size_t i = 0; i < count; ++i) { |
| 444 Element& element = *elements[i]; | 444 Element& element = *elements[i]; |
| 445 if (!(isTreeScopeRoot(rootNode) || element.isDescendantOf(&rootN
ode))) | 445 if (!(isTreeScopeRoot(rootNode) || element.isDescendantOf(&rootN
ode))) |
| 446 continue; | 446 continue; |
| 447 if (selectorMatches(selector, element, rootNode)) { | 447 if (selectorMatches(selector, element, rootNode)) { |
| 448 SelectorQueryTrait::appendElement(output, element); | 448 SelectorQueryTrait::appendElement(output, element); |
| 449 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) | 449 if (SelectorQueryTrait::shouldOnlyMatchFirstElement) |
| 450 return; | 450 return; |
| 451 } | 451 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 return m_selectors.queryAll(rootNode); | 503 return m_selectors.queryAll(rootNode); |
| 504 } | 504 } |
| 505 | 505 |
| 506 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod
e) const | 506 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod
e) const |
| 507 { | 507 { |
| 508 return m_selectors.queryFirst(rootNode); | 508 return m_selectors.queryFirst(rootNode); |
| 509 } | 509 } |
| 510 | 510 |
| 511 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) | 511 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) |
| 512 { | 512 { |
| 513 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); | 513 HashMap<AtomicString, OwnPtr<SelectorQuery>>::iterator it = m_entries.find(s
electors); |
| 514 if (it != m_entries.end()) | 514 if (it != m_entries.end()) |
| 515 return it->value.get(); | 515 return it->value.get(); |
| 516 | 516 |
| 517 CSSParser parser(CSSParserContext(document, 0)); | 517 CSSParser parser(CSSParserContext(document, 0)); |
| 518 CSSSelectorList selectorList; | 518 CSSSelectorList selectorList; |
| 519 parser.parseSelector(selectors, selectorList); | 519 parser.parseSelector(selectors, selectorList); |
| 520 | 520 |
| 521 if (!selectorList.first()) { | 521 if (!selectorList.first()) { |
| 522 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); | 522 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); |
| 523 return 0; | 523 return 0; |
| (...skipping 11 matching lines...) Expand all 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 |