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

Unified Diff: Source/core/editing/FrameSelection.cpp

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Slight clean up Created 6 years, 9 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: Source/core/editing/FrameSelection.cpp
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
index 0c6083da2dbe8c3e0c54be10ef36358e84826cc6..ccf5d819810d8996ec86a9d5ca8a3fb0ab2bee86 100644
--- a/Source/core/editing/FrameSelection.cpp
+++ b/Source/core/editing/FrameSelection.cpp
@@ -1751,15 +1751,12 @@ HTMLFormElement* FrameSelection::currentForm() const
start = this->start().deprecatedNode();
// Try walking up the node tree to find a form element.
- Node* node;
- for (node = start; node; node = node->parentNode()) {
- if (isHTMLFormElement(*node))
- return toHTMLFormElement(node);
- if (node->isHTMLElement()) {
- HTMLFormElement* owner = toHTMLElement(node)->formOwner();
- if (owner)
- return owner;
- }
+ HTMLElement* element = !start || start->isHTMLElement() ? toHTMLElement(start) : Traversal<HTMLElement>::firstAncestor(*start);
esprehn 2014/03/21 07:58:33 This seems like it makes the code less readable.
Inactive 2014/03/21 14:37:24 Fair enough, I gave it another shot.
+ for (; element; element = Traversal<HTMLElement>::firstAncestor(*element)) {
+ if (isHTMLFormElement(*element))
+ return toHTMLFormElement(element);
+ if (HTMLFormElement* owner = element->formOwner())
+ return owner;
}
// Try walking forward in the node tree to find a form element.

Powered by Google App Engine
This is Rietveld 408576698