| 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.
|
|
|