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

Unified Diff: Source/core/dom/shadow/ComposedTreeTraversal.cpp

Issue 1308063008: Introduce ComposedTreeTraversal::previousPostOrder() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-09T16:39:28 Created 5 years, 3 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
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);
« no previous file with comments | « Source/core/dom/shadow/ComposedTreeTraversal.h ('k') | Source/core/dom/shadow/ComposedTreeTraversalTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698