Bug 1499188 - Make accessibility entry input type an int in bundle message. r=jchen,Jamie

Differential Revision: https://phabricator.services.mozilla.com/D8871

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2018-10-16 16:43:16 +00:00
parent c7a8a18e88
commit d220e1c023
6 changed files with 45 additions and 33 deletions

View File

@ -6,6 +6,7 @@
#include "AccessibleWrap.h" #include "AccessibleWrap.h"
#include "Accessible-inl.h" #include "Accessible-inl.h"
#include "AndroidInputType.h"
#include "DocAccessibleWrap.h" #include "DocAccessibleWrap.h"
#include "IDSet.h" #include "IDSet.h"
#include "JavaBuiltins.h" #include "JavaBuiltins.h"
@ -286,10 +287,11 @@ AccessibleWrap::CreateBundle(int32_t aParentID,
GECKOBUNDLE_PUT(nodeInfo, "rangeInfo", rangeInfo); GECKOBUNDLE_PUT(nodeInfo, "rangeInfo", rangeInfo);
} }
nsString inputType; nsString inputTypeAttr;
nsAccUtils::GetAccAttr(aAttributes, nsGkAtoms::textInputType, inputType); nsAccUtils::GetAccAttr(aAttributes, nsGkAtoms::textInputType, inputTypeAttr);
if (!inputType.IsEmpty()) { int32_t inputType = GetInputType(inputTypeAttr);
GECKOBUNDLE_PUT(nodeInfo, "inputType", jni::StringParam(inputType)); if (inputType) {
GECKOBUNDLE_PUT(nodeInfo, "inputType", java::sdk::Integer::ValueOf(inputType));
} }
nsString posinset; nsString posinset;
@ -462,6 +464,36 @@ AccessibleWrap::GetAndroidClass(role aRole)
#undef ROLE #undef ROLE
} }
int32_t
AccessibleWrap::GetInputType(const nsString& aInputTypeAttr)
{
if (aInputTypeAttr.EqualsIgnoreCase("email")) {
return java::sdk::InputType::TYPE_CLASS_TEXT | java::sdk::InputType::TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
}
if (aInputTypeAttr.EqualsIgnoreCase("number")) {
return java::sdk::InputType::TYPE_CLASS_NUMBER;
}
if (aInputTypeAttr.EqualsIgnoreCase("password")) {
return java::sdk::InputType::TYPE_CLASS_TEXT | java::sdk::InputType::TYPE_TEXT_VARIATION_WEB_PASSWORD;
}
if (aInputTypeAttr.EqualsIgnoreCase("tel")) {
return java::sdk::InputType::TYPE_CLASS_PHONE;
}
if (aInputTypeAttr.EqualsIgnoreCase("text")) {
return java::sdk::InputType::TYPE_CLASS_TEXT | java::sdk::InputType::TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
}
if (aInputTypeAttr.EqualsIgnoreCase("url")) {
return java::sdk::InputType::TYPE_CLASS_TEXT | java::sdk::InputType::TYPE_TEXT_VARIATION_URI;
}
return 0;
}
void void
AccessibleWrap::DOMNodeID(nsString& aDOMNodeID) AccessibleWrap::DOMNodeID(nsString& aDOMNodeID)
{ {

View File

@ -57,6 +57,8 @@ protected:
static int32_t GetAndroidClass(role aRole); static int32_t GetAndroidClass(role aRole);
static int32_t GetInputType(const nsString& aInputTypeAttr);
int32_t mID; int32_t mID;
private: private:

View File

@ -333,7 +333,7 @@ public class SessionAccessibility {
// Set bundle keys like role and hint // Set bundle keys like role and hint
Bundle bundle = node.getExtras(); Bundle bundle = node.getExtras();
if (nodeInfo.containsKey("hint")) { if (nodeInfo.containsKey("hint")) {
final String hint = nodeInfo.getString("hint"); final String hint = nodeInfo.getString("hint");
bundle.putCharSequence("AccessibilityNodeInfo.hint", hint); bundle.putCharSequence("AccessibilityNodeInfo.hint", hint);
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= 26) {
node.setHintText(hint); node.setHintText(hint);
@ -397,33 +397,7 @@ public class SessionAccessibility {
node.setCollectionInfo(collectionInfo); node.setCollectionInfo(collectionInfo);
} }
// Set inputType node.setInputType(nodeInfo.getInt("inputType"));
switch (nodeInfo.getString("inputType", "").toLowerCase()) {
case "email":
node.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
break;
case "number":
node.setInputType(InputType.TYPE_CLASS_NUMBER);
break;
case "password":
node.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD);
break;
case "tel":
node.setInputType(InputType.TYPE_CLASS_PHONE);
break;
case "text":
node.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
break;
case "url":
node.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_URI);
break;
default:
break;
}
} }
// SDK 23 and above // SDK 23 and above

View File

@ -1,3 +1,3 @@
# We only use constants from KeyEvent # We only use constants from AccessibilityEvent
[android.view.accessibility.AccessibilityEvent = skip:true] [android.view.accessibility.AccessibilityEvent = skip:true]
<field> = skip:false <field> = skip:false

View File

@ -0,0 +1,3 @@
# We only use constants from InputType
[android.text.InputType = skip:true]
<field> = skip:false

View File

@ -12,6 +12,7 @@ with Files("**"):
generated = [ generated = [
'AccessibilityEvent', 'AccessibilityEvent',
'AndroidBuild', 'AndroidBuild',
'AndroidInputType',
'AndroidRect', 'AndroidRect',
'JavaBuiltins', 'JavaBuiltins',
'KeyEvent', 'KeyEvent',