From 3be3387c8c0aabddbbdab516f1f04244b59e6eb8 Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 16 Dec 2022 17:25:57 -0500 Subject: [PATCH 01/23] Use AXFragmentRootWin for MSAA functionality. Some unused code remains to be removed. Merge MSAA to AXFragmentRootWin --- shell/platform/common/BUILD.gn | 2 + .../common/alert_platform_node_delegate.cc | 44 +++++++++++++ .../common/alert_platform_node_delegate.h | 34 ++++++++++ shell/platform/windows/accessibility_alert.cc | 28 ++++++++ shell/platform/windows/accessibility_alert.h | 27 +++++--- .../windows/accessibility_root_node.cc | 22 +++---- .../windows/accessibility_root_node.h | 6 +- .../flutter_platform_node_delegate_windows.cc | 1 + shell/platform/windows/flutter_window.cc | 9 +++ shell/platform/windows/flutter_window.h | 6 ++ .../windows/flutter_window_unittests.cc | 14 ++-- .../flutter_windows_engine_unittests.cc | 4 +- .../platform/windows/flutter_windows_view.cc | 30 ++++----- shell/platform/windows/flutter_windows_view.h | 8 +-- .../testing/mock_window_binding_handler.h | 2 + shell/platform/windows/window.cc | 65 +++++++++++-------- shell/platform/windows/window.h | 9 +++ .../platform/windows/window_binding_handler.h | 7 ++ .../ax/platform/ax_fragment_root_win.cc | 16 ++++- .../ax/platform/ax_fragment_root_win.h | 10 ++- .../ax/platform/ax_platform_node_win.cc | 36 +++++++++- .../ax/platform/ax_platform_node_win.h | 3 + 22 files changed, 299 insertions(+), 84 deletions(-) create mode 100644 shell/platform/common/alert_platform_node_delegate.cc create mode 100644 shell/platform/common/alert_platform_node_delegate.h diff --git a/shell/platform/common/BUILD.gn b/shell/platform/common/BUILD.gn index a1a1817939202..0d45a8ad1eb5f 100644 --- a/shell/platform/common/BUILD.gn +++ b/shell/platform/common/BUILD.gn @@ -80,11 +80,13 @@ source_set("common_cpp_switches") { source_set("common_cpp_accessibility") { public = [ "accessibility_bridge.h", + "alert_platform_node_delegate.h", "flutter_platform_node_delegate.h", ] sources = [ "accessibility_bridge.cc", + "alert_platform_node_delegate.cc", "flutter_platform_node_delegate.cc", ] diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc new file mode 100644 index 0000000000000..8df47cd9bfd74 --- /dev/null +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -0,0 +1,44 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "alert_platform_node_delegate.h" + +namespace flutter { + +AlertPlatformNodeDelegate::AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate) : parent_delegate_(parent_delegate) { + data_.role = ax::mojom::Role::kAlert; + data_.id = id_.Get(); +} + +AlertPlatformNodeDelegate::~AlertPlatformNodeDelegate() {} + +gfx::AcceleratedWidget AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { + if (parent_delegate_) { + return parent_delegate_->GetTargetForNativeAccessibilityEvent(); + } + return nullptr; +} + +gfx::NativeViewAccessible AlertPlatformNodeDelegate::GetParent() { + if (parent_delegate_) { + return parent_delegate_->GetNativeViewAccessible(); + } + return nullptr; +} + +const ui::AXUniqueId& AlertPlatformNodeDelegate::GetUniqueId() const { + return id_; +} + +const ui::AXNodeData& AlertPlatformNodeDelegate::GetData() const { + return data_; +} + +void AlertPlatformNodeDelegate::SetText(std::u16string text) { + data_.SetName(text); + data_.SetDescription(text); + data_.SetValue(text); +} + +} diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h new file mode 100644 index 0000000000000..81623796ac207 --- /dev/null +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ +#define FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ + +#include "flutter/third_party/accessibility/ax/ax_node_data.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h" + +namespace flutter { + +class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { + public: + AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); + ~AlertPlatformNodeDelegate(); + + void SetText(std::u16string text); + + private: + // AXPlatformNodeDelegate overrides. + gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; + gfx::NativeViewAccessible GetParent() override; + const ui::AXUniqueId& GetUniqueId() const override; + const ui::AXNodeData& GetData() const override; + + ui::AXPlatformNodeDelegate* parent_delegate_; + ui::AXNodeData data_; + ui::AXUniqueId id_; +}; + +} + +#endif // FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ diff --git a/shell/platform/windows/accessibility_alert.cc b/shell/platform/windows/accessibility_alert.cc index f0dc623e6f7cf..79b93203313f8 100644 --- a/shell/platform/windows/accessibility_alert.cc +++ b/shell/platform/windows/accessibility_alert.cc @@ -10,6 +10,33 @@ namespace flutter { AccessibilityAlert::AccessibilityAlert() : text_(L""), parent_(nullptr) {} +gfx::NativeViewAccessible AccessibilityAlert::GetParent() { + if (!parent_) { + return nullptr; + } + return parent_->GetNativeViewAccessible(); +} + +const ui::AXUniqueId& AccessibilityAlert::GetUniqueId() const { + return unique_id_; +} + +gfx::AcceleratedWidget AccessibilityAlert::GetTargetForNativeAccessibilityEvent() { + if (!parent_) { + return nullptr; + } + return parent_->GetTargetForNativeAccessibilityEvent(); +} + +const ui::AXNodeData& AccessibilityAlert::GetData() const { + return data_; +} + +void AccessibilityAlert::SetText(const std::wstring& text) { + data_.SetName(base::WideToUTF16(text)); +} + +/* // IAccessible methods. IFACEMETHODIMP AccessibilityAlert::accHitTest(LONG screen_physical_pixel_x, @@ -183,5 +210,6 @@ void AccessibilityAlert::SetText(const std::wstring& text) { void AccessibilityAlert::SetParent(AccessibilityRootNode* parent) { parent_ = parent; } +*/ } // namespace flutter diff --git a/shell/platform/windows/accessibility_alert.h b/shell/platform/windows/accessibility_alert.h index cb5afba907ad6..7b67699f7f02f 100644 --- a/shell/platform/windows/accessibility_alert.h +++ b/shell/platform/windows/accessibility_alert.h @@ -11,6 +11,9 @@ #include +#include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_win.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h" + namespace flutter { class AccessibilityRootNode; @@ -22,11 +25,12 @@ class AccessibilityRootNode; // of the window's root node. // This node is not interactable to the user. class __declspec(uuid("778c1bd8-383f-4d49-b6be-8937e12b6a32")) - AccessibilityAlert : public CComObjectRootEx, - public IDispatchImpl, - public IServiceProvider { + AccessibilityAlert : public ui::AXPlatformNodeDelegateBase { public: - BEGIN_COM_MAP(AccessibilityAlert) + AccessibilityAlert(); + ~AccessibilityAlert() = default; + + /*BEGIN_COM_MAP(AccessibilityAlert) COM_INTERFACE_ENTRY(AccessibilityAlert) COM_INTERFACE_ENTRY(IAccessible) COM_INTERFACE_ENTRY(IDispatch) @@ -104,18 +108,23 @@ class __declspec(uuid("778c1bd8-383f-4d49-b6be-8937e12b6a32")) REFIID riid, void** object) override; - AccessibilityAlert(); - ~AccessibilityAlert() = default; + void SetParent(AccessibilityRootNode* parent);*/ // Sets the text of this alert to the provided message. void SetText(const std::wstring& text); - void SetParent(AccessibilityRootNode* parent); - private: + // AXPlatformNodeDelegate overrides. + gfx::NativeViewAccessible GetParent() override; + const ui::AXUniqueId& GetUniqueId() const override; + gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; + const ui::AXNodeData& GetData() const override; + std::wstring text_; - AccessibilityRootNode* parent_; + ui::AXFragmentRootWin* parent_; + ui::AXUniqueId unique_id_; + ui::AXNodeData data_; }; } // namespace flutter diff --git a/shell/platform/windows/accessibility_root_node.cc b/shell/platform/windows/accessibility_root_node.cc index caac7f76493b1..260809d65f241 100644 --- a/shell/platform/windows/accessibility_root_node.cc +++ b/shell/platform/windows/accessibility_root_node.cc @@ -12,13 +12,13 @@ namespace flutter { static constexpr LONG kWindowChildId = 1; static constexpr LONG kInvalidChildId = 3; -AccessibilityRootNode::AccessibilityRootNode() : alert_accessible_(nullptr) {} +AccessibilityRootNode::AccessibilityRootNode() /* : alert_accessible_(nullptr)*/ {} AccessibilityRootNode::~AccessibilityRootNode() { - if (alert_accessible_) { + /*if (alert_accessible_) { alert_accessible_->Release(); alert_accessible_ = nullptr; - } + }*/ } IAccessible* AccessibilityRootNode::GetTargetAndChildID(VARIANT* var_id) { @@ -35,10 +35,10 @@ IAccessible* AccessibilityRootNode::GetTargetAndChildID(VARIANT* var_id) { child_id = CHILDID_SELF; return window_accessible_; } - if (child_id == kAlertChildId && alert_accessible_) { + /*if (child_id == kAlertChildId && alert_accessible_) { child_id = CHILDID_SELF; return alert_accessible_; - } + }*/ // A negative child ID can be used to refer to an AX node directly by its ID. if (child_id < 0) { return window_accessible_; @@ -100,8 +100,8 @@ IFACEMETHODIMP AccessibilityRootNode::get_accChild(VARIANT var_child, return E_FAIL; } else if (child_id == kWindowChildId) { *disp_child = window_accessible_; - } else if (child_id == kAlertChildId && alert_accessible_) { - *disp_child = alert_accessible_; + //} else if (child_id == kAlertChildId && alert_accessible_) { + // *disp_child = alert_accessible_; } else if (child_id < 0) { // A negative child ID can be used to refer to an AX node directly by its // ID. @@ -118,9 +118,9 @@ IFACEMETHODIMP AccessibilityRootNode::get_accChildCount(LONG* child_count) { if (window_accessible_) { children++; } - if (alert_accessible_) { + /*if (alert_accessible_) { children++; - } + }*/ *child_count = children; return S_OK; } @@ -277,7 +277,7 @@ void AccessibilityRootNode::SetWindow(IAccessible* window) { window_accessible_ = window; } -AccessibilityAlert* AccessibilityRootNode::GetOrCreateAlert() { +/*AccessibilityAlert* AccessibilityRootNode::GetOrCreateAlert() { if (!alert_accessible_) { CComObject* instance = nullptr; HRESULT hr = CComObject::CreateInstance(&instance); @@ -289,7 +289,7 @@ AccessibilityAlert* AccessibilityRootNode::GetOrCreateAlert() { alert_accessible_ = instance; } return alert_accessible_; -} +}*/ // static AccessibilityRootNode* AccessibilityRootNode::Create() { diff --git a/shell/platform/windows/accessibility_root_node.h b/shell/platform/windows/accessibility_root_node.h index 5d01e83cfe4be..61966c6233fce 100644 --- a/shell/platform/windows/accessibility_root_node.h +++ b/shell/platform/windows/accessibility_root_node.h @@ -117,9 +117,9 @@ class __declspec(uuid("fedb8280-ea4f-47a9-98fe-5d1a557fe4b3")) void SetWindow(IAccessible* window); - void SetAlert(AccessibilityAlert* alert); + //void SetAlert(AccessibilityAlert* alert); - AccessibilityAlert* GetOrCreateAlert(); + //AccessibilityAlert* GetOrCreateAlert(); static AccessibilityRootNode* Create(); @@ -129,7 +129,7 @@ class __declspec(uuid("fedb8280-ea4f-47a9-98fe-5d1a557fe4b3")) IAccessible* window_accessible_; - AccessibilityAlert* alert_accessible_; + //AccessibilityAlert* alert_accessible_; }; } // namespace flutter diff --git a/shell/platform/windows/flutter_platform_node_delegate_windows.cc b/shell/platform/windows/flutter_platform_node_delegate_windows.cc index 0e2ce94c7a7e2..e895363aac97e 100644 --- a/shell/platform/windows/flutter_platform_node_delegate_windows.cc +++ b/shell/platform/windows/flutter_platform_node_delegate_windows.cc @@ -11,6 +11,7 @@ #include "flutter/third_party/accessibility/ax/ax_clipping_behavior.h" #include "flutter/third_party/accessibility/ax/ax_coordinate_system.h" #include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_win.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" namespace flutter { diff --git a/shell/platform/windows/flutter_window.cc b/shell/platform/windows/flutter_window.cc index 2aab541002abd..7160fe84d83e7 100644 --- a/shell/platform/windows/flutter_window.cc +++ b/shell/platform/windows/flutter_window.cc @@ -309,4 +309,13 @@ ui::AXFragmentRootDelegateWin* FlutterWindow::GetAxFragmentRootDelegate() { return binding_handler_delegate_->GetAxFragmentRootDelegate(); } +void FlutterWindow::Alert(const std::wstring& text) { + CreateAlertNode(); + alert_delegate_->SetText(base::WideToUTF16(text)); +} + +ui::AXPlatformNodeWin* FlutterWindow::GetAlert() { + return alert_node_.get(); +} + } // namespace flutter diff --git a/shell/platform/windows/flutter_window.h b/shell/platform/windows/flutter_window.h index f9537885ef890..d98050c24778b 100644 --- a/shell/platform/windows/flutter_window.h +++ b/shell/platform/windows/flutter_window.h @@ -153,6 +153,12 @@ class FlutterWindow : public Window, public WindowBindingHandler { // |WindowBindingHandler| AccessibilityRootNode* GetAccessibilityRootNode() override; + // |WindowBindingHandler| + void Alert(const std::wstring& text) override; + + // |WindowBindingHandler| + ui::AXPlatformNodeWin* GetAlert() override; + // |Window| ui::AXFragmentRootDelegateWin* GetAxFragmentRootDelegate() override; diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 02c57b67629de..0bacfa17f5111 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -164,7 +164,9 @@ class TestFlutterWindowsView : public FlutterWindowsView { SpyKeyboardKeyHandler* key_event_handler; SpyTextInputPlugin* text_input_plugin; - MOCK_METHOD4(NotifyWinEventWrapper, void(DWORD, HWND, LONG, LONG)); + MOCK_METHOD2(NotifyWinEventWrapper, void(ui::AXPlatformNodeWin*, ax::mojom::Event)); + + protected: std::unique_ptr CreateKeyboardKeyHandler( @@ -415,15 +417,15 @@ TEST(FlutterWindowTest, AlertNode) { std::unique_ptr win32window = std::make_unique(); ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr)); - AccessibilityRootNode* root_node = win32window->GetAccessibilityRootNode(); + // AccessibilityRootNode* root_node = win32window->GetAccessibilityRootNode(); TestFlutterWindowsView view(std::move(win32window)); + std::wstring message = L"Test alert"; EXPECT_CALL(view, - NotifyWinEventWrapper(EVENT_SYSTEM_ALERT, nullptr, OBJID_CLIENT, - AccessibilityRootNode::kAlertChildId)) + NotifyWinEventWrapper(_, ax::mojom::Event::kAlert)) .Times(1); - std::wstring message = L"Test alert"; view.AnnounceAlert(message); - IAccessible* alert = root_node->GetOrCreateAlert(); + + IAccessible* alert = view.AlertNode(); //root_node->GetOrCreateAlert(); VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF}; BSTR strptr; alert->get_accName(self, &strptr); diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 78cde4a974739..a499f8c1a1814 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -567,7 +567,7 @@ class MockFlutterWindowsView : public FlutterWindowsView { : FlutterWindowsView(std::move(wbh)) {} ~MockFlutterWindowsView() {} - MOCK_METHOD4(NotifyWinEventWrapper, void(DWORD, HWND, LONG, LONG)); + MOCK_METHOD2(NotifyWinEventWrapper, void(ui::AXPlatformNodeWin*, ax::mojom::Event)); }; TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { @@ -598,7 +598,7 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { bool did_call = false; ON_CALL(view, NotifyWinEventWrapper) - .WillByDefault([&did_call](DWORD event, HWND hwnd, LONG obj, LONG child) { + .WillByDefault([&did_call](ui::AXPlatformNodeWin* node, ax::mojom::Event event) { did_call = true; }); diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 1aee3c0ae8d2a..e62cbc9d65133 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -10,6 +10,7 @@ #include "flutter/shell/platform/windows/keyboard_key_channel_handler.h" #include "flutter/shell/platform/windows/keyboard_key_embedder_handler.h" #include "flutter/shell/platform/windows/text_input_plugin.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" namespace flutter { @@ -661,23 +662,14 @@ FlutterWindowsEngine* FlutterWindowsView::GetEngine() { } void FlutterWindowsView::AnnounceAlert(const std::wstring& text) { - AccessibilityRootNode* root_node = - binding_handler_->GetAccessibilityRootNode(); - AccessibilityAlert* alert = - binding_handler_->GetAccessibilityRootNode()->GetOrCreateAlert(); - alert->SetText(text); - HWND hwnd = GetPlatformWindow(); - NotifyWinEventWrapper(EVENT_SYSTEM_ALERT, hwnd, OBJID_CLIENT, - AccessibilityRootNode::kAlertChildId); -} - -void FlutterWindowsView::NotifyWinEventWrapper(DWORD event, - HWND hwnd, - LONG idObject, - LONG idChild) { - if (hwnd) { - NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd, OBJID_CLIENT, - AccessibilityRootNode::kAlertChildId); + binding_handler_->Alert(text); + ui::AXPlatformNodeWin* alert_node = binding_handler_->GetAlert(); + NotifyWinEventWrapper(alert_node, ax::mojom::Event::kAlert); +} + +void FlutterWindowsView::NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, ax::mojom::Event event) { + if (node) { + node->NotifyAccessibilityEvent(event); } } @@ -685,4 +677,8 @@ ui::AXFragmentRootDelegateWin* FlutterWindowsView::GetAxFragmentRootDelegate() { return engine_->accessibility_bridge().lock().get(); } +ui::AXPlatformNodeWin* FlutterWindowsView::AlertNode() const { + return binding_handler_->GetAlert(); +} + } // namespace flutter diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index 083fb13e5ece6..8c3ff33a27691 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -202,6 +202,9 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate, // |TextInputPluginDelegate| void OnResetImeComposing() override; + // Get a pointer to the alert node for this view. + ui::AXPlatformNodeWin* AlertNode() const; + // |WindowBindingHandlerDelegate| virtual ui::AXFragmentRootDelegateWin* GetAxFragmentRootDelegate() override; @@ -221,10 +224,7 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate, virtual std::unique_ptr CreateTextInputPlugin( BinaryMessenger* messenger); - virtual void NotifyWinEventWrapper(DWORD event, - HWND hwnd, - LONG idObject, - LONG idChild); + virtual void NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, ax::mojom::Event event); private: // Struct holding the state of an individual pointer. The engine doesn't keep diff --git a/shell/platform/windows/testing/mock_window_binding_handler.h b/shell/platform/windows/testing/mock_window_binding_handler.h index 2fc5cbd77e905..ae069780869a7 100644 --- a/shell/platform/windows/testing/mock_window_binding_handler.h +++ b/shell/platform/windows/testing/mock_window_binding_handler.h @@ -37,6 +37,8 @@ class MockWindowBindingHandler : public WindowBindingHandler { MOCK_METHOD0(GetPrimaryPointerLocation, PointerLocation()); MOCK_METHOD0(SendInitialAccessibilityFeatures, void()); MOCK_METHOD0(GetAccessibilityRootNode, AccessibilityRootNode*()); + MOCK_METHOD1(Alert, void(const std::wstring& text)); + MOCK_METHOD0(GetAlert, ui::AXPlatformNodeWin*()); }; } // namespace testing diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index 3a5441afad90f..b0ed1e7e926fd 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -14,6 +14,7 @@ #include +#include "flutter/shell/platform/common/flutter_platform_node_delegate.h" #include "flutter/shell/platform/windows/dpi_utils.h" #include "flutter/shell/platform/windows/keyboard_utils.h" @@ -204,35 +205,39 @@ LRESULT Window::OnGetObject(UINT const message, gfx::NativeViewAccessible root_view = GetNativeViewAccessible(); // TODO(schectman): UIA is currently disabled by default. // https://github.com/flutter/flutter/issues/114547 - if (is_uia_request && root_view) { -#ifdef FLUTTER_ENGINE_USE_UIA + if (root_view) { if (!ax_fragment_root_) { ax_fragment_root_ = std::make_unique( window_handle_, GetAxFragmentRootDelegate()); + FlutterPlatformNodeDelegate* child_delegate = static_cast(ax_fragment_root_->GetChildNodeDelegate()); + child_delegate->GetAXNode(); } - - // Retrieve UIA object for the root view. - Microsoft::WRL::ComPtr root; - if (SUCCEEDED(ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( - IID_PPV_ARGS(&root)))) { - // Return the UIA object via UiaReturnRawElementProvider(). See: - // https://docs.microsoft.com/en-us/windows/win32/winauto/wm-getobject - reference_result = UiaReturnRawElementProvider(window_handle_, wparam, - lparam, root.Get()); - } else { - FML_LOG(ERROR) << "Failed to query AX fragment root."; - } + if (is_uia_request) { +#ifdef FLUTTER_ENGINE_USE_UIA + // Retrieve UIA object for the root view. + Microsoft::WRL::ComPtr root; + if (SUCCEEDED(ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( + IID_PPV_ARGS(&root)))) { + // Return the UIA object via UiaReturnRawElementProvider(). See: + // https://docs.microsoft.com/en-us/windows/win32/winauto/wm-getobject + reference_result = UiaReturnRawElementProvider(window_handle_, wparam, + lparam, root.Get()); + } else { + FML_LOG(ERROR) << "Failed to query AX fragment root."; + } #endif // FLUTTER_ENGINE_USE_UIA - } else if (is_msaa_request && root_view) { - // Create the accessibility root if it does not already exist. - if (!accessibility_root_) { - CreateAccessibilityRootNode(); + } else if (is_msaa_request) { + // Create the accessibility root if it does not already exist. + if (!accessibility_root_) { + CreateAccessibilityRootNode(); + } + // Return the IAccessible for the root view. + // Microsoft::WRL::ComPtr root(root_view); + accessibility_root_->SetWindow(root_view); + Microsoft::WRL::ComPtr root; + ax_fragment_root_->GetNativeViewAccessible()->QueryInterface(IID_PPV_ARGS(&root)); + reference_result = LresultFromObject(IID_IAccessible, wparam, root.Get()); } - // Return the IAccessible for the root view. - // Microsoft::WRL::ComPtr root(root_view); - accessibility_root_->SetWindow(root_view); - Microsoft::WRL::ComPtr root(accessibility_root_); - reference_result = LresultFromObject(IID_IAccessible, wparam, root.Get()); } return reference_result; } @@ -621,11 +626,6 @@ void Window::Destroy() { window_handle_ = nullptr; } - if (accessibility_root_) { - accessibility_root_->Release(); - accessibility_root_ = nullptr; - } - UnregisterClass(window_class_name_.c_str(), nullptr); } @@ -685,4 +685,13 @@ void Window::CreateAccessibilityRootNode() { accessibility_root_ = AccessibilityRootNode::Create(); } +void Window::CreateAlertNode() { + if (alert_delegate_) { + return; + } + alert_delegate_ = std::make_unique(ax_fragment_root_.get()); + ui::AXPlatformNode* alert_node = ui::AXPlatformNodeWin::Create(alert_delegate_.get()); + alert_node_.reset(static_cast(alert_node)); +} + } // namespace flutter diff --git a/shell/platform/windows/window.h b/shell/platform/windows/window.h index 036883ed66a10..207aa41d61d41 100644 --- a/shell/platform/windows/window.h +++ b/shell/platform/windows/window.h @@ -12,6 +12,7 @@ #include #include +#include "flutter/shell/platform/common/alert_platform_node_delegate.h" #include "flutter/shell/platform/embedder/embedder.h" #include "flutter/shell/platform/windows/accessibility_root_node.h" #include "flutter/shell/platform/windows/direct_manipulation.h" @@ -22,6 +23,7 @@ #include "flutter/shell/platform/windows/windowsx_shim.h" #include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_delegate_win.h" #include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_win.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" #include "flutter/third_party/accessibility/gfx/native_widget_types.h" namespace flutter { @@ -214,6 +216,8 @@ class Window : public KeyboardManager::WindowDelegate { // Check if the high contrast feature is enabled on the OS virtual bool GetHighContrastEnabled(); + void CreateAlertNode(); + // Called to obtain a pointer to the fragment root delegate. virtual ui::AXFragmentRootDelegateWin* GetAxFragmentRootDelegate() = 0; @@ -241,8 +245,13 @@ class Window : public KeyboardManager::WindowDelegate { virtual void OnThemeChange() = 0; // A parent node wrapping the window root, used for siblings. + // TODO(schectman): remove if this change works out AccessibilityRootNode* accessibility_root_; + std::unique_ptr alert_delegate_; + + std::unique_ptr alert_node_; + private: // Release OS resources associated with window. void Destroy(); diff --git a/shell/platform/windows/window_binding_handler.h b/shell/platform/windows/window_binding_handler.h index 47b8ecf0e048d..35f3742b32568 100644 --- a/shell/platform/windows/window_binding_handler.h +++ b/shell/platform/windows/window_binding_handler.h @@ -10,6 +10,7 @@ #include #include +#include "flutter/shell/platform/common/alert_platform_node_delegate.h" #include "flutter/shell/platform/common/geometry.h" #include "flutter/shell/platform/windows/accessibility_root_node.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" @@ -99,6 +100,12 @@ class WindowBindingHandler { // Returns the wrapper parent accessibility node. virtual AccessibilityRootNode* GetAccessibilityRootNode() = 0; + + // Set the alert text. + virtual void Alert(const std::wstring& text) = 0; + + // Retrieve the alert node. + virtual ui::AXPlatformNodeWin* GetAlert() = 0; }; } // namespace flutter diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc index d6abe02c3e2c7..2ad14a3c0f63e 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc @@ -289,7 +289,7 @@ class AXFragmentRootMapWin { AXFragmentRootWin::AXFragmentRootWin(gfx::AcceleratedWidget widget, AXFragmentRootDelegateWin* delegate) - : widget_(widget), delegate_(delegate) { + : widget_(widget), delegate_(delegate), alert_node_(nullptr) { platform_node_ = ui::AXFragmentRootPlatformNodeWin::Create(this); AXFragmentRootMapWin::GetInstance().AddFragmentRoot(widget, this); } @@ -331,6 +331,8 @@ int AXFragmentRootWin::GetChildCount() const { gfx::NativeViewAccessible AXFragmentRootWin::ChildAtIndex(int index) { if (index == 0) { return delegate_->GetChildOfAXFragmentRoot(); + } else if (index == 1 && alert_node_) { + return alert_node_; } return nullptr; @@ -425,4 +427,16 @@ int AXFragmentRootWin::GetIndexInParentOfChild() const { return 0; } +void AXFragmentRootWin::SetAlertNode(AXPlatformNodeWin* alert_node) { + alert_node_ = alert_node; +} + +gfx::Rect AXFragmentRootWin::GetBoundsRect(AXCoordinateSystem sys, AXClippingBehavior clip, AXOffscreenResult* result) const { + AXPlatformNodeDelegate* child = GetChildNodeDelegate(); + if (!child) { + return gfx::Rect(); + } + return child->GetBoundsRect(sys, clip, result); +} + } // namespace ui diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index ec357d4dffbff..9e227d82d5b23 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -13,6 +13,7 @@ namespace ui { class AXFragmentRootDelegateWin; class AXFragmentRootPlatformNodeWin; +class AXPlatformNodeWin; // UI Automation on Windows requires the root of a multi-element provider to // implement IRawElementProviderFragmentRoot. Our internal accessibility trees @@ -55,6 +56,11 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { // If a child node is available, return its delegate. AXPlatformNodeDelegate* GetChildNodeDelegate() const; + // AXPlatformNodeDelegate override. + gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; + + void SetAlertNode(AXPlatformNodeWin* alert_node); + private: // AXPlatformNodeDelegate overrides. gfx::NativeViewAccessible GetParent() override; @@ -65,9 +71,9 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { gfx::NativeViewAccessible HitTestSync(int x, int y) const override; gfx::NativeViewAccessible GetFocus() override; const ui::AXUniqueId& GetUniqueId() const override; - gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; AXPlatformNode* GetFromTreeIDAndNodeID(const ui::AXTreeID& ax_tree_id, int32_t id) override; + gfx::Rect GetBoundsRect(const AXCoordinateSystem acs, const AXClippingBehavior acb, AXOffscreenResult* result) const override; // A fragment root does not correspond to any node in the platform neutral // accessibility tree. Rather, the fragment root's child is a child of the @@ -82,6 +88,8 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { AXFragmentRootDelegateWin* const delegate_; Microsoft::WRL::ComPtr platform_node_; ui::AXUniqueId unique_id_; + + AXPlatformNodeWin* alert_node_; }; } // namespace ui diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win.cc b/third_party/accessibility/ax/platform/ax_platform_node_win.cc index 097379a4f672f..28a6069ce7658 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win.cc +++ b/third_party/accessibility/ax/platform/ax_platform_node_win.cc @@ -1065,7 +1065,17 @@ IFACEMETHODIMP AXPlatformNodeWin::get_accParent(IDispatch** disp_parent) { (*disp_parent)->AddRef(); return S_OK; } - + IRawElementProviderFragmentRoot* root; + if (SUCCEEDED(get_FragmentRoot(&root))) { + gfx::NativeViewAccessible parent; + if (SUCCEEDED(root->QueryInterface(IID_PPV_ARGS(&parent)))) { + if (parent && parent != GetNativeViewAccessible()) { + *disp_parent = parent; + parent->AddRef(); + return S_OK; + } + } + } return S_FALSE; } @@ -5408,7 +5418,7 @@ AXPlatformNodeWin* AXPlatformNodeWin::GetTargetFromChildID( AXPlatformNodeBase* base = FromNativeViewAccessible(node->GetNativeViewAccessible()); - if (base && !IsDescendant(base)) + if (base && !base->IsDescendantOf(this)) base = nullptr; return static_cast(base); @@ -5701,4 +5711,26 @@ AXPlatformNodeWin* AXPlatformNodeWin::GetFirstTextOnlyDescendant() { return nullptr; } +bool AXPlatformNodeWin::IsDescendantOf(AXPlatformNode* ancestor) const { + if (AXPlatformNodeBase::IsDescendantOf(ancestor)) { + return true; + } + + if (!ancestor) { + return false; + } + + // Test if the ancestor is an IRawElementProviderFragmentRoot and if it matches + // this node's root fragment. + IRawElementProviderFragmentRoot* root; + if (SUCCEEDED(const_cast(this)->get_FragmentRoot(&root))) { + AXPlatformNodeWin* root_win; + if (SUCCEEDED(root->QueryInterface(__uuidof(AXPlatformNodeWin), (void**) & root_win))) { + return ancestor == static_cast(root_win); + } + } + + return false; +} + } // namespace ui diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win.h b/third_party/accessibility/ax/platform/ax_platform_node_win.h index c2dba4fcd71ec..2f5de650f7a40 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win.h +++ b/third_party/accessibility/ax/platform/ax_platform_node_win.h @@ -473,6 +473,9 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2")) static std::optional MojoEventToUIAProperty( ax::mojom::Event event); + // |AXPlatformNodeBase| + bool IsDescendantOf(AXPlatformNode* acnestor) const override; + protected: // This is hard-coded; all products based on the Chromium engine will have the // same framework name, so that assistive technology can detect any From 34652729b8b76292f198431a0152a357bad5aea0 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 11:36:45 -0500 Subject: [PATCH 02/23] Removing unused code --- shell/platform/windows/BUILD.gn | 4 ---- shell/platform/windows/flutter_window.cc | 7 ------- shell/platform/windows/flutter_window.h | 3 --- shell/platform/windows/flutter_window_unittests.cc | 1 - .../windows/flutter_windows_engine_unittests.cc | 4 +--- .../windows/testing/mock_window_binding_handler.h | 2 +- shell/platform/windows/window.cc | 14 +------------- shell/platform/windows/window.h | 8 -------- shell/platform/windows/window_binding_handler.h | 5 +---- 9 files changed, 4 insertions(+), 44 deletions(-) diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 99be6cf851aef..1f7a850b07135 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -38,12 +38,8 @@ source_set("flutter_windows_headers") { source_set("flutter_windows_source") { # Common Windows sources. sources = [ - "accessibility_alert.cc", - "accessibility_alert.h", "accessibility_bridge_windows.cc", "accessibility_bridge_windows.h", - "accessibility_root_node.cc", - "accessibility_root_node.h", "angle_surface_manager.cc", "angle_surface_manager.h", "cursor_handler.cc", diff --git a/shell/platform/windows/flutter_window.cc b/shell/platform/windows/flutter_window.cc index 7160fe84d83e7..dd6c61c31ccec 100644 --- a/shell/platform/windows/flutter_window.cc +++ b/shell/platform/windows/flutter_window.cc @@ -298,13 +298,6 @@ void FlutterWindow::SendInitialAccessibilityFeatures() { OnThemeChange(); } -AccessibilityRootNode* FlutterWindow::GetAccessibilityRootNode() { - if (!accessibility_root_) { - CreateAccessibilityRootNode(); - } - return accessibility_root_; -} - ui::AXFragmentRootDelegateWin* FlutterWindow::GetAxFragmentRootDelegate() { return binding_handler_delegate_->GetAxFragmentRootDelegate(); } diff --git a/shell/platform/windows/flutter_window.h b/shell/platform/windows/flutter_window.h index d98050c24778b..f7300c634e37a 100644 --- a/shell/platform/windows/flutter_window.h +++ b/shell/platform/windows/flutter_window.h @@ -150,9 +150,6 @@ class FlutterWindow : public Window, public WindowBindingHandler { // |WindowBindingHandler| void SendInitialAccessibilityFeatures() override; - // |WindowBindingHandler| - AccessibilityRootNode* GetAccessibilityRootNode() override; - // |WindowBindingHandler| void Alert(const std::wstring& text) override; diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 0bacfa17f5111..cb187a70bf7f8 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -417,7 +417,6 @@ TEST(FlutterWindowTest, AlertNode) { std::unique_ptr win32window = std::make_unique(); ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr)); - // AccessibilityRootNode* root_node = win32window->GetAccessibilityRootNode(); TestFlutterWindowsView view(std::move(win32window)); std::wstring message = L"Test alert"; EXPECT_CALL(view, diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index a499f8c1a1814..78240b1a5b616 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -12,6 +12,7 @@ #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h" #include "flutter/shell/platform/windows/testing/test_keyboard.h" #include "flutter/shell/platform/windows/testing/windows_test.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" #include "fml/synchronization/waitable_event.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -576,9 +577,6 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); - AccessibilityRootNode* root_node = AccessibilityRootNode::Create(); - ON_CALL(*window_binding_handler, GetAccessibilityRootNode) - .WillByDefault(::testing::Return(root_node)); MockFlutterWindowsView view(std::move(window_binding_handler)); view.SetEngine(builder.Build()); FlutterWindowsEngine* engine = view.GetEngine(); diff --git a/shell/platform/windows/testing/mock_window_binding_handler.h b/shell/platform/windows/testing/mock_window_binding_handler.h index ae069780869a7..bf4bdf752aa52 100644 --- a/shell/platform/windows/testing/mock_window_binding_handler.h +++ b/shell/platform/windows/testing/mock_window_binding_handler.h @@ -6,6 +6,7 @@ #define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_WINDOW_BINDING_HANDLER_H_ #include "flutter/shell/platform/windows/window_binding_handler.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" #include "gmock/gmock.h" namespace flutter { @@ -36,7 +37,6 @@ class MockWindowBindingHandler : public WindowBindingHandler { bool(const void* allocation, size_t row_bytes, size_t height)); MOCK_METHOD0(GetPrimaryPointerLocation, PointerLocation()); MOCK_METHOD0(SendInitialAccessibilityFeatures, void()); - MOCK_METHOD0(GetAccessibilityRootNode, AccessibilityRootNode*()); MOCK_METHOD1(Alert, void(const std::wstring& text)); MOCK_METHOD0(GetAlert, ui::AXPlatformNodeWin*()); }; diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index b0ed1e7e926fd..83e4f933d7609 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -61,7 +61,6 @@ Window::Window(std::unique_ptr windows_proc_table, : touch_id_generator_(kMinTouchDeviceId, kMaxTouchDeviceId), windows_proc_table_(std::move(windows_proc_table)), text_input_manager_(std::move(text_input_manager)), - accessibility_root_(nullptr), ax_fragment_root_(nullptr) { // Get the DPI of the primary monitor as the initial DPI. If Per-Monitor V2 is // supported, |current_dpi_| should be updated in the @@ -213,7 +212,7 @@ LRESULT Window::OnGetObject(UINT const message, child_delegate->GetAXNode(); } if (is_uia_request) { -#ifdef FLUTTER_ENGINE_USE_UIA +#ifndef FLUTTER_ENGINE_USE_UIA // Retrieve UIA object for the root view. Microsoft::WRL::ComPtr root; if (SUCCEEDED(ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( @@ -228,12 +227,8 @@ LRESULT Window::OnGetObject(UINT const message, #endif // FLUTTER_ENGINE_USE_UIA } else if (is_msaa_request) { // Create the accessibility root if it does not already exist. - if (!accessibility_root_) { - CreateAccessibilityRootNode(); - } // Return the IAccessible for the root view. // Microsoft::WRL::ComPtr root(root_view); - accessibility_root_->SetWindow(root_view); Microsoft::WRL::ComPtr root; ax_fragment_root_->GetNativeViewAccessible()->QueryInterface(IID_PPV_ARGS(&root)); reference_result = LresultFromObject(IID_IAccessible, wparam, root.Get()); @@ -678,13 +673,6 @@ bool Window::GetHighContrastEnabled() { } } -void Window::CreateAccessibilityRootNode() { - if (accessibility_root_) { - accessibility_root_->Release(); - } - accessibility_root_ = AccessibilityRootNode::Create(); -} - void Window::CreateAlertNode() { if (alert_delegate_) { return; diff --git a/shell/platform/windows/window.h b/shell/platform/windows/window.h index 207aa41d61d41..4117f3f98d0f4 100644 --- a/shell/platform/windows/window.h +++ b/shell/platform/windows/window.h @@ -14,7 +14,6 @@ #include "flutter/shell/platform/common/alert_platform_node_delegate.h" #include "flutter/shell/platform/embedder/embedder.h" -#include "flutter/shell/platform/windows/accessibility_root_node.h" #include "flutter/shell/platform/windows/direct_manipulation.h" #include "flutter/shell/platform/windows/keyboard_manager.h" #include "flutter/shell/platform/windows/sequential_id_generator.h" @@ -234,9 +233,6 @@ class Window : public KeyboardManager::WindowDelegate { // Returns the root view accessibility node, or nullptr if none. virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0; - // Create the wrapper node. - void CreateAccessibilityRootNode(); - // Handles running DirectManipulation on the window to receive trackpad // gestures. std::unique_ptr direct_manipulation_owner_; @@ -244,10 +240,6 @@ class Window : public KeyboardManager::WindowDelegate { // Called when a theme change message is issued virtual void OnThemeChange() = 0; - // A parent node wrapping the window root, used for siblings. - // TODO(schectman): remove if this change works out - AccessibilityRootNode* accessibility_root_; - std::unique_ptr alert_delegate_; std::unique_ptr alert_node_; diff --git a/shell/platform/windows/window_binding_handler.h b/shell/platform/windows/window_binding_handler.h index 35f3742b32568..46731a63897cc 100644 --- a/shell/platform/windows/window_binding_handler.h +++ b/shell/platform/windows/window_binding_handler.h @@ -12,9 +12,9 @@ #include "flutter/shell/platform/common/alert_platform_node_delegate.h" #include "flutter/shell/platform/common/geometry.h" -#include "flutter/shell/platform/windows/accessibility_root_node.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" namespace flutter { @@ -98,9 +98,6 @@ class WindowBindingHandler { // Called to set the initial state of accessibility features virtual void SendInitialAccessibilityFeatures() = 0; - // Returns the wrapper parent accessibility node. - virtual AccessibilityRootNode* GetAccessibilityRootNode() = 0; - // Set the alert text. virtual void Alert(const std::wstring& text) = 0; From 1a7171b4e9a05f27bceb5bcac3abb5f991b363ae Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 11:53:49 -0500 Subject: [PATCH 03/23] Remove unused files --- .../common/alert_platform_node_delegate.cc | 88 ++--- .../common/alert_platform_node_delegate.h | 68 ++-- shell/platform/windows/accessibility_alert.cc | 215 ------------ shell/platform/windows/accessibility_alert.h | 132 -------- .../windows/accessibility_root_node.cc | 306 ------------------ .../windows/accessibility_root_node.h | 137 -------- .../platform/windows/window_binding_handler.h | 5 +- 7 files changed, 82 insertions(+), 869 deletions(-) delete mode 100644 shell/platform/windows/accessibility_alert.cc delete mode 100644 shell/platform/windows/accessibility_alert.h delete mode 100644 shell/platform/windows/accessibility_root_node.cc delete mode 100644 shell/platform/windows/accessibility_root_node.h diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index 8df47cd9bfd74..b5dfbf98f4ade 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -1,44 +1,44 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "alert_platform_node_delegate.h" - -namespace flutter { - -AlertPlatformNodeDelegate::AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate) : parent_delegate_(parent_delegate) { - data_.role = ax::mojom::Role::kAlert; - data_.id = id_.Get(); -} - -AlertPlatformNodeDelegate::~AlertPlatformNodeDelegate() {} - -gfx::AcceleratedWidget AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { - if (parent_delegate_) { - return parent_delegate_->GetTargetForNativeAccessibilityEvent(); - } - return nullptr; -} - -gfx::NativeViewAccessible AlertPlatformNodeDelegate::GetParent() { - if (parent_delegate_) { - return parent_delegate_->GetNativeViewAccessible(); - } - return nullptr; -} - -const ui::AXUniqueId& AlertPlatformNodeDelegate::GetUniqueId() const { - return id_; -} - -const ui::AXNodeData& AlertPlatformNodeDelegate::GetData() const { - return data_; -} - -void AlertPlatformNodeDelegate::SetText(std::u16string text) { - data_.SetName(text); - data_.SetDescription(text); - data_.SetValue(text); -} - -} +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "alert_platform_node_delegate.h" + +namespace flutter { + +AlertPlatformNodeDelegate::AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate) : parent_delegate_(parent_delegate) { + data_.role = ax::mojom::Role::kAlert; + data_.id = id_.Get(); +} + +AlertPlatformNodeDelegate::~AlertPlatformNodeDelegate() {} + +gfx::AcceleratedWidget AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { + if (parent_delegate_) { + return parent_delegate_->GetTargetForNativeAccessibilityEvent(); + } + return nullptr; +} + +gfx::NativeViewAccessible AlertPlatformNodeDelegate::GetParent() { + if (parent_delegate_) { + return parent_delegate_->GetNativeViewAccessible(); + } + return nullptr; +} + +const ui::AXUniqueId& AlertPlatformNodeDelegate::GetUniqueId() const { + return id_; +} + +const ui::AXNodeData& AlertPlatformNodeDelegate::GetData() const { + return data_; +} + +void AlertPlatformNodeDelegate::SetText(std::u16string text) { + data_.SetName(text); + data_.SetDescription(text); + data_.SetValue(text); +} + +} diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index 81623796ac207..bc40fa1179c8b 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -1,34 +1,34 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ -#define FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ - -#include "flutter/third_party/accessibility/ax/ax_node_data.h" -#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h" - -namespace flutter { - -class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { - public: - AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); - ~AlertPlatformNodeDelegate(); - - void SetText(std::u16string text); - - private: - // AXPlatformNodeDelegate overrides. - gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; - gfx::NativeViewAccessible GetParent() override; - const ui::AXUniqueId& GetUniqueId() const override; - const ui::AXNodeData& GetData() const override; - - ui::AXPlatformNodeDelegate* parent_delegate_; - ui::AXNodeData data_; - ui::AXUniqueId id_; -}; - -} - -#endif // FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ +#define FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ + +#include "flutter/third_party/accessibility/ax/ax_node_data.h" +#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h" + +namespace flutter { + +class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { + public: + AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); + ~AlertPlatformNodeDelegate(); + + void SetText(std::u16string text); + + private: + // AXPlatformNodeDelegate overrides. + gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; + gfx::NativeViewAccessible GetParent() override; + const ui::AXUniqueId& GetUniqueId() const override; + const ui::AXNodeData& GetData() const override; + + ui::AXPlatformNodeDelegate* parent_delegate_; + ui::AXNodeData data_; + ui::AXUniqueId id_; +}; + +} + +#endif // FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ diff --git a/shell/platform/windows/accessibility_alert.cc b/shell/platform/windows/accessibility_alert.cc deleted file mode 100644 index 79b93203313f8..0000000000000 --- a/shell/platform/windows/accessibility_alert.cc +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/windows/accessibility_alert.h" - -#include "flutter/shell/platform/windows/accessibility_root_node.h" - -namespace flutter { - -AccessibilityAlert::AccessibilityAlert() : text_(L""), parent_(nullptr) {} - -gfx::NativeViewAccessible AccessibilityAlert::GetParent() { - if (!parent_) { - return nullptr; - } - return parent_->GetNativeViewAccessible(); -} - -const ui::AXUniqueId& AccessibilityAlert::GetUniqueId() const { - return unique_id_; -} - -gfx::AcceleratedWidget AccessibilityAlert::GetTargetForNativeAccessibilityEvent() { - if (!parent_) { - return nullptr; - } - return parent_->GetTargetForNativeAccessibilityEvent(); -} - -const ui::AXNodeData& AccessibilityAlert::GetData() const { - return data_; -} - -void AccessibilityAlert::SetText(const std::wstring& text) { - data_.SetName(base::WideToUTF16(text)); -} - -/* -// IAccessible methods. - -IFACEMETHODIMP AccessibilityAlert::accHitTest(LONG screen_physical_pixel_x, - LONG screen_physical_pixel_y, - VARIANT* child) { - child->vt = VT_EMPTY; - return S_FALSE; -} - -// Performs the object's default action. -IFACEMETHODIMP AccessibilityAlert::accDoDefaultAction(VARIANT var_id) { - return E_FAIL; -} - -// Retrieves an IDispatch interface pointer for the specified child. -IFACEMETHODIMP AccessibilityAlert::get_accChild(VARIANT var_child, - IDispatch** disp_child) { - if (V_VT(&var_child) == VT_I4 && V_I4(&var_child) == CHILDID_SELF) { - *disp_child = this; - AddRef(); - return S_OK; - } - *disp_child = nullptr; - return E_FAIL; -} - -// Retrieves the number of accessible children. -IFACEMETHODIMP AccessibilityAlert::get_accChildCount(LONG* child_count) { - *child_count = 0; - return S_OK; -} - -// Retrieves the tooltip description. -IFACEMETHODIMP AccessibilityAlert::get_accDescription(VARIANT var_id, - BSTR* desc) { - *desc = SysAllocString(text_.c_str()); - return S_OK; -} - -// Retrieves the name of the specified object. -IFACEMETHODIMP AccessibilityAlert::get_accName(VARIANT var_id, BSTR* name) { - *name = SysAllocString(text_.c_str()); - return S_OK; -} - -// Retrieves the IDispatch interface of the object's parent. -IFACEMETHODIMP AccessibilityAlert::get_accParent(IDispatch** disp_parent) { - *disp_parent = parent_; - if (*disp_parent) { - (*disp_parent)->AddRef(); - return S_OK; - } - return S_FALSE; -} - -// Retrieves information describing the role of the specified object. -IFACEMETHODIMP AccessibilityAlert::get_accRole(VARIANT var_id, VARIANT* role) { - *role = {.vt = VT_I4, .lVal = ROLE_SYSTEM_ALERT}; - return S_OK; -} - -// Retrieves the current state of the specified object. -IFACEMETHODIMP AccessibilityAlert::get_accState(VARIANT var_id, - VARIANT* state) { - *state = {.vt = VT_I4, .lVal = STATE_SYSTEM_DEFAULT}; - return S_OK; -} - -// Gets the help string for the specified object. -IFACEMETHODIMP AccessibilityAlert::get_accHelp(VARIANT var_id, BSTR* help) { - *help = SysAllocString(L""); - return S_OK; -} - -// Retrieve or set the string value associated with the specified object. -// Setting the value is not typically used by screen readers, but it's -// used frequently by automation software. -IFACEMETHODIMP AccessibilityAlert::get_accValue(VARIANT var_id, BSTR* value) { - *value = SysAllocString(text_.c_str()); - return S_OK; -} - -// IAccessible methods not implemented. -IFACEMETHODIMP AccessibilityAlert::get_accSelection(VARIANT* selected) { - selected->vt = VT_EMPTY; - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::accSelect(LONG flags_sel, VARIANT var_id) { - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::put_accValue(VARIANT var_id, - BSTR new_value) { - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::get_accFocus(VARIANT* focus_child) { - focus_child->vt = VT_EMPTY; - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::get_accHelpTopic(BSTR* help_file, - VARIANT var_id, - LONG* topic_id) { - if (help_file) { - *help_file = nullptr; - } - if (topic_id) { - *topic_id = 0; - } - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::put_accName(VARIANT var_id, BSTR put_name) { - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::get_accKeyboardShortcut(VARIANT var_id, - BSTR* access_key) { - *access_key = nullptr; - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::accLocation(LONG* physical_pixel_left, - LONG* physical_pixel_top, - LONG* width, - LONG* height, - VARIANT var_id) { - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::accNavigate(LONG nav_dir, - VARIANT start, - VARIANT* end) { - end->vt = VT_EMPTY; - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityAlert::get_accDefaultAction(VARIANT var_id, - BSTR* default_action) { - *default_action = nullptr; - return E_NOTIMPL; -} - -// End of IAccessible methods. - -// -// IServiceProvider implementation. -// - -IFACEMETHODIMP AccessibilityAlert::QueryService(REFGUID guidService, - REFIID riid, - void** object) { - if (!object) { - return E_INVALIDARG; - } - - if (guidService == IID_IAccessible) { - return QueryInterface(riid, object); - } - - *object = nullptr; - return E_FAIL; -} - -void AccessibilityAlert::SetText(const std::wstring& text) { - text_ = text; -} - -void AccessibilityAlert::SetParent(AccessibilityRootNode* parent) { - parent_ = parent; -} -*/ - -} // namespace flutter diff --git a/shell/platform/windows/accessibility_alert.h b/shell/platform/windows/accessibility_alert.h deleted file mode 100644 index 7b67699f7f02f..0000000000000 --- a/shell/platform/windows/accessibility_alert.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_ALERT_H_ -#define FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_ALERT_H_ - -#include -#include -#include - -#include - -#include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_win.h" -#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h" - -namespace flutter { - -class AccessibilityRootNode; - -// An IAccessible node representing an alert read to the screen reader. -// When an announcement is requested by the framework, an instance of -// this class, if none exists already, is created and made a child of -// the root AccessibilityRootNode node, and is therefore also a sibling -// of the window's root node. -// This node is not interactable to the user. -class __declspec(uuid("778c1bd8-383f-4d49-b6be-8937e12b6a32")) - AccessibilityAlert : public ui::AXPlatformNodeDelegateBase { - public: - AccessibilityAlert(); - ~AccessibilityAlert() = default; - - /*BEGIN_COM_MAP(AccessibilityAlert) - COM_INTERFACE_ENTRY(AccessibilityAlert) - COM_INTERFACE_ENTRY(IAccessible) - COM_INTERFACE_ENTRY(IDispatch) - COM_INTERFACE_ENTRY(IServiceProvider) - END_COM_MAP() - // - // IAccessible methods. - // - - // Retrieves the child element or child object at a given point on the screen. - IFACEMETHODIMP accHitTest(LONG screen_physical_pixel_x, - LONG screen_physical_pixel_y, - VARIANT* child) override; - - // Retrieves an IDispatch interface pointer for the specified child. - IFACEMETHODIMP get_accChild(VARIANT var_child, - IDispatch** disp_child) override; - - // Retrieves the number of accessible children. - IFACEMETHODIMP get_accChildCount(LONG* child_count) override; - - // Retrieves a string that describes the object's default action. - IFACEMETHODIMP get_accDefaultAction(VARIANT var_id, - BSTR* default_action) override; - - // Retrieves the tooltip description. - IFACEMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc) override; - - // Retrieves the name of the specified object. - IFACEMETHODIMP get_accName(VARIANT var_id, BSTR* name) override; - - // Retrieves the IDispatch interface of the object's parent. - IFACEMETHODIMP get_accParent(IDispatch** disp_parent) override; - - // Retrieves information describing the role of the specified object. - IFACEMETHODIMP get_accRole(VARIANT var_id, VARIANT* role) override; - - // Retrieves the current state of the specified object. - IFACEMETHODIMP get_accState(VARIANT var_id, VARIANT* state) override; - - // Gets the help string for the specified object. - IFACEMETHODIMP get_accHelp(VARIANT var_id, BSTR* help) override; - - // Retrieve the string value associated with the specified object. - IFACEMETHODIMP get_accValue(VARIANT var_id, BSTR* value) override; - - // IAccessible methods not implemented. - IFACEMETHODIMP accLocation(LONG* physical_pixel_left, - LONG* physical_pixel_top, - LONG* width, - LONG* height, - VARIANT var_id) override; - IFACEMETHODIMP accNavigate(LONG nav_dir, - VARIANT start, - VARIANT* end) override; - IFACEMETHODIMP accDoDefaultAction(VARIANT var_id) override; - IFACEMETHODIMP get_accFocus(VARIANT* focus_child) override; - IFACEMETHODIMP get_accKeyboardShortcut(VARIANT var_id, - BSTR* access_key) override; - IFACEMETHODIMP get_accSelection(VARIANT* selected) override; - IFACEMETHODIMP accSelect(LONG flags_sel, VARIANT var_id) override; - IFACEMETHODIMP get_accHelpTopic(BSTR* help_file, - VARIANT var_id, - LONG* topic_id) override; - IFACEMETHODIMP put_accName(VARIANT var_id, BSTR put_name) override; - IFACEMETHODIMP put_accValue(VARIANT var_id, BSTR new_value) override; - - // End of IAccessible methods. - - // - // IServiceProvider method. - // - - IFACEMETHODIMP QueryService(REFGUID guidService, - REFIID riid, - void** object) override; - - void SetParent(AccessibilityRootNode* parent);*/ - - // Sets the text of this alert to the provided message. - void SetText(const std::wstring& text); - - private: - // AXPlatformNodeDelegate overrides. - gfx::NativeViewAccessible GetParent() override; - const ui::AXUniqueId& GetUniqueId() const override; - gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; - const ui::AXNodeData& GetData() const override; - - std::wstring text_; - - ui::AXFragmentRootWin* parent_; - ui::AXUniqueId unique_id_; - ui::AXNodeData data_; -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_ALERT_H_ diff --git a/shell/platform/windows/accessibility_root_node.cc b/shell/platform/windows/accessibility_root_node.cc deleted file mode 100644 index 260809d65f241..0000000000000 --- a/shell/platform/windows/accessibility_root_node.cc +++ /dev/null @@ -1,306 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/windows/accessibility_root_node.h" - -#include "flutter/fml/logging.h" -#include "flutter/third_party/accessibility/base/win/atl_module.h" - -namespace flutter { - -static constexpr LONG kWindowChildId = 1; -static constexpr LONG kInvalidChildId = 3; - -AccessibilityRootNode::AccessibilityRootNode() /* : alert_accessible_(nullptr)*/ {} - -AccessibilityRootNode::~AccessibilityRootNode() { - /*if (alert_accessible_) { - alert_accessible_->Release(); - alert_accessible_ = nullptr; - }*/ -} - -IAccessible* AccessibilityRootNode::GetTargetAndChildID(VARIANT* var_id) { - LONG& child_id = var_id->lVal; - if (V_VT(var_id) != VT_I4) { - child_id = kInvalidChildId; - return nullptr; - } - child_id = V_I4(var_id); - if (!window_accessible_) { - return nullptr; - } - if (child_id == CHILDID_SELF || child_id == kWindowChildId) { - child_id = CHILDID_SELF; - return window_accessible_; - } - /*if (child_id == kAlertChildId && alert_accessible_) { - child_id = CHILDID_SELF; - return alert_accessible_; - }*/ - // A negative child ID can be used to refer to an AX node directly by its ID. - if (child_id < 0) { - return window_accessible_; - } - return nullptr; -} - -IFACEMETHODIMP AccessibilityRootNode::accHitTest(LONG screen_physical_pixel_x, - LONG screen_physical_pixel_y, - VARIANT* child) { - if (window_accessible_) { - return window_accessible_->accHitTest(screen_physical_pixel_x, - screen_physical_pixel_y, child); - } - child->vt = VT_EMPTY; - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::accDoDefaultAction(VARIANT var_id) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->accDoDefaultAction(var_id); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::accLocation(LONG* physical_pixel_left, - LONG* physical_pixel_top, - LONG* width, - LONG* height, - VARIANT var_id) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->accLocation(physical_pixel_left, physical_pixel_top, width, - height, var_id); - } - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::accNavigate(LONG nav_dir, - VARIANT start, - VARIANT* end) { - IAccessible* target; - if ((target = GetTargetAndChildID(&start))) { - return target->accNavigate(nav_dir, start, end); - } - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accChild(VARIANT var_child, - IDispatch** disp_child) { - if (V_VT(&var_child) != VT_I4) { - return E_FAIL; - } - LONG child_id = V_I4(&var_child); - if (child_id == CHILDID_SELF) { - *disp_child = this; - } else if (!window_accessible_) { - return E_FAIL; - } else if (child_id == kWindowChildId) { - *disp_child = window_accessible_; - //} else if (child_id == kAlertChildId && alert_accessible_) { - // *disp_child = alert_accessible_; - } else if (child_id < 0) { - // A negative child ID can be used to refer to an AX node directly by its - // ID. - return window_accessible_->get_accChild(var_child, disp_child); - } else { - return E_FAIL; - } - (*disp_child)->AddRef(); - return S_OK; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accChildCount(LONG* child_count) { - LONG children = 0; - if (window_accessible_) { - children++; - } - /*if (alert_accessible_) { - children++; - }*/ - *child_count = children; - return S_OK; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accDefaultAction(VARIANT var_id, - BSTR* def_action) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accDefaultAction(var_id, def_action); - } - *def_action = nullptr; - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accDescription(VARIANT var_id, - BSTR* desc) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accDescription(var_id, desc); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accFocus(VARIANT* focus_child) { - if (window_accessible_) { - return window_accessible_->get_accFocus(focus_child); - } - focus_child->vt = VT_EMPTY; - return S_OK; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accKeyboardShortcut(VARIANT var_id, - BSTR* acc_key) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accKeyboardShortcut(var_id, acc_key); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accName(VARIANT var_id, - BSTR* name_bstr) { - if (V_I4(&var_id) == CHILDID_SELF) { - std::wstring name = L"ROOT_NODE_VIEW"; - *name_bstr = SysAllocString(name.c_str()); - return S_OK; - } - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accName(var_id, name_bstr); - } - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accParent(IDispatch** disp_parent) { - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accRole(VARIANT var_id, - VARIANT* role) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accRole(var_id, role); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accState(VARIANT var_id, - VARIANT* state) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accState(var_id, state); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accHelp(VARIANT var_id, BSTR* help) { - if (!help) { - return E_INVALIDARG; - } - *help = {}; - return S_FALSE; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accValue(VARIANT var_id, - BSTR* value) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->get_accValue(var_id, value); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::put_accValue(VARIANT var_id, - BSTR new_value) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->put_accValue(var_id, new_value); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accSelection(VARIANT* selected) { - selected->vt = VT_EMPTY; - return S_OK; -} - -IFACEMETHODIMP AccessibilityRootNode::accSelect(LONG flagsSelect, - VARIANT var_id) { - IAccessible* target; - if ((target = GetTargetAndChildID(&var_id))) { - return target->accSelect(flagsSelect, var_id); - } - return E_FAIL; -} - -IFACEMETHODIMP AccessibilityRootNode::get_accHelpTopic(BSTR* help_file, - VARIANT var_id, - LONG* topic_id) { - if (help_file) { - *help_file = nullptr; - } - if (topic_id) { - *topic_id = -1; - } - return E_NOTIMPL; -} - -IFACEMETHODIMP AccessibilityRootNode::put_accName(VARIANT var_id, - BSTR put_name) { - return E_NOTIMPL; -} - -// -// IServiceProvider implementation. -// - -IFACEMETHODIMP AccessibilityRootNode::QueryService(REFGUID guidService, - REFIID riid, - void** object) { - if (!object) { - return E_INVALIDARG; - } - - if (guidService == IID_IAccessible) { - return QueryInterface(riid, object); - } - - *object = nullptr; - return E_FAIL; -} - -void AccessibilityRootNode::SetWindow(IAccessible* window) { - window_accessible_ = window; -} - -/*AccessibilityAlert* AccessibilityRootNode::GetOrCreateAlert() { - if (!alert_accessible_) { - CComObject* instance = nullptr; - HRESULT hr = CComObject::CreateInstance(&instance); - if (!SUCCEEDED(hr)) { - FML_LOG(FATAL) << "Failed to create alert accessible"; - } - instance->AddRef(); - instance->SetParent(this); - alert_accessible_ = instance; - } - return alert_accessible_; -}*/ - -// static -AccessibilityRootNode* AccessibilityRootNode::Create() { - ui::win::CreateATLModuleIfNeeded(); - CComObject* instance = nullptr; - HRESULT hr = CComObject::CreateInstance(&instance); - if (!SUCCEEDED(hr) || !instance) { - FML_LOG(FATAL) << "Failed to create accessibility root node"; - } - instance->AddRef(); - return instance; -} - -} // namespace flutter diff --git a/shell/platform/windows/accessibility_root_node.h b/shell/platform/windows/accessibility_root_node.h deleted file mode 100644 index 61966c6233fce..0000000000000 --- a/shell/platform/windows/accessibility_root_node.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_ROOT_NODE_H_ -#define FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_ROOT_NODE_H_ - -#include -#include -#include - -#include - -#include "flutter/shell/platform/windows/accessibility_alert.h" - -namespace flutter { - -// A parent node that wraps the window IAccessible node. -class __declspec(uuid("fedb8280-ea4f-47a9-98fe-5d1a557fe4b3")) - AccessibilityRootNode : public CComObjectRootEx, - public IDispatchImpl, - public IServiceProvider { - public: - static constexpr LONG kAlertChildId = 2; - - BEGIN_COM_MAP(AccessibilityRootNode) - COM_INTERFACE_ENTRY(AccessibilityRootNode) - COM_INTERFACE_ENTRY(IAccessible) - COM_INTERFACE_ENTRY(IDispatch) - COM_INTERFACE_ENTRY(IServiceProvider) - END_COM_MAP() - - // - // IAccessible methods. - // - - // Retrieves the child element or child object at a given point on the screen. - IFACEMETHODIMP accHitTest(LONG screen_physical_pixel_x, - LONG screen_physical_pixel_y, - VARIANT* child) override; - - // Performs the object's default action. - IFACEMETHODIMP accDoDefaultAction(VARIANT var_id) override; - - // Retrieves the specified object's current screen location. - IFACEMETHODIMP accLocation(LONG* physical_pixel_left, - LONG* physical_pixel_top, - LONG* width, - LONG* height, - VARIANT var_id) override; - - // Traverses to another UI element and retrieves the object. - IFACEMETHODIMP accNavigate(LONG nav_dir, - VARIANT start, - VARIANT* end) override; - - // Retrieves an IDispatch interface pointer for the specified child. - IFACEMETHODIMP get_accChild(VARIANT var_child, - IDispatch** disp_child) override; - - // Retrieves the number of accessible children. - IFACEMETHODIMP get_accChildCount(LONG* child_count) override; - - // Retrieves a string that describes the object's default action. - IFACEMETHODIMP get_accDefaultAction(VARIANT var_id, - BSTR* default_action) override; - - // Retrieves the tooltip description. - IFACEMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc) override; - - // Retrieves the object that has the keyboard focus. - IFACEMETHODIMP get_accFocus(VARIANT* focus_child) override; - - // Retrieves the specified object's shortcut. - IFACEMETHODIMP get_accKeyboardShortcut(VARIANT var_id, - BSTR* access_key) override; - - // Retrieves the name of the specified object. - IFACEMETHODIMP get_accName(VARIANT var_id, BSTR* name) override; - - // Retrieves the IDispatch interface of the object's parent. - IFACEMETHODIMP get_accParent(IDispatch** disp_parent) override; - - // Retrieves information describing the role of the specified object. - IFACEMETHODIMP get_accRole(VARIANT var_id, VARIANT* role) override; - - // Retrieves the current state of the specified object. - IFACEMETHODIMP get_accState(VARIANT var_id, VARIANT* state) override; - - // Gets the help string for the specified object. - IFACEMETHODIMP get_accHelp(VARIANT var_id, BSTR* help) override; - - // Retrieve or set the string value associated with the specified object. - // Setting the value is not typically used by screen readers, but it's - // used frequently by automation software. - IFACEMETHODIMP get_accValue(VARIANT var_id, BSTR* value) override; - IFACEMETHODIMP put_accValue(VARIANT var_id, BSTR new_value) override; - - // IAccessible methods not implemented. - IFACEMETHODIMP get_accSelection(VARIANT* selected) override; - IFACEMETHODIMP accSelect(LONG flags_sel, VARIANT var_id) override; - IFACEMETHODIMP get_accHelpTopic(BSTR* help_file, - VARIANT var_id, - LONG* topic_id) override; - IFACEMETHODIMP put_accName(VARIANT var_id, BSTR put_name) override; - - // - // IServiceProvider method. - // - - IFACEMETHODIMP QueryService(REFGUID guidService, - REFIID riid, - void** object) override; - - AccessibilityRootNode(); - virtual ~AccessibilityRootNode(); - - void SetWindow(IAccessible* window); - - //void SetAlert(AccessibilityAlert* alert); - - //AccessibilityAlert* GetOrCreateAlert(); - - static AccessibilityRootNode* Create(); - - private: - // Helper method to redirect method calls to the contained window or alert. - IAccessible* GetTargetAndChildID(VARIANT* var_id); - - IAccessible* window_accessible_; - - //AccessibilityAlert* alert_accessible_; -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_ROOT_NODE_H_ diff --git a/shell/platform/windows/window_binding_handler.h b/shell/platform/windows/window_binding_handler.h index 46731a63897cc..169faf71e4e10 100644 --- a/shell/platform/windows/window_binding_handler.h +++ b/shell/platform/windows/window_binding_handler.h @@ -14,7 +14,10 @@ #include "flutter/shell/platform/common/geometry.h" #include "flutter/shell/platform/windows/public/flutter_windows.h" #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" -#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" + +namespace ui { + class AXPlatformNodeWin; +} namespace flutter { From 0a20b2f3ce12b7ec6d28d5807fb3e449abc8551d Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 11:58:12 -0500 Subject: [PATCH 04/23] Flip macro --- shell/platform/windows/window.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index 83e4f933d7609..e88191fc95cce 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -212,7 +212,7 @@ LRESULT Window::OnGetObject(UINT const message, child_delegate->GetAXNode(); } if (is_uia_request) { -#ifndef FLUTTER_ENGINE_USE_UIA +#ifdef FLUTTER_ENGINE_USE_UIA // Retrieve UIA object for the root view. Microsoft::WRL::ComPtr root; if (SUCCEEDED(ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( From 7f78a69c2df311a3ad1c0d7cfc14d8d303be068d Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 12:12:59 -0500 Subject: [PATCH 05/23] Formatting --- .../common/alert_platform_node_delegate.cc | 11 +++++++---- .../common/alert_platform_node_delegate.h | 2 +- .../windows/flutter_window_unittests.cc | 10 ++++------ .../flutter_windows_engine_unittests.cc | 8 ++++---- shell/platform/windows/flutter_windows_view.cc | 3 ++- shell/platform/windows/flutter_windows_view.h | 3 ++- shell/platform/windows/window.cc | 18 ++++++++++++------ .../platform/windows/window_binding_handler.h | 2 +- .../ax/platform/ax_fragment_root_win.cc | 4 +++- .../ax/platform/ax_fragment_root_win.h | 4 +++- .../ax/platform/ax_platform_node_win.cc | 10 ++++++---- 11 files changed, 45 insertions(+), 30 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index b5dfbf98f4ade..ffdd18c51955e 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -6,18 +6,21 @@ namespace flutter { -AlertPlatformNodeDelegate::AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate) : parent_delegate_(parent_delegate) { +AlertPlatformNodeDelegate::AlertPlatformNodeDelegate( + ui::AXPlatformNodeDelegate* parent_delegate) + : parent_delegate_(parent_delegate) { data_.role = ax::mojom::Role::kAlert; data_.id = id_.Get(); } AlertPlatformNodeDelegate::~AlertPlatformNodeDelegate() {} -gfx::AcceleratedWidget AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { +gfx::AcceleratedWidget +AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { if (parent_delegate_) { return parent_delegate_->GetTargetForNativeAccessibilityEvent(); } - return nullptr; + return (gfx::AcceleratedWidget)nullptr; } gfx::NativeViewAccessible AlertPlatformNodeDelegate::GetParent() { @@ -41,4 +44,4 @@ void AlertPlatformNodeDelegate::SetText(std::u16string text) { data_.SetValue(text); } -} +} // namespace flutter diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index bc40fa1179c8b..69df71974fae9 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -29,6 +29,6 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { ui::AXUniqueId id_; }; -} +} // namespace flutter #endif // FLUTTER_SHELL_PLATFORM_COMMON_ALERT_PLATFORM_NODE_DELEGATE_H_ diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index cb187a70bf7f8..d88b815b44e4d 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -164,9 +164,8 @@ class TestFlutterWindowsView : public FlutterWindowsView { SpyKeyboardKeyHandler* key_event_handler; SpyTextInputPlugin* text_input_plugin; - MOCK_METHOD2(NotifyWinEventWrapper, void(ui::AXPlatformNodeWin*, ax::mojom::Event)); - - + MOCK_METHOD2(NotifyWinEventWrapper, + void(ui::AXPlatformNodeWin*, ax::mojom::Event)); protected: std::unique_ptr CreateKeyboardKeyHandler( @@ -419,12 +418,11 @@ TEST(FlutterWindowTest, AlertNode) { ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr)); TestFlutterWindowsView view(std::move(win32window)); std::wstring message = L"Test alert"; - EXPECT_CALL(view, - NotifyWinEventWrapper(_, ax::mojom::Event::kAlert)) + EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert)) .Times(1); view.AnnounceAlert(message); - IAccessible* alert = view.AlertNode(); //root_node->GetOrCreateAlert(); + IAccessible* alert = view.AlertNode(); // root_node->GetOrCreateAlert(); VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF}; BSTR strptr; alert->get_accName(self, &strptr); diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 78240b1a5b616..6c4f1c7314ad8 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -568,7 +568,8 @@ class MockFlutterWindowsView : public FlutterWindowsView { : FlutterWindowsView(std::move(wbh)) {} ~MockFlutterWindowsView() {} - MOCK_METHOD2(NotifyWinEventWrapper, void(ui::AXPlatformNodeWin*, ax::mojom::Event)); + MOCK_METHOD2(NotifyWinEventWrapper, + void(ui::AXPlatformNodeWin*, ax::mojom::Event)); }; TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { @@ -596,9 +597,8 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { bool did_call = false; ON_CALL(view, NotifyWinEventWrapper) - .WillByDefault([&did_call](ui::AXPlatformNodeWin* node, ax::mojom::Event event) { - did_call = true; - }); + .WillByDefault([&did_call](ui::AXPlatformNodeWin* node, + ax::mojom::Event event) { did_call = true; }); engine->UpdateSemanticsEnabled(true); engine->Run(); diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index e62cbc9d65133..7abf446406573 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -667,7 +667,8 @@ void FlutterWindowsView::AnnounceAlert(const std::wstring& text) { NotifyWinEventWrapper(alert_node, ax::mojom::Event::kAlert); } -void FlutterWindowsView::NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, ax::mojom::Event event) { +void FlutterWindowsView::NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, + ax::mojom::Event event) { if (node) { node->NotifyAccessibilityEvent(event); } diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index 8c3ff33a27691..acaa9ad106e0d 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -224,7 +224,8 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate, virtual std::unique_ptr CreateTextInputPlugin( BinaryMessenger* messenger); - virtual void NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, ax::mojom::Event event); + virtual void NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, + ax::mojom::Event event); private: // Struct holding the state of an individual pointer. The engine doesn't keep diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index e88191fc95cce..9ebb4c13e6079 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -208,15 +208,18 @@ LRESULT Window::OnGetObject(UINT const message, if (!ax_fragment_root_) { ax_fragment_root_ = std::make_unique( window_handle_, GetAxFragmentRootDelegate()); - FlutterPlatformNodeDelegate* child_delegate = static_cast(ax_fragment_root_->GetChildNodeDelegate()); + FlutterPlatformNodeDelegate* child_delegate = + static_cast( + ax_fragment_root_->GetChildNodeDelegate()); child_delegate->GetAXNode(); } if (is_uia_request) { #ifdef FLUTTER_ENGINE_USE_UIA // Retrieve UIA object for the root view. Microsoft::WRL::ComPtr root; - if (SUCCEEDED(ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( - IID_PPV_ARGS(&root)))) { + if (SUCCEEDED( + ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( + IID_PPV_ARGS(&root)))) { // Return the UIA object via UiaReturnRawElementProvider(). See: // https://docs.microsoft.com/en-us/windows/win32/winauto/wm-getobject reference_result = UiaReturnRawElementProvider(window_handle_, wparam, @@ -230,7 +233,8 @@ LRESULT Window::OnGetObject(UINT const message, // Return the IAccessible for the root view. // Microsoft::WRL::ComPtr root(root_view); Microsoft::WRL::ComPtr root; - ax_fragment_root_->GetNativeViewAccessible()->QueryInterface(IID_PPV_ARGS(&root)); + ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( + IID_PPV_ARGS(&root)); reference_result = LresultFromObject(IID_IAccessible, wparam, root.Get()); } } @@ -677,8 +681,10 @@ void Window::CreateAlertNode() { if (alert_delegate_) { return; } - alert_delegate_ = std::make_unique(ax_fragment_root_.get()); - ui::AXPlatformNode* alert_node = ui::AXPlatformNodeWin::Create(alert_delegate_.get()); + alert_delegate_ = + std::make_unique(ax_fragment_root_.get()); + ui::AXPlatformNode* alert_node = + ui::AXPlatformNodeWin::Create(alert_delegate_.get()); alert_node_.reset(static_cast(alert_node)); } diff --git a/shell/platform/windows/window_binding_handler.h b/shell/platform/windows/window_binding_handler.h index 169faf71e4e10..48d9734db8c65 100644 --- a/shell/platform/windows/window_binding_handler.h +++ b/shell/platform/windows/window_binding_handler.h @@ -16,7 +16,7 @@ #include "flutter/shell/platform/windows/window_binding_handler_delegate.h" namespace ui { - class AXPlatformNodeWin; +class AXPlatformNodeWin; } namespace flutter { diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc index 2ad14a3c0f63e..e6ef519656473 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc @@ -431,7 +431,9 @@ void AXFragmentRootWin::SetAlertNode(AXPlatformNodeWin* alert_node) { alert_node_ = alert_node; } -gfx::Rect AXFragmentRootWin::GetBoundsRect(AXCoordinateSystem sys, AXClippingBehavior clip, AXOffscreenResult* result) const { +gfx::Rect AXFragmentRootWin::GetBoundsRect(AXCoordinateSystem sys, + AXClippingBehavior clip, + AXOffscreenResult* result) const { AXPlatformNodeDelegate* child = GetChildNodeDelegate(); if (!child) { return gfx::Rect(); diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index 9e227d82d5b23..1dba487a5832c 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -73,7 +73,9 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { const ui::AXUniqueId& GetUniqueId() const override; AXPlatformNode* GetFromTreeIDAndNodeID(const ui::AXTreeID& ax_tree_id, int32_t id) override; - gfx::Rect GetBoundsRect(const AXCoordinateSystem acs, const AXClippingBehavior acb, AXOffscreenResult* result) const override; + gfx::Rect GetBoundsRect(const AXCoordinateSystem acs, + const AXClippingBehavior acb, + AXOffscreenResult* result) const override; // A fragment root does not correspond to any node in the platform neutral // accessibility tree. Rather, the fragment root's child is a child of the diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win.cc b/third_party/accessibility/ax/platform/ax_platform_node_win.cc index 28a6069ce7658..fa40da70e1ab8 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win.cc +++ b/third_party/accessibility/ax/platform/ax_platform_node_win.cc @@ -5720,12 +5720,14 @@ bool AXPlatformNodeWin::IsDescendantOf(AXPlatformNode* ancestor) const { return false; } - // Test if the ancestor is an IRawElementProviderFragmentRoot and if it matches - // this node's root fragment. + // Test if the ancestor is an IRawElementProviderFragmentRoot and if it + // matches this node's root fragment. IRawElementProviderFragmentRoot* root; - if (SUCCEEDED(const_cast(this)->get_FragmentRoot(&root))) { + if (SUCCEEDED( + const_cast(this)->get_FragmentRoot(&root))) { AXPlatformNodeWin* root_win; - if (SUCCEEDED(root->QueryInterface(__uuidof(AXPlatformNodeWin), (void**) & root_win))) { + if (SUCCEEDED(root->QueryInterface(__uuidof(AXPlatformNodeWin), + (void**)&root_win))) { return ancestor == static_cast(root_win); } } From 8982f08e3ea9ea08e760efa710fe58b5488dbcc5 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 12:28:06 -0500 Subject: [PATCH 06/23] Licenses --- ci/licenses_golden/licenses_flutter | 12 ++++-------- .../platform/common/alert_platform_node_delegate.cc | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index baecaa91972f5..21ad9f3fc4542 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -2405,6 +2405,8 @@ ORIGIN: ../../../flutter/shell/platform/android/vsync_waiter_android.cc + ../../ ORIGIN: ../../../flutter/shell/platform/android/vsync_waiter_android.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/accessibility_bridge.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/accessibility_bridge.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/common/alert_platform_node_delegate.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/common/alert_platform_node_delegate.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/byte_buffer_streams.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/core_implementations.cc + ../../../flutter/LICENSE @@ -3065,12 +3067,8 @@ ORIGIN: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_texture_re ORIGIN: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_value.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_view.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/windows/accessibility_alert.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/windows/accessibility_alert.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/accessibility_bridge_windows.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/accessibility_bridge_windows.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/windows/accessibility_root_node.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/windows/accessibility_root_node.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/angle_surface_manager.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/angle_surface_manager.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/client_wrapper/flutter_engine.cc + ../../../flutter/LICENSE @@ -4894,6 +4892,8 @@ FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.cc FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.h FILE: ../../../flutter/shell/platform/common/accessibility_bridge.cc FILE: ../../../flutter/shell/platform/common/accessibility_bridge.h +FILE: ../../../flutter/shell/platform/common/alert_platform_node_delegate.cc +FILE: ../../../flutter/shell/platform/common/alert_platform_node_delegate.h FILE: ../../../flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h FILE: ../../../flutter/shell/platform/common/client_wrapper/byte_buffer_streams.h FILE: ../../../flutter/shell/platform/common/client_wrapper/core_implementations.cc @@ -5573,12 +5573,8 @@ FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_texture_regi FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_value.h FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_view.h FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h -FILE: ../../../flutter/shell/platform/windows/accessibility_alert.cc -FILE: ../../../flutter/shell/platform/windows/accessibility_alert.h FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_windows.cc FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_windows.h -FILE: ../../../flutter/shell/platform/windows/accessibility_root_node.cc -FILE: ../../../flutter/shell/platform/windows/accessibility_root_node.h FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.cc FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.h FILE: ../../../flutter/shell/platform/windows/client_wrapper/flutter_engine.cc diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index ffdd18c51955e..6c999bffbe703 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -20,7 +20,7 @@ AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { if (parent_delegate_) { return parent_delegate_->GetTargetForNativeAccessibilityEvent(); } - return (gfx::AcceleratedWidget)nullptr; + return (gfx::AcceleratedWidget) nullptr; } gfx::NativeViewAccessible AlertPlatformNodeDelegate::GetParent() { From 77ee7b9d98b54a43e0adbd5d4435b54de852fe9c Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 13:32:05 -0500 Subject: [PATCH 07/23] Make reference --- shell/platform/common/alert_platform_node_delegate.cc | 2 +- shell/platform/common/alert_platform_node_delegate.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index 6c999bffbe703..17e90df509e53 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -38,7 +38,7 @@ const ui::AXNodeData& AlertPlatformNodeDelegate::GetData() const { return data_; } -void AlertPlatformNodeDelegate::SetText(std::u16string text) { +void AlertPlatformNodeDelegate::SetText(const std::u16string& text) { data_.SetName(text); data_.SetDescription(text); data_.SetValue(text); diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index 69df71974fae9..8a42eba0c4590 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -15,7 +15,7 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); ~AlertPlatformNodeDelegate(); - void SetText(std::u16string text); + void SetText(const std::u16string& text); private: // AXPlatformNodeDelegate overrides. From 6352acd23995da52c419b6f1eda0d0abe95b59fa Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 15:33:23 -0500 Subject: [PATCH 08/23] Disable copy constructor/assignment --- shell/platform/common/alert_platform_node_delegate.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index 8a42eba0c4590..c539e1f748733 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -12,9 +12,12 @@ namespace flutter { class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { public: - AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); + explicit AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); ~AlertPlatformNodeDelegate(); + AlertPlatformNodeDelegate(const AlertPlatformNodeDelegate& other) = delete; + AlertPlatformNodeDelegate operator=(const AlertPlatformNodeDelegate& other) = delete; + void SetText(const std::u16string& text); private: From bfa0289528f1c3ed24c22d54823f570be2e0f68a Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 15:34:36 -0500 Subject: [PATCH 09/23] Unused import --- shell/platform/windows/flutter_platform_node_delegate_windows.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/windows/flutter_platform_node_delegate_windows.cc b/shell/platform/windows/flutter_platform_node_delegate_windows.cc index e895363aac97e..0e2ce94c7a7e2 100644 --- a/shell/platform/windows/flutter_platform_node_delegate_windows.cc +++ b/shell/platform/windows/flutter_platform_node_delegate_windows.cc @@ -11,7 +11,6 @@ #include "flutter/third_party/accessibility/ax/ax_clipping_behavior.h" #include "flutter/third_party/accessibility/ax/ax_coordinate_system.h" #include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_win.h" -#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h" namespace flutter { From 5aa4c778a3256bf8bb040b1bcb2292aea7b88cd8 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 15:56:31 -0500 Subject: [PATCH 10/23] Formatting --- shell/platform/common/alert_platform_node_delegate.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index c539e1f748733..5f40cfdbadd6c 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -12,11 +12,13 @@ namespace flutter { class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { public: - explicit AlertPlatformNodeDelegate(ui::AXPlatformNodeDelegate* parent_delegate); + explicit AlertPlatformNodeDelegate( + ui::AXPlatformNodeDelegate* parent_delegate); ~AlertPlatformNodeDelegate(); AlertPlatformNodeDelegate(const AlertPlatformNodeDelegate& other) = delete; - AlertPlatformNodeDelegate operator=(const AlertPlatformNodeDelegate& other) = delete; + AlertPlatformNodeDelegate operator=(const AlertPlatformNodeDelegate& other) = + delete; void SetText(const std::u16string& text); From 2970345291eb9e5e6cc5809eaef9ce19331b1906 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 16:52:41 -0500 Subject: [PATCH 11/23] Relocate alert logic --- shell/platform/windows/flutter_window.cc | 5 +++-- shell/platform/windows/flutter_window.h | 2 +- shell/platform/windows/flutter_window_unittests.cc | 2 +- shell/platform/windows/flutter_windows_view.cc | 6 +++++- .../platform/windows/testing/mock_window_binding_handler.h | 1 + shell/platform/windows/window.cc | 7 ++----- shell/platform/windows/window_binding_handler.h | 4 ++-- .../accessibility/ax/platform/ax_fragment_root_win.cc | 5 +++-- .../accessibility/ax/platform/ax_fragment_root_win.h | 3 ++- .../ax/platform/ax_platform_node_win_unittest.cc | 2 +- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/shell/platform/windows/flutter_window.cc b/shell/platform/windows/flutter_window.cc index dd6c61c31ccec..58c632fee641e 100644 --- a/shell/platform/windows/flutter_window.cc +++ b/shell/platform/windows/flutter_window.cc @@ -302,12 +302,13 @@ ui::AXFragmentRootDelegateWin* FlutterWindow::GetAxFragmentRootDelegate() { return binding_handler_delegate_->GetAxFragmentRootDelegate(); } -void FlutterWindow::Alert(const std::wstring& text) { +AlertPlatformNodeDelegate* FlutterWindow::GetAlertDelegate() { CreateAlertNode(); - alert_delegate_->SetText(base::WideToUTF16(text)); + return alert_delegate_.get(); } ui::AXPlatformNodeWin* FlutterWindow::GetAlert() { + CreateAlertNode(); return alert_node_.get(); } diff --git a/shell/platform/windows/flutter_window.h b/shell/platform/windows/flutter_window.h index f7300c634e37a..373ab96ac1cef 100644 --- a/shell/platform/windows/flutter_window.h +++ b/shell/platform/windows/flutter_window.h @@ -151,7 +151,7 @@ class FlutterWindow : public Window, public WindowBindingHandler { void SendInitialAccessibilityFeatures() override; // |WindowBindingHandler| - void Alert(const std::wstring& text) override; + AlertPlatformNodeDelegate* GetAlertDelegate() override; // |WindowBindingHandler| ui::AXPlatformNodeWin* GetAlert() override; diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index d88b815b44e4d..74f9160205692 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -422,7 +422,7 @@ TEST(FlutterWindowTest, AlertNode) { .Times(1); view.AnnounceAlert(message); - IAccessible* alert = view.AlertNode(); // root_node->GetOrCreateAlert(); + IAccessible* alert = view.AlertNode(); VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF}; BSTR strptr; alert->get_accName(self, &strptr); diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 7abf446406573..e1b584ddf7398 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -662,7 +662,11 @@ FlutterWindowsEngine* FlutterWindowsView::GetEngine() { } void FlutterWindowsView::AnnounceAlert(const std::wstring& text) { - binding_handler_->Alert(text); + auto alert_delegate = binding_handler_->GetAlertDelegate(); + if (!alert_delegate) { + return; + } + alert_delegate->SetText(base::WideToUTF16(text)); ui::AXPlatformNodeWin* alert_node = binding_handler_->GetAlert(); NotifyWinEventWrapper(alert_node, ax::mojom::Event::kAlert); } diff --git a/shell/platform/windows/testing/mock_window_binding_handler.h b/shell/platform/windows/testing/mock_window_binding_handler.h index bf4bdf752aa52..b1ad3421b9a17 100644 --- a/shell/platform/windows/testing/mock_window_binding_handler.h +++ b/shell/platform/windows/testing/mock_window_binding_handler.h @@ -38,6 +38,7 @@ class MockWindowBindingHandler : public WindowBindingHandler { MOCK_METHOD0(GetPrimaryPointerLocation, PointerLocation()); MOCK_METHOD0(SendInitialAccessibilityFeatures, void()); MOCK_METHOD1(Alert, void(const std::wstring& text)); + MOCK_METHOD0(GetAlertDelegate, AlertPlatformNodeDelegate*()); MOCK_METHOD0(GetAlert, ui::AXPlatformNodeWin*()); }; diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index 9ebb4c13e6079..11543e1a5c23f 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -206,12 +206,9 @@ LRESULT Window::OnGetObject(UINT const message, // https://github.com/flutter/flutter/issues/114547 if (root_view) { if (!ax_fragment_root_) { + CreateAlertNode(); ax_fragment_root_ = std::make_unique( - window_handle_, GetAxFragmentRootDelegate()); - FlutterPlatformNodeDelegate* child_delegate = - static_cast( - ax_fragment_root_->GetChildNodeDelegate()); - child_delegate->GetAXNode(); + window_handle_, GetAxFragmentRootDelegate(), alert_node_.get()); } if (is_uia_request) { #ifdef FLUTTER_ENGINE_USE_UIA diff --git a/shell/platform/windows/window_binding_handler.h b/shell/platform/windows/window_binding_handler.h index 48d9734db8c65..e13d7a138cfa5 100644 --- a/shell/platform/windows/window_binding_handler.h +++ b/shell/platform/windows/window_binding_handler.h @@ -101,8 +101,8 @@ class WindowBindingHandler { // Called to set the initial state of accessibility features virtual void SendInitialAccessibilityFeatures() = 0; - // Set the alert text. - virtual void Alert(const std::wstring& text) = 0; + // Retrieve the delegate for the alert. + virtual AlertPlatformNodeDelegate* GetAlertDelegate() = 0; // Retrieve the alert node. virtual ui::AXPlatformNodeWin* GetAlert() = 0; diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc index e6ef519656473..794d9bf089afe 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc @@ -288,8 +288,9 @@ class AXFragmentRootMapWin { }; AXFragmentRootWin::AXFragmentRootWin(gfx::AcceleratedWidget widget, - AXFragmentRootDelegateWin* delegate) - : widget_(widget), delegate_(delegate), alert_node_(nullptr) { + AXFragmentRootDelegateWin* delegate, + AXPlatformNodeWin* alert_node) + : widget_(widget), delegate_(delegate), alert_node_(alert_node) { platform_node_ = ui::AXFragmentRootPlatformNodeWin::Create(this); AXFragmentRootMapWin::GetInstance().AddFragmentRoot(widget, this); } diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index 1dba487a5832c..763039c77924f 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -30,7 +30,8 @@ class AXPlatformNodeWin; class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { public: AXFragmentRootWin(gfx::AcceleratedWidget widget, - AXFragmentRootDelegateWin* delegate); + AXFragmentRootDelegateWin* delegate, + AXPlatformNodeWin* alert_node); ~AXFragmentRootWin() override; // Fragment roots register themselves in a map upon creation and unregister diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc b/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc index 9c872969037d7..f222c5bb4679e 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc +++ b/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc @@ -374,7 +374,7 @@ AXFragmentRootWin* AXPlatformNodeWinTest::InitNodeAsFragmentRoot( delegate->parent_ = AXPlatformNodeFromNode(node->parent())->GetNativeViewAccessible(); - return new AXFragmentRootWin(gfx::kMockAcceleratedWidget, delegate); + return new AXFragmentRootWin(gfx::kMockAcceleratedWidget, delegate, nullptr); } ComPtr From ae7ea182a737c88c891a93edf0d3bbd625832c80 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 16:54:06 -0500 Subject: [PATCH 12/23] Remove comment and unused mock --- shell/platform/windows/testing/mock_window_binding_handler.h | 1 - shell/platform/windows/window.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/shell/platform/windows/testing/mock_window_binding_handler.h b/shell/platform/windows/testing/mock_window_binding_handler.h index b1ad3421b9a17..709035b3506eb 100644 --- a/shell/platform/windows/testing/mock_window_binding_handler.h +++ b/shell/platform/windows/testing/mock_window_binding_handler.h @@ -37,7 +37,6 @@ class MockWindowBindingHandler : public WindowBindingHandler { bool(const void* allocation, size_t row_bytes, size_t height)); MOCK_METHOD0(GetPrimaryPointerLocation, PointerLocation()); MOCK_METHOD0(SendInitialAccessibilityFeatures, void()); - MOCK_METHOD1(Alert, void(const std::wstring& text)); MOCK_METHOD0(GetAlertDelegate, AlertPlatformNodeDelegate*()); MOCK_METHOD0(GetAlert, ui::AXPlatformNodeWin*()); }; diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index 11543e1a5c23f..b6d76b605c983 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -228,7 +228,6 @@ LRESULT Window::OnGetObject(UINT const message, } else if (is_msaa_request) { // Create the accessibility root if it does not already exist. // Return the IAccessible for the root view. - // Microsoft::WRL::ComPtr root(root_view); Microsoft::WRL::ComPtr root; ax_fragment_root_->GetNativeViewAccessible()->QueryInterface( IID_PPV_ARGS(&root)); From 463b74bb7f841d3981fb059ff56c5732898d6c4b Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 10 Jan 2023 17:47:10 -0500 Subject: [PATCH 13/23] Fix unit test --- shell/platform/windows/flutter_windows_engine_unittests.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 6c4f1c7314ad8..4e99797ebd44d 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -578,6 +578,8 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); + AlertPlatformNodeDelegate delegate(nullptr); + ON_CALL(*window_binding_handler, GetAlertDelegate).WillByDefault([&delegate]{ return &delegate; }); MockFlutterWindowsView view(std::move(window_binding_handler)); view.SetEngine(builder.Build()); FlutterWindowsEngine* engine = view.GetEngine(); From 4abf2a156a836dfc8b38c9a769370a94af3761a4 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 11 Jan 2023 09:55:22 -0500 Subject: [PATCH 14/23] Idempotency --- shell/platform/common/alert_platform_node_delegate.h | 4 +++- shell/platform/windows/flutter_window_unittests.cc | 1 + shell/platform/windows/window.cc | 7 ++++--- .../accessibility/ax/platform/ax_fragment_root_win.cc | 5 ++--- .../accessibility/ax/platform/ax_fragment_root_win.h | 3 +-- .../ax/platform/ax_platform_node_win_unittest.cc | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index 5f40cfdbadd6c..bdb0f48fd1bb9 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -22,10 +22,12 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { void SetText(const std::u16string& text); + // |AXPlatformNodeDelegate| + gfx::NativeViewAccessible GetParent() override; + private: // AXPlatformNodeDelegate overrides. gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; - gfx::NativeViewAccessible GetParent() override; const ui::AXUniqueId& GetUniqueId() const override; const ui::AXNodeData& GetData() const override; diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 74f9160205692..51652c1f604a0 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -423,6 +423,7 @@ TEST(FlutterWindowTest, AlertNode) { view.AnnounceAlert(message); IAccessible* alert = view.AlertNode(); + FML_LOG(ERROR) << "Alert = " << (void*)alert; VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF}; BSTR strptr; alert->get_accName(self, &strptr); diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index b6d76b605c983..f0af35dd63bab 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -206,9 +206,10 @@ LRESULT Window::OnGetObject(UINT const message, // https://github.com/flutter/flutter/issues/114547 if (root_view) { if (!ax_fragment_root_) { - CreateAlertNode(); ax_fragment_root_ = std::make_unique( - window_handle_, GetAxFragmentRootDelegate(), alert_node_.get()); + window_handle_, GetAxFragmentRootDelegate()); + CreateAlertNode(); + ax_fragment_root_->SetAlertNode(alert_node_.get()); } if (is_uia_request) { #ifdef FLUTTER_ENGINE_USE_UIA @@ -674,7 +675,7 @@ bool Window::GetHighContrastEnabled() { } void Window::CreateAlertNode() { - if (alert_delegate_) { + if (alert_delegate_ && (alert_delegate_->GetParent() || !ax_fragment_root_)) { return; } alert_delegate_ = diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc index 794d9bf089afe..e6ef519656473 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.cc +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.cc @@ -288,9 +288,8 @@ class AXFragmentRootMapWin { }; AXFragmentRootWin::AXFragmentRootWin(gfx::AcceleratedWidget widget, - AXFragmentRootDelegateWin* delegate, - AXPlatformNodeWin* alert_node) - : widget_(widget), delegate_(delegate), alert_node_(alert_node) { + AXFragmentRootDelegateWin* delegate) + : widget_(widget), delegate_(delegate), alert_node_(nullptr) { platform_node_ = ui::AXFragmentRootPlatformNodeWin::Create(this); AXFragmentRootMapWin::GetInstance().AddFragmentRoot(widget, this); } diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index 763039c77924f..1dba487a5832c 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -30,8 +30,7 @@ class AXPlatformNodeWin; class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { public: AXFragmentRootWin(gfx::AcceleratedWidget widget, - AXFragmentRootDelegateWin* delegate, - AXPlatformNodeWin* alert_node); + AXFragmentRootDelegateWin* delegate); ~AXFragmentRootWin() override; // Fragment roots register themselves in a map upon creation and unregister diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc b/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc index f222c5bb4679e..9c872969037d7 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc +++ b/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc @@ -374,7 +374,7 @@ AXFragmentRootWin* AXPlatformNodeWinTest::InitNodeAsFragmentRoot( delegate->parent_ = AXPlatformNodeFromNode(node->parent())->GetNativeViewAccessible(); - return new AXFragmentRootWin(gfx::kMockAcceleratedWidget, delegate, nullptr); + return new AXFragmentRootWin(gfx::kMockAcceleratedWidget, delegate); } ComPtr From 2dfe8764f374bb72e1445317a8e7a48f44f862d6 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 11 Jan 2023 12:22:09 -0500 Subject: [PATCH 15/23] Formatting --- shell/platform/windows/flutter_windows_engine_unittests.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index 4e99797ebd44d..c1370735d91aa 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -579,7 +579,9 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); AlertPlatformNodeDelegate delegate(nullptr); - ON_CALL(*window_binding_handler, GetAlertDelegate).WillByDefault([&delegate]{ return &delegate; }); + ON_CALL(*window_binding_handler, GetAlertDelegate).WillByDefault([&delegate] { + return &delegate; + }); MockFlutterWindowsView view(std::move(window_binding_handler)); view.SetEngine(builder.Build()); FlutterWindowsEngine* engine = view.GetEngine(); From 0ab24788ed8de26b8d9c222b92207129fd354091 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 11 Jan 2023 14:54:57 -0500 Subject: [PATCH 16/23] PR feedback --- shell/platform/common/alert_platform_node_delegate.cc | 2 +- shell/platform/common/alert_platform_node_delegate.h | 2 +- shell/platform/windows/flutter_window_unittests.cc | 1 - .../accessibility/ax/platform/ax_fragment_root_win.h | 2 +- .../accessibility/ax/platform/ax_platform_node_win.cc | 10 +++++----- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index 17e90df509e53..a9050e8a002bc 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -38,7 +38,7 @@ const ui::AXNodeData& AlertPlatformNodeDelegate::GetData() const { return data_; } -void AlertPlatformNodeDelegate::SetText(const std::u16string& text) { +void AlertPlatformNodeDelegate::SetText(const std::u16string_view text) { data_.SetName(text); data_.SetDescription(text); data_.SetValue(text); diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index bdb0f48fd1bb9..e78f6d2e3294c 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -20,7 +20,7 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { AlertPlatformNodeDelegate operator=(const AlertPlatformNodeDelegate& other) = delete; - void SetText(const std::u16string& text); + void SetText(const std::u16string_view text); // |AXPlatformNodeDelegate| gfx::NativeViewAccessible GetParent() override; diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 51652c1f604a0..74f9160205692 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -423,7 +423,6 @@ TEST(FlutterWindowTest, AlertNode) { view.AnnounceAlert(message); IAccessible* alert = view.AlertNode(); - FML_LOG(ERROR) << "Alert = " << (void*)alert; VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF}; BSTR strptr; alert->get_accName(self, &strptr); diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index 1dba487a5832c..497a824d20452 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -56,7 +56,7 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { // If a child node is available, return its delegate. AXPlatformNodeDelegate* GetChildNodeDelegate() const; - // AXPlatformNodeDelegate override. + // |AXPlatformNodeDelegate| gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; void SetAlertNode(AXPlatformNodeWin* alert_node); diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win.cc b/third_party/accessibility/ax/platform/ax_platform_node_win.cc index fa40da70e1ab8..b00f5d2c58eaf 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win.cc +++ b/third_party/accessibility/ax/platform/ax_platform_node_win.cc @@ -5712,14 +5712,14 @@ AXPlatformNodeWin* AXPlatformNodeWin::GetFirstTextOnlyDescendant() { } bool AXPlatformNodeWin::IsDescendantOf(AXPlatformNode* ancestor) const { - if (AXPlatformNodeBase::IsDescendantOf(ancestor)) { - return true; - } - if (!ancestor) { return false; } + if (AXPlatformNodeBase::IsDescendantOf(ancestor)) { + return true; + } + // Test if the ancestor is an IRawElementProviderFragmentRoot and if it // matches this node's root fragment. IRawElementProviderFragmentRoot* root; @@ -5727,7 +5727,7 @@ bool AXPlatformNodeWin::IsDescendantOf(AXPlatformNode* ancestor) const { const_cast(this)->get_FragmentRoot(&root))) { AXPlatformNodeWin* root_win; if (SUCCEEDED(root->QueryInterface(__uuidof(AXPlatformNodeWin), - (void**)&root_win))) { + reinterpret_cast(&root_win)))) { return ancestor == static_cast(root_win); } } From efe2657dc8d931f1bce2dda43e676635033d3481 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 11 Jan 2023 15:00:08 -0500 Subject: [PATCH 17/23] Doc comments --- shell/platform/windows/window.h | 7 +++++++ .../accessibility/ax/platform/ax_fragment_root_win.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/shell/platform/windows/window.h b/shell/platform/windows/window.h index 4117f3f98d0f4..7a4d90ee71b2a 100644 --- a/shell/platform/windows/window.h +++ b/shell/platform/windows/window.h @@ -215,6 +215,13 @@ class Window : public KeyboardManager::WindowDelegate { // Check if the high contrast feature is enabled on the OS virtual bool GetHighContrastEnabled(); + // Creates the alert_delegate_ and alert_node_ if they do not yet exist, or if + // the delegate exists but has a null parent and the current ax_fragment_root_ + // is not null. If alert_delegate_ has not already been set, the creation of + // these two objects will execute. If alert_delegate_ is already non-null, + // their values will be updated if ax_fragment_root_ is non-null, and + // alert_delegate->GetParent() is null. + // Once set, alert_node_ is not reset to nullptr. void CreateAlertNode(); // Called to obtain a pointer to the fragment root delegate. diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index 497a824d20452..6e31197a1e55f 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -59,6 +59,11 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { // |AXPlatformNodeDelegate| gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; + // alert_node is an AXPlatformNodeWin whose text value can be set by the + // application for the purposes of announcing messages to a screen reader. + // AXFragmentRootWin does not own its alert_node_; it is owned by the object + // with the responsibility of setting its text. In the case of flutter + // windows, this is the Window. void SetAlertNode(AXPlatformNodeWin* alert_node); private: From 42d7721c208588f9a0a1c37620cf90095831a5e4 Mon Sep 17 00:00:00 2001 From: schectman Date: Wed, 11 Jan 2023 15:40:09 -0500 Subject: [PATCH 18/23] Undo string change for now --- shell/platform/common/alert_platform_node_delegate.cc | 2 +- shell/platform/common/alert_platform_node_delegate.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index a9050e8a002bc..17e90df509e53 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -38,7 +38,7 @@ const ui::AXNodeData& AlertPlatformNodeDelegate::GetData() const { return data_; } -void AlertPlatformNodeDelegate::SetText(const std::u16string_view text) { +void AlertPlatformNodeDelegate::SetText(const std::u16string& text) { data_.SetName(text); data_.SetDescription(text); data_.SetValue(text); diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index e78f6d2e3294c..bdb0f48fd1bb9 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -20,7 +20,7 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { AlertPlatformNodeDelegate operator=(const AlertPlatformNodeDelegate& other) = delete; - void SetText(const std::u16string_view text); + void SetText(const std::u16string& text); // |AXPlatformNodeDelegate| gfx::NativeViewAccessible GetParent() override; From cfedb56f426da057baf1379d716cc1f32e42522e Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 13 Jan 2023 10:37:42 -0500 Subject: [PATCH 19/23] Couple fragment root and alert node --- shell/platform/windows/flutter_window.cc | 4 ++-- shell/platform/windows/flutter_window_unittests.cc | 2 ++ shell/platform/windows/flutter_windows_view.cc | 1 + shell/platform/windows/window.cc | 14 ++++++-------- shell/platform/windows/window.h | 12 ++++-------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/shell/platform/windows/flutter_window.cc b/shell/platform/windows/flutter_window.cc index 58c632fee641e..a1c84c7969eae 100644 --- a/shell/platform/windows/flutter_window.cc +++ b/shell/platform/windows/flutter_window.cc @@ -303,12 +303,12 @@ ui::AXFragmentRootDelegateWin* FlutterWindow::GetAxFragmentRootDelegate() { } AlertPlatformNodeDelegate* FlutterWindow::GetAlertDelegate() { - CreateAlertNode(); + CreateAxFragmentRoot(); return alert_delegate_.get(); } ui::AXPlatformNodeWin* FlutterWindow::GetAlert() { - CreateAlertNode(); + CreateAxFragmentRoot(); return alert_node_.get(); } diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 74f9160205692..57f816a742f3e 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -142,6 +142,7 @@ class MockFlutterWindow : public FlutterWindow { MOCK_METHOD4(Win32PeekMessage, BOOL(LPMSG, UINT, UINT, UINT)); MOCK_METHOD1(Win32MapVkToChar, uint32_t(uint32_t)); MOCK_METHOD0(GetPlatformWindow, HWND()); + MOCK_METHOD0(GetAxFragmentRootDelegate, ui::AXFragmentRootDelegateWin*()); protected: // |KeyboardManager::WindowDelegate| @@ -416,6 +417,7 @@ TEST(FlutterWindowTest, AlertNode) { std::unique_ptr win32window = std::make_unique(); ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr)); + ON_CALL(*win32window, GetAxFragmentRootDelegate()).WillByDefault(Return(nullptr)); TestFlutterWindowsView view(std::move(win32window)); std::wstring message = L"Test alert"; EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert)) diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index e1b584ddf7398..ac403053aa936 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -679,6 +679,7 @@ void FlutterWindowsView::NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, } ui::AXFragmentRootDelegateWin* FlutterWindowsView::GetAxFragmentRootDelegate() { + auto bridge = engine_->accessibility_bridge().lock().get(); return engine_->accessibility_bridge().lock().get(); } diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index f0af35dd63bab..1a744ea639850 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -205,12 +205,7 @@ LRESULT Window::OnGetObject(UINT const message, // TODO(schectman): UIA is currently disabled by default. // https://github.com/flutter/flutter/issues/114547 if (root_view) { - if (!ax_fragment_root_) { - ax_fragment_root_ = std::make_unique( - window_handle_, GetAxFragmentRootDelegate()); - CreateAlertNode(); - ax_fragment_root_->SetAlertNode(alert_node_.get()); - } + CreateAxFragmentRoot(); if (is_uia_request) { #ifdef FLUTTER_ENGINE_USE_UIA // Retrieve UIA object for the root view. @@ -674,15 +669,18 @@ bool Window::GetHighContrastEnabled() { } } -void Window::CreateAlertNode() { - if (alert_delegate_ && (alert_delegate_->GetParent() || !ax_fragment_root_)) { +void Window::CreateAxFragmentRoot() { + if (ax_fragment_root_) { return; } + ax_fragment_root_ = std::make_unique( + window_handle_, GetAxFragmentRootDelegate()); alert_delegate_ = std::make_unique(ax_fragment_root_.get()); ui::AXPlatformNode* alert_node = ui::AXPlatformNodeWin::Create(alert_delegate_.get()); alert_node_.reset(static_cast(alert_node)); + ax_fragment_root_->SetAlertNode(alert_node_.get()); } } // namespace flutter diff --git a/shell/platform/windows/window.h b/shell/platform/windows/window.h index 7a4d90ee71b2a..058b1549af7ae 100644 --- a/shell/platform/windows/window.h +++ b/shell/platform/windows/window.h @@ -215,14 +215,10 @@ class Window : public KeyboardManager::WindowDelegate { // Check if the high contrast feature is enabled on the OS virtual bool GetHighContrastEnabled(); - // Creates the alert_delegate_ and alert_node_ if they do not yet exist, or if - // the delegate exists but has a null parent and the current ax_fragment_root_ - // is not null. If alert_delegate_ has not already been set, the creation of - // these two objects will execute. If alert_delegate_ is already non-null, - // their values will be updated if ax_fragment_root_ is non-null, and - // alert_delegate->GetParent() is null. - // Once set, alert_node_ is not reset to nullptr. - void CreateAlertNode(); + // Creates the ax_fragment_root_, alert_delegate_ and alert_node_ if they do + // not yet exist. + // Once set, they are not reset to nullptr. + void CreateAxFragmentRoot(); // Called to obtain a pointer to the fragment root delegate. virtual ui::AXFragmentRootDelegateWin* GetAxFragmentRootDelegate() = 0; From 5373390a8be234b5824349587c505cf0e1285829 Mon Sep 17 00:00:00 2001 From: schectman Date: Fri, 13 Jan 2023 12:08:14 -0500 Subject: [PATCH 20/23] Formatting --- shell/platform/windows/flutter_window_unittests.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 57f816a742f3e..99c612db87671 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -417,7 +417,8 @@ TEST(FlutterWindowTest, AlertNode) { std::unique_ptr win32window = std::make_unique(); ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr)); - ON_CALL(*win32window, GetAxFragmentRootDelegate()).WillByDefault(Return(nullptr)); + ON_CALL(*win32window, GetAxFragmentRootDelegate()) + .WillByDefault(Return(nullptr)); TestFlutterWindowsView view(std::move(win32window)); std::wstring message = L"Test alert"; EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert)) From 48f03152d1458e89856a3d1767f546da2ddfef8b Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 17 Jan 2023 09:39:35 -0500 Subject: [PATCH 21/23] Add comments --- shell/platform/common/alert_platform_node_delegate.h | 10 ++++++++++ .../windows/flutter_windows_engine_unittests.cc | 3 ++- shell/platform/windows/flutter_windows_view.cc | 1 - shell/platform/windows/window.h | 2 ++ .../accessibility/ax/platform/ax_fragment_root_win.h | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index bdb0f48fd1bb9..92a044fea2858 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -10,6 +10,10 @@ namespace flutter { +// A delegate for a node that holds the text of an a11y alert that a +// screen-reader should announce. The delegate is used to construct an +// AXPlatformNode, and in order to serve as an alert, only needs to be able to +// hold a text announcement and make that text available to the platform node. class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { public: explicit AlertPlatformNodeDelegate( @@ -20,6 +24,7 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { AlertPlatformNodeDelegate operator=(const AlertPlatformNodeDelegate& other) = delete; + // Set the alert text of the node for which this is the delegate. void SetText(const std::u16string& text); // |AXPlatformNodeDelegate| @@ -31,8 +36,13 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { const ui::AXUniqueId& GetUniqueId() const override; const ui::AXNodeData& GetData() const override; + // Delegate of the parent of this node. Returned by GetParent. ui::AXPlatformNodeDelegate* parent_delegate_; + + // Node Data that contains the alert text. Returned by GetData. ui::AXNodeData data_; + + // A unique ID used to identify this node. Returned by GetUniqueId. ui::AXUniqueId id_; }; diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index c1370735d91aa..a36d71016718e 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -578,7 +578,8 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); - AlertPlatformNodeDelegate delegate(nullptr); + ui::AXPlatformNodeDelegateBase parent_delegate; + AlertPlatformNodeDelegate delegate(&parent_delegate); ON_CALL(*window_binding_handler, GetAlertDelegate).WillByDefault([&delegate] { return &delegate; }); diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index ac403053aa936..e1b584ddf7398 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -679,7 +679,6 @@ void FlutterWindowsView::NotifyWinEventWrapper(ui::AXPlatformNodeWin* node, } ui::AXFragmentRootDelegateWin* FlutterWindowsView::GetAxFragmentRootDelegate() { - auto bridge = engine_->accessibility_bridge().lock().get(); return engine_->accessibility_bridge().lock().get(); } diff --git a/shell/platform/windows/window.h b/shell/platform/windows/window.h index 058b1549af7ae..1ad35e68e2b86 100644 --- a/shell/platform/windows/window.h +++ b/shell/platform/windows/window.h @@ -243,8 +243,10 @@ class Window : public KeyboardManager::WindowDelegate { // Called when a theme change message is issued virtual void OnThemeChange() = 0; + // Delegate to a alert_node_ used to set the announcement text. std::unique_ptr alert_delegate_; + // Accessibility node that represents an alert. std::unique_ptr alert_node_; private: diff --git a/third_party/accessibility/ax/platform/ax_fragment_root_win.h b/third_party/accessibility/ax/platform/ax_fragment_root_win.h index 6e31197a1e55f..fe3699cf211ae 100644 --- a/third_party/accessibility/ax/platform/ax_fragment_root_win.h +++ b/third_party/accessibility/ax/platform/ax_fragment_root_win.h @@ -96,6 +96,7 @@ class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { Microsoft::WRL::ComPtr platform_node_; ui::AXUniqueId unique_id_; + // Node that presents the alert, if any. AXPlatformNodeWin* alert_node_; }; From 111ad30bdecfde2183e46e3a95ed301393838234 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 17 Jan 2023 14:18:45 -0500 Subject: [PATCH 22/23] Pointer to reference --- .../platform/common/alert_platform_node_delegate.cc | 12 +++--------- shell/platform/common/alert_platform_node_delegate.h | 4 ++-- .../windows/flutter_windows_engine_unittests.cc | 2 +- shell/platform/windows/window.cc | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/shell/platform/common/alert_platform_node_delegate.cc b/shell/platform/common/alert_platform_node_delegate.cc index 17e90df509e53..3208737eba956 100644 --- a/shell/platform/common/alert_platform_node_delegate.cc +++ b/shell/platform/common/alert_platform_node_delegate.cc @@ -7,7 +7,7 @@ namespace flutter { AlertPlatformNodeDelegate::AlertPlatformNodeDelegate( - ui::AXPlatformNodeDelegate* parent_delegate) + ui::AXPlatformNodeDelegate& parent_delegate) : parent_delegate_(parent_delegate) { data_.role = ax::mojom::Role::kAlert; data_.id = id_.Get(); @@ -17,17 +17,11 @@ AlertPlatformNodeDelegate::~AlertPlatformNodeDelegate() {} gfx::AcceleratedWidget AlertPlatformNodeDelegate::GetTargetForNativeAccessibilityEvent() { - if (parent_delegate_) { - return parent_delegate_->GetTargetForNativeAccessibilityEvent(); - } - return (gfx::AcceleratedWidget) nullptr; + return parent_delegate_.GetTargetForNativeAccessibilityEvent(); } gfx::NativeViewAccessible AlertPlatformNodeDelegate::GetParent() { - if (parent_delegate_) { - return parent_delegate_->GetNativeViewAccessible(); - } - return nullptr; + return parent_delegate_.GetNativeViewAccessible(); } const ui::AXUniqueId& AlertPlatformNodeDelegate::GetUniqueId() const { diff --git a/shell/platform/common/alert_platform_node_delegate.h b/shell/platform/common/alert_platform_node_delegate.h index 92a044fea2858..1cce78484b324 100644 --- a/shell/platform/common/alert_platform_node_delegate.h +++ b/shell/platform/common/alert_platform_node_delegate.h @@ -17,7 +17,7 @@ namespace flutter { class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { public: explicit AlertPlatformNodeDelegate( - ui::AXPlatformNodeDelegate* parent_delegate); + ui::AXPlatformNodeDelegate& parent_delegate); ~AlertPlatformNodeDelegate(); AlertPlatformNodeDelegate(const AlertPlatformNodeDelegate& other) = delete; @@ -37,7 +37,7 @@ class AlertPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase { const ui::AXNodeData& GetData() const override; // Delegate of the parent of this node. Returned by GetParent. - ui::AXPlatformNodeDelegate* parent_delegate_; + ui::AXPlatformNodeDelegate& parent_delegate_; // Node Data that contains the alert text. Returned by GetData. ui::AXNodeData data_; diff --git a/shell/platform/windows/flutter_windows_engine_unittests.cc b/shell/platform/windows/flutter_windows_engine_unittests.cc index a36d71016718e..207734f9e2d96 100644 --- a/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -579,7 +579,7 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); ui::AXPlatformNodeDelegateBase parent_delegate; - AlertPlatformNodeDelegate delegate(&parent_delegate); + AlertPlatformNodeDelegate delegate(parent_delegate); ON_CALL(*window_binding_handler, GetAlertDelegate).WillByDefault([&delegate] { return &delegate; }); diff --git a/shell/platform/windows/window.cc b/shell/platform/windows/window.cc index 1a744ea639850..ceb9cb8379ff9 100644 --- a/shell/platform/windows/window.cc +++ b/shell/platform/windows/window.cc @@ -676,7 +676,7 @@ void Window::CreateAxFragmentRoot() { ax_fragment_root_ = std::make_unique( window_handle_, GetAxFragmentRootDelegate()); alert_delegate_ = - std::make_unique(ax_fragment_root_.get()); + std::make_unique(*ax_fragment_root_); ui::AXPlatformNode* alert_node = ui::AXPlatformNodeWin::Create(alert_delegate_.get()); alert_node_.reset(static_cast(alert_node)); From d32c151a6a337c796ff63794c4074a77675a86eb Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 17 Jan 2023 16:17:05 -0500 Subject: [PATCH 23/23] Typo fix --- third_party/accessibility/ax/platform/ax_platform_node_win.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win.h b/third_party/accessibility/ax/platform/ax_platform_node_win.h index 2f5de650f7a40..cf977b4c7f845 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win.h +++ b/third_party/accessibility/ax/platform/ax_platform_node_win.h @@ -474,7 +474,7 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2")) ax::mojom::Event event); // |AXPlatformNodeBase| - bool IsDescendantOf(AXPlatformNode* acnestor) const override; + bool IsDescendantOf(AXPlatformNode* ancestor) const override; protected: // This is hard-coded; all products based on the Chromium engine will have the