Skip to content

Commit

Permalink
Bug 1020698 - Implement @autocomplete for <textarea>. r=baku
Browse files Browse the repository at this point in the history
The dom.forms.autocomplete.formautofill check in nsContentUtils::InternalSerializeAutocompleteAttribute
will control if values other than "on" and "off" are supported.

MozReview-Commit-ID: 48X3OzvuOpV

--HG--
rename : dom/html/test/forms/test_input_autocomplete.html => dom/html/test/forms/test_autocomplete.html
extra : rebase_source : b759672d2e9ef3b1e63fd999d149cf753df60539
  • Loading branch information
mnoorenberghe committed Nov 9, 2017
1 parent d1db4c5 commit f8961d0
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 65 deletions.
2 changes: 1 addition & 1 deletion dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ nsContentUtils::InternalSerializeAutocompleteAttribute(const nsAttrValue* aAttrV
mozilla::dom::AutocompleteInfo& aInfo,
bool aGrantAllValidValue)
{
// No sandbox attribute so we are done
// No autocomplete attribute so we are done
if (!aAttrVal) {
return eAutocompleteAttrState_Invalid;
}
Expand Down
17 changes: 17 additions & 0 deletions dom/html/HTMLTextAreaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<mozilla::dom::NodeInfo
mCanShowInvalidUI(true),
mCanShowValidUI(true),
mIsPreviewEnabled(false),
mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown),
mState(this)
{
AddMutationObserver(this);
Expand Down Expand Up @@ -436,6 +437,9 @@ HTMLTextAreaElement::ParseAttribute(int32_t aNamespaceID,
} else if (aAttribute == nsGkAtoms::rows) {
aResult.ParseIntWithFallback(aValue, DEFAULT_ROWS_TEXTAREA);
return true;
} else if (aAttribute == nsGkAtoms::autocomplete) {
aResult.ParseAtomArray(aValue);
return true;
}
}
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
Expand Down Expand Up @@ -1060,6 +1064,9 @@ HTMLTextAreaElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (aName == nsGkAtoms::readonly || aName == nsGkAtoms::disabled) {
UpdateBarredFromConstraintValidation();
}
} else if (aName == nsGkAtoms::autocomplete) {
// Clear the cached @autocomplete attribute state.
mAutocompleteAttrState = nsContentUtils::eAutocompleteAttrState_Unknown;
} else if (aName == nsGkAtoms::maxlength) {
UpdateTooLongValidityState();
} else if (aName == nsGkAtoms::minlength) {
Expand Down Expand Up @@ -1369,5 +1376,15 @@ HTMLTextAreaElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return HTMLTextAreaElementBinding::Wrap(aCx, this, aGivenProto);
}

void
HTMLTextAreaElement::GetAutocomplete(DOMString& aValue)
{
const nsAttrValue* attributeVal = GetParsedAttr(nsGkAtoms::autocomplete);

mAutocompleteAttrState =
nsContentUtils::SerializeAutocompleteAttribute(attributeVal, aValue,
mAutocompleteAttrState);
}

} // namespace dom
} // namespace mozilla
7 changes: 7 additions & 0 deletions dom/html/HTMLTextAreaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ class HTMLTextAreaElement final : public nsGenericHTMLFormElementWithState,
ValidityStateType aType) override;

// Web IDL binding methods
void GetAutocomplete(DOMString& aValue);
void SetAutocomplete(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::autocomplete, aValue, aRv);
}
bool Autofocus()
{
return GetBoolAttr(nsGkAtoms::autofocus);
Expand Down Expand Up @@ -347,6 +352,8 @@ class HTMLTextAreaElement final : public nsGenericHTMLFormElementWithState,
bool mCanShowValidUI;
bool mIsPreviewEnabled;

nsContentUtils::AutocompleteAttrState mAutocompleteAttrState;

void FireChangeEventIfNeeded();

nsString mFocusedValue;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/test/forms/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ support-files =
FAIL.html
PASS.html

[test_autocomplete.html]
[test_bug1039548.html]
[test_bug1283915.html]
[test_bug1286509.html]
Expand All @@ -25,7 +26,6 @@ skip-if = os == "android" # up/down arrow keys not supported on android
[test_formaction_attribute.html]
[test_formnovalidate_attribute.html]
[test_input_attributes_reflection.html]
[test_input_autocomplete.html]
[test_input_color_input_change_events.html]
[test_input_color_picker_initial.html]
[test_input_color_picker_popup.html]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html>
<!--
Test @autocomplete on <input>
Test @autocomplete on <input>/<select>/<textarea>
-->
<head>
<title>Test for &lt;input autocomplete='…'&gt;</title>
<title>Test for @autocomplete</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
Expand Down Expand Up @@ -108,6 +108,10 @@

var selectField = document.getElementById("select-field");
checkAutocompleteValues(selectField, "select");

var textarea = document.getElementById("textarea");
checkAutocompleteValues(textarea, "textarea");

SimpleTest.finish();
}

Expand All @@ -122,6 +126,7 @@
<form>
<input id="input-field" />
<select id="select-field" />
<textarea id="textarea"></textarea>
</form>
</div>
<pre id="test">
Expand Down
3 changes: 2 additions & 1 deletion dom/webidl/HTMLTextAreaElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ interface XULControllers;

[HTMLConstructor]
interface HTMLTextAreaElement : HTMLElement {
// attribute DOMString autocomplete;
[CEReactions, SetterThrows, Pure]
attribute DOMString autocomplete;
[CEReactions, SetterThrows, Pure]
attribute boolean autofocus;
[CEReactions, SetterThrows, Pure]
Expand Down
9 changes: 0 additions & 9 deletions testing/web-platform/meta/html/dom/interfaces.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1072,18 +1072,12 @@
[HTMLButtonElement interface: document.createElement("button") must inherit property "labels" with the proper type (18)]
expected: FAIL

[HTMLTextAreaElement interface: attribute autocomplete]
expected: FAIL

[HTMLTextAreaElement interface: attribute dirName]
expected: FAIL

[HTMLTextAreaElement interface: attribute inputMode]
expected: FAIL

[HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "autocomplete" with the proper type (0)]
expected: FAIL

[HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "dirName" with the proper type (3)]
expected: FAIL

Expand Down Expand Up @@ -3820,9 +3814,6 @@
[HTMLInputElement interface: createInput("button") must inherit property "dirName" with the proper type]
expected: FAIL

[HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "autocomplete" with the proper type]
expected: FAIL

[HTMLTextAreaElement interface: document.createElement("textarea") must inherit property "dirName" with the proper type]
expected: FAIL

Expand Down
51 changes: 0 additions & 51 deletions testing/web-platform/meta/html/dom/reflection-forms.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3463,57 +3463,6 @@
[input.inputMode: IDL set to "Kana-name"]
expected: FAIL

[textarea.autocomplete: typeof IDL attribute]
expected: FAIL

[textarea.autocomplete: IDL get with DOM attribute unset]
expected: FAIL

[textarea.autocomplete: IDL set to ""]
expected: FAIL

[textarea.autocomplete: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL

[textarea.autocomplete: IDL set to undefined]
expected: FAIL

[textarea.autocomplete: IDL set to 7]
expected: FAIL

[textarea.autocomplete: IDL set to 1.5]
expected: FAIL

[textarea.autocomplete: IDL set to true]
expected: FAIL

[textarea.autocomplete: IDL set to false]
expected: FAIL

[textarea.autocomplete: IDL set to object "[object Object\]"]
expected: FAIL

[textarea.autocomplete: IDL set to NaN]
expected: FAIL

[textarea.autocomplete: IDL set to Infinity]
expected: FAIL

[textarea.autocomplete: IDL set to -Infinity]
expected: FAIL

[textarea.autocomplete: IDL set to "\\0"]
expected: FAIL

[textarea.autocomplete: IDL set to null]
expected: FAIL

[textarea.autocomplete: IDL set to object "test-toString"]
expected: FAIL

[textarea.autocomplete: IDL set to object "test-valueOf"]
expected: FAIL

[textarea.inputMode: setAttribute() to "kana-name"]
expected: FAIL

Expand Down

0 comments on commit f8961d0

Please sign in to comment.