[orca] Ignore state active false changes for current window while in a menu



commit 91de8c27ba3ac1424a3f75b1566b1252b4663f70
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sat Jun 30 14:21:27 2018 -0400

    Ignore state active false changes for current window while in a menu

 src/orca/script_utilities.py | 33 ++++++++++++++++++++++++---------
 src/orca/scripts/default.py  | 24 +++++++++---------------
 2 files changed, 33 insertions(+), 24 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 5e502fa4d..cfae80d51 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -3614,19 +3614,34 @@ class Utilities:
 
         return self.popupMenuFor(obj) is not None
 
-    def inContextMenu(self, obj=None):
+    def inMenu(self, obj=None):
         obj = obj or orca_state.locusOfFocus
         if not obj:
             return False
 
-        roles = [pyatspi.ROLE_MENU,
-                 pyatspi.ROLE_MENU_ITEM,
-                 pyatspi.ROLE_CHECK_MENU_ITEM,
-                 pyatspi.ROLE_RADIO_MENU_ITEM,
-                 pyatspi.ROLE_TEAROFF_MENU_ITEM,
-                 pyatspi.ROLE_PANEL,
-                 pyatspi.ROLE_SEPARATOR]
-        if obj.getRole() not in roles:
+        try:
+            role = obj.getRole()
+        except:
+            msg = "ERROR: Exception getting role for %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        menuRoles = [pyatspi.ROLE_MENU,
+                     pyatspi.ROLE_MENU_ITEM,
+                     pyatspi.ROLE_CHECK_MENU_ITEM,
+                     pyatspi.ROLE_RADIO_MENU_ITEM,
+                     pyatspi.ROLE_TEAROFF_MENU_ITEM]
+        if role in menuRoles:
+            return True
+
+        if role in [pyatspi.ROLE_PANEL, pyatspi.ROLE_SEPARATOR]:
+            return obj.parent and obj.parent.getRole() in menuRoles
+
+        return False
+
+    def inContextMenu(self, obj=None):
+        obj = obj or orca_state.locusOfFocus
+        if not self.inMenu(obj):
             return False
 
         return pyatspi.findAncestor(obj, self.isContextMenu) is not None
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 396572bcc..bf37cecf6 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -2126,6 +2126,11 @@ class Script(script.Script):
                 event.source, orca_state.activeWindow)
 
             if sourceIsActiveWindow and not event.detail1:
+                if self.utilities.inMenu():
+                    msg = "DEFAULT: Ignoring event. In menu."
+                    debug.println(debug.LEVEL_INFO, msg, True)
+                    return
+
                 msg = "DEFAULT: Event is for active window. Clearing state."
                 debug.println(debug.LEVEL_INFO, msg, True)
                 orca_state.activeWindow = None
@@ -2806,21 +2811,10 @@ class Script(script.Script):
 
         self.pointOfReference = {}
 
-        menuRoles = [pyatspi.ROLE_MENU,
-                     pyatspi.ROLE_MENU_ITEM,
-                     pyatspi.ROLE_CHECK_MENU_ITEM,
-                     pyatspi.ROLE_RADIO_MENU_ITEM]
-
-        # If we get into a popup menu, the parent application will likely
-        # emit a window-deactivate event. But functionally we're still in
-        # the same window. In this case, we do not want to update anything.
-        try:
-            role = orca_state.locusOfFocus.getRole()
-        except:
-            pass
-        else:
-            if role in menuRoles:
-                return
+        if self.utilities.inMenu():
+            msg = "DEFAULT: Ignoring event. In menu."
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return
 
         # If we receive a "window:deactivate" event for the object that
         # currently has focus, then stop the current speech output.


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