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); |