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

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

Issue 365223004: Have the form control element directly handle validation message updating. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move m_hasValidationMessage checks out from validationMessageClient() Created 6 years, 5 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/forms/ValidationMessage.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 d3d3b22cbcb4d91167b83e1dd0dc7f5e0f13edf4..546f51e2ab5fa829b3f40acf6ca10ebe8e9d4516 100644
--- a/Source/core/html/HTMLFormControlElement.cpp
+++ b/Source/core/html/HTMLFormControlElement.cpp
@@ -32,8 +32,9 @@
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLLegendElement.h"
#include "core/html/ValidityState.h"
-#include "core/html/forms/ValidationMessage.h"
#include "core/frame/UseCounter.h"
+#include "core/page/Page.h"
+#include "core/page/ValidationMessageClient.h"
#include "core/rendering/RenderBox.h"
#include "core/rendering/RenderTheme.h"
#include "wtf/Vector.h"
@@ -48,6 +49,7 @@ HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc
, m_isAutofilled(false)
, m_isReadOnly(false)
, m_isRequired(false)
+ , m_hasValidationMessage(false)
, m_ancestorDisabledState(AncestorDisabledStateUnknown)
, m_dataListAncestorState(Unknown)
, m_willValidateInitialized(false)
@@ -253,7 +255,7 @@ Node::InsertionNotificationRequest HTMLFormControlElement::insertedInto(Containe
void HTMLFormControlElement::removedFrom(ContainerNode* insertionPoint)
{
hideVisibleValidationMessage();
- m_validationMessage = nullptr;
+ m_hasValidationMessage = false;
m_ancestorDisabledState = AncestorDisabledStateUnknown;
m_dataListAncestorState = Unknown;
HTMLElement::removedFrom(insertionPoint);
@@ -411,15 +413,43 @@ void HTMLFormControlElement::updateVisibleValidationMessage()
String message;
if (renderer() && willValidate())
message = validationMessage().stripWhiteSpace();
- if (!m_validationMessage)
- m_validationMessage = ValidationMessage::create(this);
- m_validationMessage->updateValidationMessage(message);
+
+ m_hasValidationMessage = true;
+ ValidationMessageClient* client = &page->validationMessageClient();
+ if (message.isEmpty())
+ client->hideValidationMessage(*this);
+ else
+ client->showValidationMessage(*this, message);
}
void HTMLFormControlElement::hideVisibleValidationMessage()
{
- if (m_validationMessage)
- m_validationMessage->requestToHideMessage();
+ if (!m_hasValidationMessage)
+ return;
+
+ if (ValidationMessageClient* client = validationMessageClient())
+ client->hideValidationMessage(*this);
+}
+
+bool HTMLFormControlElement::isValidationMessageVisible() const
+{
+ if (!m_hasValidationMessage)
+ return false;
+
+ ValidationMessageClient* client = validationMessageClient();
+ if (!client)
+ return false;
+
+ return client->isValidationMessageVisible(*this);
+}
+
+ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const
+{
+ Page* page = document().page();
+ if (!page)
+ return 0;
+
+ return &page->validationMessageClient();
}
bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls)
@@ -453,9 +483,9 @@ void HTMLFormControlElement::setNeedsValidityCheck()
m_isValid = newIsValid;
// Updates only if this control already has a validation message.
- if (m_validationMessage && m_validationMessage->isVisible()) {
+ if (isValidationMessageVisible()) {
// Calls updateVisibleValidationMessage() even if m_isValid is not
- // changed because a validation message can be chagned.
+ // changed because a validation message can be changed.
updateVisibleValidationMessage();
}
}
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/forms/ValidationMessage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698