[orca] Chromium: Present popup menus with no selected child



commit d064353244b47f7dd6a5c5642bfb03cbe6a79b79
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Fri Nov 30 19:24:30 2018 -0500

    Chromium: Present popup menus with no selected child

 src/orca/event_manager.py                          |  1 +
 src/orca/scripts/toolkits/Chromium/script.py       |  8 +++++
 .../scripts/toolkits/Chromium/script_utilities.py  | 35 +++++++++++++++++++++-
 3 files changed, 43 insertions(+), 1 deletion(-)
---
diff --git a/src/orca/event_manager.py b/src/orca/event_manager.py
index 096573c65..d621788f9 100644
--- a/src/orca/event_manager.py
+++ b/src/orca/event_manager.py
@@ -190,6 +190,7 @@ class EventManager:
             if role not in [pyatspi.ROLE_ALERT,
                             pyatspi.ROLE_ANIMATION,
                             pyatspi.ROLE_INFO_BAR,
+                            pyatspi.ROLE_MENU,
                             pyatspi.ROLE_NOTIFICATION,
                             pyatspi.ROLE_PANEL,
                             pyatspi.ROLE_STATUS_BAR,
diff --git a/src/orca/scripts/toolkits/Chromium/script.py b/src/orca/scripts/toolkits/Chromium/script.py
index 319ed561e..202c00a71 100644
--- a/src/orca/scripts/toolkits/Chromium/script.py
+++ b/src/orca/scripts/toolkits/Chromium/script.py
@@ -36,6 +36,7 @@ import time
 
 from orca import debug
 from orca import orca
+from orca import orca_state
 from orca.scripts import default
 from orca.scripts import web
 from .braille_generator import BrailleGenerator
@@ -305,6 +306,13 @@ class Script(web.Script):
     def onShowingChanged(self, event):
         """Callback for object:state-changed:showing accessibility events."""
 
+        if event.detail1 and self.utilities.isMenuWithNoSelectedChild(event.source):
+            topLevel = self.utilities.topLevelObject(event.source)
+            if self.utilities.canBeActiveWindow(topLevel):
+                orca_state.activeWindow = topLevel
+                orca.setLocusOfFocus(event, event.source)
+            return
+
         if super().onShowingChanged(event):
             return
 
diff --git a/src/orca/scripts/toolkits/Chromium/script_utilities.py 
b/src/orca/scripts/toolkits/Chromium/script_utilities.py
index b1b4b4fa5..7f739f6a4 100644
--- a/src/orca/scripts/toolkits/Chromium/script_utilities.py
+++ b/src/orca/scripts/toolkits/Chromium/script_utilities.py
@@ -103,6 +103,39 @@ class Utilities(web.Utilities):
 
         return True
 
+    def selectedChildCount(self, obj):
+        count = super().selectedChildCount(obj)
+        if count or "Selection" in pyatspi.listInterfaces(obj):
+            return count
+
+        # HACK: Ideally, we'd use the selection interface to get the selected
+        # children and then only present this menu if there isn't a selected
+        # child. But that interface is not implemented yet. This hackaround
+        # is extremely non-performant.
+        for child in obj:
+            if child.getState().contains(pyatspi.STATE_SELECTED):
+                count += 1
+
+        msg = "CHROMIUM: NO SELECTION INTERFACE HACK: Selected children: %i" % count
+        debug.println(debug.LEVEL_INFO, msg, True)
+        return count
+
+    def isMenuWithNoSelectedChild(self, obj):
+        if not obj:
+            return False
+
+        try:
+            role = obj.getRole()
+        except:
+            msg = "CHROMIUM: Exception getting role for %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        if role != pyatspi.ROLE_MENU:
+            return False
+
+        return not self.selectedChildCount(obj)
+
     def _isFrameContainerForBrowserUIPopUp(self, frame):
         if not frame or self.isDead(frame):
             return False
@@ -149,7 +182,7 @@ class Utilities(web.Utilities):
             role = obj.getRole()
             state = obj.getState()
         except:
-            msg = "ERROR: Exception getting role and state for %s" % obj
+            msg = "CHROMIUM: Exception getting role and state for %s" % obj
             debug.println(debug.LEVEL_INFO, msg, True)
             return False
 


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