Index: Source/core/dom/LiveNodeListBase.h |
diff --git a/Source/core/dom/LiveNodeListBase.h b/Source/core/dom/LiveNodeListBase.h |
index dbef5afcefe5c0aff7c3f206c18c3534bb961457..0170f85cf9336c4ca7c31ea79fef2840b88d976a 100644 |
--- a/Source/core/dom/LiveNodeListBase.h |
+++ b/Source/core/dom/LiveNodeListBase.h |
@@ -28,6 +28,7 @@ |
#include "HTMLNames.h" |
#include "core/dom/Document.h" |
#include "core/dom/Element.h" |
+#include "core/dom/ElementTraversal.h" |
#include "core/dom/NodeTraversal.h" |
#include "core/html/CollectionType.h" |
@@ -86,6 +87,12 @@ protected: |
template <typename Collection> |
static Element* itemBefore(const Collection&, const Element* previousItem); |
+ template <class NodeListType> |
+ static Element* firstMatchingElement(const NodeListType&, const ContainerNode&); |
+ template <class NodeListType> |
+ static Element* nextMatchingElement(const NodeListType&, Element& current, const ContainerNode& root); |
+ template <class NodeListType> |
+ static Element* traverseMatchingElementsForwardToOffset(const NodeListType&, unsigned offset, Element& currentElement, unsigned& currentOffset, const ContainerNode& root); |
private: |
void invalidateIdNameCacheMaps() const; |
@@ -167,6 +174,37 @@ Element* LiveNodeListBase::itemBefore(const Collection& collection, const Elemen |
return iterateForPreviousNode(collection, current); |
} |
+template <class NodeListType> |
+Element* LiveNodeListBase::firstMatchingElement(const NodeListType& nodeList, const ContainerNode& root) |
+{ |
+ Element* element = ElementTraversal::firstWithin(root); |
+ while (element && !isMatchingElement(nodeList, *element)) |
+ element = ElementTraversal::next(*element, &root); |
+ return element; |
+} |
+ |
+template <class NodeListType> |
+Element* LiveNodeListBase::nextMatchingElement(const NodeListType& nodeList, Element& current, const ContainerNode& root) |
+{ |
+ Element* next = ¤t; |
+ do { |
+ next = ElementTraversal::next(*next, &root); |
+ } while (next && !isMatchingElement(nodeList, *next)); |
+ return next; |
+} |
+ |
+template <class NodeListType> |
+Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(const NodeListType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffset, const ContainerNode& root) |
+{ |
+ ASSERT(currentOffset < offset); |
+ Element* next = ¤tElement; |
+ while ((next = nextMatchingElement(nodeList, *next, root))) { |
+ if (++currentOffset == offset) |
+ return next; |
+ } |
+ return 0; |
+} |
+ |
} // namespace WebCore |
#endif // LiveNodeListBase_h |