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

Unified Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 1932523003: Introduce NodeTraversal::ancestorsOf() and inclusiveAncestors() for range-based for loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-28T18:38:12 Created 4 years, 8 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: third_party/WebKit/Source/core/dom/Range.cpp
diff --git a/third_party/WebKit/Source/core/dom/Range.cpp b/third_party/WebKit/Source/core/dom/Range.cpp
index 9fd0d868fca088ed527d147653961b2f3b649b1c..b662e2bbdc9d43968c99f0126332ed0825b854e1 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -655,8 +655,11 @@ Node* Range::processAncestorsAndTheirSiblings(ActionType action, Node* container
typedef HeapVector<Member<Node>> NodeVector;
NodeVector ancestors;
- for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n->parentNode())
- ancestors.append(n);
+ for (Node& runner : NodeTraversal::ancestorsOf(*container)) {
+ if (runner == commonRoot)
+ break;
+ ancestors.append(runner);
+ }
Node* firstChildInAncestorToProcess = direction == ProcessContentsForward ? container->nextSibling() : container->previousSibling();
for (const auto& ancestor : ancestors) {
@@ -766,8 +769,8 @@ void Range::insertNode(Node* newNode, ExceptionState& exceptionState)
}
}
- for (Node* n = m_start.container(); n; n = n->parentNode()) {
- if (n == newNode) {
+ for (Node& node : NodeTraversal::inclusiveAncestorsOf(*m_start.container())) {
+ if (node == newNode) {
exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted contains the insertion point; it may not be inserted into itself.");
return;
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/NodeTraversal.cpp ('k') | third_party/WebKit/Source/core/editing/EditingStyle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698