diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index bd2371307843..d2f2077151e8 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -138,7 +138,7 @@ NativeWindowViews::NativeWindowViews( menu_bar_visible_(false), menu_bar_alt_pressed_(false), #if defined(OS_WIN) - enabled_a11y_support_(false), + checked_for_a11y_support_(false), thick_frame_(true), #endif keyboard_event_handler_(new views::UnhandledKeyboardEventHandler), diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 0b4a9245db10..caaf64ba7134 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -18,6 +18,8 @@ #include "atom/browser/ui/win/message_handler_delegate.h" #include "atom/browser/ui/win/taskbar_host.h" #include "base/win/scoped_gdi_object.h" +#include "ui/base/win/accessibility_misc_utils.h" +#include #endif namespace views { @@ -228,8 +230,8 @@ class NativeWindowViews : public NativeWindow, // In charge of running taskbar related APIs. TaskbarHost taskbar_host_; - // If true we have enabled a11y - bool enabled_a11y_support_; + // Memoized version of a11y check + bool checked_for_a11y_support_; // Whether to show the WS_THICKFRAME style. bool thick_frame_; diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index bb6d9858f045..9ba6c746671b 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -92,15 +92,24 @@ bool NativeWindowViews::PreHandleMSG( // accessibility object. case WM_GETOBJECT: { const DWORD obj_id = static_cast(l_param); - if (enabled_a11y_support_) return false; - if (obj_id == OBJID_CLIENT) { - const auto axState = content::BrowserAccessibilityState::GetInstance(); - if (axState && !axState->IsAccessibleBrowser()) { - axState->OnScreenReaderDetected(); - enabled_a11y_support_ = true; - Browser::Get()->OnAccessibilitySupportChanged(); - } + if (obj_id != OBJID_CLIENT) { + return false; + } + + if (checked_for_a11y_support_) return false; + checked_for_a11y_support_ = true; + + UINT screenReader = 0; + SystemParametersInfo(SPI_GETSCREENREADER, 0, &screenReader, 0); + if (!screenReader || !UiaClientsAreListening()) { + return false; + } + + const auto axState = content::BrowserAccessibilityState::GetInstance(); + if (axState && !axState->IsAccessibleBrowser()) { + axState->OnScreenReaderDetected(); + Browser::Get()->OnAccessibilitySupportChanged(); } return false; diff --git a/electron.gyp b/electron.gyp index 821ec27707a4..a186197f4743 100644 --- a/electron.gyp +++ b/electron.gyp @@ -281,6 +281,7 @@ '-lwininet.lib', '-lwinmm.lib', '-lcrypt32.lib', + '-luiautomationcore.lib', ], }, 'dependencies': [