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 18 matching lines...) Expand all Loading... |
29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
30 #include "core/css/SelectorChecker.h" | 30 #include "core/css/SelectorChecker.h" |
31 #include "core/css/parser/CSSParser.h" | 31 #include "core/css/parser/CSSParser.h" |
32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
33 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
35 #include "core/dom/Node.h" | 35 #include "core/dom/Node.h" |
36 #include "core/dom/StaticNodeList.h" | 36 #include "core/dom/StaticNodeList.h" |
37 #include "core/dom/shadow/ElementShadow.h" | 37 #include "core/dom/shadow/ElementShadow.h" |
38 #include "core/dom/shadow/ShadowRoot.h" | 38 #include "core/dom/shadow/ShadowRoot.h" |
39 #include "wtf/PtrUtil.h" | |
40 #include <memory> | |
41 | 39 |
42 namespace blink { | 40 namespace blink { |
43 | 41 |
44 struct SingleElementSelectorQueryTrait { | 42 struct SingleElementSelectorQueryTrait { |
45 typedef Element* OutputType; | 43 typedef Element* OutputType; |
46 static const bool shouldOnlyMatchFirstElement = true; | 44 static const bool shouldOnlyMatchFirstElement = true; |
47 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element
) | 45 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element
) |
48 { | 46 { |
49 DCHECK(!output); | 47 DCHECK(!output); |
50 output = &element; | 48 output = &element; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 DCHECK_EQ(firstSelector.tagQName().namespaceURI(), nullAtom); | 518 DCHECK_EQ(firstSelector.tagQName().namespaceURI(), nullAtom); |
521 break; | 519 break; |
522 default: | 520 default: |
523 break; // If we need another fast path, add here. | 521 break; // If we need another fast path, add here. |
524 } | 522 } |
525 } | 523 } |
526 | 524 |
527 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); | 525 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); |
528 } | 526 } |
529 | 527 |
530 std::unique_ptr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList selectorList
) | 528 PassOwnPtr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList selectorList) |
531 { | 529 { |
532 return wrapUnique(new SelectorQuery(std::move(selectorList))); | 530 return adoptPtr(new SelectorQuery(std::move(selectorList))); |
533 } | 531 } |
534 | 532 |
535 SelectorQuery::SelectorQuery(CSSSelectorList selectorList) | 533 SelectorQuery::SelectorQuery(CSSSelectorList selectorList) |
536 { | 534 { |
537 m_selectorList = std::move(selectorList); | 535 m_selectorList = std::move(selectorList); |
538 m_selectors.initialize(m_selectorList); | 536 m_selectors.initialize(m_selectorList); |
539 } | 537 } |
540 | 538 |
541 bool SelectorQuery::matches(Element& element) const | 539 bool SelectorQuery::matches(Element& element) const |
542 { | 540 { |
(...skipping 10 matching lines...) Expand all Loading... |
553 return m_selectors.queryAll(rootNode); | 551 return m_selectors.queryAll(rootNode); |
554 } | 552 } |
555 | 553 |
556 Element* SelectorQuery::queryFirst(ContainerNode& rootNode) const | 554 Element* SelectorQuery::queryFirst(ContainerNode& rootNode) const |
557 { | 555 { |
558 return m_selectors.queryFirst(rootNode); | 556 return m_selectors.queryFirst(rootNode); |
559 } | 557 } |
560 | 558 |
561 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) | 559 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) |
562 { | 560 { |
563 HashMap<AtomicString, std::unique_ptr<SelectorQuery>>::iterator it = m_entri
es.find(selectors); | 561 HashMap<AtomicString, OwnPtr<SelectorQuery>>::iterator it = m_entries.find(s
electors); |
564 if (it != m_entries.end()) | 562 if (it != m_entries.end()) |
565 return it->value.get(); | 563 return it->value.get(); |
566 | 564 |
567 CSSSelectorList selectorList = CSSParser::parseSelector(CSSParserContext(doc
ument, nullptr), nullptr, selectors); | 565 CSSSelectorList selectorList = CSSParser::parseSelector(CSSParserContext(doc
ument, nullptr), nullptr, selectors); |
568 | 566 |
569 if (!selectorList.first()) { | 567 if (!selectorList.first()) { |
570 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); | 568 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); |
571 return nullptr; | 569 return nullptr; |
572 } | 570 } |
573 | 571 |
574 const unsigned maximumSelectorQueryCacheSize = 256; | 572 const unsigned maximumSelectorQueryCacheSize = 256; |
575 if (m_entries.size() == maximumSelectorQueryCacheSize) | 573 if (m_entries.size() == maximumSelectorQueryCacheSize) |
576 m_entries.remove(m_entries.begin()); | 574 m_entries.remove(m_entries.begin()); |
577 | 575 |
578 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(); |
579 } | 577 } |
580 | 578 |
581 void SelectorQueryCache::invalidate() | 579 void SelectorQueryCache::invalidate() |
582 { | 580 { |
583 m_entries.clear(); | 581 m_entries.clear(); |
584 } | 582 } |
585 | 583 |
586 } // namespace blink | 584 } // namespace blink |
OLD | NEW |