[orca] Web: Improve recovery related to locusOfFocus destruction



commit 826ff9459dae41c618c209fd6952114dce76bca4
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon May 2 15:29:10 2022 +0200

    Web: Improve recovery related to locusOfFocus destruction
    
    We attempt to recover when the currently-focused object is destroyed.
    That logic relies on some equality checks, namely that the event.any_data
    contains the same object as our current focus. Unfortunately, at least in
    the case of Firefox, those checks can fail. It appears that in some cases
    a new accessible object is being created for the purpose of firing the
    event for that object's removal.
    
    This commit solves that problem by calling isSameObject and doing a
    path comparison. In addition, when doing the path comparison, it
    strips off the final -1 child index when it is present in both paths.
    The theory being that if the paths are otherwise valid and identical,
    and the roles and names match, the objects are probably the same.

 src/orca/script_utilities.py             | 7 +++++++
 src/orca/scripts/web/script_utilities.py | 3 +++
 2 files changed, 10 insertions(+)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 7674fd978..50ad34b95 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -1698,6 +1698,13 @@ class Utilities:
         path1 = path1[1:]
         path2 = path2[1:]
 
+        # If the object is being destroyed and the replacement is too, which
+        # sadly can happen in at least Firefox, both will have an index of -1.
+        # If the rest of the paths are valid and match, it's probably ok.
+        if path1[-1] == -1 and path2[-1] == -1:
+            path1 = path1[:-1]
+            path2 = path2[:-1]
+
         # If both have invalid child indices, all bets are off.
         if path1.count(-1) and path2.count(-1):
             return False
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 83c8081ed..9585ab56a 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -5005,6 +5005,9 @@ class Utilities(script_utilities.Utilities):
         elif pyatspi.findAncestor(orca_state.locusOfFocus, lambda x: x == event.any_data):
             msg = "WEB: Removed child is ancestor of locusOfFocus."
             debug.println(debug.LEVEL_INFO, msg, True)
+        elif self.isSameObject(event.any_data, orca_state.locusOfFocus, True, True):
+            msg = "WEB: Removed child appears to be replicant oflocusOfFocus."
+            debug.println(debug.LEVEL_INFO, msg, True)
         else:
             return False
 


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