[orca] Chromium: Work around bogus/misleading selected state in browser menus



commit 7751cb7a5c21d29b91778d1451b319b29039b899
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Feb 3 18:55:39 2021 +0100

    Chromium: Work around bogus/misleading selected state in browser menus
    
    Once one arrows past zoom-related or edit-related items in the three-dot
    menu, zoom and edit each claim to be selected. Because AtkSelection does
    not report the selected children for this menu, we resort to examining
    all children to find those with state-selected and wind up with two:
    the real selected child and zoom or edit. All this needs to be fixed in
    Chromium, but it appears that catching this condition and sanity-checking
    items by also examining the focused state is a safe workaround in the
    meantime.

 .../scripts/toolkits/Chromium/script_utilities.py  | 23 ++++++++--------------
 1 file changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/src/orca/scripts/toolkits/Chromium/script_utilities.py 
b/src/orca/scripts/toolkits/Chromium/script_utilities.py
index 02bead6b7..b4baa9136 100644
--- a/src/orca/scripts/toolkits/Chromium/script_utilities.py
+++ b/src/orca/scripts/toolkits/Chromium/script_utilities.py
@@ -145,23 +145,16 @@ class Utilities(web.Utilities):
             return []
 
         result = super().selectedChildren(obj)
-        if result or "Selection" in pyatspi.listInterfaces(obj):
-            return result
-
-        try:
-            childCount = obj.childCount
-        except:
-            msg = "CHROMIUM: Exception getting child count of %s" % obj
+        if obj.getRole() == pyatspi.ROLE_MENU and not self.inDocumentContent(obj) and len(result) > 1:
+            msg = "CHROMIUM: Browser menu %s claims more than one state-selected child." % obj
             debug.println(debug.LEVEL_INFO, msg, True)
-            return result
 
-        # HACK: Ideally, we'd use the selection interface to get the selected
-        # children. But that interface is not implemented yet. This hackaround
-        # is extremely non-performant.
-        for i in range(childCount):
-            child = obj[i]
-            if child and child.getState().contains(pyatspi.STATE_SELECTED):
-                result.append(child)
+            isFocused = lambda x: x and x.getState().contains(pyatspi.STATE_FOCUSED)
+            focused = list(filter(isFocused, result))
+            if len(focused) == 1:
+                msg = "CHROMIUM: Suspecting %s is the only actually-selected child" % focused[0]
+                debug.println(debug.LEVEL_INFO, msg, True)
+                return focused
 
         return result
 


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