Index: Source/core/dom/Position.cpp |
diff --git a/Source/core/dom/Position.cpp b/Source/core/dom/Position.cpp |
index 63fb25c95d51ace7c8bec00fa511bd12260750d0..f7bb399d42f1febe46e0eb0341114cf0d6e2a285 100644 |
--- a/Source/core/dom/Position.cpp |
+++ b/Source/core/dom/Position.cpp |
@@ -278,10 +278,10 @@ Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo |
// FIXME: This method is confusing (does it return anchorNode() or containerNode()?) and should be renamed or removed |
Element* Position::element() const |
{ |
- Node* n = anchorNode(); |
- while (n && !n->isElementNode()) |
- n = n->parentNode(); |
- return toElement(n); |
+ Node* node = anchorNode(); |
+ if (!node || node->isElementNode()) |
+ return toElement(node); |
+ return node->parentElement(); |
} |
PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> Position::computedStyle() const |