[orca/gnome-3-36] Add more logic to try to find valid selection container



commit c72a3c4c1c9ed1f96433096dcb0282ce826a6e86
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Mar 5 19:37:20 2020 +0100

    Add more logic to try to find valid selection container
    
    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. Therefore ascend the hierarchy further and check
    roles to ensure we don't return in irrelevant ancestor which happens
    to implement the selection interface.

 src/orca/script_utilities.py | 19 +++++++++++++++++++
 src/orca/scripts/default.py  |  9 +++------
 2 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 397438983..13a0f694e 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -3748,6 +3748,25 @@ class Utilities:
 
         return children
 
+    def getSelectionContainer(self, obj):
+        if not obj:
+            return None
+
+        isSelection = lambda x: x and "Selection" in pyatspi.listInterfaces(x)
+        if isSelection(obj):
+            return obj
+
+        rolemap = {
+            pyatspi.ROLE_LIST_ITEM: [pyatspi.ROLE_LIST_BOX],
+            pyatspi.ROLE_TREE_ITEM: [pyatspi.ROLE_TREE, pyatspi.ROLE_TREE_TABLE],
+            pyatspi.ROLE_TABLE_CELL: [pyatspi.ROLE_TABLE, pyatspi.ROLE_TREE_TABLE],
+            pyatspi.ROLE_TABLE_ROW: [pyatspi.ROLE_TABLE, pyatspi.ROLE_TREE_TABLE],
+        }
+
+        role = obj.getRole()
+        isMatch = lambda x: isSelection(x) and x.getRole() in rolemap.get(role)
+        return pyatspi.findAncestor(obj, isMatch)
+
     def selectedChildCount(self, obj):
         try:
             selection = obj.querySelection()
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index e5292e6ca..893964d7f 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -2120,12 +2120,9 @@ class Script(script.Script):
         if not obj:
             return True
 
-        container = obj
-        if "Selection" in pyatspi.listInterfaces(container.parent):
-            container = obj.parent
-
-        if "Selection" not in pyatspi.listInterfaces(container):
-            msg = "INFO: %s and %s don't implement selection interface" % (obj, obj.parent)
+        container = self.utilities.getSelectionContainer(obj)
+        if not container:
+            msg = "INFO: Selection container not found for %s" % obj
             debug.println(debug.LEVEL_INFO, msg, True)
             return self._whereAmISelectedText(inputEvent, obj)
 


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