Index: Source/core/dom/shadow/ComposedTreeTraversal.cpp |
diff --git a/Source/core/dom/shadow/ComposedTreeTraversal.cpp b/Source/core/dom/shadow/ComposedTreeTraversal.cpp |
index 0638446807433a64423e28eaba265caf8db8805b..f857d81122d12d1f4806593f7bab481ac2c5db20 100644 |
--- a/Source/core/dom/shadow/ComposedTreeTraversal.cpp |
+++ b/Source/core/dom/shadow/ComposedTreeTraversal.cpp |
@@ -191,6 +191,38 @@ Node* ComposedTreeTraversal::previousSkippingChildren(const Node& node) |
return traversePreviousAncestorSibling(node); |
} |
+static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* stayWithin) |
+{ |
+ ASSERT(!ComposedTreeTraversal::previousSibling(current)); |
+ for (Node* parent = ComposedTreeTraversal::parent(current); parent; parent = ComposedTreeTraversal::parent(*parent)) { |
+ if (parent == stayWithin) |
+ return nullptr; |
+ if (Node* previousSibling = ComposedTreeTraversal::previousSibling(*parent)) |
+ return previousSibling; |
+ } |
+ return nullptr; |
+} |
+ |
+// TODO(yosin) We should consider introducing template class to share code |
+// between DOM tree traversal and composed tree tarversal. |
+Node* ComposedTreeTraversal::previousPostOrder(const Node& current, const Node* stayWithin) |
+{ |
+ assertPrecondition(current); |
+ if (stayWithin) |
+ assertPrecondition(*stayWithin); |
+ if (Node* lastChild = traverseLastChild(current)) { |
+ assertPostcondition(lastChild); |
+ return lastChild; |
+ } |
+ if (current == stayWithin) |
+ return nullptr; |
+ if (Node* previousSibling = traversePreviousSibling(current)) { |
+ assertPostcondition(previousSibling); |
+ return previousSibling; |
+ } |
+ return previousAncestorSiblingPostOrder(current, stayWithin); |
+} |
+ |
bool ComposedTreeTraversal::isDescendantOf(const Node& node, const Node& other) |
{ |
assertPrecondition(node); |