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

Unified Diff: Source/core/html/HTMLFormElement.cpp

Issue 660783002: Implement reportValidity() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Apply couple more tkent's comments + pull Created 6 years, 2 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/html/HTMLFormElement.h ('k') | Source/core/html/HTMLFormElement.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLFormElement.cpp
diff --git a/Source/core/html/HTMLFormElement.cpp b/Source/core/html/HTMLFormElement.cpp
index 80e639c76fa517f94a3ec3bdaa01b0f5b25cca09..64e97f6e786d763b1f5d4e3d33b0389db352ee63 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,20 @@ 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->isFocusable()) {
+ 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);
- if (unhandled->isFocusable() && unhandled->inDocument())
+ HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get();
+ if (unhandled->isFocusable())
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 +321,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 +729,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 +750,11 @@ bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
return hasInvalidControls;
}
+bool HTMLFormElement::reportValidity()
+{
+ return validateInteractively();
+}
+
Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName)
{
if (pastName.isEmpty() || !m_pastNamesMap)
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | Source/core/html/HTMLFormElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698