[orca] Web: Try to be a little bit smart about dumping cache



commit 208ee0d774fd6e048d2bec81da170a66b4df94fc
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Dec 16 12:55:18 2020 +0100

    Web: Try to be a little bit smart about dumping cache
    
    Quirks in web sites and web browsers are tricky....
    
    * If the children-changed event is our current object, dump cache and
      also the context because all bets are off regarding whether or not
      our current location is stale.
    * If the children-changed event is an ancestor of our current object,
      dump cache but preserve the context because something around us
      has changed, but our present location should still be valid. Plus
      subsequent sanity checks should trigger us to update things if
      our present location isn't valid after all.
    * Otherwise, something elsewhere has changed so don't dump the cache.
    
    Also add more debugging to get to the bottom of remaining quirks.

 src/orca/debug.py                        | 20 ++++++++++++++++----
 src/orca/event_manager.py                |  6 +++++-
 src/orca/scripts/web/script.py           | 28 ++++++++++++++++++++++------
 src/orca/scripts/web/script_utilities.py | 12 +++++-------
 4 files changed, 48 insertions(+), 18 deletions(-)
---
diff --git a/src/orca/debug.py b/src/orca/debug.py
index c9df9ae22..8ba8e660f 100644
--- a/src/orca/debug.py
+++ b/src/orca/debug.py
@@ -32,6 +32,7 @@ import inspect
 import traceback
 import os
 import pyatspi
+import re
 import subprocess
 import sys
 
@@ -338,7 +339,7 @@ def attributesToString(acc, indent=""):
     except:
         return "%sattributes=(exception)" % indent
 
-    return "%sattributes='%s'" % (indent, " ".join(attributes))
+    return "%sattributes='%s'" % (indent, re.sub("\s+", " ", ", ".join(attributes)))
 
 def getAccessibleDetails(level, acc, indent="", includeApp=True):
     """Returns a string, suitable for printing, that describes the
@@ -371,23 +372,34 @@ def getAccessibleDetails(level, acc, indent="", includeApp=True):
         string = indent
 
     try:
-        name_string = "name='%s'" % acc.name
+        name_string = "name='%s'".replace("\n", "\\n") % acc.name
     except:
         name_string = "name=(exception)"
 
+    try:
+        desc_string = "%sdescription='%s'".replace("\n", "\\n") % (indent, acc.description)
+    except:
+        desc_string = "%sdescription=(exception)" % indent
+
     try:
         role_string = "role='%s'" % acc.getRoleName()
     except:
         role_string = "role=(exception)"
 
+    try:
+        path_string = "%spath=%s" % (indent, pyatspi.getPath(acc))
+    except:
+        path_string = "%spath=(exception)" % indent
+
     state_string = statesToString(acc, indent)
     rel_string = relationsToString(acc, indent)
     iface_string = interfacesToString(acc, indent)
     attr_string = attributesToString(acc, indent)
 
     try:
-        string += "%s %s \n%s \n%s \n%s \n%s" \
-                  % (name_string, role_string, state_string, rel_string, iface_string, attr_string)
+        string += "%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
+                  % (name_string, role_string, desc_string, state_string, rel_string,
+                     iface_string, attr_string, path_string)
     except:
         string += "(exception fetching data)"
 
diff --git a/src/orca/event_manager.py b/src/orca/event_manager.py
index 7761e846e..4243e54e2 100644
--- a/src/orca/event_manager.py
+++ b/src/orca/event_manager.py
@@ -754,7 +754,11 @@ class EventManager:
 
         if not debug.eventDebugFilter or debug.eventDebugFilter.match(eType) \
            and not eType.startswith("mouse:"):
-            debug.printDetails(debug.LEVEL_INFO, ' ' * 18, event.source)
+            indent = " " * 32
+            debug.printDetails(debug.LEVEL_INFO, indent, event.source)
+            if isinstance(event.any_data, pyatspi.Accessible):
+                debug.println(debug.LEVEL_INFO, '%sANY DATA:' % indent)
+                debug.printDetails(debug.LEVEL_INFO, indent, event.any_data, includeApp=False)
 
         script = self._getScriptForEvent(event)
         if not script:
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 556787899..3bb4bd801 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -1697,9 +1697,17 @@ class Script(default.Script):
         isLiveRegion = self.utilities.isLiveRegion(event.source)
         document = self.utilities.getDocumentForObject(event.source)
         if document and not isLiveRegion:
-            # Issues in Firefox are leading to our not relocating our position.
-            inTable = self.utilities.getTable(orca_state.locusOfFocus) is not None
-            self.utilities.dumpCache(document, preserveContext=inTable)
+            if event.source == orca_state.locusOfFocus:
+                msg = "WEB: Dumping cache and context: source is focus %s" % orca_state.locusOfFocus
+                debug.println(debug.LEVEL_INFO, msg, True)
+                self.utilities.dumpCache(document, preserveContext=False)
+            elif pyatspi.findAncestor(orca_state.locusOfFocus, lambda x: x == event.source):
+                msg = "WEB: Dumping cache: source is ancestor of focus %s" % orca_state.locusOfFocus
+                debug.println(debug.LEVEL_INFO, msg, True)
+                self.utilities.dumpCache(document, preserveContext=True)
+            else:
+                msg = "WEB: Not dumping cache. Focus is %s" % orca_state.locusOfFocus
+                debug.println(debug.LEVEL_INFO, msg, True)
         else:
             msg = "WEB: Could not get document for event source"
             debug.println(debug.LEVEL_INFO, msg, True)
@@ -1797,9 +1805,17 @@ class Script(default.Script):
 
         document = self.utilities.getDocumentForObject(event.source)
         if document:
-            # Issues in Firefox are leading to our not relocating our position.
-            inTable = self.utilities.getTable(orca_state.locusOfFocus) is not None
-            self.utilities.dumpCache(document, preserveContext=inTable)
+            if event.source == orca_state.locusOfFocus:
+                msg = "WEB: Dumping cache and context: source is focus %s" % orca_state.locusOfFocus
+                debug.println(debug.LEVEL_INFO, msg, True)
+                self.utilities.dumpCache(document, preserveContext=False)
+            elif pyatspi.findAncestor(orca_state.locusOfFocus, lambda x: x == event.source):
+                msg = "WEB: Dumping cache: source is ancestor of focus %s" % orca_state.locusOfFocus
+                debug.println(debug.LEVEL_INFO, msg, True)
+                self.utilities.dumpCache(document, preserveContext=True)
+            else:
+                msg = "WEB: Not dumping cache. Focus is %s" % orca_state.locusOfFocus
+                debug.println(debug.LEVEL_INFO, msg, True)
 
         if self.utilities.handleEventForRemovedChild(event):
             msg = "WEB: Event handled for removed child."
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 6061c6dc0..92497a645 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -1555,6 +1555,7 @@ class Utilities(script_utilities.Utilities):
 
         if useCache:
             if self.findObjectInContents(obj, offset, self._currentObjectContents, usingCache=True) != -1:
+                self._debugContentsInfo(obj, offset, self._currentObjectContents, "Object (cached)")
                 return self._currentObjectContents
 
         objIsLandmark = self.isLandmark(obj)
@@ -1595,6 +1596,7 @@ class Utilities(script_utilities.Utilities):
         if useCache:
             self._currentObjectContents = objects
 
+        self._debugContentsInfo(obj, offset, objects, "Object (not cached)")
         return objects
 
     def _contentIsSubsetOf(self, contentA, contentB):
@@ -1614,18 +1616,14 @@ class Utilities(script_utilities.Utilities):
         msg = "WEB: %s for %s at offset %i:" % (contentsMsg, obj, offset)
         debug.println(debug.LEVEL_INFO, msg, True)
 
+        indent = " " * 8
         for i, (acc, start, end, string) in enumerate(contents):
-            indent = " " * 8
             try:
-                description = acc.description
                 extents = self.getExtents(acc, start, end)
             except:
-                description = "(exception)"
                 extents = "(exception)"
-            states = debug.statesToString(acc, indent)
-            attrs = debug.attributesToString(acc, indent)
-            msg = "     %i. %s (chars: %i-%i) '%s' extents=%s description=%s\n%s\n%s" % \
-                (i, acc, start, end, string, extents, description, states, attrs)
+            msg = "     %i. chars: %i-%i: '%s' extents=%s\n" % (i, start, end, string, extents)
+            msg += debug.getAccessibleDetails(debug.LEVEL_INFO, acc, indent)
             debug.println(debug.LEVEL_INFO, msg, True)
 
     def treatAsEndOfLine(self, obj, offset):


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