Bug 1499188 - Make accessibility entry input type an int in bundle message. r=jchen,Jamie
authorEitan Isaacson <eitan@monotonous.org>
Tue, 16 Oct 2018 16:43:16 +0000
changeset 441968 50cc3c94b20d7ba104fc24b887e15064cad69d41
parent 441967 b786be7eb3b5fc1acf0cb38d85cf7104ae2f274c
child 441969 740c3623a44aed64203d830a03682e14f90917f9
push id71289
push usereisaacson@mozilla.com
push dateThu, 18 Oct 2018 17:38:06 +0000
treeherderautoland@50cc3c94b20d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, Jamie
bugs1499188
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499188 - Make accessibility entry input type an int in bundle message. r=jchen,Jamie Differential Revision: https://phabricator.services.mozilla.com/D8871
accessible/android/AccessibleWrap.cpp
accessible/android/AccessibleWrap.h
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionAccessibility.java
widget/android/bindings/AccessibilityEvent-classes.txt
widget/android/bindings/AndroidInputType-classes.txt
widget/android/bindings/moz.build
--- a/accessible/android/AccessibleWrap.cpp
+++ b/accessible/android/AccessibleWrap.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AccessibleWrap.h"
 
 #include "Accessible-inl.h"
+#include "AndroidInputType.h"
 #include "DocAccessibleWrap.h"
 #include "IDSet.h"
 #include "JavaBuiltins.h"
 #include "SessionAccessibility.h"
 #include "nsAccessibilityService.h"
 #include "nsIPersistentProperties2.h"
 #include "nsIStringBundle.h"
 #include "nsAccUtils.h"
@@ -281,20 +282,21 @@ AccessibleWrap::CreateBundle(int32_t aPa
     if (!IsNaN(aMaxVal)) {
       GECKOBUNDLE_PUT(rangeInfo, "max", java::sdk::Double::New(aMaxVal));
     }
 
     GECKOBUNDLE_FINISH(rangeInfo);
     GECKOBUNDLE_PUT(nodeInfo, "rangeInfo", rangeInfo);
   }
 
-  nsString inputType;
-  nsAccUtils::GetAccAttr(aAttributes, nsGkAtoms::textInputType, inputType);
-  if (!inputType.IsEmpty()) {
-    GECKOBUNDLE_PUT(nodeInfo, "inputType", jni::StringParam(inputType));
+  nsString inputTypeAttr;
+  nsAccUtils::GetAccAttr(aAttributes, nsGkAtoms::textInputType, inputTypeAttr);
+  int32_t inputType = GetInputType(inputTypeAttr);
+  if (inputType) {
+    GECKOBUNDLE_PUT(nodeInfo, "inputType", java::sdk::Integer::ValueOf(inputType));
   }
 
   nsString posinset;
   nsresult rv = aAttributes->GetStringProperty(NS_LITERAL_CSTRING("posinset"), posinset);
   if (NS_SUCCEEDED(rv)) {
     int32_t rowIndex;
     if (sscanf(NS_ConvertUTF16toUTF8(posinset).get(), "%d", &rowIndex) > 0) {
       GECKOBUNDLE_START(collectionItemInfo);
@@ -457,16 +459,46 @@ AccessibleWrap::GetAndroidClass(role aRo
 #include "RoleMap.h"
     default:
       return java::SessionAccessibility::CLASSNAME_VIEW;
   }
 
 #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
 AccessibleWrap::DOMNodeID(nsString& aDOMNodeID)
 {
   if (mContent) {
     nsAtom* id = mContent->GetID();
     if (id) {
       id->ToString(aDOMNodeID);
     }
--- a/accessible/android/AccessibleWrap.h
+++ b/accessible/android/AccessibleWrap.h
@@ -52,16 +52,18 @@ protected:
     const nsTArray<int32_t>& aChildren) const;
 
   // IDs should be a positive 32bit integer.
   static int32_t AcquireID();
   static void ReleaseID(int32_t aID);
 
   static int32_t GetAndroidClass(role aRole);
 
+  static int32_t GetInputType(const nsString& aInputTypeAttr);
+
   int32_t mID;
 
 private:
   void DOMNodeID(nsString& aDOMNodeID);
 
   static void GetRoleDescription(role aRole,
                                  nsAString& aGeckoRole,
                                  nsAString& aRoleDescription);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionAccessibility.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionAccessibility.java
@@ -328,17 +328,17 @@ public class SessionAccessibility {
             // SDK 19 and above
             if (Build.VERSION.SDK_INT >= 19) {
                 node.setMultiLine((flags & FLAG_MULTI_LINE) != 0);
                 node.setContentInvalid((flags & FLAG_CONTENT_INVALID) != 0);
 
                 // Set bundle keys like role and hint
                 Bundle bundle = node.getExtras();
                 if (nodeInfo.containsKey("hint")) {
-                    final String hint =  nodeInfo.getString("hint");
+                    final String hint = nodeInfo.getString("hint");
                     bundle.putCharSequence("AccessibilityNodeInfo.hint", hint);
                     if (Build.VERSION.SDK_INT >= 26) {
                         node.setHintText(hint);
                     }
                 }
                 if (nodeInfo.containsKey("geckoRole")) {
                     bundle.putCharSequence("AccessibilityNodeInfo.geckoRole", nodeInfo.getString("geckoRole"));
                 }
@@ -392,43 +392,17 @@ public class SessionAccessibility {
                                 collectionBundle.getInt("selectionMode", 0))
                             : CollectionInfo.obtain(
                                 collectionBundle.getInt("rowCount"),
                                 collectionBundle.getInt("columnCount"),
                                 collectionBundle.getBoolean("isHierarchical", false));
                     node.setCollectionInfo(collectionInfo);
                 }
 
-                // Set 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;
-                }
+                node.setInputType(nodeInfo.getInt("inputType"));
             }
 
             // SDK 23 and above
             if (Build.VERSION.SDK_INT >= 23) {
                 node.setContextClickable((flags & FLAG_CONTEXT_CLICKABLE) != 0);
             }
         }
     }
--- a/widget/android/bindings/AccessibilityEvent-classes.txt
+++ b/widget/android/bindings/AccessibilityEvent-classes.txt
@@ -1,3 +1,3 @@
-# We only use constants from KeyEvent
+# We only use constants from AccessibilityEvent
 [android.view.accessibility.AccessibilityEvent = skip:true]
 <field> = skip:false
new file mode 100644
--- /dev/null
+++ b/widget/android/bindings/AndroidInputType-classes.txt
@@ -0,0 +1,3 @@
+# We only use constants from InputType
+[android.text.InputType = skip:true]
+<field> = skip:false
--- a/widget/android/bindings/moz.build
+++ b/widget/android/bindings/moz.build
@@ -7,16 +7,17 @@
 with Files("**"):
     BUG_COMPONENT = ("Firefox for Android", "Graphics, Panning and Zooming")
 
 # List of stems to generate .cpp and .h files for.  To add a stem, add it to
 # this list and ensure that $(stem)-classes.txt exists in this directory.
 generated = [
     'AccessibilityEvent',
     'AndroidBuild',
+    'AndroidInputType',
     'AndroidRect',
     'JavaBuiltins',
     'KeyEvent',
     'MediaCodec',
     'MotionEvent',
     'SurfaceTexture',
     'ViewConfiguration'
 ]