[orca] Web: Improve handling of the focused object being replaced while focused



commit 78242e667ccb68e194e9dea562375421763f205b
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Fri Feb 14 13:08:25 2020 +0100

    Web: Improve handling of the focused object being replaced while focused
    
    * Don't assume we'll get children-changed events first
    * Check focused events to see if they are for the replacement object
    * Do the work before getting the caret context so that we don't do an
      unnecessary search

 src/orca/scripts/web/script.py           | 19 ++++++++++---------
 src/orca/scripts/web/script_utilities.py | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 7a5be6a43..923c3a2a0 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -1664,20 +1664,16 @@ class Script(default.Script):
             debug.println(debug.LEVEL_INFO, msg, True)
             return True
 
+        if self.utilities.handleEventFromContextReplicant(event, event.any_data):
+            msg = "WEB: Event handled by updating locusOfFocus and context to child."
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return True
+
         obj, offset = self.utilities.getCaretContext(getZombieReplicant=False)
         msg = "WEB: Context: %s, %i (focus: %s)" % (obj, offset, orca_state.locusOfFocus)
         debug.println(debug.LEVEL_INFO, msg, True)
 
         if self.utilities.isZombie(obj):
-            if self.utilities.isSameObject(obj, event.any_data, comparePaths=True, ignoreNames=True):
-                path, role, name = self.utilities.getCaretContextPathRoleAndName()
-                notify = event.any_data.name != name
-                msg = "WEB: Event handled by updating locusOfFocus and context"
-                debug.println(debug.LEVEL_INFO, msg, True)
-                orca.setLocusOfFocus(event, event.any_data, notify)
-                self.utilities.setCaretContext(event.any_data, offset)
-                return True
-
             obj, offset = self.utilities.getCaretContext(getZombieReplicant=True)
             if not obj:
                 if self._inFocusMode:
@@ -1834,6 +1830,11 @@ class Script(default.Script):
             orca.setLocusOfFocus(event, event.source)
             return True
 
+        if self.utilities.handleEventFromContextReplicant(event, event.source):
+            msg = "WEB: Event handled by updating locusOfFocus and context to source."
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return True
+
         obj, offset = self.utilities.getCaretContext()
         msg = "WEB: Caret context is %s, %i (focus: %s)" \
               % (obj, offset, orca_state.locusOfFocus)
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 8a986a211..4c09691f3 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -4267,6 +4267,25 @@ class Utilities(script_utilities.Utilities):
         self._caretContexts.pop(hash(parent), None)
         self._priorContexts.pop(hash(parent), None)
 
+    def handleEventFromContextReplicant(self, event, replicant):
+        if self.isDead(replicant):
+            return False
+
+        path, role, name = self.getCaretContextPathRoleAndName()
+        if path != pyatspi.getPath(replicant):
+            return False
+
+        if role != replicant.getRole():
+            return False
+
+        notify = replicant.name != name
+        documentFrame = self.documentFrame()
+        obj, offset = self._caretContexts.get(hash(documentFrame.parent))
+
+        orca.setLocusOfFocus(event, replicant, notify)
+        self.setCaretContext(replicant, offset, documentFrame)
+        return True
+
     def findContextReplicant(self, documentFrame=None, matchRole=True, matchName=True):
         path, oldRole, oldName = self.getCaretContextPathRoleAndName(documentFrame)
         obj = self.getObjectFromPath(path)


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