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

Unified Diff: Source/core/html/HTMLFormControlElement.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/HTMLFormControlElement.h ('k') | Source/core/html/HTMLFormElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLFormControlElement.cpp
diff --git a/Source/core/html/HTMLFormControlElement.cpp b/Source/core/html/HTMLFormControlElement.cpp
index e68ef591c249e14d48f2e2c46acd21bf7c96fe0b..75f2402d2c782128eb57e2c5c92b7f9adfe90112 100644
--- a/Source/core/html/HTMLFormControlElement.cpp
+++ b/Source/core/html/HTMLFormControlElement.cpp
@@ -502,7 +502,7 @@ ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const
return &page->validationMessageClient();
}
-bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls, CheckValidityEventBehavior eventBehavior)
+bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement> >* unhandledInvalidControls, CheckValidityEventBehavior eventBehavior)
{
if (!willValidate() || isValidElement())
return true;
@@ -517,6 +517,37 @@ bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F
return false;
}
+void HTMLFormControlElement::showValidationMessage()
+{
+ scrollIntoViewIfNeeded(false);
+ RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this);
+ focus();
+ updateVisibleValidationMessage();
+}
+
+bool HTMLFormControlElement::reportValidity()
+{
+ WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement> > unhandledInvalidControls;
+ bool isValid = checkValidity(&unhandledInvalidControls, CheckValidityDispatchInvalidEvent);
+ if (isValid || unhandledInvalidControls.isEmpty())
+ return isValid;
+ ASSERT(unhandledInvalidControls.size() == 1);
+ ASSERT(unhandledInvalidControls[0].get() == this);
+ // Update layout now before calling isFocusable(), which has
+ // !renderer()->needsLayout() assertion.
+ document().updateLayoutIgnorePendingStylesheets();
+ if (isFocusable()) {
+ showValidationMessage();
+ return false;
+ }
+ if (document().frame()) {
+ String message("An invalid form control with name='%name' is not focusable.");
+ message.replace("%name", name());
+ document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSource, ErrorMessageLevel, message));
+ }
+ return false;
+}
+
bool HTMLFormControlElement::matchesValidityPseudoClasses() const
{
return willValidate();
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/HTMLFormElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698