[orca] Braille: Add additional attempts to recover from broken apps/toolkits



commit 32d0bea29ca2914d0069a7c32289ba61c92fb275
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Apr 22 18:29:43 2020 -0400

    Braille: Add additional attempts to recover from broken apps/toolkits
    
    We're already doing a lot of work to determine what should be the first
    visible object on the braille display (aka the "focused region"). This
    work is needed because certain apps and toolkits seem to like to destroy
    and recreate objects. Calling isSameObject() solves much of that problem,
    but apparently it can still fail. Therefore if all of our hard work still
    fails to find a match and we have a single object with the same name and
    role, prefer it over what is likely an ancestor object so users do not
    have to pan their display to the right to get to what is being spoken.
    
    Also add some more debugging to get to the bottom of app/toolkit bugs
    which I cannot reproduce myself.

 src/orca/braille_generator.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/src/orca/braille_generator.py b/src/orca/braille_generator.py
index a5ebb799f..0e04f174e 100644
--- a/src/orca/braille_generator.py
+++ b/src/orca/braille_generator.py
@@ -74,6 +74,20 @@ class BrailleGenerator(generator.Generator):
         globalsDict['Link'] = braille.Link
         globalsDict['asString'] = self.asString
 
+    def _isCandidateFocusedRegion(self, obj, region):
+        if not isinstance(region, (braille.Component, braille.Text)):
+            return False
+
+        try:
+            sameRole = obj.getRole() == region.accessible.getRole()
+            sameName = obj.name == region.accessible.name
+        except:
+            msg = 'ERROR: Could not get names, roles for %s, %s' % (obj, region.accessible)
+            debug.println(debug.LEVEL_INFO, msg)
+            return False
+
+        return sameRole and sameName
+
     def generateBraille(self, obj, **args):
         if not _settingsManager.getSetting('enableBraille') \
            and not _settingsManager.getSetting('enableBrailleMonitor'):
@@ -117,6 +131,12 @@ class BrailleGenerator(generator.Generator):
                  and region.accessible.parent == obj:
                 focusedRegion = region
                 break
+        else:
+            candidates = list(filter(lambda x: self._isCandidateFocusedRegion(obj, x), result))
+            msg = 'INFO: Could not determine focused region. Candidates: %i' % len(candidates)
+            debug.println(debug.LEVEL_INFO, msg)
+            if len(candidates) == 1:
+                focusedRegion = candidates[0]
 
         return [result, focusedRegion]
 


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