From 9e8e4196a7a140fa6ec2504d910b5c7960265565 Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Mon, 21 Aug 2023 09:56:36 +0200 Subject: [PATCH] Fix context menu focus for Edge downloads (#15300) Fixes #14916 Summary of the issue: When opening the context menu from the Edge downloads window, NVDA doesn't reflect this. Description of user facing changes Context menu is read again. Description of development approach It looks like the context menu items aren't direct children of the foreground window, therefore we compare the root of the foreground and the root of the focus window instead. Fixed a typo in a UIAHandler debug string Ensured that UIAHandler.getNearestWindowHandle returns when a cached window handle couldn't be fetched from an UIAElement due to a COMError. --- source/UIAHandler/__init__.py | 8 ++++++-- source/eventHandler.py | 13 ++++++++++--- user_docs/en/changes.t2t | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/UIAHandler/__init__.py b/source/UIAHandler/__init__.py index 7cd3effac2f..64bf5b7362a 100644 --- a/source/UIAHandler/__init__.py +++ b/source/UIAHandler/__init__.py @@ -1198,7 +1198,7 @@ def getNearestWindowHandle(self, UIAElement): return windowHandle if _isDebug(): log.debug( - " locating nearest ancestor windowHandle " + "Locating nearest ancestor windowHandle " f"for element {self.getUIAElementDebugString(UIAElement)}" ) try: @@ -1232,7 +1232,11 @@ def getNearestWindowHandle(self, UIAElement): try: window = new.cachedNativeWindowHandle except COMError: - window = None + if _isDebug(): + log.debugWarning( + "Unable to get cachedNativeWindowHandle from found ancestor element", exc_info=True + ) + return None if _isDebug(): log.debug( "Found ancestor element " diff --git a/source/eventHandler.py b/source/eventHandler.py index 96b1a7f86f9..7ac85b04deb 100755 --- a/source/eventHandler.py +++ b/source/eventHandler.py @@ -499,11 +499,18 @@ def shouldAcceptEvent(eventName, windowHandle=None): fg = winUser.getForegroundWindow() fgClassName=winUser.getClassName(fg) - if wClass == "NetUIHWND" and fgClassName in ("Net UI Tool Window Layered","Net UI Tool Window"): + if ( # #5504: In Office >= 2013 with the ribbon showing only tabs, # when a tab is expanded, the window we get from the focus object is incorrect. - # This window isn't beneath the foreground window, - # so our foreground application checks fail. + # This window isn't beneath the foreground window. + wClass == "NetUIHWND" and fgClassName in ("Net UI Tool Window Layered", "Net UI Tool Window") + or ( + # #14916: The context menu in the Edge download window isn't beneath the foreground window. + wClass == fgClassName + and wClass.startswith("Chrome_WidgetWin_") and fgClassName.startswith("Chrome_WidgetWin_") + ) + ): + # Our foreground application checks fail. # Just compare the root owners. if winUser.getAncestor(windowHandle, winUser.GA_ROOTOWNER) == winUser.getAncestor(fg, winUser.GA_ROOTOWNER): return True diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index dc88653ceba..b552133d454 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -28,6 +28,7 @@ What's New in NVDA - NVDA will no longer jump back to the last browse mode position when opening the context menu in Microsoft Edge. (#15309) - Fixed support for System List view (``SysListView32``) controls in Windows Forms applications. (#15283) - NVDA will no longer be sluggish in rich edit controls when braille is enabled, such as in MemPad. (#14285) +- NVDA is once again able to read context menus of downloads in Microsoft Edge. (#14916) - == Changes for Developers ==