Unreviewed, rolling out r116752.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2012 12:56:04 +0000 (12:56 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2012 12:56:04 +0000 (12:56 +0000)
http://trac.webkit.org/changeset/116752
https://bugs.webkit.org/show_bug.cgi?id=86201

Build failure on Chromium-mac (Requested by tkent on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2012-05-11

* html/FormAssociatedElement.cpp:
* html/FormAssociatedElement.h:
(FormAssociatedElement):
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::setCustomValidity):
* html/HTMLFormControlElement.h:
(HTMLFormControlElement):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::isValidValue):
(WebCore::HTMLInputElement::typeMismatch):
(WebCore::HTMLInputElement::valueMissing):
(WebCore::HTMLInputElement::patternMismatch):
(WebCore::HTMLInputElement::rangeUnderflow):
(WebCore::HTMLInputElement::rangeOverflow):
(WebCore::HTMLInputElement::minimum):
(WebCore::HTMLInputElement::maximum):
(WebCore::HTMLInputElement::stepMismatch):
(WebCore::HTMLInputElement::minimumString):
(WebCore::HTMLInputElement::maximumString):
(WebCore):
(WebCore::HTMLInputElement::stepBaseString):
(WebCore::HTMLInputElement::stepString):
(WebCore::HTMLInputElement::typeMismatchText):
(WebCore::HTMLInputElement::valueMissingText):
(WebCore::HTMLInputElement::isInRange):
(WebCore::HTMLInputElement::isOutOfRange):
* html/HTMLInputElement.h:
(HTMLInputElement):
* html/HTMLObjectElement.h:
(WebCore::HTMLObjectElement::setCustomValidity):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::valueMissing):
* html/HTMLSelectElement.h:
(HTMLSelectElement):
* html/HTMLTextAreaElement.cpp:
* html/HTMLTextAreaElement.h:
(WebCore::HTMLTextAreaElement::valueMissing):
(HTMLTextAreaElement):
* html/InputType.cpp:
(WebCore::InputType::alignValueForStep):
(WebCore::InputType::stepUpFromRenderer):
* html/InputType.h:
(InputType):
* html/ValidityState.cpp:
(WebCore::ValidityState::validationMessage):
(WebCore):
(WebCore::ValidityState::setCustomErrorMessage):
(WebCore::ValidityState::valueMissing):
(WebCore::ValidityState::typeMismatch):
(WebCore::ValidityState::patternMismatch):
(WebCore::ValidityState::tooLong):
(WebCore::ValidityState::rangeUnderflow):
(WebCore::ValidityState::rangeOverflow):
(WebCore::ValidityState::stepMismatch):
(WebCore::ValidityState::customError):
(WebCore::ValidityState::valid):
* html/ValidityState.h:
(ValidityState):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@116756 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/FormAssociatedElement.cpp
Source/WebCore/html/FormAssociatedElement.h
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLObjectElement.h
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElement.h
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/HTMLTextAreaElement.h
Source/WebCore/html/InputType.cpp
Source/WebCore/html/InputType.h
Source/WebCore/html/ValidityState.cpp
Source/WebCore/html/ValidityState.h

index 58a4827..2f8c35b 100644 (file)
@@ -1,3 +1,70 @@
+2012-05-11  Sheriff Bot  <webkit.review.bot@gmail.com>
+
+        Unreviewed, rolling out r116752.
+        http://trac.webkit.org/changeset/116752
+        https://bugs.webkit.org/show_bug.cgi?id=86201
+
+        Build failure on Chromium-mac (Requested by tkent on #webkit).
+
+        * html/FormAssociatedElement.cpp:
+        * html/FormAssociatedElement.h:
+        (FormAssociatedElement):
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::setCustomValidity):
+        * html/HTMLFormControlElement.h:
+        (HTMLFormControlElement):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::isValidValue):
+        (WebCore::HTMLInputElement::typeMismatch):
+        (WebCore::HTMLInputElement::valueMissing):
+        (WebCore::HTMLInputElement::patternMismatch):
+        (WebCore::HTMLInputElement::rangeUnderflow):
+        (WebCore::HTMLInputElement::rangeOverflow):
+        (WebCore::HTMLInputElement::minimum):
+        (WebCore::HTMLInputElement::maximum):
+        (WebCore::HTMLInputElement::stepMismatch):
+        (WebCore::HTMLInputElement::minimumString):
+        (WebCore::HTMLInputElement::maximumString):
+        (WebCore):
+        (WebCore::HTMLInputElement::stepBaseString):
+        (WebCore::HTMLInputElement::stepString):
+        (WebCore::HTMLInputElement::typeMismatchText):
+        (WebCore::HTMLInputElement::valueMissingText):
+        (WebCore::HTMLInputElement::isInRange):
+        (WebCore::HTMLInputElement::isOutOfRange):
+        * html/HTMLInputElement.h:
+        (HTMLInputElement):
+        * html/HTMLObjectElement.h:
+        (WebCore::HTMLObjectElement::setCustomValidity):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::valueMissing):
+        * html/HTMLSelectElement.h:
+        (HTMLSelectElement):
+        * html/HTMLTextAreaElement.cpp:
+        * html/HTMLTextAreaElement.h:
+        (WebCore::HTMLTextAreaElement::valueMissing):
+        (HTMLTextAreaElement):
+        * html/InputType.cpp:
+        (WebCore::InputType::alignValueForStep):
+        (WebCore::InputType::stepUpFromRenderer):
+        * html/InputType.h:
+        (InputType):
+        * html/ValidityState.cpp:
+        (WebCore::ValidityState::validationMessage):
+        (WebCore):
+        (WebCore::ValidityState::setCustomErrorMessage):
+        (WebCore::ValidityState::valueMissing):
+        (WebCore::ValidityState::typeMismatch):
+        (WebCore::ValidityState::patternMismatch):
+        (WebCore::ValidityState::tooLong):
+        (WebCore::ValidityState::rangeUnderflow):
+        (WebCore::ValidityState::rangeOverflow):
+        (WebCore::ValidityState::stepMismatch):
+        (WebCore::ValidityState::customError):
+        (WebCore::ValidityState::valid):
+        * html/ValidityState.h:
+        (ValidityState):
+
 2012-05-11  Alexander Pavlov  <apavlov@chromium.org>
 
         Web Inspector: Search box doesn't allow CSS selectors anymore
index 76dd0d1..665efa7 100644 (file)
@@ -157,69 +157,6 @@ void FormAssociatedElement::formAttributeChanged()
         resetFormOwner();
 }
 
-bool FormAssociatedElement::customError() const
-{
-    const HTMLElement* element = toHTMLElement(this);
-    return element->willValidate() && !m_customValidationMessage.isEmpty();
-}
-
-bool FormAssociatedElement::patternMismatch() const
-{
-    return false;
-}
-
-bool FormAssociatedElement::rangeOverflow() const
-{
-    return false;
-}
-
-bool FormAssociatedElement::rangeUnderflow() const
-{
-    return false;
-}
-
-bool FormAssociatedElement::stepMismatch() const
-{
-    return false;
-}
-
-bool FormAssociatedElement::tooLong() const
-{
-    return false;
-}
-
-bool FormAssociatedElement::typeMismatch() const
-{
-    return false;
-}
-
-bool FormAssociatedElement::valid() const
-{
-    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
-        || tooLong() || patternMismatch() || valueMissing() || customError();
-    return !someError;
-}
-
-bool FormAssociatedElement::valueMissing() const
-{
-    return false;
-}
-
-String FormAssociatedElement::customValidationMessage() const
-{
-    return m_customValidationMessage;
-}
-
-String FormAssociatedElement::validationMessage() const
-{
-    return customError() ? m_customValidationMessage : String();
-}
-
-void FormAssociatedElement::setCustomValidity(const String& error)
-{
-    m_customValidationMessage = error;
-}
-
 const HTMLElement* toHTMLElement(const FormAssociatedElement* associatedElement)
 {
     if (associatedElement->isFormControlElement())
index 92eb8d7..284e298 100644 (file)
@@ -60,22 +60,6 @@ public:
 
     void formRemovedFromTree(const Node* formRoot);
 
-    // ValidityState attribute implementations
-    bool customError() const;
-
-    // Override functions for patterMismatch, rangeOverflow, rangerUnderflow,
-    // stepMismatch, tooLong and valueMissing must call willValidate method.
-    virtual bool patternMismatch() const;
-    virtual bool rangeOverflow() const;
-    virtual bool rangeUnderflow() const;
-    virtual bool stepMismatch() const;
-    virtual bool tooLong() const;
-    virtual bool typeMismatch() const;
-    virtual bool valueMissing() const;
-    virtual String validationMessage() const;
-    bool valid() const;
-    virtual void setCustomValidity(const String&);
-
 protected:
     FormAssociatedElement();
 
@@ -92,8 +76,6 @@ protected:
     virtual void willChangeForm();
     virtual void didChangeForm();
 
-    String customValidationMessage() const;
-
 private:
     virtual const AtomicString& formControlName() const = 0;
 
@@ -102,7 +84,6 @@ private:
 
     HTMLFormElement* m_form;
     OwnPtr<ValidityState> m_validityState;
-    String m_customValidationMessage;
 };
 
 HTMLElement* toHTMLElement(FormAssociatedElement*);
index 7021753..2f9f225 100644 (file)
@@ -484,8 +484,7 @@ void HTMLFormControlElement::setNeedsValidityCheck()
 
 void HTMLFormControlElement::setCustomValidity(const String& error)
 {
-    FormAssociatedElement::setCustomValidity(error);
-    setNeedsValidityCheck();
+    validity()->setCustomErrorMessage(error);
 }
 
 void HTMLFormControlElement::dispatchBlurEvent(PassRefPtr<Node> newFocusedNode)
index cafbf52..608411f 100644 (file)
@@ -101,7 +101,7 @@ public:
     bool checkValidity(Vector<RefPtr<FormAssociatedElement> >* unhandledInvalidControls = 0);
     // This must be called when a validation constraint or control value is changed.
     void setNeedsValidityCheck();
-    virtual void setCustomValidity(const String&) OVERRIDE;
+    void setCustomValidity(const String&);
 
     bool readOnly() const { return m_readOnly; }
 
index d6cecc8..778ed25 100644 (file)
@@ -191,32 +191,27 @@ bool HTMLInputElement::isValidValue(const String& value) const
         return false;
     }
     return !m_inputType->typeMismatchFor(value)
-        && !m_inputType->stepMismatch(value)
-        && !m_inputType->rangeUnderflow(value)
-        && !m_inputType->rangeOverflow(value)
+        && !stepMismatch(value)
+        && !rangeUnderflow(value)
+        && !rangeOverflow(value)
         && !tooLong(value, IgnoreDirtyFlag)
-        && !m_inputType->patternMismatch(value)
-        && !m_inputType->valueMissing(value);
-}
-
-bool HTMLInputElement::tooLong() const
-{
-    return willValidate() && tooLong(value(), CheckDirtyFlag);
+        && !patternMismatch(value)
+        && !valueMissing(value);
 }
 
 bool HTMLInputElement::typeMismatch() const
 {
-    return willValidate() && m_inputType->typeMismatch();
+    return m_inputType->typeMismatch();
 }
 
-bool HTMLInputElement::valueMissing() const
+bool HTMLInputElement::valueMissing(const String& value) const
 {
-    return willValidate() && m_inputType->valueMissing(value());
+    return m_inputType->valueMissing(value);
 }
 
-bool HTMLInputElement::patternMismatch() const
+bool HTMLInputElement::patternMismatch(const String& value) const
 {
-    return willValidate() && m_inputType->patternMismatch(value());
+    return m_inputType->patternMismatch(value);
 }
 
 bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
@@ -237,40 +232,68 @@ bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check)
     return numGraphemeClusters(value) > static_cast<unsigned>(max);
 }
 
-bool HTMLInputElement::rangeUnderflow() const
+bool HTMLInputElement::rangeUnderflow(const String& value) const
 {
-    return willValidate() && m_inputType->rangeUnderflow(value());
+    return m_inputType->rangeUnderflow(value);
 }
 
-bool HTMLInputElement::rangeOverflow() const
+bool HTMLInputElement::rangeOverflow(const String& value) const
 {
-    return willValidate() && m_inputType->rangeOverflow(value());
+    return m_inputType->rangeOverflow(value);
 }
 
-String HTMLInputElement::validationMessage() const
+double HTMLInputElement::minimum() const
 {
-    if (!willValidate())
-        return String();
+    return m_inputType->minimum();
+}
 
-    if (customError())
-        return customValidationMessage();
+double HTMLInputElement::maximum() const
+{
+    return m_inputType->maximum();
+}
 
-    return m_inputType->validationMessage();
+bool HTMLInputElement::stepMismatch(const String& value) const
+{
+    double step;
+    if (!getAllowedValueStep(&step))
+        return false;
+    return m_inputType->stepMismatch(value, step);
 }
 
-double HTMLInputElement::minimum() const
+String HTMLInputElement::minimumString() const
 {
-    return m_inputType->minimum();
+    return m_inputType->serialize(minimum());
 }
 
-double HTMLInputElement::maximum() const
+String HTMLInputElement::maximumString() const
 {
-    return m_inputType->maximum();
+    return m_inputType->serialize(maximum());
+}
+
+String HTMLInputElement::stepBaseString() const
+{
+    return m_inputType->serialize(m_inputType->stepBase());
+}
+
+String HTMLInputElement::stepString() const
+{
+    double step;
+    if (!getAllowedValueStep(&step)) {
+        // stepString() should be called only if stepMismatch() can be true.
+        ASSERT_NOT_REACHED();
+        return String();
+    }
+    return serializeForNumberType(step / m_inputType->stepScaleFactor());
+}
+
+String HTMLInputElement::typeMismatchText() const
+{
+    return m_inputType->typeMismatchText();
 }
 
-bool HTMLInputElement::stepMismatch() const
+String HTMLInputElement::valueMissingText() const
 {
-    return willValidate() && m_inputType->stepMismatch(value());
+    return m_inputType->valueMissingText();
 }
 
 bool HTMLInputElement::getAllowedValueStep(double* step) const
@@ -1252,12 +1275,12 @@ bool HTMLInputElement::hasUnacceptableValue() const
 
 bool HTMLInputElement::isInRange() const
 {
-    return m_inputType->supportsRangeLimitation() && !m_inputType->rangeUnderflow(value()) && !m_inputType->rangeOverflow(value());
+    return m_inputType->supportsRangeLimitation() && !rangeUnderflow(value()) && !rangeOverflow(value());
 }
 
 bool HTMLInputElement::isOutOfRange() const
 {
-    return m_inputType->supportsRangeLimitation() && (m_inputType->rangeUnderflow(value()) || m_inputType->rangeOverflow(value()));
+    return m_inputType->supportsRangeLimitation() && (rangeUnderflow(value()) || rangeOverflow(value()));
 }
 
 bool HTMLInputElement::needsSuspensionCallback()
index 5c2e812..e34a03e 100644 (file)
@@ -48,15 +48,13 @@ public:
     virtual bool shouldAutocomplete() const;
 
     // For ValidityState
-    virtual bool patternMismatch() const OVERRIDE;
-    virtual bool rangeUnderflow() const OVERRIDE;
-    virtual bool rangeOverflow() const;
-    virtual bool stepMismatch() const OVERRIDE;
-    virtual bool tooLong() const OVERRIDE;
-    virtual bool typeMismatch() const OVERRIDE;
-    virtual bool valueMissing() const OVERRIDE;
-    virtual String validationMessage() const OVERRIDE;
-
+    bool typeMismatch() const;
+    // valueMissing() ignores the specified string value for CHECKBOX and RADIO.
+    bool valueMissing(const String&) const;
+    bool patternMismatch(const String&) const;
+    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
+    bool rangeUnderflow(const String&) const;
+    bool rangeOverflow(const String&) const;
     // Returns the minimum value for type=date, number, or range.  Don't call this for other types.
     double minimum() const;
     // Returns the maximum value for type=date, number, or range.  Don't call this for other types.
@@ -66,6 +64,15 @@ public:
     // Returns false if there is no "allowed value step."
     bool getAllowedValueStep(double*) const;
 
+    // For ValidityState.
+    bool stepMismatch(const String&) const;
+    String minimumString() const;
+    String maximumString() const;
+    String stepBaseString() const;
+    String stepString() const;
+    String typeMismatchText() const;
+    String valueMissingText() const;
+
     // Implementations of HTMLInputElement::stepUp() and stepDown().
     void stepUp(int, ExceptionCode&);
     void stepDown(int, ExceptionCode&);
@@ -318,7 +325,6 @@ private:
 
     bool supportsMaxLength() const { return isTextType(); }
     bool isTextType() const;
-    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
 
     virtual bool supportsPlaceholder() const;
     virtual bool isPlaceholderEmpty() const OVERRIDE;
index 313893b..a0e6637 100644 (file)
@@ -56,7 +56,7 @@ public:
     // Note that the object elements are always barred from constraint validation.
     String validationMessage() { return String(); }
     bool checkValidity() { return true; }
-    virtual void setCustomValidity(const String&) OVERRIDE { }
+    void setCustomValidity(const String&) { }
 
     using TreeShared<ContainerNode>::ref;
     using TreeShared<ContainerNode>::deref;
index ee57dae..58a9a73 100644 (file)
@@ -41,7 +41,6 @@
 #include "HTMLOptionElement.h"
 #include "HTMLOptionsCollection.h"
 #include "KeyboardEvent.h"
-#include "LocalizedStrings.h"
 #include "MouseEvent.h"
 #include "NodeRenderingContext.h"
 #include "Page.h"
@@ -146,22 +145,8 @@ bool HTMLSelectElement::hasPlaceholderLabelOption() const
     return !listIndex && option->value().isEmpty();
 }
 
-String HTMLSelectElement::validationMessage() const
-{
-    if (!willValidate())
-        return String();
-
-    if (customError())
-        return customValidationMessage();
-
-    return valueMissing() ? validationMessageValueMissingForSelectText() : String();
-}
-
 bool HTMLSelectElement::valueMissing() const
 {
-    if (!willValidate())
-        return false;
-
     if (!isRequiredFormControl())
         return false;
 
index 82b7273..52665e1 100644 (file)
@@ -46,8 +46,7 @@ public:
     void optionSelectedByUser(int index, bool dispatchChangeEvent, bool allowMultipleSelection = false);
 
     // For ValidityState
-    virtual String validationMessage() const OVERRIDE;
-    virtual bool valueMissing() const OVERRIDE;
+    bool valueMissing() const;
 
     unsigned length() const;
 
index 3fc8151..8257d0f 100644 (file)
@@ -37,7 +37,6 @@
 #include "FormDataList.h"
 #include "Frame.h"
 #include "HTMLNames.h"
-#include "LocalizedStrings.h"
 #include "RenderTextControlMultiLine.h"
 #include "ShadowRoot.h"
 #include "Text.h"
@@ -424,33 +423,6 @@ void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode& ec)
         setAttribute(maxlengthAttr, String::number(newValue));
 }
 
-String HTMLTextAreaElement::validationMessage() const
-{
-    if (!willValidate())
-        return String();
-
-    if (customError())
-        return customValidationMessage();
-
-    if (valueMissing())
-        return validationMessageValueMissingText();
-
-    if (tooLong())
-        return validationMessageTooLongText(numGraphemeClusters(value()), maxLength());
-
-    return String();
-}
-
-bool HTMLTextAreaElement::valueMissing() const
-{
-    return willValidate() && valueMissing(value());
-}
-
-bool HTMLTextAreaElement::tooLong() const
-{
-    return willValidate() && tooLong(value(), CheckDirtyFlag);
-}
-
 bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
 {
     // Return false for the default value or value set by script even if it is
index d755d88..a19a471 100644 (file)
@@ -47,10 +47,8 @@ public:
     int textLength() const { return value().length(); }
     virtual int maxLength() const;
     void setMaxLength(int, ExceptionCode&);
-    // For ValidityState
-    virtual String validationMessage() const OVERRIDE;
-    virtual bool valueMissing() const OVERRIDE;
-    virtual bool tooLong() const OVERRIDE;
+    bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); }
+    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
     bool isValidValue(const String&) const;
     
     virtual HTMLElement* innerTextElement() const;
@@ -110,9 +108,6 @@ private:
 
     virtual bool shouldUseInputMethod();
 
-    bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); }
-    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
-
     int m_rows;
     int m_cols;
     WrapMethod m_wrap;
index 146d918..cf125c9 100644 (file)
@@ -283,14 +283,6 @@ bool InputType::sizeShouldIncludeDecoration(int, int& preferredSize) const
     return false;
 }
 
-bool InputType::stepMismatch(const String& value) const
-{
-    double step;
-    if (!getAllowedValueStep(&step))
-        return false;
-    return stepMismatch(value, step);
-}
-
 bool InputType::stepMismatch(const String&, double) const
 {
     // Non-supported types should be rejected by HTMLInputElement::getAllowedValueStep().
@@ -346,41 +338,6 @@ String InputType::valueMissingText() const
     return validationMessageValueMissingText();
 }
 
-String InputType::validationMessage() const
-{
-    const String value = element()->value();
-
-    // The order of the following checks is meaningful. e.g. We'd like to show the
-    // valueMissing message even if the control has other validation errors.
-    if (valueMissing(value))
-        return valueMissingText();
-
-    if (typeMismatch())
-        return typeMismatchText();
-
-    if (patternMismatch(value))
-        return validationMessagePatternMismatchText();
-
-    if (element()->tooLong())
-        return validationMessageTooLongText(numGraphemeClusters(value), element()->maxLength());
-
-    if (rangeUnderflow(value))
-        return validationMessageRangeUnderflowText(serialize(minimum()));
-
-    if (rangeOverflow(value))
-        return validationMessageRangeOverflowText(serialize(maximum()));
-
-    if (stepMismatch(value)) {
-        String stepString;
-        double step;
-        if (getAllowedValueStep(&step))
-            stepString = serializeForNumberType(step / stepScaleFactor());
-        return validationMessageStepMismatchText(serialize(stepBase()), stepString);
-    }
-
-    return String();
-}
-
 void InputType::handleClickEvent(MouseEvent*)
 {
 }
@@ -913,7 +870,7 @@ double InputType::alignValueForStep(double newValue, double step, unsigned curre
     unsigned baseDecimalPlaces;
     double base = stepBaseWithDecimalPlaces(&baseDecimalPlaces);
     baseDecimalPlaces = min(baseDecimalPlaces, 16u);
-    if (stepMismatch(element()->value())) {
+    if (element()->stepMismatch(element()->value())) {
         double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
         newValue = round(newValue * scale) / scale;
     } else {
@@ -1066,7 +1023,7 @@ void InputType::stepUpFromRenderer(int n)
         element()->setValue(serialize(sign > 0 ? minimum() : maximum()), DispatchInputAndChangeEvent);
     else {
         ExceptionCode ec;
-        if (stepMismatch(element()->value())) {
+        if (element()->stepMismatch(element()->value())) {
             ASSERT(step);
             double newValue;
             double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, baseDecimalPlaces)));
index b00826b..1c86cb0 100644 (file)
@@ -140,7 +140,7 @@ public:
     virtual void setValueAsNumber(double, TextFieldEventBehavior, ExceptionCode&) const;
 
     // Validation functions
-    virtual String validationMessage() const;
+
     virtual bool supportsValidation() const;
     virtual bool typeMismatchFor(const String&) const;
     // Type check for the current input value. We do nothing for some types
@@ -157,7 +157,6 @@ public:
     virtual double minimum() const;
     virtual double maximum() const;
     virtual bool sizeShouldIncludeDecoration(int defaultSize, int& preferredSize) const;
-    bool stepMismatch(const String&) const;
     virtual bool stepMismatch(const String&, double step) const;
     virtual double stepBase() const;
     virtual double stepBaseWithDecimalPlaces(unsigned*) const;
index 649765d..fe7312c 100644 (file)
@@ -38,52 +38,177 @@ using namespace HTMLNames;
 
 String ValidityState::validationMessage() const
 {
-    return m_control->validationMessage();
+    if (!toHTMLElement(m_control)->willValidate())
+        return String();
+
+    if (customError())
+        return m_customErrorMessage;
+    HTMLElement* element = toHTMLElement(m_control);
+    bool isInputElement = element->isFormControlElement() && element->hasTagName(inputTag);
+    bool isTextAreaElement = element->isFormControlElement() && element->hasTagName(textareaTag);
+    // The order of the following checks is meaningful. e.g. We'd like to show the
+    // valueMissing message even if the control has other validation errors.
+    if (valueMissing()) {
+        if (element->hasTagName(selectTag))
+            return validationMessageValueMissingForSelectText();
+        if (isInputElement)
+            return static_cast<HTMLInputElement*>(element)->valueMissingText();
+        return validationMessageValueMissingText();
+    }
+    if (typeMismatch()) {
+        if (isInputElement)
+            return static_cast<HTMLInputElement*>(element)->typeMismatchText();
+        return validationMessageTypeMismatchText();
+    }
+    if (patternMismatch())
+        return validationMessagePatternMismatchText();
+    if (tooLong()) {
+        if (!isInputElement && !isTextAreaElement) {
+            ASSERT_NOT_REACHED();
+            return String();
+        }
+        HTMLTextFormControlElement* text = static_cast<HTMLTextFormControlElement*>(element);
+        return validationMessageTooLongText(numGraphemeClusters(text->value()), text->maxLength());
+    }
+    if (rangeUnderflow()) {
+        if (!isInputElement) {
+            ASSERT_NOT_REACHED();
+            return String();
+        }
+        return validationMessageRangeUnderflowText(static_cast<HTMLInputElement*>(element)->minimumString());
+    }
+    if (rangeOverflow()) {
+        if (!isInputElement) {
+            ASSERT_NOT_REACHED();
+            return String();
+        }
+        return validationMessageRangeOverflowText(static_cast<HTMLInputElement*>(element)->maximumString());
+    }
+    if (stepMismatch()) {
+        if (!isInputElement) {
+            ASSERT_NOT_REACHED();
+            return String();
+        }
+        HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+        return validationMessageStepMismatchText(input->stepBaseString(), input->stepString());
+    }
+
+    return String();
+}
+
+void ValidityState::setCustomErrorMessage(const String& message)
+{
+    m_customErrorMessage = message;
+    if (m_control->isFormControlElement())
+        static_cast<HTMLFormControlElement*>(m_control)->setNeedsValidityCheck();
 }
 
 bool ValidityState::valueMissing() const
 {
-    return m_control->valueMissing();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (element->hasTagName(inputTag)) {
+        HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+        return input->valueMissing(input->value());
+    }
+    if (element->hasTagName(textareaTag)) {
+        HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element);
+        return textArea->valueMissing(textArea->value());
+    }
+    if (element->hasTagName(selectTag))
+        return toHTMLSelectElement(element)->valueMissing();
+    return false;
 }
 
 bool ValidityState::typeMismatch() const
 {
-    return m_control->typeMismatch();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (!element->hasTagName(inputTag))
+        return false;
+    return static_cast<HTMLInputElement*>(element)->typeMismatch();
 }
 
 bool ValidityState::patternMismatch() const
 {
-    return m_control->patternMismatch();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (!element->hasTagName(inputTag))
+        return false;
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+    return input->patternMismatch(input->value());
 }
 
 bool ValidityState::tooLong() const
 {
-    return m_control->tooLong();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (element->hasTagName(inputTag)) {
+        HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+        return input->tooLong(input->value(), HTMLTextFormControlElement::CheckDirtyFlag);
+    }
+    if (element->hasTagName(textareaTag)) {
+        HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element);
+        return textArea->tooLong(textArea->value(), HTMLTextFormControlElement::CheckDirtyFlag);
+    }
+    return false;
 }
 
 bool ValidityState::rangeUnderflow() const
 {
-    return m_control->rangeUnderflow();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (!element->hasTagName(inputTag))
+        return false;
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+    return input->rangeUnderflow(input->value());
 }
 
 bool ValidityState::rangeOverflow() const
 {
-    return m_control->rangeOverflow();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (!element->hasTagName(inputTag))
+        return false;
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+    return input->rangeOverflow(input->value());
 }
 
 bool ValidityState::stepMismatch() const
 {
-    return m_control->stepMismatch();
+    HTMLElement* element = toHTMLElement(m_control);
+    if (!element->willValidate())
+        return false;
+
+    if (!element->hasTagName(inputTag))
+        return false;
+    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+    return input->stepMismatch(input->value());
 }
 
 bool ValidityState::customError() const
 {
-    return m_control->customError();
+    HTMLElement* element = toHTMLElement(m_control);
+    return element->willValidate() && !m_customErrorMessage.isEmpty();
 }
 
 bool ValidityState::valid() const
 {
-    return m_control->valid();
+    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
+        || tooLong() || patternMismatch() || valueMissing() || customError();
+    return !someError;
 }
 
 } // namespace
index 17e94c9..4a96488 100644 (file)
@@ -57,7 +57,11 @@ public:
 private:
     ValidityState(FormAssociatedElement* control) : m_control(control) { }
 
+    static bool isValidColorString(const String&);
+    static bool isValidEmailAddress(const String&);
+
     FormAssociatedElement* m_control;
+    String m_customErrorMessage;
 };
 
 } // namespace WebCore