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

Unified Diff: third_party/WebKit/Source/core/editing/EditingUtilities.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/EditingUtilities.cpp
diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
index bdfadf91e7e879e8979ea1e9a80befa2227020fc..3c2340e321369b119cd5fb6eb6c05924cdac5b2f 100644
--- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
+++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
@@ -773,9 +773,9 @@ Element* enclosingBlockFlowElement(const Node& node)
if (isBlockFlowElement(node))
return const_cast<Element*>(&toElement(node));
- for (Node* n = node.parentNode(); n; n = n->parentNode()) {
- if (isBlockFlowElement(*n) || isHTMLBodyElement(*n))
- return toElement(n);
+ for (Node& runner : NodeTraversal::ancestorsOf(node)) {
+ if (isBlockFlowElement(runner) || isHTMLBodyElement(runner))
+ return toElement(&runner);
}
return nullptr;
}
@@ -886,9 +886,11 @@ static bool isSpecialHTMLElement(const Node& n)
static HTMLElement* firstInSpecialElement(const Position& pos)
{
Element* rootEditableElement = pos.computeContainerNode()->rootEditableElement();
- for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode()) {
- if (isSpecialHTMLElement(*n)) {
- HTMLElement* specialElement = toHTMLElement(n);
+ for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*pos.anchorNode())) {
+ if (runner.rootEditableElement() != rootEditableElement)
+ break;
+ if (isSpecialHTMLElement(runner)) {
+ HTMLElement* specialElement = toHTMLElement(&runner);
VisiblePosition vPos = createVisiblePosition(pos);
VisiblePosition firstInElement = createVisiblePosition(firstPositionInOrBeforeNode(specialElement));
if (isDisplayInsideTable(specialElement) && vPos.deepEquivalent() == nextPositionOf(firstInElement).deepEquivalent())
@@ -903,9 +905,11 @@ static HTMLElement* firstInSpecialElement(const Position& pos)
static HTMLElement* lastInSpecialElement(const Position& pos)
{
Element* rootEditableElement = pos.computeContainerNode()->rootEditableElement();
- for (Node* n = pos.anchorNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode()) {
- if (isSpecialHTMLElement(*n)) {
- HTMLElement* specialElement = toHTMLElement(n);
+ for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*pos.anchorNode())) {
+ if (runner.rootEditableElement() != rootEditableElement)
+ break;
+ if (isSpecialHTMLElement(runner)) {
+ HTMLElement* specialElement = toHTMLElement(&runner);
VisiblePosition vPos = createVisiblePosition(pos);
VisiblePosition lastInElement = createVisiblePosition(lastPositionInOrAfterNode(specialElement));
if (isDisplayInsideTable(specialElement) && vPos.deepEquivalent() == previousPositionOf(lastInElement).deepEquivalent())
@@ -1178,10 +1182,10 @@ HTMLElement* enclosingList(Node* node)
ContainerNode* root = highestEditableRoot(firstPositionInOrBeforeNode(node));
- for (ContainerNode* n = node->parentNode(); n; n = n->parentNode()) {
- if (isHTMLUListElement(*n) || isHTMLOListElement(*n))
- return toHTMLElement(n);
- if (n == root)
+ for (Node& runner : NodeTraversal::ancestorsOf(*node)) {
+ if (isHTMLUListElement(runner) || isHTMLOListElement(runner))
+ return toHTMLElement(&runner);
+ if (runner == root)
return 0;
}

Powered by Google App Engine
This is Rietveld 408576698