Chromium Code Reviews| Index: Source/core/html/HTMLInputElement.cpp |
| diff --git a/Source/core/html/HTMLInputElement.cpp b/Source/core/html/HTMLInputElement.cpp |
| index dac3fce275919fe93debdd3d287bda9411d6df63..84f9395f380c069b8c2bc24be679f7e733ca6bcd 100644 |
| --- a/Source/core/html/HTMLInputElement.cpp |
| +++ b/Source/core/html/HTMLInputElement.cpp |
| @@ -110,6 +110,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) |
| @@ -210,6 +211,7 @@ bool HTMLInputElement::isValidValue(const String& value) const |
| && !m_inputType->rangeUnderflow(value) |
| && !m_inputType->rangeOverflow(value) |
| && !tooLong(value, IgnoreDirtyFlag) |
| + && !tooShort(value, IgnoreDirtyFlag) |
| && !m_inputType->patternMismatch(value) |
| && !m_inputType->valueMissing(value); |
| } |
| @@ -219,6 +221,11 @@ bool HTMLInputElement::tooLong() const |
| return willValidate() && tooLong(value(), CheckDirtyFlag); |
| } |
| +bool HTMLInputElement::tooShort() const |
| +{ |
| + return willValidate() && tooShort(value(), CheckDirtyFlag); |
| +} |
| + |
| bool HTMLInputElement::typeMismatch() const |
| { |
| return willValidate() && m_inputType->typeMismatch(); |
| @@ -244,6 +251,11 @@ bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) |
| return m_inputType->tooLong(value, check); |
| } |
| +bool HTMLInputElement::tooShort(const String& value, NeedsToCheckDirtyFlag check) const |
| +{ |
| + return m_inputType->tooShort(value, check); |
| +} |
| + |
| bool HTMLInputElement::rangeUnderflow() const |
| { |
| return willValidate() && m_inputType->rangeUnderflow(value()); |
| @@ -671,9 +683,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; |
| @@ -1291,14 +1305,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) + "."); |
|
keishi
2014/10/06 03:58:23
nit: Maybe we can use indexExceedsMinimumBound so
Bartek Nowierski
2014/10/06 13:18:16
Done.
|
| 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) + "."); |
|
keishi
2014/10/06 03:58:23
Ditto.
Bartek Nowierski
2014/10/06 13:18:16
Done.
|
| + else |
| + setIntegralAttribute(minlengthAttr, minLength); |
| +} |
| + |
| bool HTMLInputElement::multiple() const |
| { |
| return fastHasAttribute(multipleAttr); |
| @@ -1597,6 +1628,18 @@ 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; |
| + m_minLength = minLength; |
| + setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::fromAttribute(minlengthAttr)); |
| + setNeedsValidityCheck(); |
| +} |
| + |
| void HTMLInputElement::updateValueIfNeeded() |
| { |
| String newValue = sanitizeValue(m_valueIfDirty); |