Bug 769385 - Add type attribute date for <input> behind "dom.experimental_forms" pref. r=mounir

This commit is contained in:
Raphael Catolino 2012-12-27 16:06:53 +00:00
parent 0dae975a9a
commit 9ac55077bf
15 changed files with 78 additions and 23 deletions

View File

@ -282,14 +282,12 @@ function getJSON(element) {
// Until the input type=date/datetime/time have been implemented
// let's return their real type even if the platform returns 'text'
// Related to Bug 769352 - Implement <input type=date>
// Related to Bug 777279 - Implement <input type=time>
let attributeType = element.getAttribute("type") || "";
if (attributeType) {
var typeLowerCase = attributeType.toLowerCase();
switch (typeLowerCase) {
case "date":
case "time":
case "datetime":
case "datetime-local":

View File

@ -1899,6 +1899,7 @@ nsEventStateManager::FireContextClick()
type == NS_FORM_INPUT_PASSWORD ||
type == NS_FORM_INPUT_FILE ||
type == NS_FORM_INPUT_NUMBER ||
type == NS_FORM_INPUT_DATE ||
type == NS_FORM_TEXTAREA);
}
else if (tag == nsGkAtoms::applet ||

View File

@ -48,6 +48,7 @@ enum ButtonElementTypes {
enum InputElementTypes {
NS_FORM_INPUT_BUTTON = NS_FORM_INPUT_ELEMENT + 1,
NS_FORM_INPUT_CHECKBOX,
NS_FORM_INPUT_DATE,
NS_FORM_INPUT_EMAIL,
NS_FORM_INPUT_FILE,
NS_FORM_INPUT_HIDDEN,
@ -232,6 +233,8 @@ nsIFormControl::IsSingleLineTextControl(bool aExcludePassword, uint32_t aType)
aType == NS_FORM_INPUT_URL ||
// TODO: this is temporary until bug 635240 is fixed.
aType == NS_FORM_INPUT_NUMBER ||
// TODO: this is temporary until bug 773205 is fixed.
aType == NS_FORM_INPUT_DATE ||
(!aExcludePassword && aType == NS_FORM_INPUT_PASSWORD);
}

View File

@ -184,6 +184,7 @@ ShouldBeInElements(nsIFormControl* aFormControl)
case NS_FORM_INPUT_TEL :
case NS_FORM_INPUT_URL :
case NS_FORM_INPUT_NUMBER :
case NS_FORM_INPUT_DATE :
case NS_FORM_SELECT :
case NS_FORM_TEXTAREA :
case NS_FORM_FIELDSET :

View File

@ -117,6 +117,7 @@ UploadLastDir* nsHTMLInputElement::gUploadLastDir;
static const nsAttrValue::EnumTable kInputTypeTable[] = {
{ "button", NS_FORM_INPUT_BUTTON },
{ "checkbox", NS_FORM_INPUT_CHECKBOX },
{ "date", NS_FORM_INPUT_DATE },
{ "email", NS_FORM_INPUT_EMAIL },
{ "file", NS_FORM_INPUT_FILE },
{ "hidden", NS_FORM_INPUT_HIDDEN },
@ -134,7 +135,7 @@ static const nsAttrValue::EnumTable kInputTypeTable[] = {
};
// Default type is 'text'.
static const nsAttrValue::EnumTable* kInputDefaultType = &kInputTypeTable[13];
static const nsAttrValue::EnumTable* kInputDefaultType = &kInputTypeTable[14];
static const uint8_t NS_INPUT_AUTOCOMPLETE_OFF = 0;
static const uint8_t NS_INPUT_AUTOCOMPLETE_ON = 1;
@ -696,6 +697,7 @@ nsHTMLInputElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
case NS_FORM_INPUT_TEL:
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
if (mValueChanged) {
// We don't have our default value anymore. Set our value on
// the clone.
@ -1373,8 +1375,8 @@ nsHTMLInputElement::MozSetFileNameArray(const PRUnichar **aFileNames, uint32_t a
NS_IMETHODIMP
nsHTMLInputElement::MozIsTextField(bool aExcludePassword, bool* aResult)
{
// TODO: temporary until bug 635240 is fixed.
if (mType == NS_FORM_INPUT_NUMBER) {
// TODO: temporary until bug 635240 and 773205 are fixed.
if (mType == NS_FORM_INPUT_NUMBER || mType == NS_FORM_INPUT_DATE) {
*aResult = false;
return NS_OK;
}
@ -2460,7 +2462,8 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
(keyEvent->keyCode == NS_VK_RETURN ||
keyEvent->keyCode == NS_VK_ENTER) &&
(IsSingleLineTextControl(false, mType) ||
mType == NS_FORM_INPUT_NUMBER)) {
mType == NS_FORM_INPUT_NUMBER ||
mType == NS_FORM_INPUT_DATE)) {
FireChangeEventIfNeeded();
rv = MaybeSubmitForm(aVisitor.mPresContext);
NS_ENSURE_SUCCESS(rv, rv);
@ -2771,8 +2774,9 @@ nsHTMLInputElement::ParseAttribute(int32_t aNamespaceID,
bool success = aResult.ParseEnumValue(aValue, kInputTypeTable, false);
if (success) {
newType = aResult.GetEnumValue();
if (newType == NS_FORM_INPUT_NUMBER &&
!Preferences::GetBool("dom.experimental_forms", false)) {
if ((newType == NS_FORM_INPUT_NUMBER ||
newType == NS_FORM_INPUT_DATE) &&
!Preferences::GetBool("dom.experimental_forms", false)) {
newType = kInputDefaultType->value;
aResult.SetTo(newType, &aValue);
}
@ -3397,6 +3401,7 @@ nsHTMLInputElement::SaveState()
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_HIDDEN:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
{
if (mValueChanged) {
inputState = new nsHTMLInputElementState();
@ -3581,6 +3586,7 @@ nsHTMLInputElement::RestoreState(nsPresState* aState)
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_HIDDEN:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
{
SetValueInternal(inputState->GetValue(), false, true);
break;
@ -3805,6 +3811,7 @@ nsHTMLInputElement::GetValueMode() const
case NS_FORM_INPUT_EMAIL:
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
return VALUE_MODE_VALUE;
default:
NS_NOTYETIMPLEMENTED("Unexpected input type in GetValueMode()");
@ -3849,6 +3856,7 @@ nsHTMLInputElement::DoesReadOnlyApply() const
case NS_FORM_INPUT_EMAIL:
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
return true;
default:
NS_NOTYETIMPLEMENTED("Unexpected input type in DoesReadOnlyApply()");
@ -3885,6 +3893,7 @@ nsHTMLInputElement::DoesRequiredApply() const
case NS_FORM_INPUT_EMAIL:
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
return true;
default:
NS_NOTYETIMPLEMENTED("Unexpected input type in DoesRequiredApply()");
@ -3896,11 +3905,21 @@ nsHTMLInputElement::DoesRequiredApply() const
}
}
bool
nsHTMLInputElement::PlaceholderApplies() const
{
if (mType == NS_FORM_INPUT_DATE) {
return false;
}
return IsSingleLineTextControl(false);
}
bool
nsHTMLInputElement::DoesPatternApply() const
{
// TODO: temporary until bug 635240 is fixed.
if (mType == NS_FORM_INPUT_NUMBER) {
if (mType == NS_FORM_INPUT_NUMBER || mType == NS_FORM_INPUT_DATE) {
return false;
}
@ -3913,6 +3932,7 @@ nsHTMLInputElement::DoesMinMaxApply() const
switch (mType)
{
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
// TODO:
// case NS_FORM_INPUT_RANGE:
// All date/time types.
@ -4109,7 +4129,8 @@ nsHTMLInputElement::HasPatternMismatch() const
bool
nsHTMLInputElement::IsRangeOverflow() const
{
if (!DoesMinMaxApply()) {
// Ignore <input type=date> until bug 769355 is fixed.
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATE) {
return false;
}
@ -4129,7 +4150,8 @@ nsHTMLInputElement::IsRangeOverflow() const
bool
nsHTMLInputElement::IsRangeUnderflow() const
{
if (!DoesMinMaxApply()) {
// Ignore <input type=date> until bug 769357 is fixed.
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATE) {
return false;
}

View File

@ -502,7 +502,7 @@ protected:
/**
* Returns whether the placeholder attribute applies for the current type.
*/
bool PlaceholderApplies() const { return IsSingleLineTextControl(false, mType); }
bool PlaceholderApplies() const;
/**
* Set the current default value to the value of the input element.

View File

@ -201,10 +201,10 @@ reflectLimitedEnumerated({
attribute: "type",
validValues: [ "hidden", "text", "search", "tel", "url", "email", "password",
"checkbox", "radio", "file", "submit", "image", "reset",
"button", "number" ],
"button", "date", "number" ],
invalidValues: [ "this-is-probably-a-wrong-type", "", "tulip" ],
defaultValue: "text",
unsupportedValues: [ "datetime", "date", "month", "week", "time",
unsupportedValues: [ "datetime", "month", "week", "time",
"datetime-local", "range", "color" ]
});

View File

@ -48,6 +48,7 @@ var gInputTestData = [
['email', true],
['url', true],
['number', false],
['date', false],
];
/**
@ -58,7 +59,6 @@ var gInputTodoData = [
/* type expected result */
['range', false],
['color', false],
['date', false],
['datetime', false],
['month', false],
['week', false],

View File

@ -261,8 +261,8 @@ var input = document.getElementById('i');
// and |invalidTypes| are the ones which do not accept it.
var validTypes = Array('text', 'password', 'search', 'tel', 'email', 'url');
var barredTypes = Array('hidden', 'reset', 'button', 'submit', 'image');
var invalidTypes = Array('checkbox', 'radio', 'file', 'number');
// TODO: 'datetime', 'date', 'month', 'week', 'time', 'datetime-local',
var invalidTypes = Array('checkbox', 'radio', 'file', 'number', 'date');
// TODO: 'datetime', 'month', 'week', 'time', 'datetime-local',
// 'range', and 'color' do not accept the @pattern too but are not
// implemented yet.

View File

@ -164,6 +164,8 @@ function checkInputRequiredValidity(type)
element.value = 'http://mozilla.org/';
} else if (element.type == 'number') {
element.value = '42';
} else if (element.type == 'date') {
element.value = '2010-10-10';
} else {
element.value = 'foo';
}
@ -352,6 +354,9 @@ function checkInputRequiredValidityForFile()
checkNotSufferingFromBeingMissing(element);
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
checkTextareaRequiredValidity();
// The require attribute behavior depend of the input type.
@ -370,10 +375,10 @@ for (type of typeRequireNotApply) {
}
// Now, checking for all types which accept the required attribute.
// TODO: check 'datetime', 'date', 'month', 'week', 'time' and 'datetime-local'
// TODO: check 'datetime', 'month', 'week', 'time' and 'datetime-local'
// when they will be implemented.
var typeRequireApply = ["text", "password", "search", "tel", "email", "url",
"number"];
"number", "date"];
for (type of typeRequireApply) {
checkInputRequiredValidity(type);
@ -383,6 +388,9 @@ checkInputRequiredValidityForCheckbox();
checkInputRequiredValidityForRadio();
checkInputRequiredValidityForFile();
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -25,13 +25,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=549475
var inputTypes =
[
"text", "password", "search", "tel", "hidden", "checkbox", "radio",
"submit", "image", "reset", "button", "email", "url", "number",
"submit", "image", "reset", "button", "email", "url", "number", "date",
];
var todoTypes =
[
"range", "color",
"date", "month", "week", "time", "datetime", "datetime-local",
"month", "week", "time", "datetime", "datetime-local",
];
var valueModeValue =

View File

@ -35,11 +35,12 @@ var testData = [
[ "search", true ],
[ "password", true ],
[ "number", true ],
[ "date", true ],
// 'file' is treated separatly.
];
var todoTypes = [
"datetime", "date", "month", "week", "time", "datetime-local", "range", "color"
"datetime", "month", "week", "time", "datetime-local", "range", "color"
];
var length = testData.length;

View File

@ -3264,6 +3264,7 @@ nsWebBrowserPersist::CloneNodeWithFixedUpAttributes(
case NS_FORM_INPUT_TEL:
case NS_FORM_INPUT_URL:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
nodeAsInput->GetValue(valueStr);
// Avoid superfluous value="" serialization
if (valueStr.IsEmpty())

View File

@ -3432,6 +3432,8 @@ nsCSSFrameConstructor::FindInputData(Element* aElement,
SIMPLE_INT_CREATE(NS_FORM_INPUT_PASSWORD, NS_NewTextControlFrame),
// TODO: this is temporary until a frame is written: bug 635240.
SIMPLE_INT_CREATE(NS_FORM_INPUT_NUMBER, NS_NewTextControlFrame),
// TODO: this is temporary until a frame is written: bug 773205.
SIMPLE_INT_CREATE(NS_FORM_INPUT_DATE, NS_NewTextControlFrame),
{ NS_FORM_INPUT_SUBMIT,
FCDATA_WITH_WRAPPING_BLOCK(0, NS_NewGfxButtonControlFrame,
nsCSSAnonBoxes::buttonContent) },

View File

@ -92,6 +92,12 @@ Form History test: form field autocomplete
<button type="submit">Submit</button>
</form>
<!-- form with input type='date' -->
<form id="form14" onsubmit="return false;">
<input type="date" name="field11">
<button type="submit">Submit</button>
</form>
</div>
<pre id="test">
@ -134,10 +140,11 @@ fh.addEntry("field7", "value");
fh.addEntry("field8", "value");
fh.addEntry("field9", "value");
fh.addEntry("field10", "42");
fh.addEntry("field11", "2010-10-10");
fh.addEntry("searchbar-history", "blacklist test");
// All these non-implemeted types might need autocomplete tests in the future.
var todoTypes = [ "datetime", "date", "month", "week", "time", "datetime-local",
var todoTypes = [ "datetime", "month", "week", "time", "datetime-local",
"range", "color" ];
var todoInput = document.createElement("input");
for (var type of todoTypes) {
@ -730,6 +737,17 @@ function runTest(testNum) {
doKey("return");
checkForm("42");
input = $_(14, "field11");
restoreForm();
doKey("down");
break;
case 405:
checkMenuEntries(["2010-10-10"]);
doKey("down");
doKey("return");
checkForm("2010-10-10");
// Go to test 500.
fh.addEntry("field1", "value1");
input = $_(1, "field1");