[orca] Make it possible for scripts to process children-changed:removed events



commit 799098fac9558eace86b3748df4635aeb3f8041b
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Apr 2 16:58:57 2020 -0400

    Make it possible for scripts to process children-changed:removed events
    
    We were preventing scripts from handling children-changed:removed events
    mainly because there was nothing to present to the user for them. However,
    in the case of rich-text editors and other web applications, we might wish
    to present removed objects. In addition, for applications which can be
    super spammy with children removals, allowing the associated script to
    temporarily deregister from these events may improve responsiveness.
    
    Note that at the present time, no script is doing anything with these
    events; they are just getting ignored at a different point.

 src/orca/event_manager.py                    | 18 +++---------------
 src/orca/scripts/apps/Instantbird/script.py  |  7 ++-----
 src/orca/scripts/apps/pidgin/script.py       |  8 ++------
 src/orca/scripts/apps/soffice/script.py      |  6 +++---
 src/orca/scripts/default.py                  | 18 +++++++++++-------
 src/orca/scripts/toolkits/Chromium/script.py |  8 ++++----
 src/orca/scripts/toolkits/Gecko/script.py    |  8 ++++----
 src/orca/scripts/web/script.py               |  4 ++--
 8 files changed, 31 insertions(+), 46 deletions(-)
---
diff --git a/src/orca/event_manager.py b/src/orca/event_manager.py
index ecea02f73..52ec7e0d4 100644
--- a/src/orca/event_manager.py
+++ b/src/orca/event_manager.py
@@ -126,7 +126,7 @@ class EventManager:
             return False
 
         script = orca_state.activeScript
-        if event.type.startswith('object:children-changed:add'):
+        if event.type.startswith('object:children-changed'):
             if not script:
                 msg = 'EVENT MANAGER: Ignoring because there is no active script'
                 debug.println(debug.LEVEL_INFO, msg, True)
@@ -136,14 +136,6 @@ class EventManager:
                 debug.println(debug.LEVEL_INFO, msg, True)
                 return True
 
-        # This should ultimately be changed as there are valid reasons
-        # to handle these events at the application level.
-        if event.type.startswith('object:children-changed:remove') \
-           and event.source != self._desktop:
-            msg = 'EVENT MANAGER: Ignoring because event type is ignored'
-            debug.println(debug.LEVEL_INFO, msg, True)
-            return True
-
         if event.type.startswith('object:text-changed') and event.type.endswith('system'):
             # We should also get children-changed events telling us the same thing.
             # Getting a bunch of both can result in a flood that grinds us to a halt.
@@ -223,7 +215,7 @@ class EventManager:
                 debug.println(debug.LEVEL_INFO, msg, True)
                 return True
 
-        if event.type.startswith('object:children-changed:add') \
+        if event.type.startswith('object:children-changed') \
            or event.type.startswith('object:active-descendant-changed'):
             if role in [pyatspi.ROLE_MENU,
                         pyatspi.ROLE_LAYERED_PANE,
@@ -238,6 +230,7 @@ class EventManager:
             try:
                 childState = event.any_data.getState()
                 childRole = event.any_data.getRole()
+                name = event.any_data.name
             except:
                 msg = 'ERROR: Event any_data contains potentially-defunct child/descendant'
                 debug.println(debug.LEVEL_INFO, msg, True)
@@ -691,12 +684,7 @@ class EventManager:
                 if event.source == self._desktop:
                     _scriptManager.reclaimScripts()
                     return
-            except (LookupError, RuntimeError):
-                # If we got this error here, we'll get it again when we
-                # attempt to get the state, catch it, and clean up.
-                pass
             except:
-                debug.printException(debug.LEVEL_WARNING)
                 return
 
         if eType.startswith("window:") and not eType.endswith("create"):
diff --git a/src/orca/scripts/apps/Instantbird/script.py b/src/orca/scripts/apps/Instantbird/script.py
index e113b3b83..60216f68e 100644
--- a/src/orca/scripts/apps/Instantbird/script.py
+++ b/src/orca/scripts/apps/Instantbird/script.py
@@ -146,11 +146,8 @@ class Script(Gecko.Script):
         else:
             default.Script.onCaretMoved(self, event)
 
-    def onChildrenChanged(self, event):
-        """Called when a child node has changed.  In particular, we are looking
-        for addition events often associated with Javascipt insertion. One such
-        such example would be the programmatic insertion of a tooltip or alert
-        dialog."""
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
 
         return
 
diff --git a/src/orca/scripts/apps/pidgin/script.py b/src/orca/scripts/apps/pidgin/script.py
index 7a56a23ff..87498870a 100644
--- a/src/orca/scripts/apps/pidgin/script.py
+++ b/src/orca/scripts/apps/pidgin/script.py
@@ -106,12 +106,8 @@ class Script(GAIL.Script):
 
         return self.chat.getPreferencesFromGUI()
 
-    def onChildrenChanged(self, event):
-        """Called whenever a child object changes in some way.
-
-        Arguments:
-        - event: the text inserted Event
-        """
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
 
         # Check to see if a new chat room tab has been created and if it
         # has, then announce its name. See bug #469098 for more details.
diff --git a/src/orca/scripts/apps/soffice/script.py b/src/orca/scripts/apps/soffice/script.py
index 611c33e1c..c156d28fd 100644
--- a/src/orca/scripts/apps/soffice/script.py
+++ b/src/orca/scripts/apps/soffice/script.py
@@ -642,8 +642,8 @@ class Script(default.Script):
 
         default.Script.onActiveDescendantChanged(self, event)
 
-    def onChildrenChanged(self, event):
-        """Callback for object:children-changed accessibility events."""
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
 
         if self.utilities.isSpreadSheetCell(event.any_data):
             orca.setLocusOfFocus(event, event.any_data)
@@ -669,7 +669,7 @@ class Script(default.Script):
             self.presentMessage(full, brief)
             return
 
-        default.Script.onChildrenChanged(self, event)
+        default.Script.onChildrenAdded(self, event)
 
     def onFocus(self, event):
         """Callback for focus: accessibility events."""
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 24ed77688..0786b4ddc 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -559,8 +559,10 @@ class Script(script.Script):
             self.onTextInserted
         listeners["object:active-descendant-changed"]       = \
             self.onActiveDescendantChanged
-        listeners["object:children-changed"]                = \
-            self.onChildrenChanged
+        listeners["object:children-changed:add"]            = \
+            self.onChildrenAdded
+        listeners["object:children-changed:remove"]         = \
+            self.onChildrenRemoved
         listeners["object:state-changed:active"]            = \
             self.onActiveChanged
         listeners["object:state-changed:busy"]              = \
@@ -2239,12 +2241,14 @@ class Script(script.Script):
         speech.speak(self.speechGenerator.generateSpeech(obj, alreadyFocused=True))
         self.pointOfReference['checkedChange'] = hash(obj), event.detail1
 
-    def onChildrenChanged(self, event):
-        """Called when a child node has changed.
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
+
+        pass
+
+    def onChildrenRemoved(self, event):
+        """Callback for object:children-changed:remove accessibility events."""
 
-        Arguments:
-        - event: the Event
-        """
         pass
 
     def onCaretMoved(self, event):
diff --git a/src/orca/scripts/toolkits/Chromium/script.py b/src/orca/scripts/toolkits/Chromium/script.py
index a6567e9d9..54547684e 100644
--- a/src/orca/scripts/toolkits/Chromium/script.py
+++ b/src/orca/scripts/toolkits/Chromium/script.py
@@ -165,20 +165,20 @@ class Script(web.Script):
         debug.println(debug.LEVEL_INFO, msg, True)
         default.Script.onCheckedChanged(self, event)
 
-    def onChildrenChanged(self, event):
-        """Callback for object:children-changed accessibility events."""
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
 
         if self.utilities.isStaticTextLeaf(event.any_data):
             msg = "CHROMIUM: Ignoring because child is static text leaf"
             debug.println(debug.LEVEL_INFO, msg, True)
             return
 
-        if super().onChildrenChanged(event):
+        if super().onChildrenAdded(event):
             return
 
         msg = "CHROMIUM: Passing along event to default script"
         debug.println(debug.LEVEL_INFO, msg, True)
-        default.Script.onChildrenChanged(self, event)
+        default.Script.onChildrenAdded(self, event)
 
     def onDocumentLoadComplete(self, event):
         """Callback for document:load-complete accessibility events."""
diff --git a/src/orca/scripts/toolkits/Gecko/script.py b/src/orca/scripts/toolkits/Gecko/script.py
index 3b99c2a2d..0de4ed118 100644
--- a/src/orca/scripts/toolkits/Gecko/script.py
+++ b/src/orca/scripts/toolkits/Gecko/script.py
@@ -131,15 +131,15 @@ class Script(web.Script):
         debug.println(debug.LEVEL_INFO, msg, True)
         default.Script.onCheckedChanged(self, event)
 
-    def onChildrenChanged(self, event):
-        """Callback for object:children-changed accessibility events."""
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
 
-        if super().onChildrenChanged(event):
+        if super().onChildrenAdded(event):
             return
 
         msg = "GECKO: Passing along event to default script"
         debug.println(debug.LEVEL_INFO, msg, True)
-        default.Script.onChildrenChanged(self, event)
+        default.Script.onChildrenAdded(self, event)
 
     def onDocumentLoadComplete(self, event):
         """Callback for document:load-complete accessibility events."""
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 7fdaa4ee7..1c9e3d656 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -1631,8 +1631,8 @@ class Script(default.Script):
         self.pointOfReference['checkedChange'] = hash(obj), event.detail1
         return True
 
-    def onChildrenChanged(self, event):
-        """Callback for object:children-changed accessibility events."""
+    def onChildrenAdded(self, event):
+        """Callback for object:children-changed:add accessibility events."""
 
         if self.utilities.eventIsBrowserUINoise(event):
             msg = "WEB: Ignoring event believed to be browser UI noise"


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