Chromium Code Reviews| Index: Source/core/html/HTMLTextAreaElement.cpp |
| diff --git a/Source/core/html/HTMLTextAreaElement.cpp b/Source/core/html/HTMLTextAreaElement.cpp |
| index 7ca0838c5313cde3fb9694071bf6070a5c014000..844aad59761c3ae4e4c9af9812dab9f6ce93f627 100644 |
| --- a/Source/core/html/HTMLTextAreaElement.cpp |
| +++ b/Source/core/html/HTMLTextAreaElement.cpp |
| @@ -190,9 +190,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); |
| } |
| @@ -447,14 +449,42 @@ int HTMLTextAreaElement::maxLength() const |
| return ok && value >= 0 ? value : -1; |
| } |
| +int HTMLTextAreaElement::minLength() const |
| +{ |
| + bool ok; |
| + int value = getAttribute(minlengthAttr).string().toInt(&ok); |
| + if (ok && value >= 0) { |
| + int max = maxLength(); |
|
keishi
2014/08/01 03:14:54
We don't need to clamp to maxLength
Bartek Nowierski
2014/10/03 12:52:00
Done.
|
| + if (max >= 0 && value > max) { |
| + value = max; |
| + } |
| + return value; |
| + } |
| + return -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; |
| @@ -486,6 +516,8 @@ String HTMLTextAreaElement::validationMessage() const |
| if (tooLong()) |
| return locale().validationMessageTooLongText(computeLengthForSubmission(value()), maxLength()); |
| + // TODO(bartekn): Add a message for tooShort(). |
|
keishi
2014/08/01 03:14:54
I think you need to land the blink side change fir
Bartek Nowierski
2014/10/03 12:52:00
I'll do it in the next patchset. Let's focus on ge
|
| + |
| return String(); |
| } |
| @@ -499,6 +531,11 @@ bool HTMLTextAreaElement::tooLong() const |
| return willValidate() && tooLong(value(), CheckDirtyFlag); |
| } |
| +bool HTMLTextAreaElement::tooShort() const |
| +{ |
| + return willValidate() && tooShort(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 |
| @@ -512,6 +549,21 @@ bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag che |
| return computeLengthForSubmission(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); |
| + return len > 0 && len < static_cast<unsigned>(min); |
| +} |
| + |
| bool HTMLTextAreaElement::isValidValue(const String& candidate) const |
| { |
| return !valueMissing(candidate) && !tooLong(candidate, IgnoreDirtyFlag); |