Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: Source/core/dom/LiveNodeListBase.h

Issue 181103005: Move LiveNodeList code out of HTMLCollection.cpp (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/LiveNodeList.cpp ('k') | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = &current;
+ 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 = &currentElement;
+ while ((next = nextMatchingElement(nodeList, *next, root))) {
+ if (++currentOffset == offset)
+ return next;
+ }
+ return 0;
+}
+
} // namespace WebCore
#endif // LiveNodeListBase_h
« no previous file with comments | « Source/core/dom/LiveNodeList.cpp ('k') | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698