[orca] Chromium: Filter out some redundant live region events



commit a51dd7b0582204a344865ca039893e32b9d2c4ae
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Jul 16 20:30:11 2019 -0400

    Chromium: Filter out some redundant live region events

 src/orca/scripts/toolkits/Chromium/script_utilities.py | 15 +++++++++++++++
 src/orca/scripts/web/script_utilities.py               |  4 ++++
 2 files changed, 19 insertions(+)
---
diff --git a/src/orca/scripts/toolkits/Chromium/script_utilities.py 
b/src/orca/scripts/toolkits/Chromium/script_utilities.py
index 828af0cad..acd991602 100644
--- a/src/orca/scripts/toolkits/Chromium/script_utilities.py
+++ b/src/orca/scripts/toolkits/Chromium/script_utilities.py
@@ -340,3 +340,18 @@ class Utilities(web.Utilities):
             msg = "CHROMIUM: HACK: Grabbing focus on %s's ancestor %s" % (obj, link)
             debug.println(debug.LEVEL_INFO, msg, True)
             self.grabFocus(link)
+
+    def handleAsLiveRegion(self, event):
+        # At least some of the time, we're getting text insertion events immediately
+        # followed by children-changed events to tell us that the object whose text
+        # changed is now being added to the accessibility tree. Furthermore the
+        # additions are not always coming to us in presentational order, whereas
+        # the text changes appear to be.
+        if isinstance(event.any_data, pyatspi.Accessible):
+            pEvent, pTime = self._mostRecentLiveRegionEvent.get(hash(event.any_data), ("", 0))
+            if pEvent.startwith("object-text-changed:insert") and time.time() - pTime < 0.5:
+                msg = "CHROMIUM: Event is believed to be redundant live region notification"
+                debug.println(debug.LEVEL_INFO, msg, True)
+                return False
+
+        return super().handleAsLiveRegion(event)
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 2080f913e..b39e8445b 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -27,6 +27,7 @@ __license__   = "LGPL"
 
 import pyatspi
 import re
+import time
 import urllib
 
 from orca import debug
@@ -86,6 +87,7 @@ class Utilities(script_utilities.Utilities):
         self._isInlineListDescendant = {}
         self._isLandmark = {}
         self._isLiveRegion = {}
+        self._mostRecentLiveRegionEvent = {}
         self._isLink = {}
         self._isNonNavigablePopup = {}
         self._isNonEntryTextWidget = {}
@@ -164,6 +166,7 @@ class Utilities(script_utilities.Utilities):
         self._isInlineListDescendant = {}
         self._isLandmark = {}
         self._isLiveRegion = {}
+        self._mostRecentLiveRegionEvent = {}
         self._isLink = {}
         self._isNonNavigablePopup = {}
         self._isNonEntryTextWidget = {}
@@ -4285,6 +4288,7 @@ class Utilities(script_utilities.Utilities):
                 return False
 
         self._lastQueuedLiveRegionEvent = event
+        self._mostRecentLiveRegionEvent[hash(event.source)] = (event.type, time.time())
         return True
 
     def getPageObjectCount(self, obj):


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