From e96e9dacf530dbda6761992f0d7ad6a04357bd8c Mon Sep 17 00:00:00 2001 From: Zoe Bellot Date: Fri, 17 Aug 2012 11:53:44 +0200 Subject: [PATCH] Bug 746142 - Part 1 - Add inputmode attribute to HTMLInputElement. r=mounir sr=smaug --- content/base/src/nsGkAtomList.h | 1 + .../html/content/src/nsHTMLInputElement.cpp | 27 +++++++++++++++++++ .../test_input_attributes_reflection.html | 9 +++++++ .../html/nsIDOMHTMLInputElement.idl | 4 ++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 0e6f37c88145..34871866ec2a 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -445,6 +445,7 @@ GK_ATOM(inherits, "inherits") GK_ATOM(inheritstyle, "inheritstyle") GK_ATOM(initial_scale, "initial-scale") GK_ATOM(input, "input") +GK_ATOM(inputmode, "inputmode") GK_ATOM(ins, "ins") GK_ATOM(insertafter, "insertafter") GK_ATOM(insertbefore, "insertbefore") diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 24ed3dea7781..3578f887c481 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -147,6 +147,28 @@ static const nsAttrValue::EnumTable kInputAutocompleteTable[] = { // Default autocomplete value is "". static const nsAttrValue::EnumTable* kInputDefaultAutocomplete = &kInputAutocompleteTable[0]; +static const uint8_t NS_INPUT_INPUTMODE_AUTO = 0; +static const uint8_t NS_INPUT_INPUTMODE_NUMERIC = 1; +static const uint8_t NS_INPUT_INPUTMODE_DIGIT = 2; +static const uint8_t NS_INPUT_INPUTMODE_UPPERCASE = 3; +static const uint8_t NS_INPUT_INPUTMODE_LOWERCASE = 4; +static const uint8_t NS_INPUT_INPUTMODE_TITLECASE = 5; +static const uint8_t NS_INPUT_INPUTMODE_AUTOCAPITALIZED = 6; + +static const nsAttrValue::EnumTable kInputInputmodeTable[] = { + { "auto", NS_INPUT_INPUTMODE_AUTO }, + { "numeric", NS_INPUT_INPUTMODE_NUMERIC }, + { "digit", NS_INPUT_INPUTMODE_DIGIT }, + { "uppercase", NS_INPUT_INPUTMODE_UPPERCASE }, + { "lowercase", NS_INPUT_INPUTMODE_LOWERCASE }, + { "titlecase", NS_INPUT_INPUTMODE_TITLECASE }, + { "autocapitalized", NS_INPUT_INPUTMODE_AUTOCAPITALIZED }, + { 0 } +}; + +// Default inputmode value is "auto". +static const nsAttrValue::EnumTable* kInputDefaultInputmode = &kInputInputmodeTable[0]; + const double nsHTMLInputElement::kDefaultStepBase = 0; const double nsHTMLInputElement::kStepAny = 0; @@ -866,6 +888,8 @@ NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLInputElement, FormMethod, formmethod, kFormDefaultMethod->tag) NS_IMPL_BOOL_ATTR(nsHTMLInputElement, FormNoValidate, formnovalidate) NS_IMPL_STRING_ATTR(nsHTMLInputElement, FormTarget, formtarget) +NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLInputElement, Inputmode, inputmode, + kInputDefaultInputmode->tag) NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Multiple, multiple) NS_IMPL_NON_NEGATIVE_INT_ATTR(nsHTMLInputElement, MaxLength, maxlength) NS_IMPL_STRING_ATTR(nsHTMLInputElement, Name, name) @@ -2741,6 +2765,9 @@ nsHTMLInputElement::ParseAttribute(int32_t aNamespaceID, if (aAttribute == nsGkAtoms::autocomplete) { return aResult.ParseEnumValue(aValue, kInputAutocompleteTable, false); } + if (aAttribute == nsGkAtoms::inputmode) { + return aResult.ParseEnumValue(aValue, kInputInputmodeTable, false); + } if (ParseImageAttribute(aAttribute, aValue, aResult)) { // We have to call |ParseImageAttribute| unconditionally since we // don't know if we're going to have a type="image" attribute yet, diff --git a/content/html/content/test/forms/test_input_attributes_reflection.html b/content/html/content/test/forms/test_input_attributes_reflection.html index 1573afaa0903..7967fadc7aa4 100644 --- a/content/html/content/test/forms/test_input_attributes_reflection.html +++ b/content/html/content/test/forms/test_input_attributes_reflection.html @@ -110,6 +110,15 @@ reflectUnsignedInt({ // .indeterminate doesn't reflect a content attribute. +// .inputmode +reflectLimitedEnumerated({ + element: document.createElement("input"), + attribute: "inputmode", + validValues: [ "numeric", "digit", "uppercase", "lowercase", "titlecase", "autocapitalized", "auto" ], + invalidValues: [ "", "foo", "tulip" ], + defaultValue: "auto" +}); + // TODO: list (HTMLElement) // .max diff --git a/dom/interfaces/html/nsIDOMHTMLInputElement.idl b/dom/interfaces/html/nsIDOMHTMLInputElement.idl index b199a2e53498..3cfae14a6a4a 100644 --- a/dom/interfaces/html/nsIDOMHTMLInputElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLInputElement.idl @@ -20,7 +20,7 @@ interface nsIDOMValidityState; * http://www.whatwg.org/specs/web-apps/current-work/ */ -[scriptable, uuid(c12471c8-155f-4368-9e8b-13a231e85f3b)] +[scriptable, uuid(83984fd0-b0b2-11e1-afa6-0800200c9a66)] interface nsIDOMHTMLInputElement : nsIDOMHTMLElement { attribute DOMString accept; @@ -43,6 +43,8 @@ interface nsIDOMHTMLInputElement : nsIDOMHTMLElement attribute unsigned long height; attribute boolean indeterminate; + attribute DOMString inputmode; + readonly attribute nsIDOMHTMLElement list; attribute DOMString max; attribute long maxLength;