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

Unified Diff: Source/core/dom/ElementTraversal.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 | « no previous file | Source/core/dom/LiveNodeList.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ElementTraversal.h
diff --git a/Source/core/dom/ElementTraversal.h b/Source/core/dom/ElementTraversal.h
index 99de80b26254a9585993d91efa30e394a3c88747..c5a39068ce5c6abc6801fbee57fdc919c7cd1865 100644
--- a/Source/core/dom/ElementTraversal.h
+++ b/Source/core/dom/ElementTraversal.h
@@ -37,8 +37,12 @@ public:
// First or last ElementType child of the node.
static ElementType* firstChild(const ContainerNode& current) { return firstChildTemplate(current); }
static ElementType* firstChild(const Node& current) { return firstChildTemplate(current); }
+ template <class MatchFunc>
+ static ElementType* firstChild(const ContainerNode&, MatchFunc);
static ElementType* lastChild(const ContainerNode& current) { return lastChildTemplate(current); }
static ElementType* lastChild(const Node& current) { return lastChildTemplate(current); }
+ template <class MatchFunc>
+ static ElementType* lastChild(const ContainerNode&, MatchFunc);
// First ElementType ancestor of the node.
static ElementType* firstAncestor(const Node& current);
@@ -51,16 +55,24 @@ public:
// For Elements firstWithin() is always the same as firstChild().
static ElementType* firstWithin(const ContainerNode& current) { return firstWithinTemplate(current); }
static ElementType* firstWithin(const Node& current) { return firstWithinTemplate(current); }
+ template <typename MatchFunc>
+ static ElementType* firstWithin(const ContainerNode&, MatchFunc);
static ElementType* lastWithin(const ContainerNode& current) { return lastWithinTemplate(current); }
static ElementType* lastWithin(const Node& current) { return lastWithinTemplate(current); }
+ template <class MatchFunc>
+ static ElementType* lastWithin(const ContainerNode&, MatchFunc);
// Pre-order traversal skipping non-element nodes.
static ElementType* next(const ContainerNode& current) { return nextTemplate(current); }
static ElementType* next(const Node& current) { return nextTemplate(current); }
static ElementType* next(const ContainerNode& current, const Node* stayWithin) { return nextTemplate(current, stayWithin); }
static ElementType* next(const Node& current, const Node* stayWithin) { return nextTemplate(current, stayWithin); }
+ template <class MatchFunc>
+ static ElementType* next(const ContainerNode& current, const Node* stayWithin, MatchFunc);
static ElementType* previous(const Node&);
static ElementType* previous(const Node&, const Node* stayWithin);
+ template <class MatchFunc>
+ static ElementType* previous(const ContainerNode& current, const Node* stayWithin, MatchFunc);
// Like next, but skips children.
static ElementType* nextSkippingChildren(const Node&);
@@ -76,7 +88,11 @@ public:
// Previous / Next sibling.
static ElementType* previousSibling(const Node&);
+ template <class MatchFunc>
+ static ElementType* previousSibling(const Node&, MatchFunc);
static ElementType* nextSibling(const Node&);
+ template <class MatchFunc>
+ static ElementType* nextSibling(const Node&, MatchFunc);
private:
template <class NodeType>
@@ -137,6 +153,16 @@ inline ElementType* Traversal<ElementType>::firstChildTemplate(NodeType& current
}
template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::firstChild(const ContainerNode& current, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::firstChild(current);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::nextSibling(*element);
+ return element;
+}
+
+template <class ElementType>
inline ElementType* Traversal<ElementType>::firstAncestor(const Node& current)
{
ContainerNode* ancestor = current.parentNode();
@@ -165,6 +191,16 @@ inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current)
}
template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::lastChild(const ContainerNode& current, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::lastChild(current);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::previousSibling(*element);
+ return element;
+}
+
+template <class ElementType>
template <class NodeType>
inline ElementType* Traversal<ElementType>::firstWithinTemplate(NodeType& current)
{
@@ -175,6 +211,16 @@ inline ElementType* Traversal<ElementType>::firstWithinTemplate(NodeType& curren
}
template <class ElementType>
+template <typename MatchFunc>
+inline ElementType* Traversal<ElementType>::firstWithin(const ContainerNode& current, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::firstWithin(current);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::next(*element, &current, isMatch);
+ return element;
+}
+
+template <class ElementType>
template <class NodeType>
inline ElementType* Traversal<ElementType>::lastWithinTemplate(NodeType& current)
{
@@ -185,6 +231,16 @@ inline ElementType* Traversal<ElementType>::lastWithinTemplate(NodeType& current
}
template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::lastWithin(const ContainerNode& current, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::lastWithin(current);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::previous(*element, &current, isMatch);
+ return element;
+}
+
+template <class ElementType>
template <class NodeType>
inline ElementType* Traversal<ElementType>::nextTemplate(NodeType& current)
{
@@ -205,6 +261,16 @@ inline ElementType* Traversal<ElementType>::nextTemplate(NodeType& current, cons
}
template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::next(const ContainerNode& current, const Node* stayWithin, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::next(current, stayWithin);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::next(*element, stayWithin);
+ return element;
+}
+
+template <class ElementType>
inline ElementType* Traversal<ElementType>::previous(const Node& current)
{
Node* node = NodeTraversal::previous(current);
@@ -223,6 +289,16 @@ inline ElementType* Traversal<ElementType>::previous(const Node& current, const
}
template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::previous(const ContainerNode& current, const Node* stayWithin, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::previous(current, stayWithin);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::previous(*element, stayWithin);
+ return element;
+}
+
+template <class ElementType>
inline ElementType* Traversal<ElementType>::nextSkippingChildren(const Node& current)
{
Node* node = NodeTraversal::nextSkippingChildren(current);
@@ -286,6 +362,16 @@ inline ElementType* Traversal<ElementType>::previousSibling(const Node& current)
}
template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::previousSibling(const Node& current, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::previousSibling(current);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::previousSibling(*element);
+ return element;
+}
+
+template <class ElementType>
inline ElementType* Traversal<ElementType>::nextSibling(const Node& current)
{
Node* node = current.nextSibling();
@@ -294,6 +380,16 @@ inline ElementType* Traversal<ElementType>::nextSibling(const Node& current)
return toElement<ElementType>(node);
}
+template <class ElementType>
+template <class MatchFunc>
+inline ElementType* Traversal<ElementType>::nextSibling(const Node& current, MatchFunc isMatch)
+{
+ ElementType* element = Traversal<ElementType>::nextSibling(current);
+ while (element && !isMatch(*element))
+ element = Traversal<ElementType>::nextSibling(*element);
+ return element;
+}
+
} // namespace blink
#endif
« no previous file with comments | « no previous file | Source/core/dom/LiveNodeList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698