| Index: sky/engine/core/dom/NodeRenderingTraversal.cpp
|
| diff --git a/sky/engine/core/dom/NodeRenderingTraversal.cpp b/sky/engine/core/dom/NodeRenderingTraversal.cpp
|
| index 1b2fe5ff4c0985188b93467e6b7febc982cfdfb2..b1dda328f31df8cf35b95708ab95852f31455d1f 100644
|
| --- a/sky/engine/core/dom/NodeRenderingTraversal.cpp
|
| +++ b/sky/engine/core/dom/NodeRenderingTraversal.cpp
|
| @@ -137,6 +137,43 @@ RenderObject* previousSiblingRenderer(const Node* node)
|
| return 0;
|
| }
|
|
|
| +Node* commonAncestor(Node& a, Node& b)
|
| +{
|
| + if (a == b)
|
| + return &a;
|
| + if (a.document() != b.document())
|
| + return 0;
|
| + int thisDepth = 0;
|
| + for (Node* node = &a; node; node = parent(node)) {
|
| + if (node == b)
|
| + return node;
|
| + thisDepth++;
|
| + }
|
| + int otherDepth = 0;
|
| + for (const Node* node = &b; node; node = parent(node)) {
|
| + if (node == a)
|
| + return &a;
|
| + otherDepth++;
|
| + }
|
| + Node* thisIterator = &a;
|
| + const Node* otherIterator = &b;
|
| + if (thisDepth > otherDepth) {
|
| + for (int i = thisDepth; i > otherDepth; --i)
|
| + thisIterator = parent(thisIterator);
|
| + } else if (otherDepth > thisDepth) {
|
| + for (int i = otherDepth; i > thisDepth; --i)
|
| + otherIterator = parent(otherIterator);
|
| + }
|
| + while (thisIterator) {
|
| + if (thisIterator == otherIterator)
|
| + return thisIterator;
|
| + thisIterator = parent(thisIterator);
|
| + otherIterator = parent(otherIterator);
|
| + }
|
| + ASSERT(!otherIterator);
|
| + return 0;
|
| +}
|
| +
|
| }
|
|
|
| } // namespace
|
|
|