Bug 1520611 - Prune children in Android. r=yzen
authorEitan Isaacson <eitan@monotonous.org>
Thu, 24 Jan 2019 00:23:45 +0000
changeset 515214 556063466b9865fec4a390594ea8f1d1bc271f95
parent 515213 8507cbf5c07accbc6bfc4fa0f7f610a4407bc92b
child 515215 4634649d3189fc3d34fec2058758f978de5f8a5b
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen
bugs1520611
milestone66.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 1520611 - Prune children in Android. r=yzen Differential Revision: https://phabricator.services.mozilla.com/D16743
accessible/android/AccessibleWrap.cpp
accessible/base/nsAccUtils.cpp
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt
--- a/accessible/android/AccessibleWrap.cpp
+++ b/accessible/android/AccessibleWrap.cpp
@@ -576,21 +576,26 @@ mozilla::java::GeckoBundle::LocalRef Acc
         }
 
         GECKOBUNDLE_FINISH(collectionInfo);
         GECKOBUNDLE_PUT(nodeInfo, "collectionInfo", collectionInfo);
       }
     }
   }
 
-  auto childCount = ChildCount();
-  nsTArray<int32_t> children(childCount);
-  for (uint32_t i = 0; i < childCount; i++) {
-    auto child = static_cast<AccessibleWrap*>(GetChildAt(i));
-    children.AppendElement(child->VirtualViewID());
+  bool mustPrune =
+      IsProxy() ? nsAccUtils::MustPrune(Proxy()) : nsAccUtils::MustPrune(this);
+  if (!mustPrune) {
+    auto childCount = ChildCount();
+    nsTArray<int32_t> children(childCount);
+    for (uint32_t i = 0; i < childCount; i++) {
+      auto child = static_cast<AccessibleWrap*>(GetChildAt(i));
+      children.AppendElement(child->VirtualViewID());
+    }
+
+    GECKOBUNDLE_PUT(nodeInfo, "children",
+                    jni::IntArray::New(children.Elements(), children.Length()));
   }
 
-  GECKOBUNDLE_PUT(nodeInfo, "children",
-                  jni::IntArray::New(children.Elements(), children.Length()));
   GECKOBUNDLE_FINISH(nodeInfo);
 
   return nodeInfo;
 }
--- a/accessible/base/nsAccUtils.cpp
+++ b/accessible/base/nsAccUtils.cpp
@@ -394,21 +394,31 @@ bool nsAccUtils::MustPrune(AccessibleOrP
   roles::Role role = aAccessible.Role();
 
   if (role == roles::SLIDER) {
     // Always prune the tree for sliders, as it doesn't make sense for a
     // slider to have descendants and this confuses NVDA.
     return true;
   }
 
+#if defined(ANDROID)
+  if (role == roles::LINK) {
+    // Always prune links in Android
+    return true;
+  }
+#endif
+
   if (role != roles::MENUITEM && role != roles::COMBOBOX_OPTION &&
       role != roles::OPTION && role != roles::ENTRY &&
       role != roles::FLAT_EQUATION && role != roles::PASSWORD_TEXT &&
       role != roles::PUSHBUTTON && role != roles::TOGGLE_BUTTON &&
       role != roles::GRAPHIC && role != roles::PROGRESSBAR &&
+#if defined(ANDROID)
+      role != roles::HEADING &&
+#endif
       role != roles::SEPARATOR) {
     // If it doesn't match any of these roles, don't prune its children.
     return false;
   }
 
   if (aAccessible.ChildCount() != 1) {
     // If the accessible has more than one child, don't prune it.
     return false;
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt
@@ -834,22 +834,19 @@ class AccessibilityTest : BaseSessionTes
                     equalTo("Name:"))
             assertThat("Entry input type is correct", entryNode.inputType,
                     equalTo(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT))
         }
 
 
         val buttonNode = createNodeInfo(rootNode.getChildId(2))
         assertThat("Last node is a button", buttonNode.className.toString(), equalTo("android.widget.Button"))
-        assertThat("Button has a single text leaf", buttonNode.childCount, equalTo(1))
+        // The child text leaf is pruned, so this button is childless.
+        assertThat("Button has a single text leaf", buttonNode.childCount, equalTo(0))
         assertThat("Button has correct text", buttonNode.text.toString(), equalTo("Submit"))
-
-        val textLeaf = createNodeInfo(buttonNode.getChildId(0))
-        assertThat("First node is a label", textLeaf.className.toString(), equalTo("android.view.View"))
-        assertThat("Text leaf has correct text", textLeaf.text.toString(), equalTo("Submit"))
     }
 
     @Setting(key = Setting.Key.FULL_ACCESSIBILITY_TREE, value = "true")
     @Test fun testCollection() {
         sessionRule.session.loadString(
                 """<ul>
                   |  <li>One</li>
                   |  <li>Two</li>