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

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: Add firstAncestorOrSelf() 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
« no previous file with comments | « Source/core/dom/ElementTraversal.h ('k') | Source/core/html/HTMLElement.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/FrameSelection.cpp
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
index f765bad62803e38aa94f4bd3333a15ad4ddc878f..bdbd6665c8e5dae3984333ed050da15e41c3adb5 100644
--- a/Source/core/editing/FrameSelection.cpp
+++ b/Source/core/editing/FrameSelection.cpp
@@ -1720,18 +1720,23 @@ FloatRect FrameSelection::bounds(bool clipToVisibleContent) const
return clipToVisibleContent ? intersection(selectionRect, view->visibleContentRect()) : selectionRect;
}
+static inline HTMLFormElement* associatedFormElement(HTMLElement& element)
+{
+ if (isHTMLFormElement(element))
+ return &toHTMLFormElement(element);
+ return element.formOwner();
+}
+
// Scans logically forward from "start", including any child frames.
static HTMLFormElement* scanForForm(Node* start)
{
if (!start)
return 0;
+
HTMLElement* element = start->isHTMLElement() ? toHTMLElement(start) : Traversal<HTMLElement>::next(*start);
for (; element; element = Traversal<HTMLElement>::next(*element)) {
- if (isHTMLFormElement(*element))
- return toHTMLFormElement(element);
-
- if (HTMLFormElement* owner = element->formOwner())
- return owner;
+ if (HTMLFormElement* form = associatedFormElement(*element))
+ return form;
if (isHTMLFrameElementBase(*element)) {
Node* childDocument = toHTMLFrameElementBase(*element).contentDocument();
@@ -1749,17 +1754,13 @@ HTMLFormElement* FrameSelection::currentForm() const
Node* start = m_frame->document()->focusedElement();
if (!start)
start = this->start().deprecatedNode();
+ if (!start)
+ return 0;
// 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;
- }
+ for (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*start); element; element = Traversal<HTMLElement>::firstAncestor(*element)) {
+ if (HTMLFormElement* form = associatedFormElement(*element))
+ return form;
}
// Try walking forward in the node tree to find a form element.
« no previous file with comments | « Source/core/dom/ElementTraversal.h ('k') | Source/core/html/HTMLElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698