Chromium Code Reviews| Index: Source/core/html/HTMLInputElement.cpp |
| diff --git a/Source/core/html/HTMLInputElement.cpp b/Source/core/html/HTMLInputElement.cpp |
| index 1cb6779a02a95296de74a5bc614f9b5e5b87e8d9..9d26fd9b5062a5561a64d71b0c40ff243ffd1c8b 100644 |
| --- a/Source/core/html/HTMLInputElement.cpp |
| +++ b/Source/core/html/HTMLInputElement.cpp |
| @@ -107,6 +107,7 @@ HTMLInputElement::HTMLInputElement(Document& document, HTMLFormElement* form, bo |
| : HTMLTextFormControlElement(inputTag, document, form) |
| , m_size(defaultSize) |
| , m_maxLength(maximumLength) |
| + , m_minLength(0) |
| , m_maxResults(-1) |
| , m_isChecked(false) |
| , m_reflectsCheckedAttribute(true) |
| @@ -217,6 +218,12 @@ bool HTMLInputElement::tooLong() const |
| return willValidate() && tooLong(value(), CheckDirtyFlag); |
| } |
| +bool HTMLInputElement::tooShort() const |
| +{ |
| + bool ret = willValidate() && tooShort(value(), CheckDirtyFlag); |
| + return ret; |
| +} |
| + |
| bool HTMLInputElement::typeMismatch() const |
| { |
| return willValidate() && m_inputType->typeMismatch(); |
| @@ -239,8 +246,6 @@ bool HTMLInputElement::patternMismatch() const |
| bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const |
| { |
| - // We use isTextType() instead of supportsMaxLength() because of the |
| - // 'virtual' overhead. |
| if (!isTextType()) |
| return false; |
| int max = maxLength(); |
| @@ -255,6 +260,24 @@ bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) |
| return value.length() > static_cast<unsigned>(max); |
| } |
| +bool HTMLInputElement::tooShort(const String& value, NeedsToCheckDirtyFlag check) const |
| +{ |
| + if (!isTextType()) |
|
keishi
2014/08/01 03:14:54
We don't have WMLInputElement anymore so I think w
Bartek Nowierski
2014/10/03 12:52:00
The code has been moved to forms/BaseTextInputType
|
| + return false; |
| + int min = minLength(); |
| + if (min <= 0) |
| + return false; |
| + if (check == CheckDirtyFlag) { |
| + // Return false for the default value or a value set by a script even if |
| + // it is shorter than minLength. |
| + if (!hasDirtyValue() || !lastChangeWasUserEdit()) |
| + return false; |
| + } |
| + // An empty string is excluded from minlength check. |
| + unsigned len = value.length(); |
| + return len > 0 && len < static_cast<unsigned>(min); |
| +} |
| + |
| bool HTMLInputElement::rangeUnderflow() const |
| { |
| return willValidate() && m_inputType->rangeUnderflow(value()); |
| @@ -665,9 +688,11 @@ void HTMLInputElement::parseAttribute(const QualifiedName& name, const AtomicStr |
| setChecked(!value.isNull()); |
| m_reflectsCheckedAttribute = true; |
| } |
| - } else if (name == maxlengthAttr) |
| + } else if (name == maxlengthAttr) { |
| parseMaxLengthAttribute(value); |
| - else if (name == sizeAttr) { |
| + } else if (name == minlengthAttr) { |
| + parseMinLengthAttribute(value); |
| + } else if (name == sizeAttr) { |
| int oldSize = m_size; |
| int valueAsInteger = value.toInt(); |
| m_size = valueAsInteger > 0 ? valueAsInteger : defaultSize; |
| @@ -1288,14 +1313,31 @@ int HTMLInputElement::maxLength() const |
| return m_maxLength; |
| } |
| +int HTMLInputElement::minLength() const |
| +{ |
| + return m_minLength; |
| +} |
| + |
| void HTMLInputElement::setMaxLength(int maxLength, ExceptionState& exceptionState) |
| { |
| if (maxLength < 0) |
| exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(maxLength) + ") is negative."); |
| + else if (maxLength < m_minLength) |
| + exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(maxLength) + ") is less than minlength" + String::number(m_minLength) + "."); |
| else |
| setIntegralAttribute(maxlengthAttr, maxLength); |
| } |
| +void HTMLInputElement::setMinLength(int minLength, ExceptionState& exceptionState) |
| +{ |
| + if (minLength < 0) |
| + exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(minLength) + ") is negative."); |
| + else if (minLength > m_maxLength) |
| + exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(minLength) + ") is more than maxlength" + String::number(m_maxLength) + "."); |
| + else |
| + setIntegralAttribute(minlengthAttr, minLength); |
| +} |
| + |
| bool HTMLInputElement::multiple() const |
| { |
| return fastHasAttribute(multipleAttr); |
| @@ -1674,6 +1716,8 @@ void HTMLInputElement::parseMaxLengthAttribute(const AtomicString& value) |
| maxLength = maximumLength; |
| if (maxLength < 0 || maxLength > maximumLength) |
| maxLength = maximumLength; |
| + if (m_minLength > maxLength) |
|
keishi
2014/08/01 03:14:54
We should just apply the rules for "parsing non-ne
Bartek Nowierski
2014/10/03 12:52:00
I assume you want me to remove this part. Done.
|
| + m_minLength = maxLength; |
| int oldMaxLength = m_maxLength; |
| m_maxLength = maxLength; |
| if (oldMaxLength != maxLength) |
| @@ -1682,6 +1726,20 @@ void HTMLInputElement::parseMaxLengthAttribute(const AtomicString& value) |
| setNeedsValidityCheck(); |
| } |
| +void HTMLInputElement::parseMinLengthAttribute(const AtomicString& value) |
| +{ |
| + int minLength; |
| + if (!parseHTMLInteger(value, minLength)) |
| + minLength = 0; |
| + if (minLength < 0) |
| + minLength = 0; |
| + if (minLength > m_maxLength) |
|
keishi
2014/08/01 03:14:54
We should just parse the minLength value here and
Bartek Nowierski
2014/10/03 12:52:00
Done.
|
| + minLength = m_maxLength; |
| + m_minLength = minLength; |
| + setNeedsStyleRecalc(SubtreeStyleChange); |
| + setNeedsValidityCheck(); |
| +} |
| + |
| void HTMLInputElement::updateValueIfNeeded() |
| { |
| String newValue = sanitizeValue(m_valueIfDirty); |