| 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 17 matching lines...) Expand all Loading... |
| 28 #define SelectorQuery_h | 28 #define SelectorQuery_h |
| 29 | 29 |
| 30 #include "core/css/CSSSelectorList.h" | 30 #include "core/css/CSSSelectorList.h" |
| 31 #include "wtf/HashMap.h" | 31 #include "wtf/HashMap.h" |
| 32 #include "wtf/Vector.h" | 32 #include "wtf/Vector.h" |
| 33 #include "wtf/text/AtomicStringHash.h" | 33 #include "wtf/text/AtomicStringHash.h" |
| 34 | 34 |
| 35 namespace WebCore { | 35 namespace WebCore { |
| 36 | 36 |
| 37 class CSSSelector; | 37 class CSSSelector; |
| 38 class ContainerNode; |
| 38 class Document; | 39 class Document; |
| 39 class Element; | 40 class Element; |
| 40 class ExceptionState; | 41 class ExceptionState; |
| 41 class Node; | 42 class Node; |
| 42 class NodeList; | 43 class NodeList; |
| 43 class SimpleNodeList; | 44 class SimpleNodeList; |
| 44 class SpaceSplitString; | 45 class SpaceSplitString; |
| 45 | 46 |
| 46 class SelectorDataList { | 47 class SelectorDataList { |
| 47 public: | 48 public: |
| 48 void initialize(const CSSSelectorList&); | 49 void initialize(const CSSSelectorList&); |
| 49 bool matches(Element&) const; | 50 bool matches(Element&) const; |
| 50 PassRefPtr<NodeList> queryAll(Node& rootNode) const; | 51 PassRefPtr<NodeList> queryAll(ContainerNode& rootNode) const; |
| 51 PassRefPtr<Element> queryFirst(Node& rootNode) const; | 52 PassRefPtr<Element> queryFirst(ContainerNode& rootNode) const; |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 struct SelectorData { | 55 struct SelectorData { |
| 55 SelectorData(const CSSSelector* selector, bool isFastCheckable) : select
or(selector), isFastCheckable(isFastCheckable) { } | 56 SelectorData(const CSSSelector* selector, bool isFastCheckable) : select
or(selector), isFastCheckable(isFastCheckable) { } |
| 56 const CSSSelector* selector; | 57 const CSSSelector* selector; |
| 57 bool isFastCheckable; | 58 bool isFastCheckable; |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 bool canUseFastQuery(const Node& rootNode) const; | 61 bool canUseFastQuery(const ContainerNode& rootNode) const; |
| 61 bool selectorMatches(const SelectorData&, Element&, const Node&) const; | 62 bool selectorMatches(const SelectorData&, Element&, const ContainerNode&) co
nst; |
| 62 | 63 |
| 63 template <typename SelectorQueryTrait> | 64 template <typename SelectorQueryTrait> |
| 64 void collectElementsByClassName(Node& rootNode, const AtomicString& classNam
e, typename SelectorQueryTrait::OutputType&) const; | 65 void collectElementsByClassName(ContainerNode& rootNode, const AtomicString&
className, typename SelectorQueryTrait::OutputType&) const; |
| 65 template <typename SelectorQueryTrait> | 66 template <typename SelectorQueryTrait> |
| 66 void collectElementsByTagName(Node& rootNode, const QualifiedName& tagName,
typename SelectorQueryTrait::OutputType&) const; | 67 void collectElementsByTagName(ContainerNode& rootNode, const QualifiedName&
tagName, typename SelectorQueryTrait::OutputType&) const; |
| 67 | 68 |
| 68 template <typename SelectorQueryTrait> | 69 template <typename SelectorQueryTrait> |
| 69 void findTraverseRootsAndExecute(Node& rootNode, typename SelectorQueryTrait
::OutputType&) const; | 70 void findTraverseRootsAndExecute(ContainerNode& rootNode, typename SelectorQ
ueryTrait::OutputType&) const; |
| 70 | 71 |
| 71 enum MatchTraverseRootState { DoesNotMatchTraverseRoots, MatchesTraverseRoot
s }; | 72 enum MatchTraverseRootState { DoesNotMatchTraverseRoots, MatchesTraverseRoot
s }; |
| 72 template <typename SelectorQueryTrait> | 73 template <typename SelectorQueryTrait> |
| 73 void executeForTraverseRoot(const SelectorData&, Node* traverseRoot, MatchTr
averseRootState, Node& rootNode, typename SelectorQueryTrait::OutputType&) const
; | 74 void executeForTraverseRoot(const SelectorData&, Node* traverseRoot, MatchTr
averseRootState, ContainerNode& rootNode, typename SelectorQueryTrait::OutputTyp
e&) const; |
| 74 template <typename SelectorQueryTrait, typename SimpleNodeListType> | 75 template <typename SelectorQueryTrait, typename SimpleNodeListType> |
| 75 void executeForTraverseRoots(const SelectorData&, SimpleNodeListType& traver
seRoots, MatchTraverseRootState, Node& rootNode, typename SelectorQueryTrait::Ou
tputType&) const; | 76 void executeForTraverseRoots(const SelectorData&, SimpleNodeListType& traver
seRoots, MatchTraverseRootState, ContainerNode& rootNode, typename SelectorQuery
Trait::OutputType&) const; |
| 76 | 77 |
| 77 template <typename SelectorQueryTrait> | 78 template <typename SelectorQueryTrait> |
| 78 void executeSlow(Node& rootNode, typename SelectorQueryTrait::OutputType&) c
onst; | 79 void executeSlow(ContainerNode& rootNode, typename SelectorQueryTrait::Outpu
tType&) const; |
| 79 template <typename SelectorQueryTrait> | 80 template <typename SelectorQueryTrait> |
| 80 void execute(Node& rootNode, typename SelectorQueryTrait::OutputType&) const
; | 81 void execute(ContainerNode& rootNode, typename SelectorQueryTrait::OutputTyp
e&) const; |
| 81 const CSSSelector* selectorForIdLookup(const CSSSelector*) const; | 82 const CSSSelector* selectorForIdLookup(const CSSSelector*) const; |
| 82 | 83 |
| 83 Vector<SelectorData> m_selectors; | 84 Vector<SelectorData> m_selectors; |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 class SelectorQuery { | 87 class SelectorQuery { |
| 87 WTF_MAKE_NONCOPYABLE(SelectorQuery); | 88 WTF_MAKE_NONCOPYABLE(SelectorQuery); |
| 88 WTF_MAKE_FAST_ALLOCATED; | 89 WTF_MAKE_FAST_ALLOCATED; |
| 89 public: | 90 public: |
| 90 explicit SelectorQuery(const CSSSelectorList&); | 91 explicit SelectorQuery(const CSSSelectorList&); |
| 91 bool matches(Element&) const; | 92 bool matches(Element&) const; |
| 92 PassRefPtr<NodeList> queryAll(Node& rootNode) const; | 93 PassRefPtr<NodeList> queryAll(ContainerNode& rootNode) const; |
| 93 PassRefPtr<Element> queryFirst(Node& rootNode) const; | 94 PassRefPtr<Element> queryFirst(ContainerNode& rootNode) const; |
| 94 private: | 95 private: |
| 95 SelectorDataList m_selectors; | 96 SelectorDataList m_selectors; |
| 96 CSSSelectorList m_selectorList; | 97 CSSSelectorList m_selectorList; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 class SelectorQueryCache { | 100 class SelectorQueryCache { |
| 100 WTF_MAKE_FAST_ALLOCATED; | 101 WTF_MAKE_FAST_ALLOCATED; |
| 101 public: | 102 public: |
| 102 SelectorQuery* add(const AtomicString&, const Document&, ExceptionState&); | 103 SelectorQuery* add(const AtomicString&, const Document&, ExceptionState&); |
| 103 void invalidate(); | 104 void invalidate(); |
| 104 | 105 |
| 105 private: | 106 private: |
| 106 HashMap<AtomicString, OwnPtr<SelectorQuery> > m_entries; | 107 HashMap<AtomicString, OwnPtr<SelectorQuery> > m_entries; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } | 110 } |
| 110 | 111 |
| 111 #endif | 112 #endif |
| OLD | NEW |