Commit 9e57ef9c authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Add support for inheriting autocapitalize attribute from form owner

This CL adds support for inheriting the autocapitalize attribute from a form
owner as described in the new spec for autocapitalize:
https://html.spec.whatwg.org/multipage/interaction.html#autocapitalization

This CL also adds tests for this new behavior.

Bug: 776618
Change-Id: Ib96354fb320736255369bd2df3113e172dfdb42e
Reviewed-on: https://chromium-review.googlesource.com/872090Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532020}
parent ad9fe998
...@@ -64,6 +64,11 @@ public class ImeAutocapitalizeTest { ...@@ -64,6 +64,11 @@ public class ImeAutocapitalizeTest {
Assert.assertEquals(EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES, Assert.assertEquals(EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES,
mRule.getConnectionFactory().getOutAttrs().inputType & autocapitalizeFlagMask); mRule.getConnectionFactory().getOutAttrs().inputType & autocapitalizeFlagMask);
// <input> element that inherits autocapitalize="none" from its parent <form> element.
mRule.focusElement("input_autocapitalize_inherit_none");
Assert.assertEquals(
0, mRule.getConnectionFactory().getOutAttrs().inputType & autocapitalizeFlagMask);
// contenteditable <div> element with autocapitalize="characters". // contenteditable <div> element with autocapitalize="characters".
mRule.focusElement("div_autocapitalize_characters"); mRule.focusElement("div_autocapitalize_characters");
Assert.assertEquals(EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS, Assert.assertEquals(EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS,
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
<input id="input_autocapitalize_words" autocapitalize="words"> <input id="input_autocapitalize_words" autocapitalize="words">
<input id="input_autocapitalize_sentences" autocapitalize="sentences"> <input id="input_autocapitalize_sentences" autocapitalize="sentences">
<form autocapitalize="none">
<input id="input_autocapitalize_inherit_none">
</form>
<div id="div_autocapitalize_characters" contenteditable autocapitalize="characters"> <div id="div_autocapitalize_characters" contenteditable autocapitalize="characters">
</div> </div>
</body> </body>
......
<!DOCTYPE html>
<html>
<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#autocapitalization">
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
assert_true('autocapitalize' in document.createElement('input'));
}, "Test that the autocapitalize is available on HTMLInputElement.")
test(function() {
assert_true('autocapitalize' in document.createElement('textarea'));
}, "Test that the autocapitalize is available on HTMLTextAreaElement.")
test(function() {
assert_true('autocapitalize' in document.createElement('div'));
}, "Test that the autocapitalize is available on div.")
test(function() {
var elements = [ document.createElement('input'),
document.createElement('textarea'),
document.createElement('div') ];
elements.forEach(function(e) {
e.autocapitalize = 'on';
assert_equals(e.autocapitalize, 'sentences');
e.autocapitalize = 'off';
assert_equals(e.autocapitalize, 'none');
});
}, "Test deprecated values of autocapitalize.");
test(function() {
var elements = [ document.createElement('input'),
document.createElement('textarea'),
document.createElement('div') ];
var knownValues = [ 'none', 'characters', 'words', 'sentences' ];
elements.forEach(function(e) {
// Default value.
assert_equals(e.autocapitalize, '');
// Empty value.
e.autocapitalize = '';
assert_equals(e.autocapitalize, '');
assert_equals(e.getAttribute('autocapitalize'), '');
e.setAttribute('autocapitalize', '');
assert_equals(e.autocapitalize, '');
assert_equals(e.getAttribute('autocapitalize'), '');
assert_equals(e.autocapitalize, '');
// Invalid value.
e.autocapitalize = 'foo';
assert_equals(e.autocapitalize, 'sentences');
assert_equals(e.getAttribute('autocapitalize'), 'foo');
e.setAttribute('autocapitalize', 'bar');
assert_equals(e.autocapitalize, 'sentences');
assert_equals(e.getAttribute('autocapitalize'), 'bar');
// Default value.
e.removeAttribute('autocapitalize');
assert_equals(e.autocapitalize, '');
assert_equals(e.getAttribute('autocapitalize'), null);
// Case insensitive.
e.setAttribute('autocapitalize', 'NoNe');
assert_equals(e.autocapitalize, 'none');
assert_equals(e.getAttribute('autocapitalize'), 'NoNe');
e.autocapitalize = 'WORDS';
assert_equals(e.autocapitalize, 'words');
assert_equals(e.getAttribute('autocapitalize'), 'WORDS');
knownValues.forEach(function(value) {
e.setAttribute('autocapitalize', value);
assert_equals(e.autocapitalize, value);
assert_equals(e.getAttribute('autocapitalize'), value);
e.removeAttribute('autocapitalize');
e.autocapitalize = value;
assert_equals(e.autocapitalize, value);
assert_equals(e.getAttribute('autocapitalize'), value);
e.removeAttribute('autocapitalize');
});
});
}, "Test reflection of autocapitalize.");
test(function() {
var testData = [ 'text',
'search',
'email',
'url',
'tel',
'number',
'date',
'color',
'password' ];
testData.forEach(function(data) {
const input = document.createElement('input');
input.type = data;
assert_equals(input.autocapitalize, '');
// Verify that wrapping the input element in a form doesn't change the
// defaults.
const form = document.createElement('form');
form.appendChild(input);
assert_equals(input.autocapitalize, '');
});
}, "Test that the IDL attribute returns the empty string if the content "
+ "attribute is not set.")
test(function() {
const testData = [ 'text',
'search',
'email',
'url',
'tel',
'number',
'date',
'color',
'password' ];
testData.forEach(function(data) {
const input = document.createElement('input');
input.setAttribute('type', data);
input.setAttribute('autocapitalize', 'sentences');
assert_equals(input.autocapitalize, 'sentences');
});
}, "Verify that even input types that are never autocapitalized support the "
+ "IDL interface.")
</script>
</body>
</html>
...@@ -3054,6 +3054,13 @@ TEST_F( ...@@ -3054,6 +3054,13 @@ TEST_F(
} }
TEST_F(InputMethodControllerTest, AutocapitalizeTextInputFlags) { TEST_F(InputMethodControllerTest, AutocapitalizeTextInputFlags) {
// This test assumes that the behavior tested in
// LayoutTests/fast/forms/autocapitalize.html works properly and tests the
// following:
// - The autocapitalize IDL states map properly to WebTextInputFlags for
// <input> elements, <textarea> elements, and editable regions
// - We ignore the value of the IDL attribute for password/email/URL inputs
// and always send None for this case.
Vector<std::pair<String, int>> element_and_expected_flags_pairs = { Vector<std::pair<String, int>> element_and_expected_flags_pairs = {
{"<input type='text'>", kWebTextInputFlagAutocapitalizeSentences}, {"<input type='text'>", kWebTextInputFlagAutocapitalizeSentences},
{"<input type='text' autocapitalize='none'>", {"<input type='text' autocapitalize='none'>",
......
...@@ -237,6 +237,19 @@ void HTMLFormControlElement::SetAutofilled(bool autofilled) { ...@@ -237,6 +237,19 @@ void HTMLFormControlElement::SetAutofilled(bool autofilled) {
PseudoStateChanged(CSSSelector::kPseudoAutofill); PseudoStateChanged(CSSSelector::kPseudoAutofill);
} }
const AtomicString& HTMLFormControlElement::autocapitalize() const {
if (!FastGetAttribute(autocapitalizeAttr).IsEmpty())
return HTMLElement::autocapitalize();
// If the form control itself does not have the autocapitalize attribute set,
// but the form owner is non-null and does have the autocapitalize attribute
// set, we inherit from the form owner.
if (HTMLFormElement* form = Form())
return form->autocapitalize();
return g_empty_atom;
}
static bool ShouldAutofocusOnAttach(const HTMLFormControlElement* element) { static bool ShouldAutofocusOnAttach(const HTMLFormControlElement* element) {
if (!element->IsAutofocusable()) if (!element->IsAutofocusable())
return false; return false;
......
...@@ -125,6 +125,8 @@ class CORE_EXPORT HTMLFormControlElement : public LabelableElement, ...@@ -125,6 +125,8 @@ class CORE_EXPORT HTMLFormControlElement : public LabelableElement,
bool IsAutofilled() const { return is_autofilled_; } bool IsAutofilled() const { return is_autofilled_; }
void SetAutofilled(bool = true); void SetAutofilled(bool = true);
const AtomicString& autocapitalize() const final;
static const HTMLFormControlElement* EnclosingFormControlElement(const Node*); static const HTMLFormControlElement* EnclosingFormControlElement(const Node*);
String NameForAutofill() const; String NameForAutofill() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment