Bug 1278737 - Add 'month' to the list of valid types attributes for <input>. r=smaug
This commit is contained in:
@@ -165,6 +165,7 @@ static const nsAttrValue::EnumTable kInputTypeTable[] = {
|
||||
{ "hidden", NS_FORM_INPUT_HIDDEN },
|
||||
{ "reset", NS_FORM_INPUT_RESET },
|
||||
{ "image", NS_FORM_INPUT_IMAGE },
|
||||
{ "month", NS_FORM_INPUT_MONTH },
|
||||
{ "number", NS_FORM_INPUT_NUMBER },
|
||||
{ "password", NS_FORM_INPUT_PASSWORD },
|
||||
{ "radio", NS_FORM_INPUT_RADIO },
|
||||
@@ -179,7 +180,7 @@ static const nsAttrValue::EnumTable kInputTypeTable[] = {
|
||||
};
|
||||
|
||||
// Default type is 'text'.
|
||||
static const nsAttrValue::EnumTable* kInputDefaultType = &kInputTypeTable[16];
|
||||
static const nsAttrValue::EnumTable* kInputDefaultType = &kInputTypeTable[17];
|
||||
|
||||
static const uint8_t NS_INPUT_INPUTMODE_AUTO = 0;
|
||||
static const uint8_t NS_INPUT_INPUTMODE_NUMERIC = 1;
|
||||
@@ -2137,9 +2138,9 @@ HTMLInputElement::GetValue(nsAString& aValue)
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Don't return non-sanitized value for types that are experimental on mobile.
|
||||
// or date types
|
||||
if (IsExperimentalMobileType(mType) || mType == NS_FORM_INPUT_DATE) {
|
||||
// Don't return non-sanitized value for types that are experimental on mobile
|
||||
// or datetime types
|
||||
if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
|
||||
SanitizeValue(aValue);
|
||||
}
|
||||
|
||||
@@ -2777,9 +2778,19 @@ HTMLInputElement::ApplyStep(int32_t aStep)
|
||||
bool
|
||||
HTMLInputElement::IsExperimentalMobileType(uint8_t aType)
|
||||
{
|
||||
return aType == NS_FORM_INPUT_TIME ||
|
||||
(aType == NS_FORM_INPUT_DATE &&
|
||||
!Preferences::GetBool("dom.forms.datepicker", false));
|
||||
return (aType == NS_FORM_INPUT_DATE &&
|
||||
!Preferences::GetBool("dom.forms.datetime", false) &&
|
||||
!Preferences::GetBool("dom.forms.datepicker", false)) ||
|
||||
(aType == NS_FORM_INPUT_TIME &&
|
||||
!Preferences::GetBool("dom.forms.datetime", false));
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLInputElement::IsDateTimeInputType(uint8_t aType)
|
||||
{
|
||||
return aType == NS_FORM_INPUT_DATE || aType == NS_FORM_INPUT_TIME ||
|
||||
aType == NS_FORM_INPUT_MONTH;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -2970,8 +2981,8 @@ HTMLInputElement::MozSetDirectory(const nsAString& aDirectoryPath,
|
||||
bool
|
||||
HTMLInputElement::MozIsTextField(bool aExcludePassword)
|
||||
{
|
||||
// TODO: temporary until bug 773205 is fixed.
|
||||
if (IsExperimentalMobileType(mType) || mType == NS_FORM_INPUT_DATE) {
|
||||
// TODO: temporary until bug 888320 is fixed.
|
||||
if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4019,7 +4030,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
||||
// Experimental mobile types rely on the system UI to prevent users to not
|
||||
// set invalid values but we have to be extra-careful. Especially if the
|
||||
// option has been enabled on desktop.
|
||||
if (IsExperimentalMobileType(mType) || mType == NS_FORM_INPUT_DATE) {
|
||||
if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
|
||||
nsAutoString aValue;
|
||||
GetValueInternal(aValue);
|
||||
nsresult rv =
|
||||
@@ -4719,7 +4730,7 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
||||
(IsSingleLineTextControl(false, mType) ||
|
||||
mType == NS_FORM_INPUT_NUMBER ||
|
||||
IsExperimentalMobileType(mType) ||
|
||||
mType == NS_FORM_INPUT_DATE)) {
|
||||
IsDateTimeInputType(mType))) {
|
||||
FireChangeEventIfNeeded();
|
||||
rv = MaybeSubmitForm(aVisitor.mPresContext);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -5538,6 +5549,20 @@ HTMLInputElement::ParseTime(const nsAString& aValue, uint32_t* aResult)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
IsDateTimeEnabled(int32_t aNewType)
|
||||
{
|
||||
return (aNewType == NS_FORM_INPUT_DATE &&
|
||||
(Preferences::GetBool("dom.forms.datetime", false) ||
|
||||
Preferences::GetBool("dom.experimental_forms", false) ||
|
||||
Preferences::GetBool("dom.forms.datepicker", false))) ||
|
||||
(aNewType == NS_FORM_INPUT_TIME &&
|
||||
(Preferences::GetBool("dom.forms.datetime", false) ||
|
||||
Preferences::GetBool("dom.experimental_forms", false))) ||
|
||||
(aNewType == NS_FORM_INPUT_MONTH &&
|
||||
Preferences::GetBool("dom.forms.datetime", false));
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLInputElement::ParseAttribute(int32_t aNamespaceID,
|
||||
nsIAtom* aAttribute,
|
||||
@@ -5557,7 +5582,8 @@ HTMLInputElement::ParseAttribute(int32_t aNamespaceID,
|
||||
(newType == NS_FORM_INPUT_NUMBER &&
|
||||
!Preferences::GetBool("dom.forms.number", false)) ||
|
||||
(newType == NS_FORM_INPUT_COLOR &&
|
||||
!Preferences::GetBool("dom.forms.color", false))) {
|
||||
!Preferences::GetBool("dom.forms.color", false)) ||
|
||||
(IsDateTimeInputType(newType) && !IsDateTimeEnabled(newType))) {
|
||||
newType = kInputDefaultType->value;
|
||||
aResult.SetTo(newType, &aValue);
|
||||
}
|
||||
@@ -6953,6 +6979,7 @@ HTMLInputElement::GetValueMode() const
|
||||
case NS_FORM_INPUT_DATE:
|
||||
case NS_FORM_INPUT_TIME:
|
||||
case NS_FORM_INPUT_COLOR:
|
||||
case NS_FORM_INPUT_MONTH:
|
||||
return VALUE_MODE_VALUE;
|
||||
default:
|
||||
NS_NOTYETIMPLEMENTED("Unexpected input type in GetValueMode()");
|
||||
@@ -6998,6 +7025,7 @@ HTMLInputElement::DoesReadOnlyApply() const
|
||||
case NS_FORM_INPUT_NUMBER:
|
||||
case NS_FORM_INPUT_DATE:
|
||||
case NS_FORM_INPUT_TIME:
|
||||
case NS_FORM_INPUT_MONTH:
|
||||
return true;
|
||||
default:
|
||||
NS_NOTYETIMPLEMENTED("Unexpected input type in DoesReadOnlyApply()");
|
||||
@@ -7035,6 +7063,7 @@ HTMLInputElement::DoesRequiredApply() const
|
||||
case NS_FORM_INPUT_NUMBER:
|
||||
case NS_FORM_INPUT_DATE:
|
||||
case NS_FORM_INPUT_TIME:
|
||||
case NS_FORM_INPUT_MONTH:
|
||||
return true;
|
||||
default:
|
||||
NS_NOTYETIMPLEMENTED("Unexpected input type in DoesRequiredApply()");
|
||||
@@ -7049,8 +7078,7 @@ HTMLInputElement::DoesRequiredApply() const
|
||||
bool
|
||||
HTMLInputElement::PlaceholderApplies() const
|
||||
{
|
||||
if (mType == NS_FORM_INPUT_DATE ||
|
||||
mType == NS_FORM_INPUT_TIME) {
|
||||
if (IsDateTimeInputType(mType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7061,7 +7089,7 @@ bool
|
||||
HTMLInputElement::DoesPatternApply() const
|
||||
{
|
||||
// TODO: temporary until bug 773205 is fixed.
|
||||
if (IsExperimentalMobileType(mType)) {
|
||||
if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7077,6 +7105,7 @@ HTMLInputElement::DoesMinMaxApply() const
|
||||
case NS_FORM_INPUT_DATE:
|
||||
case NS_FORM_INPUT_TIME:
|
||||
case NS_FORM_INPUT_RANGE:
|
||||
case NS_FORM_INPUT_MONTH:
|
||||
// TODO:
|
||||
// All date/time types.
|
||||
return true;
|
||||
@@ -7124,6 +7153,7 @@ HTMLInputElement::DoesAutocompleteApply() const
|
||||
case NS_FORM_INPUT_NUMBER:
|
||||
case NS_FORM_INPUT_RANGE:
|
||||
case NS_FORM_INPUT_COLOR:
|
||||
case NS_FORM_INPUT_MONTH:
|
||||
return true;
|
||||
#ifdef DEBUG
|
||||
case NS_FORM_INPUT_RESET:
|
||||
@@ -7301,7 +7331,8 @@ HTMLInputElement::HasPatternMismatch() const
|
||||
bool
|
||||
HTMLInputElement::IsRangeOverflow() const
|
||||
{
|
||||
if (!DoesMinMaxApply()) {
|
||||
// TODO: this is temporary until bug 888324 is fixed.
|
||||
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_MONTH) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7321,7 +7352,8 @@ HTMLInputElement::IsRangeOverflow() const
|
||||
bool
|
||||
HTMLInputElement::IsRangeUnderflow() const
|
||||
{
|
||||
if (!DoesMinMaxApply()) {
|
||||
// TODO: this is temporary until bug 888324 is fixed.
|
||||
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_MONTH) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8300,7 +8332,8 @@ HTMLInputElement::UpdateHasRange()
|
||||
|
||||
mHasRange = false;
|
||||
|
||||
if (!DoesMinMaxApply()) {
|
||||
// TODO: this is temporary until bug 888324 is fixed.
|
||||
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_MONTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user