| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 RenderObject* previousSiblingRenderer(const Node* node) | 131 RenderObject* previousSiblingRenderer(const Node* node) |
| 132 { | 132 { |
| 133 for (Node* sibling = NodeRenderingTraversal::previousSibling(node); sibling;
sibling = NodeRenderingTraversal::previousSibling(sibling)) { | 133 for (Node* sibling = NodeRenderingTraversal::previousSibling(node); sibling;
sibling = NodeRenderingTraversal::previousSibling(sibling)) { |
| 134 if (RenderObject* renderer = sibling->renderer()) | 134 if (RenderObject* renderer = sibling->renderer()) |
| 135 return renderer; | 135 return renderer; |
| 136 } | 136 } |
| 137 return 0; | 137 return 0; |
| 138 } | 138 } |
| 139 | 139 |
| 140 Node* commonAncestor(Node& a, Node& b) |
| 141 { |
| 142 if (a == b) |
| 143 return &a; |
| 144 if (a.document() != b.document()) |
| 145 return 0; |
| 146 int thisDepth = 0; |
| 147 for (Node* node = &a; node; node = parent(node)) { |
| 148 if (node == b) |
| 149 return node; |
| 150 thisDepth++; |
| 151 } |
| 152 int otherDepth = 0; |
| 153 for (const Node* node = &b; node; node = parent(node)) { |
| 154 if (node == a) |
| 155 return &a; |
| 156 otherDepth++; |
| 157 } |
| 158 Node* thisIterator = &a; |
| 159 const Node* otherIterator = &b; |
| 160 if (thisDepth > otherDepth) { |
| 161 for (int i = thisDepth; i > otherDepth; --i) |
| 162 thisIterator = parent(thisIterator); |
| 163 } else if (otherDepth > thisDepth) { |
| 164 for (int i = otherDepth; i > thisDepth; --i) |
| 165 otherIterator = parent(otherIterator); |
| 166 } |
| 167 while (thisIterator) { |
| 168 if (thisIterator == otherIterator) |
| 169 return thisIterator; |
| 170 thisIterator = parent(thisIterator); |
| 171 otherIterator = parent(otherIterator); |
| 172 } |
| 173 ASSERT(!otherIterator); |
| 174 return 0; |
| 175 } |
| 176 |
| 140 } | 177 } |
| 141 | 178 |
| 142 } // namespace | 179 } // namespace |
| OLD | NEW |