From 3a963aaf6a254c6a99e923a1612ddd62e20cec5a Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Thu, 9 Feb 2023 15:04:07 -0500 Subject: [PATCH] Enable UIA in Window (flutter/engine#39513) * Enable UIA * Unit test getobject * Formatting * Formatting * Formatting * Formatting --- .../flutter/shell/platform/windows/BUILD.gn | 7 ++++++- .../platform/windows/testing/mock_window.h | 2 ++ .../flutter/shell/platform/windows/window.h | 6 +++--- .../shell/platform/windows/window_unittests.cc | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/BUILD.gn b/engine/src/flutter/shell/platform/windows/BUILD.gn index 1f7a850b07..fcd51e7cdd 100644 --- a/engine/src/flutter/shell/platform/windows/BUILD.gn +++ b/engine/src/flutter/shell/platform/windows/BUILD.gn @@ -122,7 +122,10 @@ source_set("flutter_windows_source") { public_configs = [ ":relative_angle_headers" ] - defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ] + defines = [ + "FLUTTER_ENGINE_NO_PROTOTYPES", + "FLUTTER_ENGINE_USE_UIA", + ] public_deps = [ "//flutter/fml:string_conversion", @@ -227,6 +230,8 @@ executable("flutter_windows_unittests") { public_configs = [ "//flutter:config" ] + defines = [ "FLUTTER_ENGINE_USE_UIA" ] + deps = [ ":flutter_windows_fixtures", ":flutter_windows_headers", diff --git a/engine/src/flutter/shell/platform/windows/testing/mock_window.h b/engine/src/flutter/shell/platform/windows/testing/mock_window.h index f25732ee63..22429cf32a 100644 --- a/engine/src/flutter/shell/platform/windows/testing/mock_window.h +++ b/engine/src/flutter/shell/platform/windows/testing/mock_window.h @@ -67,6 +67,8 @@ class MockWindow : public Window { MOCK_METHOD0(GetAxFragmentRootDelegate, ui::AXFragmentRootDelegateWin*()); + MOCK_METHOD3(OnGetObject, LRESULT(UINT, WPARAM, LPARAM)); + void CallOnImeComposition(UINT const message, WPARAM const wparam, LPARAM const lparam); diff --git a/engine/src/flutter/shell/platform/windows/window.h b/engine/src/flutter/shell/platform/windows/window.h index 1ad35e68e2..632e140979 100644 --- a/engine/src/flutter/shell/platform/windows/window.h +++ b/engine/src/flutter/shell/platform/windows/window.h @@ -141,9 +141,9 @@ class Window : public KeyboardManager::WindowDelegate { // // The primary use of this function is to supply Windows with wrapped // semantics objects for use by Windows accessibility. - LRESULT OnGetObject(UINT const message, - WPARAM const wparam, - LPARAM const lparam); + virtual LRESULT OnGetObject(UINT const message, + WPARAM const wparam, + LPARAM const lparam); // Called when IME composing begins. virtual void OnComposeBegin() = 0; diff --git a/engine/src/flutter/shell/platform/windows/window_unittests.cc b/engine/src/flutter/shell/platform/windows/window_unittests.cc index 82fbede827..251ef3f217 100644 --- a/engine/src/flutter/shell/platform/windows/window_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/window_unittests.cc @@ -360,5 +360,23 @@ TEST(MockWindow, UnknownPointerTypeSkipsDirectManipulation) { window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0); } +// Test that the root UIA object is queried by WM_GETOBJECT. +TEST(MockWindow, GetObjectUia) { + MockWindow window; + bool uia_called = false; + ON_CALL(window, OnGetObject) + .WillByDefault(Invoke([&uia_called](UINT msg, WPARAM wpar, LPARAM lpar) { +#ifdef FLUTTER_ENGINE_USE_UIA + uia_called = true; +#endif // FLUTTER_ENGINE_USE_UIA + return static_cast(0); + })); + EXPECT_CALL(window, OnGetObject).Times(1); + + window.InjectWindowMessage(WM_GETOBJECT, 0, UiaRootObjectId); + + EXPECT_TRUE(uia_called); +} + } // namespace testing } // namespace flutter