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

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

Issue 468183002: Move matching Element traversal functions from LiveNodeListBase to ElementTraversal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use anonymous namespace Created 6 years, 4 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.h » ('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 7d2a56fc3f37a5c6291bf19bb29fcb68181a9dd9..3daef7952d2bd125c71302b85aafabdbe556062b 100644
--- a/Source/core/dom/LiveNodeListBase.h
+++ b/Source/core/dom/LiveNodeListBase.h
@@ -79,18 +79,10 @@ protected:
ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeListRootType>(m_rootType); }
- template <class NodeListType>
- static Element* firstMatchingElement(const NodeListType&);
- template <class NodeListType>
- static Element* lastMatchingElement(const NodeListType&);
- template <class NodeListType>
- static Element* nextMatchingElement(const NodeListType&, Element& current);
- template <class NodeListType>
- static Element* previousMatchingElement(const NodeListType&, Element& current);
- template <class NodeListType>
- static Element* traverseMatchingElementsForwardToOffset(const NodeListType&, unsigned offset, Element& currentElement, unsigned& currentOffset);
- template <class NodeListType>
- static Element* traverseMatchingElementsBackwardToOffset(const NodeListType&, unsigned offset, Element& currentElement, unsigned& currentOffset);
+ template <typename MatchFunc>
+ static Element* traverseMatchingElementsForwardToOffset(Element& currentElement, const ContainerNode* stayWithin, unsigned offset, unsigned& currentOffset, MatchFunc);
+ template <typename MatchFunc>
+ static Element* traverseMatchingElementsBackwardToOffset(Element& currentElement, const ContainerNode* stayWithin, unsigned offset, unsigned& currentOffset, MatchFunc);
virtual void trace(Visitor* visitor) { visitor->trace(m_ownerNode); }
@@ -125,64 +117,22 @@ ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
return false;
}
-template <typename NodeListType>
-Element* LiveNodeListBase::lastMatchingElement(const NodeListType& nodeList)
-{
- ContainerNode& root = nodeList.rootNode();
- Element* element = ElementTraversal::lastWithin(root);
- while (element && !isMatchingElement(nodeList, *element))
- element = ElementTraversal::previous(*element, &root);
- return element;
-}
-
-template <class NodeListType>
-Element* LiveNodeListBase::firstMatchingElement(const NodeListType& nodeList)
-{
- ContainerNode& root = nodeList.rootNode();
- 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)
-{
- ContainerNode& root = nodeList.rootNode();
- Element* next = &current;
- do {
- next = ElementTraversal::next(*next, &root);
- } while (next && !isMatchingElement(nodeList, *next));
- return next;
-}
-
-template <class NodeListType>
-Element* LiveNodeListBase::previousMatchingElement(const NodeListType& nodeList, Element& current)
-{
- ContainerNode& root = nodeList.rootNode();
- Element* previous = &current;
- do {
- previous = ElementTraversal::previous(*previous, &root);
- } while (previous && !isMatchingElement(nodeList, *previous));
- return previous;
-}
-
-template <class NodeListType>
-Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(const NodeListType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffset)
+template <typename MatchFunc>
+Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(Element& currentElement, const ContainerNode* stayWithin, unsigned offset, unsigned& currentOffset, MatchFunc isMatch)
{
ASSERT(currentOffset < offset);
- for (Element* next = nextMatchingElement(nodeList, currentElement); next; next = nextMatchingElement(nodeList, *next)) {
+ for (Element* next = ElementTraversal::next(currentElement, stayWithin, isMatch); next; next = ElementTraversal::next(*next, stayWithin, isMatch)) {
if (++currentOffset == offset)
return next;
}
return 0;
}
-template <class NodeListType>
-Element* LiveNodeListBase::traverseMatchingElementsBackwardToOffset(const NodeListType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffset)
+template <typename MatchFunc>
+Element* LiveNodeListBase::traverseMatchingElementsBackwardToOffset(Element& currentElement, const ContainerNode* stayWithin, unsigned offset, unsigned& currentOffset, MatchFunc isMatch)
{
ASSERT(currentOffset > offset);
- for (Element* previous = previousMatchingElement(nodeList, currentElement); previous; previous = previousMatchingElement(nodeList, *previous)) {
+ for (Element* previous = ElementTraversal::previous(currentElement, stayWithin, isMatch); previous; previous = ElementTraversal::previous(*previous, stayWithin, isMatch)) {
if (--currentOffset == offset)
return previous;
}
« no previous file with comments | « Source/core/dom/LiveNodeList.cpp ('k') | Source/core/html/HTMLCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698