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

Unified Diff: third_party/WebKit/Source/core/editing/commands/FormatBlockCommand.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/editing/commands/FormatBlockCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/FormatBlockCommand.cpp b/third_party/WebKit/Source/core/editing/commands/FormatBlockCommand.cpp
index 92195e87d13240e3597cf17b5a4896bcc494ecc3..cf92fefad19f1c4bf5e4f2b0da5ef1f402765da1 100644
--- a/third_party/WebKit/Source/core/editing/commands/FormatBlockCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/FormatBlockCommand.cpp
@@ -163,16 +163,17 @@ bool isElementForFormatBlock(const QualifiedName& tagName)
Node* enclosingBlockToSplitTreeTo(Node* startNode)
{
+ DCHECK(startNode);
Node* lastBlock = startNode;
- for (Node* n = startNode; n; n = n->parentNode()) {
- if (!n->hasEditableStyle())
+ for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*startNode)) {
+ if (!runner.hasEditableStyle())
return lastBlock;
- if (isTableCell(n) || isHTMLBodyElement(*n) || !n->parentNode() || !n->parentNode()->hasEditableStyle() || isElementForFormatBlock(n))
- return n;
- if (isEnclosingBlock(n))
- lastBlock = n;
- if (isHTMLListElement(n))
- return n->parentNode()->hasEditableStyle() ? n->parentNode() : n;
+ if (isTableCell(&runner) || isHTMLBodyElement(&runner) || !runner.parentNode() || !runner.parentNode()->hasEditableStyle() || isElementForFormatBlock(&runner))
+ return &runner;
+ if (isEnclosingBlock(&runner))
+ lastBlock = &runner;
+ if (isHTMLListElement(&runner))
+ return runner.parentNode()->hasEditableStyle() ? runner.parentNode() : &runner;
}
return lastBlock;
}

Powered by Google App Engine
This is Rietveld 408576698