Commit e31793ab authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Fix web contents accessibility focus

ScopedAccessibilityFocus should have changed the focus to return
-[NSWindow accessibilityFocusedUIElement].

TBR=ellyjones

Bug: 900846
Change-Id: I7813e4eb7099c69d1106630050b9581b4927d79b
Reviewed-on: https://chromium-review.googlesource.com/c/1340911
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608971}
parent 69bc5c76
...@@ -7,25 +7,22 @@ ...@@ -7,25 +7,22 @@
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace views_bridge_mac {
class BridgedNativeWidgetHostHelper;
} // namespace views_bridge_mac
namespace views { namespace views {
class BridgedNativeWidgetHostImpl;
// This object, while instantiated, will swizzle -[NSApplication // This object, while instantiated, will swizzle -[NSApplication
// accessibilityFocusedUIElement] to return the GetNativeViewAccessible of the // accessibilityFocusedUIElement] to return the NSWindow of the specified
// specified BridgedNativeWidgetHostHelper. This is needed to handle remote // BridgedNativeWidgetHostHelper. This is needed to handle remote accessibility
// accessibility queries. If two of these objects are instantiated at the same // queries. If two of these objects are instantiated at the same time, the most
// time, the most recently created object will take precedence. // recently created object will take precedence.
class VIEWS_EXPORT ScopedAccessibilityFocus { class VIEWS_EXPORT ScopedAccessibilityFocus {
public: public:
ScopedAccessibilityFocus( ScopedAccessibilityFocus(BridgedNativeWidgetHostImpl* host);
views_bridge_mac::BridgedNativeWidgetHostHelper* host_helper);
~ScopedAccessibilityFocus(); ~ScopedAccessibilityFocus();
private: private:
views_bridge_mac::BridgedNativeWidgetHostHelper* const host_helper_; BridgedNativeWidgetHostImpl* const host_;
}; };
} // namespace views } // namespace views
......
...@@ -8,29 +8,29 @@ ...@@ -8,29 +8,29 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <objc/runtime.h> #import <objc/runtime.h>
#include "ui/views_bridge_mac/bridged_native_widget_host_helper.h" #include "ui/views/cocoa/bridged_native_widget_host_impl.h"
namespace views { namespace views {
namespace { namespace {
bool g_has_swizzled_method = false; bool g_has_swizzled_method = false;
views_bridge_mac::BridgedNativeWidgetHostHelper* g_overridden_key_element = nil; BridgedNativeWidgetHostImpl* g_overridden_key_element = nil;
// Swizzled method for -[NSApplication accessibilityFocusedUIElement]. This // Swizzled method for -[NSApplication accessibilityFocusedUIElement]. This
// will return the overridden element if one is present. Otherwise, it will // will return the overridden element if one is present. Otherwise, it will
// return the key window. // return the key window.
id SwizzledAccessibilityFocusedUIElement(NSApplication* app, SEL) { id SwizzledAccessibilityFocusedUIElement(NSApplication* app, SEL) {
if (g_overridden_key_element) { if (g_overridden_key_element) {
return [g_overridden_key_element->GetNativeViewAccessible() return [g_overridden_key_element->GetLocalNSWindow()
accessibilityFocusedUIElement]; accessibilityFocusedUIElement];
} }
return [app keyWindow]; return [[app keyWindow] accessibilityFocusedUIElement];
} }
} // namespace } // namespace
ScopedAccessibilityFocus::ScopedAccessibilityFocus( ScopedAccessibilityFocus::ScopedAccessibilityFocus(
views_bridge_mac::BridgedNativeWidgetHostHelper* host_helper) BridgedNativeWidgetHostImpl* host)
: host_helper_(host_helper) { : host_(host) {
if (!g_has_swizzled_method) { if (!g_has_swizzled_method) {
Method method = class_getInstanceMethod( Method method = class_getInstanceMethod(
[NSApplication class], @selector(accessibilityFocusedUIElement)); [NSApplication class], @selector(accessibilityFocusedUIElement));
...@@ -38,11 +38,11 @@ ScopedAccessibilityFocus::ScopedAccessibilityFocus( ...@@ -38,11 +38,11 @@ ScopedAccessibilityFocus::ScopedAccessibilityFocus(
(IMP)SwizzledAccessibilityFocusedUIElement); (IMP)SwizzledAccessibilityFocusedUIElement);
g_has_swizzled_method = true; g_has_swizzled_method = true;
} }
g_overridden_key_element = host_helper_; g_overridden_key_element = host_;
} }
ScopedAccessibilityFocus::~ScopedAccessibilityFocus() { ScopedAccessibilityFocus::~ScopedAccessibilityFocus() {
if (g_overridden_key_element == host_helper_) if (g_overridden_key_element == host_)
g_overridden_key_element = nullptr; g_overridden_key_element = nullptr;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment