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 @@
#include "ui/views/views_export.h"
namespace views_bridge_mac {
class BridgedNativeWidgetHostHelper;
} // namespace views_bridge_mac
namespace views {
class BridgedNativeWidgetHostImpl;
// This object, while instantiated, will swizzle -[NSApplication
// accessibilityFocusedUIElement] to return the GetNativeViewAccessible of the
// specified BridgedNativeWidgetHostHelper. This is needed to handle remote
// accessibility queries. If two of these objects are instantiated at the same
// time, the most recently created object will take precedence.
// accessibilityFocusedUIElement] to return the NSWindow of the specified
// BridgedNativeWidgetHostHelper. This is needed to handle remote accessibility
// queries. If two of these objects are instantiated at the same time, the most
// recently created object will take precedence.
class VIEWS_EXPORT ScopedAccessibilityFocus {
public:
ScopedAccessibilityFocus(
views_bridge_mac::BridgedNativeWidgetHostHelper* host_helper);
ScopedAccessibilityFocus(BridgedNativeWidgetHostImpl* host);
~ScopedAccessibilityFocus();
private:
views_bridge_mac::BridgedNativeWidgetHostHelper* const host_helper_;
BridgedNativeWidgetHostImpl* const host_;
};
} // namespace views
......
......@@ -8,29 +8,29 @@
#import <Foundation/Foundation.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 {
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
// will return the overridden element if one is present. Otherwise, it will
// return the key window.
id SwizzledAccessibilityFocusedUIElement(NSApplication* app, SEL) {
if (g_overridden_key_element) {
return [g_overridden_key_element->GetNativeViewAccessible()
return [g_overridden_key_element->GetLocalNSWindow()
accessibilityFocusedUIElement];
}
return [app keyWindow];
return [[app keyWindow] accessibilityFocusedUIElement];
}
} // namespace
ScopedAccessibilityFocus::ScopedAccessibilityFocus(
views_bridge_mac::BridgedNativeWidgetHostHelper* host_helper)
: host_helper_(host_helper) {
BridgedNativeWidgetHostImpl* host)
: host_(host) {
if (!g_has_swizzled_method) {
Method method = class_getInstanceMethod(
[NSApplication class], @selector(accessibilityFocusedUIElement));
......@@ -38,11 +38,11 @@ ScopedAccessibilityFocus::ScopedAccessibilityFocus(
(IMP)SwizzledAccessibilityFocusedUIElement);
g_has_swizzled_method = true;
}
g_overridden_key_element = host_helper_;
g_overridden_key_element = host_;
}
ScopedAccessibilityFocus::~ScopedAccessibilityFocus() {
if (g_overridden_key_element == host_helper_)
if (g_overridden_key_element == host_)
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