Chromium Code Reviews| Index: Source/core/html/HTMLFormElement.cpp |
| diff --git a/Source/core/html/HTMLFormElement.cpp b/Source/core/html/HTMLFormElement.cpp |
| index 80e639c76fa517f94a3ec3bdaa01b0f5b25cca09..2e5a830bd72ffd1c5477c9f9c3fa14a17d5b2279 100644 |
| --- a/Source/core/html/HTMLFormElement.cpp |
| +++ b/Source/core/html/HTMLFormElement.cpp |
| @@ -273,23 +273,15 @@ static inline HTMLFormControlElement* submitElementFromEvent(const Event* event) |
| return 0; |
| } |
| -bool HTMLFormElement::validateInteractively(Event* event) |
| +bool HTMLFormElement::validateInteractively() |
| { |
| - ASSERT(event); |
| - if (!document().page() || noValidate()) |
| - return true; |
| - |
| - HTMLFormControlElement* submitElement = submitElementFromEvent(event); |
| - if (submitElement && submitElement->formNoValidate()) |
| - return true; |
| - |
| const FormAssociatedElement::List& elements = associatedElements(); |
| for (unsigned i = 0; i < elements.size(); ++i) { |
| if (elements[i]->isFormControlElement()) |
| toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage(); |
| } |
| - WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvalidControls; |
| + WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement> > unhandledInvalidControls; |
| if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls, CheckValidityDispatchInvalidEvent)) |
| return true; |
| // Because the form has invalid controls, we abort the form submission and |
| @@ -302,25 +294,18 @@ bool HTMLFormElement::validateInteractively(Event* event) |
| RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
| // Focus on the first focusable control and show a validation message. |
| for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { |
| - FormAssociatedElement* unhandledAssociatedElement = unhandledInvalidControls[i].get(); |
| - HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); |
| - if (unhandled->isFocusable() && unhandled->inDocument()) { |
| - unhandled->scrollIntoViewIfNeeded(false); |
| - unhandled->focus(); |
| - if (unhandled->isFormControlElement()) |
| - toHTMLFormControlElement(unhandled)->updateVisibleValidationMessage(); |
| + HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get(); |
| + if (unhandled->showValidationMessage()) |
| break; |
| - } |
| } |
| // Warn about all of unfocusable controls. |
| if (document().frame()) { |
| for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { |
| - FormAssociatedElement* unhandledAssociatedElement = unhandledInvalidControls[i].get(); |
| - HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); |
| + HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get(); |
| if (unhandled->isFocusable() && unhandled->inDocument()) |
| continue; |
| String message("An invalid form control with name='%name' is not focusable."); |
| - message.replace("%name", unhandledAssociatedElement->name()); |
| + message.replace("%name", unhandled->name()); |
| document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSource, ErrorMessageLevel, message)); |
| } |
| } |
| @@ -334,8 +319,14 @@ void HTMLFormElement::prepareForSubmission(Event* event) |
| if (!frame || m_isSubmittingOrInUserJSSubmitEvent) |
| return; |
| + bool skipValidation = !document().page() || noValidate(); |
| + ASSERT(event); |
| + HTMLFormControlElement* submitElement = submitElementFromEvent(event); |
| + if (submitElement && submitElement->formNoValidate()) |
| + skipValidation = true; |
| + |
| // Interactive validation must be done before dispatching the submit event. |
| - if (!validateInteractively(event)) |
| + if (!skipValidation && !validateInteractively()) |
| return; |
| m_isSubmittingOrInUserJSSubmitEvent = true; |
| @@ -736,7 +727,7 @@ bool HTMLFormElement::checkValidity() |
| return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInvalidEvent); |
| } |
| -bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls, CheckValidityEventBehavior eventBehavior) |
| +bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement> >* unhandledInvalidControls, CheckValidityEventBehavior eventBehavior) |
| { |
| RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
| // Copy associatedElements because event handlers called from |
| @@ -757,6 +748,11 @@ bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R |
| return hasInvalidControls; |
| } |
| +bool HTMLFormElement::reportValidity() |
| +{ |
| + return validateInteractively(); |
|
tkent
2014/10/22 01:14:15
I checked the specification, and confirmed we need
Bartek Nowierski
2014/10/22 04:56:43
Acknowledged.
|
| +} |
| + |
| Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) |
| { |
| if (pastName.isEmpty() || !m_pastNamesMap) |