[orca] Web: Ensure we clear the caret context when the document changes



commit 17da4b22e750364a487a9ceb26f50dd507263a81
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Oct 11 12:08:08 2022 +0200

    Web: Ensure we clear the caret context when the document changes
    
    There are several scenarios we need to handle when a page loads and
    focus changes:
    
    1. The document is loaded in the same browser tab, resulting in the
       current caret context being null/dead. This causes us to get the
       new caret context for the document.
    2. The document is loaded in a new tab, and the user agent has updated
       the accessible embeds relation. This causes us to not yet have a
       stored caret context for the document, so we get it.
    3. The document is loaded in a new tab, but the user agent hasn't yet
       updated the accessible embeds relation and the old document is also
       opened. Here we think the user is still in the old document, and it
       has a valid caret context. Thus when the user arrows in the newly
       loaded page, we present the page from the previous tab.
    
    Address the third issue by checking if the document changed. If it
    has, clear the existing caret context and search the event source
    which emitted the focus event for the new context.
    
    Fixes issue #264.

 src/orca/scripts/web/script.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index c08475d5e..43668ffd3 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -2045,6 +2045,11 @@ class Script(default.Script):
             debug.println(debug.LEVEL_INFO, msg, True)
             return False
 
+        prevDocument = self.utilities.getDocumentForObject(orca_state.locusOfFocus)
+        if prevDocument != document:
+            msg = "WEB: document changed from %s to %s" % (prevDocument, document)
+            debug.println(debug.LEVEL_INFO, msg, True)
+
         role = event.source.getRole()
         if self.utilities.isWebAppDescendant(event.source):
             if self._browseModeIsSticky:
@@ -2083,8 +2088,8 @@ class Script(default.Script):
               % (obj, offset, orca_state.locusOfFocus)
         debug.println(debug.LEVEL_INFO, msg, True)
 
-        if not obj or self.utilities.isZombie(obj):
-            msg = "WEB: Clearing context - obj is null or zombie"
+        if not obj or self.utilities.isZombie(obj) or prevDocument != document:
+            msg = "WEB: Clearing context - obj %s is null or zombie or document changed" % obj
             debug.println(debug.LEVEL_INFO, msg, True)
             self.utilities.clearCaretContext()
 


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