Chromium Code Reviews| Index: Source/core/html/HTMLTextAreaElement.cpp |
| diff --git a/Source/core/html/HTMLTextAreaElement.cpp b/Source/core/html/HTMLTextAreaElement.cpp |
| index bd11c103d89d92ec18bcf450aae93ad93c8c8a9d..7b711f6a509c0050baad851f6b7501f1b9375474 100644 |
| --- a/Source/core/html/HTMLTextAreaElement.cpp |
| +++ b/Source/core/html/HTMLTextAreaElement.cpp |
| @@ -189,9 +189,11 @@ void HTMLTextAreaElement::parseAttribute(const QualifiedName& name, const Atomic |
| } |
| } else if (name == accesskeyAttr) { |
| // ignore for the moment |
| - } else if (name == maxlengthAttr) |
| + } else if (name == maxlengthAttr) { |
| setNeedsValidityCheck(); |
| - else |
| + } else if (name == minlengthAttr) { |
| + setNeedsValidityCheck(); |
| + } else |
| HTMLTextFormControlElement::parseAttribute(name, value); |
| } |
| @@ -451,14 +453,35 @@ int HTMLTextAreaElement::maxLength() const |
| return ok && value >= 0 ? value : -1; |
| } |
| +int HTMLTextAreaElement::minLength() const |
| +{ |
| + bool ok; |
| + int value = getAttribute(minlengthAttr).string().toInt(&ok); |
| + return ok && value >= 0 ? value : -1; |
| +} |
| + |
| void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionState& exceptionState) |
| { |
| + int min = minLength(); |
| if (newValue < 0) |
| exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0."); |
| + else if (min >= 0 && newValue < min) |
| + exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is less than minlength" + String::number(min) + "."); |
| else |
| setIntegralAttribute(maxlengthAttr, newValue); |
| } |
| +void HTMLTextAreaElement::setMinLength(int newValue, ExceptionState& exceptionState) |
| +{ |
| + int max = maxLength(); |
| + if (newValue < 0) |
| + exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0."); |
| + else if (max >= 0 && newValue > max) |
| + exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is more than maxlength" + String::number(max) + "."); |
| + else |
| + setIntegralAttribute(minlengthAttr, newValue); |
| +} |
| + |
| String HTMLTextAreaElement::suggestedValue() const |
| { |
| return m_suggestedValue; |
| @@ -490,6 +513,11 @@ String HTMLTextAreaElement::validationMessage() const |
| if (tooLong()) |
| return locale().validationMessageTooLongText(computeLengthForSubmission(value()), maxLength()); |
| + if (tooShort()) |
| + return "Too short"; // DO NOT CHECK IN!!! |
|
keishi
2014/10/06 03:58:23
Ditto.
Bartek Nowierski
2014/10/06 13:18:16
Acknowledged.
|
| + // TODO(bartekn): Add a localized message for tooShort(). |
| + // return locale().validationMessageTooShortText(computeLengthForSubmission(value()), minLength()); |
|
keishi
2014/10/06 03:58:23
Ditto.
Bartek Nowierski
2014/10/06 13:18:16
Acknowledged.
|
| + |
| return String(); |
| } |
| @@ -510,6 +538,12 @@ bool HTMLTextAreaElement::tooLong() const |
| return willValidate() && tooLong(0, CheckDirtyFlag); |
| } |
| +bool HTMLTextAreaElement::tooShort() const |
| +{ |
| + // We should not call value() for performance. |
| + return willValidate() && tooShort(0, 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 |
| @@ -523,9 +557,24 @@ bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag che |
| return computeLengthForSubmission(value ? *value : this->value()) > static_cast<unsigned>(max); |
| } |
| +bool HTMLTextAreaElement::tooShort(const String* value, NeedsToCheckDirtyFlag check) const |
| +{ |
| + // Return false for the default value or value set by script even if it is |
| + // shorter than minLength. |
| + if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) |
| + return false; |
| + |
| + int min = minLength(); |
| + if (min <= 0) |
| + return false; |
| + // An empty string is excluded from minlength check. |
| + unsigned len = computeLengthForSubmission(value ? *value : this->value()); |
| + return len > 0 && len < static_cast<unsigned>(min); |
| +} |
| + |
| bool HTMLTextAreaElement::isValidValue(const String& candidate) const |
| { |
| - return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag); |
| + return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag) && !tooShort(&candidate, IgnoreDirtyFlag); |
| } |
| void HTMLTextAreaElement::accessKeyAction(bool) |