summaryrefslogtreecommitdiffstats
path: root/WebCore/html/HTMLFormControlElement.cpp
diff options
context:
space:
mode:
authorTeng-Hui Zhu <ztenghui@google.com>2010-11-10 15:31:59 -0800
committerTeng-Hui Zhu <ztenghui@google.com>2010-11-17 13:35:59 -0800
commit28040489d744e0c5d475a88663056c9040ed5320 (patch)
treec463676791e4a63e452a95f0a12b2a8519730693 /WebCore/html/HTMLFormControlElement.cpp
parenteff9be92c41913c92fb1d3b7983c071f3e718678 (diff)
downloadexternal_webkit-28040489d744e0c5d475a88663056c9040ed5320.zip
external_webkit-28040489d744e0c5d475a88663056c9040ed5320.tar.gz
external_webkit-28040489d744e0c5d475a88663056c9040ed5320.tar.bz2
Merge WebKit at r71558: Initial merge by git.
Change-Id: Ib345578fa29df7e4bc72b4f00e4a6fddcb754c4c
Diffstat (limited to 'WebCore/html/HTMLFormControlElement.cpp')
-rw-r--r--WebCore/html/HTMLFormControlElement.cpp59
1 files changed, 55 insertions, 4 deletions
diff --git a/WebCore/html/HTMLFormControlElement.cpp b/WebCore/html/HTMLFormControlElement.cpp
index 710cda1..8fa000f 100644
--- a/WebCore/html/HTMLFormControlElement.cpp
+++ b/WebCore/html/HTMLFormControlElement.cpp
@@ -45,6 +45,7 @@
#include "RenderTextControl.h"
#include "RenderTheme.h"
#include "ScriptEventListener.h"
+#include "ValidationMessage.h"
#include "ValidityState.h"
#include <limits>
#include <wtf/Vector.h>
@@ -77,6 +78,12 @@ HTMLFormControlElement::~HTMLFormControlElement()
m_form->removeFormElement(this);
}
+void HTMLFormControlElement::detach()
+{
+ hideVisibleValidationMessage();
+ HTMLElement::detach();
+}
+
bool HTMLFormControlElement::formNoValidate() const
{
return !getAttribute(formnovalidateAttr).isNull();
@@ -301,7 +308,8 @@ void HTMLFormControlElement::setNeedsWillValidateCheck()
m_willValidateInitialized = true;
m_willValidate = newWillValidate;
setNeedsStyleRecalc();
- // FIXME: Show/hide a validation message.
+ if (!m_willValidate)
+ hideVisibleValidationMessage();
}
String HTMLFormControlElement::validationMessage()
@@ -309,6 +317,42 @@ String HTMLFormControlElement::validationMessage()
return validity()->validationMessage();
}
+void HTMLFormControlElement::updateVisibleValidationMessage()
+{
+ Page* page = document()->page();
+ if (!page)
+ return;
+ String message;
+ if (renderer() && willValidate()) {
+ message = validationMessage().stripWhiteSpace();
+ // HTML5 specification doesn't ask UA to show the title attribute value
+ // with the validationMessage. However, this behavior is same as Opera
+ // and the specification describes such behavior as an example.
+ const AtomicString& title = getAttribute(titleAttr);
+ if (!message.isEmpty() && !title.isEmpty()) {
+ message.append('\n');
+ message.append(title);
+ }
+ }
+ if (!m_validationMessage) {
+ m_validationMessage = ValidationMessage::create(this);
+ m_validationMessage->setMessage(message);
+ } else if (message.isEmpty())
+ hideVisibleValidationMessage();
+ else if (m_validationMessage->message() != message)
+ m_validationMessage->setMessage(message);
+}
+
+void HTMLFormControlElement::hideVisibleValidationMessage()
+{
+ m_validationMessage = 0;
+}
+
+String HTMLFormControlElement::visibleValidationMessage() const
+{
+ return m_validationMessage ? m_validationMessage->message() : String();
+}
+
bool HTMLFormControlElement::checkValidity(Vector<RefPtr<HTMLFormControlElement> >* unhandledInvalidControls)
{
if (!willValidate() || isValidFormControlElement())
@@ -338,7 +382,13 @@ void HTMLFormControlElement::setNeedsValidityCheck()
setNeedsStyleRecalc();
}
m_isValid = newIsValid;
- // FIXME: show/hide a validation message.
+
+ // Updates only if this control already has a validtion message.
+ if (!visibleValidationMessage().isEmpty()) {
+ // Calls updateVisibleValidationMessage() even if m_isValid is not
+ // changed because a validation message can be chagned.
+ updateVisibleValidationMessage();
+ }
}
void HTMLFormControlElement::setCustomValidity(const String& error)
@@ -360,6 +410,7 @@ void HTMLFormControlElement::dispatchBlurEvent()
document()->page()->chrome()->client()->formDidBlur(this);
HTMLElement::dispatchBlurEvent();
+ hideVisibleValidationMessage();
}
HTMLFormElement* HTMLFormControlElement::virtualForm() const
@@ -568,7 +619,7 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end)
WebCore::setSelectionRange(this, start, end);
}
-int HTMLTextFormControlElement::selectionStart()
+int HTMLTextFormControlElement::selectionStart() const
{
if (!isTextFormControl())
return 0;
@@ -579,7 +630,7 @@ int HTMLTextFormControlElement::selectionStart()
return toRenderTextControl(renderer())->selectionStart();
}
-int HTMLTextFormControlElement::selectionEnd()
+int HTMLTextFormControlElement::selectionEnd() const
{
if (!isTextFormControl())
return 0;