From 88b78d7a07deaac83f3001907c2a68d8ef768444 Mon Sep 17 00:00:00 2001 From: Raphael Catolino Date: Fri, 21 Dec 2012 18:26:56 +0100 Subject: [PATCH] Bug 769355 - Implements max attribute for . r=mounir --- .../html/content/src/nsHTMLInputElement.cpp | 29 ++++++++------ .../test/forms/test_max_attribute.html | 39 ++++++++++++++++++- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 7106eee2386a..ee29cd46d105 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -1335,8 +1335,8 @@ nsHTMLInputElement::GetMinAsDouble() const double nsHTMLInputElement::GetMaxAsDouble() const { - // Should only be used for for the moment. - MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER); + // Should only be used for for the moment. + MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER || mType == NS_FORM_INPUT_DATE); if (!HasAttr(kNameSpaceID_None, nsGkAtoms::max)) { return MOZ_DOUBLE_NaN(); @@ -1345,9 +1345,8 @@ nsHTMLInputElement::GetMaxAsDouble() const nsAutoString maxStr; GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr); - nsresult ec; - double max = maxStr.ToDouble(&ec); - return NS_SUCCEEDED(ec) ? max : MOZ_DOUBLE_NaN(); + double max; + return ConvertStringToNumber(maxStr, max) ? max : MOZ_DOUBLE_NaN(); } double @@ -4420,8 +4419,7 @@ nsHTMLInputElement::HasPatternMismatch() const bool nsHTMLInputElement::IsRangeOverflow() const { - // Ignore until bug 769355 is fixed. - if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATE) { + if (!DoesMinMaxApply()) { return false; } @@ -4699,11 +4697,18 @@ nsHTMLInputElement::GetValidationMessage(nsAString& aValidationMessage, { nsXPIDLString message; - double max = GetMaxAsDouble(); - MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(max)); - nsAutoString maxStr; - maxStr.AppendFloat(max); + if (mType == NS_FORM_INPUT_NUMBER) { + //We want to show the value as parsed when it's a number + double max = GetMaxAsDouble(); + MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(max)); + + maxStr.AppendFloat(max); + } else if (mType == NS_FORM_INPUT_DATE) { + GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr); + } else { + NS_NOTREACHED("Unexpected input type"); + } const PRUnichar* params[] = { maxStr.get() }; rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, @@ -5196,7 +5201,7 @@ nsHTMLInputElement::UpdateHasRange() { mHasRange = false; - if (mType != NS_FORM_INPUT_NUMBER) { + if (mType != NS_FORM_INPUT_NUMBER && mType != NS_FORM_INPUT_DATE) { return; } diff --git a/content/html/content/test/forms/test_max_attribute.html b/content/html/content/test/forms/test_max_attribute.html index 489a83845ff7..0075f0e14bd0 100644 --- a/content/html/content/test/forms/test_max_attribute.html +++ b/content/html/content/test/forms/test_max_attribute.html @@ -28,7 +28,7 @@ var types = [ [ 'email', false ], [ 'password', false ], [ 'datetime', true, true ], - [ 'date', true, true ], + [ 'date', true ], [ 'month', true, true ], [ 'week', true, true ], [ 'time', true, true ], @@ -90,7 +90,12 @@ for (var data of types) { checkValidity(input, true, apply, false); - input.max = '2'; + if (input.type == 'date') { + input.max = '2012-06-27'; + } else { + input.max = '2'; + } + checkValidity(input, true, apply, apply); if (input.type == 'url') { @@ -118,6 +123,36 @@ for (var data of types) { checkValidity(input, true, apply, apply); file.remove(false); + } else if (input.type == 'date') { + input.value = '2012-06-26'; + checkValidity(input, true, apply, apply); + + input.value = '2012-06-27'; + checkValidity(input, true, apply, apply); + + input.value = 'foo'; + checkValidity(input, true, apply, apply); + + input.value = '2012-06-28'; + checkValidity(input, false, apply, apply); + + input.max = '2012-06-30'; + checkValidity(input, true, apply, apply); + + input.value = '2012-07-05'; + checkValidity(input, false, apply, apply); + + input.value = '1000-01-01'; + checkValidity(input, true, apply, apply); + + input.value = '20120-01-01'; + checkValidity(input, false, apply, apply); + + input.max = '0050-01-01'; + checkValidity(input, false, apply, apply); + + input.value = '0049-01-01'; + checkValidity(input, true, apply, apply); } else { input.value = '1'; checkValidity(input, true, apply, apply);