Bug 557628 (1/2) - Implement the autocomplete IDL attribute for form elements. r=smaug a=sicking

This commit is contained in:
Mounir Lamouri 2010-09-14 19:55:16 +02:00
Родитель 35c3089b33
Коммит 6a33bda346
4 изменённых файлов: 93 добавлений и 2 удалений

Просмотреть файл

@ -85,6 +85,17 @@
static const int NS_FORM_CONTROL_LIST_HASHTABLE_SIZE = 16;
static const PRUint8 NS_FORM_AUTOCOMPLETE_ON = 1;
static const PRUint8 NS_FORM_AUTOCOMPLETE_OFF = 0;
static const nsAttrValue::EnumTable kFormAutocompleteTable[] = {
{ "on", NS_FORM_AUTOCOMPLETE_ON },
{ "off", NS_FORM_AUTOCOMPLETE_OFF },
{ 0 }
};
// Default autocomplete value is 'on'.
static const nsAttrValue::EnumTable* kFormDefaultAutocomplete = &kFormAutocompleteTable[0];
// nsHTMLFormElement
PRBool nsHTMLFormElement::gFirstFormSubmitted = PR_FALSE;
@ -365,6 +376,8 @@ nsHTMLFormElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
NS_IMPL_STRING_ATTR(nsHTMLFormElement, AcceptCharset, acceptcharset)
NS_IMPL_STRING_ATTR(nsHTMLFormElement, Action, action)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLFormElement, Autocomplete, autocomplete,
kFormDefaultAutocomplete->tag)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLFormElement, Enctype, enctype,
kFormDefaultEnctype->tag)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLFormElement, Method, method,
@ -431,6 +444,9 @@ nsHTMLFormElement::ParseAttribute(PRInt32 aNamespaceID,
if (aAttribute == nsGkAtoms::enctype) {
return aResult.ParseEnumValue(aValue, kFormEnctypeTable, PR_FALSE);
}
if (aAttribute == nsGkAtoms::autocomplete) {
return aResult.ParseEnumValue(aValue, kFormAutocompleteTable, PR_FALSE);
}
}
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,

Просмотреть файл

@ -221,6 +221,7 @@ _TEST_FILES = \
test_bug561636.html \
test_bug556013.html \
test_bug590363.html \
test_bug557628.html \
$(NULL)
libs:: $(_TEST_FILES)

Просмотреть файл

@ -0,0 +1,72 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=557628
-->
<head>
<title>Test for Bug 557628</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557628">Mozilla Bug 557628</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 557628 **/
var formAutocompleteTestData = [
// Default value.
[ "on" ],
// Valid values.
[ "on", "off" ],
// Invalid values.
[ "", " ", "foo", "default" ]
];
function checkAttribute(element, name, data)
{
is(element.getAttribute(name), undefined,
"By default " + name + " content attribute should be undefined");
is(element[name], data[0][0],
"By default " + name + " IDL attribute should be equal to " +
data[0][0]);
// Valid values.
for (i in data[1]) {
element.setAttribute(name, data[1][i]);
is(element.getAttribute(name), data[1][i],
"getAttribute should return the content attribute");
is(element[name], data[1][i], "When getting, " + name + " IDL attribute " +
"should be equal to the content attribute if the value is known");
}
// Invalid values.
for (i in data[2]) {
element.setAttribute(name, data[2][i]);
is(element.getAttribute(name), data[2][i],
"getAttribute should return the content attribute");
is(element[name], data[0][0], "When getting, " + name + " IDL attribute " +
"should return the default value if the content attribute value isn't known");
}
// TODO values.
for (i in data[3]) {
element.setAttribute(name, data[3][i]);
is(element.getAttribute(name), data[3][i],
"getAttribute should return the content attribute");
todo_is(element[name], data[3][i], "When getting, " + name + " IDL attribute " +
"should be equal to the content attribute if the value is known");
}
}
var form = document.createElement('form');
checkAttribute(form, 'autocomplete', formAutocompleteTestData);
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -47,16 +47,18 @@
* http://www.w3.org/TR/DOM-Level-2-HTML/
*/
[scriptable, uuid(48db9517-3a85-4f6d-af5f-106ce6aadd7d)]
[scriptable, uuid(653dc482-d6db-4e85-bdd9-151fd110e7b1)]
interface nsIDOMHTMLFormElement : nsIDOMHTMLElement
{
attribute DOMString name;
attribute DOMString acceptCharset;
attribute DOMString action;
attribute DOMString autocomplete;
attribute DOMString enctype;
attribute DOMString method;
attribute DOMString target;
attribute boolean noValidate;
attribute DOMString target;
readonly attribute nsIDOMHTMLCollection elements;
readonly attribute long length;