[orca] Add more logic to find valid selectable and selected children



commit 5b2315f730c499f1cf1b3605fbaf247b43d39269
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Mar 5 21:51:17 2020 +0100

    Add more logic to find valid selectable and selected children
    
    We cannot count there not being bogus items in the accessibility tree,
    such as an unexpected role section standing in between a tree item and
    the tree container. In addition, there might be missing expected items
    such as tables which lack children with role of table row. Therefore:
    
    * For objects which implement the table interface, use it to get
      the row count and selected row count
    * For listbox and tree, get a count of all the children which
      have the right role (listitem and treeitem respectively)

 src/orca/script_utilities.py | 25 +++++++++++++++++++++++++
 src/orca/scripts/default.py  |  3 ++-
 2 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 13a0f694e..c41a2d312 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -3767,7 +3767,32 @@ class Utilities:
         isMatch = lambda x: isSelection(x) and x.getRole() in rolemap.get(role)
         return pyatspi.findAncestor(obj, isMatch)
 
+    def selectableChildCount(self, obj):
+        if not (obj and "Selection" in pyatspi.listInterfaces(obj)):
+            return 0
+
+        if "Table" in pyatspi.listInterfaces(obj):
+            rows, cols = self.rowAndColumnCount(obj)
+            return max(0, rows)
+
+        rolemap = {
+            pyatspi.ROLE_LIST_BOX: [pyatspi.ROLE_LIST_ITEM],
+            pyatspi.ROLE_TREE: [pyatspi.ROLE_TREE_ITEM],
+        }
+
+        role = obj.getRole()
+        if role not in rolemap:
+            return obj.childCount
+
+        isMatch = lambda x: x.getRole() in rolemap.get(role)
+        return len(self.findAllDescendants(obj, isMatch))
+
     def selectedChildCount(self, obj):
+        if "Table" in pyatspi.listInterfaces(obj):
+            table = obj.queryTable()
+            if table.nSelectedRows:
+                return table.nSelectedRows
+
         try:
             selection = obj.querySelection()
             count = selection.nSelectedChildren
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 893964d7f..331c19910 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -2127,7 +2127,8 @@ class Script(script.Script):
             return self._whereAmISelectedText(inputEvent, obj)
 
         count = self.utilities.selectedChildCount(container)
-        self.presentMessage(messages.selectedItemsCount(count, container.childCount))
+        childCount = self.utilities.selectableChildCount(container)
+        self.presentMessage(messages.selectedItemsCount(count, childCount))
         if not count:
             return True
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]