OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef SelectorQuery_h | 26 #ifndef SelectorQuery_h |
27 #define SelectorQuery_h | 27 #define SelectorQuery_h |
28 | 28 |
29 #include "core/css/CSSSelectorList.h" | 29 #include "core/css/CSSSelectorList.h" |
| 30 #include "core/dom/DocumentOrderedList.h" |
30 #include <wtf/HashMap.h> | 31 #include <wtf/HashMap.h> |
31 #include <wtf/text/AtomicStringHash.h> | 32 #include <wtf/text/AtomicStringHash.h> |
32 #include <wtf/Vector.h> | 33 #include <wtf/Vector.h> |
33 | 34 |
34 namespace WebCore { | 35 namespace WebCore { |
35 | 36 |
36 typedef int ExceptionCode; | 37 typedef int ExceptionCode; |
37 | 38 |
38 class CSSSelector; | 39 class CSSSelector; |
39 class Document; | 40 class Document; |
40 class Element; | 41 class Element; |
41 class Node; | 42 class Node; |
42 class NodeList; | 43 class NodeList; |
43 | 44 |
44 class SelectorDataList { | 45 class SelectorDataList { |
45 public: | 46 public: |
46 void initialize(const CSSSelectorList&); | 47 void initialize(const CSSSelectorList&); |
47 bool matches(Element*) const; | 48 bool matches(Element*) const; |
48 PassRefPtr<NodeList> queryAll(Node* rootNode) const; | 49 PassRefPtr<NodeList> queryAll(Node* rootNode) const; |
49 PassRefPtr<Element> queryFirst(Node* rootNode) const; | 50 PassRefPtr<Element> queryFirst(Node* rootNode) const; |
50 | 51 |
51 private: | 52 private: |
52 struct SelectorData { | 53 struct SelectorData { |
53 SelectorData(const CSSSelector* selector, bool isFastCheckable) : select
or(selector), isFastCheckable(isFastCheckable) { } | 54 SelectorData(const CSSSelector* selector, bool isFastCheckable) : select
or(selector), isFastCheckable(isFastCheckable) { } |
54 const CSSSelector* selector; | 55 const CSSSelector* selector; |
55 bool isFastCheckable; | 56 bool isFastCheckable; |
56 }; | 57 }; |
57 | 58 |
58 bool selectorMatches(const SelectorData&, Element*, const Node*) const; | 59 bool selectorMatches(const SelectorData&, Element*, const Node*) const; |
59 std::pair<bool, Node*> findTraverseRoot(Node* traverseRoot) const; | 60 bool findTraverseRoot(Node* rootNode, DocumentOrderedList& traversalRoots) c
onst; |
60 template <bool firstMatchOnly> | 61 template <bool firstMatchOnly> |
61 void execute(Node* rootNode, Vector<RefPtr<Node> >&) const; | 62 void execute(Node* rootNode, Vector<RefPtr<Node> >&) const; |
62 | 63 |
63 Vector<SelectorData> m_selectors; | 64 Vector<SelectorData> m_selectors; |
64 }; | 65 }; |
65 | 66 |
66 class SelectorQuery { | 67 class SelectorQuery { |
67 WTF_MAKE_NONCOPYABLE(SelectorQuery); | 68 WTF_MAKE_NONCOPYABLE(SelectorQuery); |
68 WTF_MAKE_FAST_ALLOCATED; | 69 WTF_MAKE_FAST_ALLOCATED; |
69 public: | 70 public: |
(...skipping 12 matching lines...) Expand all Loading... |
82 SelectorQuery* add(const AtomicString&, Document*, ExceptionCode&); | 83 SelectorQuery* add(const AtomicString&, Document*, ExceptionCode&); |
83 void invalidate(); | 84 void invalidate(); |
84 | 85 |
85 private: | 86 private: |
86 HashMap<AtomicString, OwnPtr<SelectorQuery> > m_entries; | 87 HashMap<AtomicString, OwnPtr<SelectorQuery> > m_entries; |
87 }; | 88 }; |
88 | 89 |
89 } | 90 } |
90 | 91 |
91 #endif | 92 #endif |
OLD | NEW |