| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
| 22 * | 22 * |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef LiveNodeListBase_h | 25 #ifndef LiveNodeListBase_h |
| 26 #define LiveNodeListBase_h | 26 #define LiveNodeListBase_h |
| 27 | 27 |
| 28 #include "HTMLNames.h" | 28 #include "HTMLNames.h" |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
| 31 #include "core/dom/ElementTraversal.h" |
| 31 #include "core/dom/NodeTraversal.h" | 32 #include "core/dom/NodeTraversal.h" |
| 32 #include "core/html/CollectionType.h" | 33 #include "core/html/CollectionType.h" |
| 33 | 34 |
| 34 namespace WebCore { | 35 namespace WebCore { |
| 35 | 36 |
| 36 enum NodeListRootType { | 37 enum NodeListRootType { |
| 37 NodeListIsRootedAtNode, | 38 NodeListIsRootedAtNode, |
| 38 NodeListIsRootedAtDocument | 39 NodeListIsRootedAtDocument |
| 39 }; | 40 }; |
| 40 | 41 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 80 |
| 80 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); | 81 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); |
| 81 | 82 |
| 82 protected: | 83 protected: |
| 83 Document& document() const { return m_ownerNode->document(); } | 84 Document& document() const { return m_ownerNode->document(); } |
| 84 | 85 |
| 85 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } | 86 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } |
| 86 | 87 |
| 87 template <typename Collection> | 88 template <typename Collection> |
| 88 static Element* itemBefore(const Collection&, const Element* previousItem); | 89 static Element* itemBefore(const Collection&, const Element* previousItem); |
| 90 template <class NodeListType> |
| 91 static Element* firstMatchingElement(const NodeListType&, const ContainerNod
e&); |
| 92 template <class NodeListType> |
| 93 static Element* nextMatchingElement(const NodeListType&, Element& current, c
onst ContainerNode& root); |
| 94 template <class NodeListType> |
| 95 static Element* traverseMatchingElementsForwardToOffset(const NodeListType&,
unsigned offset, Element& currentElement, unsigned& currentOffset, const Contai
nerNode& root); |
| 89 | 96 |
| 90 private: | 97 private: |
| 91 void invalidateIdNameCacheMaps() const; | 98 void invalidateIdNameCacheMaps() const; |
| 92 template <typename Collection> | 99 template <typename Collection> |
| 93 static Element* iterateForPreviousNode(const Collection&, Node* current); | 100 static Element* iterateForPreviousNode(const Collection&, Node* current); |
| 94 static Node* previousNode(const ContainerNode&, const Node& previous, bool o
nlyIncludeDirectChildren); | 101 static Node* previousNode(const ContainerNode&, const Node& previous, bool o
nlyIncludeDirectChildren); |
| 95 static Node* lastDescendant(const ContainerNode&); | 102 static Node* lastDescendant(const ContainerNode&); |
| 96 static Node* lastNode(const ContainerNode&, bool onlyIncludeDirectChildren); | 103 static Node* lastNode(const ContainerNode&, bool onlyIncludeDirectChildren); |
| 97 | 104 |
| 98 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. | 105 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 { | 167 { |
| 161 Node* current; | 168 Node* current; |
| 162 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1
0% slower. | 169 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1
0% slower. |
| 163 current = previousNode(collection.rootNode(), *previous, collection.shou
ldOnlyIncludeDirectChildren()); | 170 current = previousNode(collection.rootNode(), *previous, collection.shou
ldOnlyIncludeDirectChildren()); |
| 164 else | 171 else |
| 165 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi
rectChildren()); | 172 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi
rectChildren()); |
| 166 | 173 |
| 167 return iterateForPreviousNode(collection, current); | 174 return iterateForPreviousNode(collection, current); |
| 168 } | 175 } |
| 169 | 176 |
| 177 template <class NodeListType> |
| 178 Element* LiveNodeListBase::firstMatchingElement(const NodeListType& nodeList, co
nst ContainerNode& root) |
| 179 { |
| 180 Element* element = ElementTraversal::firstWithin(root); |
| 181 while (element && !isMatchingElement(nodeList, *element)) |
| 182 element = ElementTraversal::next(*element, &root); |
| 183 return element; |
| 184 } |
| 185 |
| 186 template <class NodeListType> |
| 187 Element* LiveNodeListBase::nextMatchingElement(const NodeListType& nodeList, Ele
ment& current, const ContainerNode& root) |
| 188 { |
| 189 Element* next = ¤t; |
| 190 do { |
| 191 next = ElementTraversal::next(*next, &root); |
| 192 } while (next && !isMatchingElement(nodeList, *next)); |
| 193 return next; |
| 194 } |
| 195 |
| 196 template <class NodeListType> |
| 197 Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(const NodeLis
tType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffs
et, const ContainerNode& root) |
| 198 { |
| 199 ASSERT(currentOffset < offset); |
| 200 Element* next = ¤tElement; |
| 201 while ((next = nextMatchingElement(nodeList, *next, root))) { |
| 202 if (++currentOffset == offset) |
| 203 return next; |
| 204 } |
| 205 return 0; |
| 206 } |
| 207 |
| 170 } // namespace WebCore | 208 } // namespace WebCore |
| 171 | 209 |
| 172 #endif // LiveNodeListBase_h | 210 #endif // LiveNodeListBase_h |
| OLD | NEW |