| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 class CSSSelector; | 39 class CSSSelector; |
| 40 class ContainerNode; | 40 class ContainerNode; |
| 41 class Document; | 41 class Document; |
| 42 class Element; | 42 class Element; |
| 43 class ExceptionState; | 43 class ExceptionState; |
| 44 template <typename NodeType> | 44 template <typename NodeType> |
| 45 class StaticNodeTypeList; | 45 class StaticNodeTypeList; |
| 46 using StaticElementList = StaticNodeTypeList<Element>; | 46 using StaticElementList = StaticNodeTypeList<Element>; |
| 47 | 47 |
| 48 class SelectorDataList { | 48 class CORE_EXPORT SelectorQuery { |
| 49 DISALLOW_NEW(); | 49 WTF_MAKE_NONCOPYABLE(SelectorQuery); |
| 50 USING_FAST_MALLOC(SelectorQuery); |
| 50 | 51 |
| 51 public: | 52 public: |
| 52 void initialize(const CSSSelectorList&); | 53 static std::unique_ptr<SelectorQuery> adopt(CSSSelectorList); |
| 54 |
| 55 // https://dom.spec.whatwg.org/#dom-element-matches |
| 53 bool matches(Element&) const; | 56 bool matches(Element&) const; |
| 57 |
| 58 // https://dom.spec.whatwg.org/#dom-element-closest |
| 54 Element* closest(Element&) const; | 59 Element* closest(Element&) const; |
| 60 |
| 61 // https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall |
| 55 StaticElementList* queryAll(ContainerNode& rootNode) const; | 62 StaticElementList* queryAll(ContainerNode& rootNode) const; |
| 63 |
| 64 // https://dom.spec.whatwg.org/#dom-parentnode-queryselector |
| 56 Element* queryFirst(ContainerNode& rootNode) const; | 65 Element* queryFirst(ContainerNode& rootNode) const; |
| 57 | 66 |
| 58 private: | 67 private: |
| 68 explicit SelectorQuery(CSSSelectorList); |
| 69 |
| 59 bool canUseFastQuery(const ContainerNode& rootNode) const; | 70 bool canUseFastQuery(const ContainerNode& rootNode) const; |
| 60 bool selectorMatches(const CSSSelector&, | |
| 61 Element&, | |
| 62 const ContainerNode&) const; | |
| 63 | |
| 64 template <typename SelectorQueryTrait> | |
| 65 void collectElementsByClassName( | |
| 66 ContainerNode& rootNode, | |
| 67 const AtomicString& className, | |
| 68 typename SelectorQueryTrait::OutputType&) const; | |
| 69 template <typename SelectorQueryTrait> | |
| 70 void collectElementsByTagName(ContainerNode& rootNode, | |
| 71 const QualifiedName& tagName, | |
| 72 typename SelectorQueryTrait::OutputType&) const; | |
| 73 | 71 |
| 74 template <typename SelectorQueryTrait> | 72 template <typename SelectorQueryTrait> |
| 75 void findTraverseRootsAndExecute( | 73 void findTraverseRootsAndExecute( |
| 76 ContainerNode& rootNode, | 74 ContainerNode& rootNode, |
| 77 typename SelectorQueryTrait::OutputType&) const; | 75 typename SelectorQueryTrait::OutputType&) const; |
| 78 | 76 |
| 79 enum MatchTraverseRootState { | 77 enum MatchTraverseRootState { |
| 80 DoesNotMatchTraverseRoots, | 78 DoesNotMatchTraverseRoots, |
| 81 MatchesTraverseRoots | 79 MatchesTraverseRoots |
| 82 }; | 80 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 void executeSlow(ContainerNode& rootNode, | 99 void executeSlow(ContainerNode& rootNode, |
| 102 typename SelectorQueryTrait::OutputType&) const; | 100 typename SelectorQueryTrait::OutputType&) const; |
| 103 template <typename SelectorQueryTrait> | 101 template <typename SelectorQueryTrait> |
| 104 void executeSlowTraversingShadowTree( | 102 void executeSlowTraversingShadowTree( |
| 105 ContainerNode& rootNode, | 103 ContainerNode& rootNode, |
| 106 typename SelectorQueryTrait::OutputType&) const; | 104 typename SelectorQueryTrait::OutputType&) const; |
| 107 template <typename SelectorQueryTrait> | 105 template <typename SelectorQueryTrait> |
| 108 void execute(ContainerNode& rootNode, | 106 void execute(ContainerNode& rootNode, |
| 109 typename SelectorQueryTrait::OutputType&) const; | 107 typename SelectorQueryTrait::OutputType&) const; |
| 110 | 108 |
| 109 CSSSelectorList m_selectorList; |
| 111 Vector<const CSSSelector*> m_selectors; | 110 Vector<const CSSSelector*> m_selectors; |
| 112 bool m_usesDeepCombinatorOrShadowPseudo : 1; | 111 bool m_usesDeepCombinatorOrShadowPseudo : 1; |
| 113 bool m_needsUpdatedDistribution : 1; | 112 bool m_needsUpdatedDistribution : 1; |
| 114 }; | 113 }; |
| 115 | 114 |
| 116 class CORE_EXPORT SelectorQuery { | |
| 117 WTF_MAKE_NONCOPYABLE(SelectorQuery); | |
| 118 USING_FAST_MALLOC(SelectorQuery); | |
| 119 | |
| 120 public: | |
| 121 static std::unique_ptr<SelectorQuery> adopt(CSSSelectorList); | |
| 122 | |
| 123 bool matches(Element&) const; | |
| 124 Element* closest(Element&) const; | |
| 125 StaticElementList* queryAll(ContainerNode& rootNode) const; | |
| 126 Element* queryFirst(ContainerNode& rootNode) const; | |
| 127 | |
| 128 private: | |
| 129 explicit SelectorQuery(CSSSelectorList); | |
| 130 | |
| 131 SelectorDataList m_selectors; | |
| 132 CSSSelectorList m_selectorList; | |
| 133 }; | |
| 134 | |
| 135 class SelectorQueryCache { | 115 class SelectorQueryCache { |
| 136 USING_FAST_MALLOC(SelectorQueryCache); | 116 USING_FAST_MALLOC(SelectorQueryCache); |
| 137 | 117 |
| 138 public: | 118 public: |
| 139 SelectorQuery* add(const AtomicString&, const Document&, ExceptionState&); | 119 SelectorQuery* add(const AtomicString&, const Document&, ExceptionState&); |
| 140 void invalidate(); | 120 void invalidate(); |
| 141 | 121 |
| 142 private: | 122 private: |
| 143 HashMap<AtomicString, std::unique_ptr<SelectorQuery>> m_entries; | 123 HashMap<AtomicString, std::unique_ptr<SelectorQuery>> m_entries; |
| 144 }; | 124 }; |
| 145 | 125 |
| 146 } // namespace blink | 126 } // namespace blink |
| 147 | 127 |
| 148 #endif | 128 #endif |
| OLD | NEW |