From 8b7af53124667fa6d206c4339a81adc6ecef6163 Mon Sep 17 00:00:00 2001 From: Nik Pavlov Date: Tue, 20 Feb 2024 16:27:48 +0000 Subject: [PATCH] chrome: Add SetAccessibilityState support (fixes #3649) --- .../browser/alloy/alloy_browser_host_impl.cc | 14 ---------- .../browser/alloy/alloy_browser_host_impl.h | 1 - .../alloy/browser_platform_delegate_alloy.cc | 26 ------------------- .../alloy/browser_platform_delegate_alloy.h | 1 - libcef/browser/browser_host_base.cc | 14 ++++++++++ libcef/browser/browser_host_base.h | 1 + libcef/browser/browser_platform_delegate.cc | 23 +++++++++++++++- .../chrome/chrome_browser_host_impl.cc | 5 ---- .../browser/chrome/chrome_browser_host_impl.h | 1 - 9 files changed, 37 insertions(+), 49 deletions(-) diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index 77427f543..3fa30b79c 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -368,20 +368,6 @@ bool AlloyBrowserHostImpl::HasDevTools() { return devtools_manager_->HasDevTools(); } -void AlloyBrowserHostImpl::SetAccessibilityState( - cef_state_t accessibility_state) { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::BindOnce(&AlloyBrowserHostImpl::SetAccessibilityState, - this, accessibility_state)); - return; - } - - if (platform_delegate_) { - platform_delegate_->SetAccessibilityState(accessibility_state); - } -} - void AlloyBrowserHostImpl::SetAutoResizeEnabled(bool enabled, const CefSize& min_size, const CefSize& max_size) { diff --git a/libcef/browser/alloy/alloy_browser_host_impl.h b/libcef/browser/alloy/alloy_browser_host_impl.h index af2e82db6..04fdd3ef3 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.h +++ b/libcef/browser/alloy/alloy_browser_host_impl.h @@ -117,7 +117,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase, void DragSourceEndedAt(int x, int y, DragOperationsMask op) override; void SetAudioMuted(bool mute) override; bool IsAudioMuted() override; - void SetAccessibilityState(cef_state_t accessibility_state) override; void SetAutoResizeEnabled(bool enabled, const CefSize& min_size, const CefSize& max_size) override; diff --git a/libcef/browser/alloy/browser_platform_delegate_alloy.cc b/libcef/browser/alloy/browser_platform_delegate_alloy.cc index c926518aa..7520ed9b7 100644 --- a/libcef/browser/alloy/browser_platform_delegate_alloy.cc +++ b/libcef/browser/alloy/browser_platform_delegate_alloy.cc @@ -26,7 +26,6 @@ #include "components/permissions/permission_request_manager.h" #include "components/zoom/zoom_controller.h" #include "content/browser/renderer_host/render_widget_host_impl.h" -#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/render_view_host.h" #include "extensions/browser/process_manager.h" #include "pdf/pdf_features.h" @@ -313,31 +312,6 @@ void CefBrowserPlatformDelegateAlloy::ConfigureAutoResize() { } } -void CefBrowserPlatformDelegateAlloy::SetAccessibilityState( - cef_state_t accessibility_state) { - // Do nothing if state is set to default. It'll be disabled by default and - // controlled by the commmand-line flags "force-renderer-accessibility" and - // "disable-renderer-accessibility". - if (accessibility_state == STATE_DEFAULT) { - return; - } - - content::WebContentsImpl* web_contents_impl = - static_cast(web_contents_); - - if (!web_contents_impl) { - return; - } - - ui::AXMode accMode; - // In windowless mode set accessibility to TreeOnly mode. Else native - // accessibility APIs, specific to each platform, are also created. - if (accessibility_state == STATE_ENABLED) { - accMode = IsWindowless() ? ui::kAXModeWebContentsOnly : ui::kAXModeComplete; - } - web_contents_impl->SetAccessibilityMode(accMode); -} - bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const { REQUIRE_ALLOY_RUNTIME(); diff --git a/libcef/browser/alloy/browser_platform_delegate_alloy.h b/libcef/browser/alloy/browser_platform_delegate_alloy.h index dbd9e5c0e..be500ab08 100644 --- a/libcef/browser/alloy/browser_platform_delegate_alloy.h +++ b/libcef/browser/alloy/browser_platform_delegate_alloy.h @@ -54,7 +54,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate { void SetAutoResizeEnabled(bool enabled, const CefSize& min_size, const CefSize& max_size) override; - void SetAccessibilityState(cef_state_t accessibility_state) override; bool IsPrintPreviewSupported() const override; void Find(const CefString& searchText, bool forward, diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index 308a2ecdb..cbcee7b8b 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -1009,6 +1009,20 @@ void CefBrowserHostBase::GetFrameNames(std::vector& names) { } } +void CefBrowserHostBase::SetAccessibilityState( + cef_state_t accessibility_state) { + if (!CEF_CURRENTLY_ON_UIT()) { + CEF_POST_TASK(CEF_UIT, + base::BindOnce(&CefBrowserHostBase::SetAccessibilityState, + this, accessibility_state)); + return; + } + + if (platform_delegate_) { + platform_delegate_->SetAccessibilityState(accessibility_state); + } +} + void CefBrowserHostBase::OnStateChanged(CefBrowserContentsState state_changed) { // Make sure that CefBrowser state is consistent before the associated // CefClient callback is executed. diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h index d6b1993cd..cfbb86130 100644 --- a/libcef/browser/browser_host_base.h +++ b/libcef/browser/browser_host_base.h @@ -262,6 +262,7 @@ class CefBrowserHostBase : public CefBrowserHost, size_t GetFrameCount() override; void GetFrameIdentifiers(std::vector& identifiers) override; void GetFrameNames(std::vector& names) override; + void SetAccessibilityState(cef_state_t accessibility_state) override; // CefBrowserContentsDelegate::Observer methods: void OnStateChanged(CefBrowserContentsState state_changed) override; diff --git a/libcef/browser/browser_platform_delegate.cc b/libcef/browser/browser_platform_delegate.cc index 92ec8cd1c..12a2407b5 100644 --- a/libcef/browser/browser_platform_delegate.cc +++ b/libcef/browser/browser_platform_delegate.cc @@ -10,6 +10,7 @@ #include "base/logging.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/shell_integration.h" +#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host_view.h" @@ -409,7 +410,27 @@ void CefBrowserPlatformDelegate::SetAutoResizeEnabled(bool enabled, void CefBrowserPlatformDelegate::SetAccessibilityState( cef_state_t accessibility_state) { - NOTIMPLEMENTED(); + // Do nothing if state is set to default. It'll be disabled by default and + // controlled by the command-line flags "force-renderer-accessibility" and + // "disable-renderer-accessibility". + if (accessibility_state == STATE_DEFAULT) { + return; + } + + content::WebContentsImpl* web_contents_impl = + static_cast(web_contents_); + + if (!web_contents_impl) { + return; + } + + ui::AXMode accMode; + // In windowless mode set accessibility to TreeOnly mode. Else native + // accessibility APIs, specific to each platform, are also created. + if (accessibility_state == STATE_ENABLED) { + accMode = IsWindowless() ? ui::kAXModeWebContentsOnly : ui::kAXModeComplete; + } + web_contents_impl->SetAccessibilityMode(accMode); } bool CefBrowserPlatformDelegate::IsPrintPreviewSupported() const { diff --git a/libcef/browser/chrome/chrome_browser_host_impl.cc b/libcef/browser/chrome/chrome_browser_host_impl.cc index 7532bc3d3..5ce824ef5 100644 --- a/libcef/browser/chrome/chrome_browser_host_impl.cc +++ b/libcef/browser/chrome/chrome_browser_host_impl.cc @@ -369,11 +369,6 @@ bool ChromeBrowserHostImpl::IsAudioMuted() { return false; } -void ChromeBrowserHostImpl::SetAccessibilityState( - cef_state_t accessibility_state) { - NOTIMPLEMENTED(); -} - void ChromeBrowserHostImpl::SetAutoResizeEnabled(bool enabled, const CefSize& min_size, const CefSize& max_size) { diff --git a/libcef/browser/chrome/chrome_browser_host_impl.h b/libcef/browser/chrome/chrome_browser_host_impl.h index 8ffd89a17..408bdeba8 100644 --- a/libcef/browser/chrome/chrome_browser_host_impl.h +++ b/libcef/browser/chrome/chrome_browser_host_impl.h @@ -104,7 +104,6 @@ class ChromeBrowserHostImpl : public CefBrowserHostBase { void DragSourceEndedAt(int x, int y, DragOperationsMask op) override; void SetAudioMuted(bool mute) override; bool IsAudioMuted() override; - void SetAccessibilityState(cef_state_t accessibility_state) override; void SetAutoResizeEnabled(bool enabled, const CefSize& min_size, const CefSize& max_size) override;