diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 183e7a69773..fc57c148343 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -815,6 +815,8 @@ nsHTMLInputElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, UpdateTypeMismatchValidityState(); } else if (aName == nsGkAtoms::max) { UpdateRangeOverflowValidityState(); + } else if (aName == nsGkAtoms::min) { + UpdateRangeUnderflowValidityState(); } UpdateState(aNotify); @@ -3800,6 +3802,30 @@ nsHTMLInputElement::IsRangeOverflow() const return value > max; } +bool +nsHTMLInputElement::IsRangeUnderflow() const +{ + nsAutoString minStr; + if (!DoesMinMaxApply() || + !GetAttr(kNameSpaceID_None, nsGkAtoms::min, minStr)) { + return false; + } + + PRInt32 ec; + double min = minStr.ToDouble(&ec); + if (NS_FAILED(ec)) { + return false; + } + + double value = GetValueAsDouble(); + // value can be NaN when value="". + if (value != value) { + return false; + } + + return value < min; +} + void nsHTMLInputElement::UpdateTooLongValidityState() { @@ -3884,6 +3910,12 @@ nsHTMLInputElement::UpdateRangeOverflowValidityState() SetValidityState(VALIDITY_STATE_RANGE_OVERFLOW, IsRangeOverflow()); } +void +nsHTMLInputElement::UpdateRangeUnderflowValidityState() +{ + SetValidityState(VALIDITY_STATE_RANGE_UNDERFLOW, IsRangeUnderflow()); +} + void nsHTMLInputElement::UpdateAllValidityStates(bool aNotify) { @@ -3893,6 +3925,7 @@ nsHTMLInputElement::UpdateAllValidityStates(bool aNotify) UpdateTypeMismatchValidityState(); UpdatePatternMismatchValidityState(); UpdateRangeOverflowValidityState(); + UpdateRangeUnderflowValidityState(); if (validBefore != IsValid()) { UpdateState(aNotify); @@ -4020,6 +4053,26 @@ nsHTMLInputElement::GetValidationMessage(nsAString& aValidationMessage, aValidationMessage = message; break; } + case VALIDITY_STATE_RANGE_UNDERFLOW: + { + nsXPIDLString message; + nsAutoString minStr; + GetAttr(kNameSpaceID_None, nsGkAtoms::min, minStr); + + // We want to show the double as parsed so we parse it and change minStr. + PRInt32 ec; + double min = minStr.ToDouble(&ec); + NS_ASSERTION(NS_SUCCEEDED(ec), "min must be a number at this point!"); + minStr.Truncate(); + minStr.AppendFloat(min); + + const PRUnichar* params[] = { minStr.get() }; + rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, + "FormValidationRangeUnderflow", + params, message); + aValidationMessage = message; + break; + } default: rv = nsIConstraintValidation::GetValidationMessage(aValidationMessage, aType); } diff --git a/content/html/content/src/nsHTMLInputElement.h b/content/html/content/src/nsHTMLInputElement.h index 015ef1110f0..3981803d490 100644 --- a/content/html/content/src/nsHTMLInputElement.h +++ b/content/html/content/src/nsHTMLInputElement.h @@ -217,11 +217,13 @@ public: bool HasTypeMismatch() const; bool HasPatternMismatch() const; bool IsRangeOverflow() const; + bool IsRangeUnderflow() const; void UpdateTooLongValidityState(); void UpdateValueMissingValidityState(); void UpdateTypeMismatchValidityState(); void UpdatePatternMismatchValidityState(); void UpdateRangeOverflowValidityState(); + void UpdateRangeUnderflowValidityState(); void UpdateAllValidityStates(bool aNotify); void UpdateBarredFromConstraintValidation(); nsresult GetValidationMessage(nsAString& aValidationMessage, diff --git a/content/html/content/src/nsIConstraintValidation.cpp b/content/html/content/src/nsIConstraintValidation.cpp index 1a377ccc480..24919a626df 100644 --- a/content/html/content/src/nsIConstraintValidation.cpp +++ b/content/html/content/src/nsIConstraintValidation.cpp @@ -74,6 +74,8 @@ nsIConstraintValidation::GetValidationMessage(nsAString& aValidationMessage) GetValidationMessage(aValidationMessage, VALIDITY_STATE_PATTERN_MISMATCH); } else if (GetValidityState(VALIDITY_STATE_RANGE_OVERFLOW)) { GetValidationMessage(aValidationMessage, VALIDITY_STATE_RANGE_OVERFLOW); + } else if (GetValidityState(VALIDITY_STATE_RANGE_UNDERFLOW)) { + GetValidationMessage(aValidationMessage, VALIDITY_STATE_RANGE_UNDERFLOW); } else { // TODO: The other messages have not been written // because related constraint validation are not implemented yet. diff --git a/content/html/content/test/forms/Makefile.in b/content/html/content/test/forms/Makefile.in index 9e455ff4d2e..81a71feadb7 100644 --- a/content/html/content/test/forms/Makefile.in +++ b/content/html/content/test/forms/Makefile.in @@ -43,6 +43,7 @@ _TEST_FILES = \ test_meter_element.html \ test_meter_pseudo-classes.html \ test_max_attribute.html \ + test_min_attribute.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/html/content/test/forms/test_min_attribute.html b/content/html/content/test/forms/test_min_attribute.html new file mode 100644 index 00000000000..7e0af0bf58e --- /dev/null +++ b/content/html/content/test/forms/test_min_attribute.html @@ -0,0 +1,152 @@ + + + + + Test for Bug 635553 + + + + + +Mozilla Bug 635499 +

+ +
+
+
+ + diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index de292d08965..77db8becfb4 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -42,6 +42,8 @@ FormValidationPatternMismatch=Please match the requested format. FormValidationPatternMismatchWithTitle=Please match the requested format: %S. # LOCALIZATION NOTE (FormValidationRangeOverflow): %S can be a number or a date. FormValidationRangeOverflow=Please select a value that is lower than %S. +# LOCALIZATION NOTE (FormValidationRangeUnderflow): %S can be a number or a date. +FormValidationRangeUnderflow=Please select a value that is higher than %S. GetAttributeNodeWarning=Use of getAttributeNode() is deprecated. Use getAttribute() instead. SetAttributeNodeWarning=Use of setAttributeNode() is deprecated. Use setAttribute() instead. GetAttributeNodeNSWarning=Use of getAttributeNodeNS() is deprecated. Use getAttributeNS() instead.