Index: third_party/WebKit/Source/core/html/HTMLFormElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLFormElement.cpp b/third_party/WebKit/Source/core/html/HTMLFormElement.cpp |
index 6e0639b6ceef796b13321feaab62e9f7bd4f9469..ad9d90724c81b50af19a4532bd10fbd647dab4df 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLFormElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLFormElement.cpp |
@@ -235,17 +235,7 @@ void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission |
} |
} |
if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) |
- prepareForSubmission(event); |
-} |
- |
-// FIXME: Consolidate this and similar code in FormSubmission.cpp. |
-static inline HTMLFormControlElement* submitElementFromEvent(const Event* event) |
-{ |
- for (Node* node = event->target()->toNode(); node; node = node->parentOrShadowHostNode()) { |
- if (node->isElementNode() && toElement(node)->isFormControlElement()) |
- return toHTMLFormControlElement(node); |
- } |
- return 0; |
+ prepareForSubmission(event, nullptr); |
} |
bool HTMLFormElement::validateInteractively() |
@@ -291,7 +281,7 @@ bool HTMLFormElement::validateInteractively() |
return false; |
} |
-void HTMLFormElement::prepareForSubmission(Event* event) |
+void HTMLFormElement::prepareForSubmission(Event* event, HTMLFormControlElement* submitButton) |
{ |
LocalFrame* frame = document().frame(); |
if (!frame || m_isSubmitting || m_inUserJSSubmitEvent) |
@@ -304,8 +294,7 @@ void HTMLFormElement::prepareForSubmission(Event* event) |
bool skipValidation = !document().page() || noValidate(); |
DCHECK(event); |
- HTMLFormControlElement* submitElement = submitElementFromEvent(event); |
- if (submitElement && submitElement->formNoValidate()) |
+ if (submitButton && submitButton->formNoValidate()) |
skipValidation = true; |
UseCounter::count(document(), UseCounter::FormSubmissionStarted); |
@@ -321,7 +310,7 @@ void HTMLFormElement::prepareForSubmission(Event* event) |
} |
if (shouldSubmit) { |
m_plannedNavigation = nullptr; |
- submit(event, true); |
+ submit(event, submitButton); |
} |
if (!m_plannedNavigation) |
return; |
@@ -332,7 +321,7 @@ void HTMLFormElement::prepareForSubmission(Event* event) |
void HTMLFormElement::submitFromJavaScript() |
{ |
- submit(0, false); |
+ submit(nullptr, nullptr); |
} |
void HTMLFormElement::submitDialog(FormSubmission* formSubmission) |
@@ -345,7 +334,7 @@ void HTMLFormElement::submitDialog(FormSubmission* formSubmission) |
} |
} |
-void HTMLFormElement::submit(Event* event, bool activateSubmitButton) |
+void HTMLFormElement::submit(Event* event, HTMLFormControlElement* submitButton) |
{ |
FrameView* view = document().view(); |
LocalFrame* frame = document().frame(); |
@@ -366,27 +355,24 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton) |
EventQueueScope scopeForDialogClose; |
AutoReset<bool> submitScope(&m_isSubmitting, true); |
- HTMLFormControlElement* firstSuccessfulSubmitButton = nullptr; |
- bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button? |
- |
- const FormAssociatedElement::List& elements = associatedElements(); |
- for (unsigned i = 0; i < elements.size(); ++i) { |
- FormAssociatedElement* associatedElement = elements[i]; |
- if (!associatedElement->isFormControlElement()) |
- continue; |
- if (needButtonActivation) { |
+ if (event && !submitButton) { |
+ // In a case of implicit submission without a submit button, 'submit' |
+ // event handler might add a submit button. We search for a submit |
+ // button again. |
+ // TODO(tkent): Do we really need to activate such submit button? |
+ for (const auto& associatedElement : associatedElements()) { |
+ if (!associatedElement->isFormControlElement()) |
+ continue; |
HTMLFormControlElement* control = toHTMLFormControlElement(associatedElement); |
- if (control->isActivatedSubmit()) |
- needButtonActivation = false; |
- else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSubmitButton()) |
- firstSuccessfulSubmitButton = control; |
+ DCHECK(!control->isActivatedSubmit()); |
+ if (control->isSuccessfulSubmitButton()) { |
+ submitButton = control; |
+ break; |
+ } |
} |
} |
- if (needButtonActivation && firstSuccessfulSubmitButton) |
- firstSuccessfulSubmitButton->setActivatedSubmit(true); |
- |
- FormSubmission* formSubmission = FormSubmission::create(this, m_attributes, event); |
+ FormSubmission* formSubmission = FormSubmission::create(this, m_attributes, event, submitButton); |
if (formSubmission->method() == FormSubmission::DialogMethod) { |
submitDialog(formSubmission); |
} else if (m_inUserJSSubmitEvent) { |
@@ -398,9 +384,6 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton) |
// protocol. |
scheduleFormSubmission(formSubmission); |
} |
- |
- if (needButtonActivation && firstSuccessfulSubmitButton) |
- firstSuccessfulSubmitButton->setActivatedSubmit(false); |
} |
void HTMLFormElement::scheduleFormSubmission(FormSubmission* submission) |