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

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

Issue 166573003: Port ParentNode API to ElementTraversal (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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/Element.cpp ('k') | Source/core/dom/ParentNode.h » ('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 4235e80d45b0ab0f15809a3a2ba5a98f57dc1c13..d040468c89b42152fba2038e385dc6aafb891fd2 100644
--- a/Source/core/dom/ElementTraversal.h
+++ b/Source/core/dom/ElementTraversal.h
@@ -32,9 +32,11 @@ namespace WebCore {
namespace ElementTraversal {
-// First element child of the node.
+// First / Last element child of the node.
Element* firstWithin(const Node&);
Element* firstWithin(const ContainerNode&);
+Element* lastWithin(const Node&);
+Element* lastWithin(const ContainerNode&);
// Pre-order traversal skipping non-element nodes.
Element* next(const Node&);
@@ -72,6 +74,17 @@ inline Element* firstWithin(const ContainerNode& current) { return firstElementW
inline Element* firstWithin(const Node& current) { return firstElementWithinTemplate(current); }
template <class NodeType>
+inline Element* lastWithinTemplate(NodeType& current)
+{
+ Node* node = current.lastChild();
+ while (node && !node->isElementNode())
+ node = node->previousSibling();
+ return toElement(node);
+}
+inline Element* lastWithin(const ContainerNode& current) { return lastWithinTemplate(current); }
+inline Element* lastWithin(const Node& current) { return lastWithinTemplate(current); }
+
+template <class NodeType>
inline Element* traverseNextElementTemplate(NodeType& current)
{
Node* node = NodeTraversal::next(current);
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ParentNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698