diff options
Diffstat (limited to 'WebCore/html/HTMLInputElement.cpp')
-rw-r--r-- | WebCore/html/HTMLInputElement.cpp | 97 |
1 files changed, 59 insertions, 38 deletions
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp index 5567fe2..79f8c14 100644 --- a/WebCore/html/HTMLInputElement.cpp +++ b/WebCore/html/HTMLInputElement.cpp @@ -83,12 +83,20 @@ static const double numberDefaultStep = 1.0; static const double numberStepScaleFactor = 1.0; // Constant values for minimum(). static const double dateDefaultMinimum = -12219292800000.0; // This means 1582-10-15T00:00Z. +static const double dateTimeDefaultMinimum = -12219292800000.0; // ditto. +static const double monthDefaultMinimum = (1582.0 - 1970) * 12 + 10 - 1; // 1582-10 static const double numberDefaultMinimum = -DBL_MAX; static const double rangeDefaultMinimum = 0.0; +static const double timeDefaultMinimum = 0.0; // 00:00:00.000 +static const double weekDefaultMinimum = -12212380800000.0; // 1583-01-03, the first Monday of 1583. // Constant values for maximum(). static const double dateDefaultMaximum = DBL_MAX; +static const double dateTimeDefaultMaximum = DBL_MAX; +static const double monthDefaultMaximum = DBL_MAX; static const double numberDefaultMaximum = DBL_MAX; static const double rangeDefaultMaximum = 100.0; +static const double timeDefaultMaximum = 86399999.0; // 23:59:59.999 +static const double weekDefaultMaximum = DBL_MAX; HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) : HTMLTextFormControlElement(tagName, doc, f) @@ -274,22 +282,24 @@ bool HTMLInputElement::rangeUnderflow() const const double nan = numeric_limits<double>::quiet_NaN(); switch (inputType()) { case DATE: + case DATETIME: + case DATETIMELOCAL: + case MONTH: case NUMBER: - case RANGE: { + case RANGE: + case TIME: + case WEEK: { double doubleValue = parseToDouble(value(), nan); return isfinite(doubleValue) && doubleValue < minimum(); } case BUTTON: case CHECKBOX: case COLOR: - case DATETIME: - case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: - case MONTH: case PASSWORD: case RADIO: case RESET: @@ -297,9 +307,7 @@ bool HTMLInputElement::rangeUnderflow() const case SUBMIT: case TELEPHONE: case TEXT: - case TIME: case URL: - case WEEK: break; } return false; @@ -310,22 +318,24 @@ bool HTMLInputElement::rangeOverflow() const const double nan = numeric_limits<double>::quiet_NaN(); switch (inputType()) { case DATE: + case DATETIME: + case DATETIMELOCAL: + case MONTH: case NUMBER: - case RANGE: { + case RANGE: + case TIME: + case WEEK: { double doubleValue = parseToDouble(value(), nan); return isfinite(doubleValue) && doubleValue > maximum(); } case BUTTON: case CHECKBOX: case COLOR: - case DATETIME: - case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: - case MONTH: case PASSWORD: case RADIO: case RESET: @@ -333,9 +343,7 @@ bool HTMLInputElement::rangeOverflow() const case SUBMIT: case TELEPHONE: case TEXT: - case TIME: case URL: - case WEEK: break; } return false; @@ -346,21 +354,27 @@ double HTMLInputElement::minimum() const switch (inputType()) { case DATE: return parseToDouble(getAttribute(minAttr), dateDefaultMinimum); + case DATETIME: + case DATETIMELOCAL: + return parseToDouble(getAttribute(minAttr), dateTimeDefaultMinimum); + case MONTH: + return parseToDouble(getAttribute(minAttr), monthDefaultMinimum); case NUMBER: return parseToDouble(getAttribute(minAttr), numberDefaultMinimum); case RANGE: return parseToDouble(getAttribute(minAttr), rangeDefaultMinimum); + case TIME: + return parseToDouble(getAttribute(minAttr), timeDefaultMinimum); + case WEEK: + return parseToDouble(getAttribute(minAttr), weekDefaultMinimum); case BUTTON: case CHECKBOX: case COLOR: - case DATETIME: - case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: - case MONTH: case PASSWORD: case RADIO: case RESET: @@ -368,9 +382,7 @@ double HTMLInputElement::minimum() const case SUBMIT: case TELEPHONE: case TEXT: - case TIME: case URL: - case WEEK: break; } ASSERT_NOT_REACHED(); @@ -382,6 +394,11 @@ double HTMLInputElement::maximum() const switch (inputType()) { case DATE: return parseToDouble(getAttribute(maxAttr), dateDefaultMaximum); + case DATETIME: + case DATETIMELOCAL: + return parseToDouble(getAttribute(maxAttr), dateTimeDefaultMaximum); + case MONTH: + return parseToDouble(getAttribute(maxAttr), monthDefaultMaximum); case NUMBER: return parseToDouble(getAttribute(maxAttr), numberDefaultMaximum); case RANGE: { @@ -393,17 +410,18 @@ double HTMLInputElement::maximum() const max = std::max(min, rangeDefaultMaximum); return max; } + case TIME: + return parseToDouble(getAttribute(maxAttr), timeDefaultMaximum); + case WEEK: + return parseToDouble(getAttribute(maxAttr), weekDefaultMaximum); case BUTTON: case CHECKBOX: case COLOR: - case DATETIME: - case DATETIMELOCAL: case EMAIL: case FILE: case HIDDEN: case IMAGE: case ISINDEX: - case MONTH: case PASSWORD: case RADIO: case RESET: @@ -411,9 +429,7 @@ double HTMLInputElement::maximum() const case SUBMIT: case TELEPHONE: case TEXT: - case TIME: case URL: - case WEEK: break; } ASSERT_NOT_REACHED(); @@ -704,6 +720,7 @@ void HTMLInputElement::setInputType(const String& t) // type change, otherwise a JavaScript programmer would be able to set a text // field's value to something like /etc/passwd and then change it to a file field. if (inputType() != newType) { + bool oldWillValidate = willValidate(); if (newType == FILE && m_haveType) // Set the attribute back to the old value. // Useful in case we were called from inside parseMappedAttribute. @@ -760,8 +777,10 @@ void HTMLInputElement::setInputType(const String& t) checkedRadioButtons(this).addButton(this); } + setNeedsValidityCheck(); + if (oldWillValidate != willValidate()) + setNeedsWillValidateCheck(); InputElement::notifyFormStateChanged(this); - updateValidity(); } m_haveType = true; @@ -983,17 +1002,18 @@ void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr) if (m_data.value().isNull()) setNeedsStyleRecalc(); setFormControlValueMatchesRenderer(false); - updateValidity(); + setNeedsValidityCheck(); } else if (attr->name() == checkedAttr) { m_defaultChecked = !attr->isNull(); if (m_useDefaultChecked) { setChecked(m_defaultChecked); m_useDefaultChecked = true; } - updateValidity(); - } else if (attr->name() == maxlengthAttr) + setNeedsValidityCheck(); + } else if (attr->name() == maxlengthAttr) { InputElement::parseMaxLengthAttribute(m_data, this, this, attr); - else if (attr->name() == sizeAttr) + setNeedsValidityCheck(); + } else if (attr->name() == sizeAttr) InputElement::parseSizeAttribute(m_data, this, attr); else if (attr->name() == altAttr) { if (renderer() && inputType() == IMAGE) @@ -1037,15 +1057,16 @@ void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr) attach(); } setNeedsStyleRecalc(); - } else if (attr->name() == autosaveAttr || - attr->name() == incrementalAttr || - attr->name() == minAttr || - attr->name() == maxAttr || - attr->name() == multipleAttr || - attr->name() == precisionAttr) + } else if (attr->name() == autosaveAttr + || attr->name() == incrementalAttr) setNeedsStyleRecalc(); - else if (attr->name() == patternAttr) - updateValidity(); + else if (attr->name() == minAttr + || attr->name() == maxAttr + || attr->name() == multipleAttr + || attr->name() == patternAttr + || attr->name() == precisionAttr + || attr->name() == stepAttr) + setNeedsValidityCheck(); #if ENABLE(DATALIST) else if (attr->name() == listAttr) m_hasNonEmptyList = !attr->isEmpty(); @@ -1491,7 +1512,7 @@ void HTMLInputElement::setValue(const String& value, bool sendChangeEvent) dispatchFormControlChangeEvent(); InputElement::notifyFormStateChanged(this); - updateValidity(); + setNeedsValidityCheck(); } double HTMLInputElement::parseToDouble(const String& src, double defaultValue) const @@ -1765,7 +1786,7 @@ void HTMLInputElement::setValueFromRenderer(const String& value) m_data.setSuggestedValue(String()); updatePlaceholderVisibility(false); InputElement::setValueFromRenderer(m_data, this, this, value); - updateValidity(); + setNeedsValidityCheck(); } void HTMLInputElement::setFileListFromRenderer(const Vector<String>& paths) @@ -1777,7 +1798,7 @@ void HTMLInputElement::setFileListFromRenderer(const Vector<String>& paths) setFormControlValueMatchesRenderer(true); InputElement::notifyFormStateChanged(this); - updateValidity(); + setNeedsValidityCheck(); } bool HTMLInputElement::storesValueSeparateFromAttribute() const |