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

RemoteMacViews: Return NSAccessibilityRemoteUIElement where appropriate

When using RemoteMacViews, for a given widget, the widget's NSWindow
and content NSView exist in the app shim process, while the tree of
AXPlatformNodeCocoas exists in the browser process.

In the browser process, the widget's NSWindow and content NSView are
represented by NSAccessibilityRemoteUIElements in
views::BridgedNativeWidgetHostImpl.

Update AXPlatformNodeDelegateMac::GetParent and GetNSWindow to retrieve
these values from views::BridgedNativeWidgetHostImpl.

In AXPlatformNodeDelegate, replace the method GetTopLevelWidget with
the method GetNSWindow and call this method in -[AXPlatformNodeCocoa
AXWindow]. Replace all subclass implementations except for
AXPlatformNodeDelegateMac with NOTREACHED.

Bug: 900846
Change-Id: Ia0d26c4d118391ce66cc1e080ca3b62fb228aa8c
Reviewed-on: https://chromium-review.googlesource.com/c/1338722
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609959}
parent 858f8a1e
...@@ -952,7 +952,7 @@ const ui::AXTreeData& BrowserAccessibility::GetTreeData() const { ...@@ -952,7 +952,7 @@ const ui::AXTreeData& BrowserAccessibility::GetTreeData() const {
return *empty_data; return *empty_data;
} }
gfx::NativeWindow BrowserAccessibility::GetTopLevelWidget() { gfx::NativeViewAccessible BrowserAccessibility::GetNSWindow() {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
......
...@@ -334,7 +334,7 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate { ...@@ -334,7 +334,7 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
// AXPlatformNodeDelegate. // AXPlatformNodeDelegate.
const ui::AXNodeData& GetData() const override; const ui::AXNodeData& GetData() const override;
const ui::AXTreeData& GetTreeData() const override; const ui::AXTreeData& GetTreeData() const override;
gfx::NativeWindow GetTopLevelWidget() override; gfx::NativeViewAccessible GetNSWindow() override;
gfx::NativeViewAccessible GetParent() override; gfx::NativeViewAccessible GetParent() override;
int GetChildCount() override; int GetChildCount() override;
gfx::NativeViewAccessible ChildAtIndex(int index) override; gfx::NativeViewAccessible ChildAtIndex(int index) override;
......
...@@ -50,8 +50,9 @@ class AX_EXPORT AXPlatformNodeDelegate { ...@@ -50,8 +50,9 @@ class AX_EXPORT AXPlatformNodeDelegate {
// Get the accessibility tree data for this node. // Get the accessibility tree data for this node.
virtual const AXTreeData& GetTreeData() const = 0; virtual const AXTreeData& GetTreeData() const = 0;
// Get the window the node is contained in. // Get the accessibility node for the NSWindow the node is contained in. This
virtual gfx::NativeWindow GetTopLevelWidget() = 0; // method is only meaningful on macOS.
virtual gfx::NativeViewAccessible GetNSWindow() = 0;
// Get the parent of the node, which may be an AXPlatformNode or it may // Get the parent of the node, which may be an AXPlatformNode or it may
// be a native accessible object implemented by another class. // be a native accessible object implemented by another class.
......
...@@ -24,7 +24,7 @@ const AXTreeData& AXPlatformNodeDelegateBase::GetTreeData() const { ...@@ -24,7 +24,7 @@ const AXTreeData& AXPlatformNodeDelegateBase::GetTreeData() const {
return *empty_data; return *empty_data;
} }
gfx::NativeWindow AXPlatformNodeDelegateBase::GetTopLevelWidget() { gfx::NativeViewAccessible AXPlatformNodeDelegateBase::GetNSWindow() {
return nullptr; return nullptr;
} }
......
...@@ -27,8 +27,8 @@ class AX_EXPORT AXPlatformNodeDelegateBase : public AXPlatformNodeDelegate { ...@@ -27,8 +27,8 @@ class AX_EXPORT AXPlatformNodeDelegateBase : public AXPlatformNodeDelegate {
// Get the accessibility tree data for this node. // Get the accessibility tree data for this node.
const AXTreeData& GetTreeData() const override; const AXTreeData& GetTreeData() const override;
// Get the window the node is contained in. // See comments in AXPlatformNodeDelegate.
gfx::NativeWindow GetTopLevelWidget() override; gfx::NativeViewAccessible GetNSWindow() override;
// Get the parent of the node, which may be an AXPlatformNode or it may // Get the parent of the node, which may be an AXPlatformNode or it may
// be a native accessible object implemented by another class. // be a native accessible object implemented by another class.
......
...@@ -805,10 +805,7 @@ bool AlsoUseShowMenuActionForDefaultAction(const ui::AXNodeData& data) { ...@@ -805,10 +805,7 @@ bool AlsoUseShowMenuActionForDefaultAction(const ui::AXNodeData& data) {
} }
- (id)AXWindow { - (id)AXWindow {
// TODO(ccameron): This should return the NSAccessibilityRemoteUIElement for return node_->GetDelegate()->GetNSWindow();
// the NSWindow in the viewer process. This requires that Widget have a method
// to retrieve this object, which does not exist yet.
return node_->GetDelegate()->GetTopLevelWidget().GetNativeNSWindow();
} }
- (id)AXTopLevelUIElement { - (id)AXTopLevelUIElement {
......
...@@ -191,9 +191,8 @@ gfx::NativeViewAccessible AXVirtualView::ChildAtIndex(int index) { ...@@ -191,9 +191,8 @@ gfx::NativeViewAccessible AXVirtualView::ChildAtIndex(int index) {
return nullptr; return nullptr;
} }
gfx::NativeWindow AXVirtualView::GetTopLevelWidget() { gfx::NativeViewAccessible AXVirtualView::GetNSWindow() {
if (GetOwnerView() && GetOwnerView()->GetWidget()) NOTREACHED();
return GetOwnerView()->GetWidget()->GetTopLevelWidget()->GetNativeWindow();
return nullptr; return nullptr;
} }
......
...@@ -108,7 +108,7 @@ class VIEWS_EXPORT AXVirtualView : public ui::AXPlatformNodeDelegateBase { ...@@ -108,7 +108,7 @@ class VIEWS_EXPORT AXVirtualView : public ui::AXPlatformNodeDelegateBase {
const ui::AXNodeData& GetData() const override; const ui::AXNodeData& GetData() const override;
int GetChildCount() override; int GetChildCount() override;
gfx::NativeViewAccessible ChildAtIndex(int index) override; gfx::NativeViewAccessible ChildAtIndex(int index) override;
gfx::NativeWindow GetTopLevelWidget() override; gfx::NativeViewAccessible GetNSWindow() override;
gfx::NativeViewAccessible GetParent() override; gfx::NativeViewAccessible GetParent() override;
gfx::Rect GetClippedScreenBoundsRect() const override; gfx::Rect GetClippedScreenBoundsRect() const override;
gfx::Rect GetUnclippedScreenBoundsRect() const override; gfx::Rect GetUnclippedScreenBoundsRect() const override;
......
...@@ -285,9 +285,8 @@ gfx::NativeViewAccessible ViewAXPlatformNodeDelegate::ChildAtIndex(int index) { ...@@ -285,9 +285,8 @@ gfx::NativeViewAccessible ViewAXPlatformNodeDelegate::ChildAtIndex(int index) {
return nullptr; return nullptr;
} }
gfx::NativeWindow ViewAXPlatformNodeDelegate::GetTopLevelWidget() { gfx::NativeViewAccessible ViewAXPlatformNodeDelegate::GetNSWindow() {
if (view()->GetWidget()) NOTREACHED();
return view()->GetWidget()->GetTopLevelWidget()->GetNativeWindow();
return nullptr; return nullptr;
} }
......
...@@ -50,7 +50,7 @@ class ViewAXPlatformNodeDelegate : public ViewAccessibility, ...@@ -50,7 +50,7 @@ class ViewAXPlatformNodeDelegate : public ViewAccessibility,
const ui::AXNodeData& GetData() const override; const ui::AXNodeData& GetData() const override;
int GetChildCount() override; int GetChildCount() override;
gfx::NativeViewAccessible ChildAtIndex(int index) override; gfx::NativeViewAccessible ChildAtIndex(int index) override;
gfx::NativeWindow GetTopLevelWidget() override; gfx::NativeViewAccessible GetNSWindow() override;
gfx::NativeViewAccessible GetParent() override; gfx::NativeViewAccessible GetParent() override;
gfx::Rect GetClippedScreenBoundsRect() const override; gfx::Rect GetClippedScreenBoundsRect() const override;
gfx::Rect GetUnclippedScreenBoundsRect() const override; gfx::Rect GetUnclippedScreenBoundsRect() const override;
......
...@@ -17,6 +17,7 @@ class ViewAXPlatformNodeDelegateMac : public ViewAXPlatformNodeDelegate { ...@@ -17,6 +17,7 @@ class ViewAXPlatformNodeDelegateMac : public ViewAXPlatformNodeDelegate {
~ViewAXPlatformNodeDelegateMac() override; ~ViewAXPlatformNodeDelegateMac() override;
// |ViewAXPlatformNodeDelegate| overrides: // |ViewAXPlatformNodeDelegate| overrides:
gfx::NativeViewAccessible GetNSWindow() override;
gfx::NativeViewAccessible GetParent() override; gfx::NativeViewAccessible GetParent() override;
private: private:
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "ui/views/cocoa/bridged_native_widget_host_impl.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -21,18 +22,37 @@ ViewAXPlatformNodeDelegateMac::ViewAXPlatformNodeDelegateMac(View* view) ...@@ -21,18 +22,37 @@ ViewAXPlatformNodeDelegateMac::ViewAXPlatformNodeDelegateMac(View* view)
ViewAXPlatformNodeDelegateMac::~ViewAXPlatformNodeDelegateMac() = default; ViewAXPlatformNodeDelegateMac::~ViewAXPlatformNodeDelegateMac() = default;
gfx::NativeViewAccessible ViewAXPlatformNodeDelegateMac::GetNSWindow() {
auto* widget = view()->GetWidget();
if (!widget)
return nil;
auto* top_level_widget = widget->GetTopLevelWidget();
if (!top_level_widget)
return nil;
auto* bridge_host = BridgedNativeWidgetHostImpl::GetFromNativeWindow(
top_level_widget->GetNativeWindow());
if (!bridge_host)
return nil;
return bridge_host->GetNativeViewAccessibleForNSWindow();
}
gfx::NativeViewAccessible ViewAXPlatformNodeDelegateMac::GetParent() { gfx::NativeViewAccessible ViewAXPlatformNodeDelegateMac::GetParent() {
if (view()->parent()) if (view()->parent())
return view()->parent()->GetNativeViewAccessible(); return view()->parent()->GetNativeViewAccessible();
// TODO(ccameron): This should return the NSAccessibilityRemoteUIElement for auto* widget = view()->GetWidget();
// the NSView in the viewer process. This requires that Widget have a if (!widget)
// method to retrieve this object, which will not necessarily coincide with return nil;
// GetNativeView.
if (view()->GetWidget()) auto* bridge_host = BridgedNativeWidgetHostImpl::GetFromNativeWindow(
return view()->GetWidget()->GetNativeView().GetNativeNSView(); view()->GetWidget()->GetNativeWindow());
if (!bridge_host)
return nil;
return nullptr; return bridge_host->GetNativeViewAccessibleForNSView();
} }
} // namespace views } // namespace views
...@@ -90,12 +90,11 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -90,12 +90,11 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
// NSWindow. Otherwise, it mirrors the id and bounds of the child window. // NSWindow. Otherwise, it mirrors the id and bounds of the child window.
NativeWidgetMacNSWindow* GetLocalNSWindow() const; NativeWidgetMacNSWindow* GetLocalNSWindow() const;
// Return the accessibility object for the parent NSView of the widget's root // Return the accessibility object for the content NSView.
// views::View. gfx::NativeViewAccessible GetNativeViewAccessibleForNSView() const;
gfx::NativeViewAccessible GetParentViewAccessible() const;
// Return the accessibility object for this widget's window. // Return the accessibility object for the NSWindow.
gfx::NativeViewAccessible GetWindowAccessible() const; gfx::NativeViewAccessible GetNativeViewAccessibleForNSWindow() const;
// The mojo interface through which to communicate with the underlying // The mojo interface through which to communicate with the underlying
// NSWindow and NSView. // NSWindow and NSView.
......
...@@ -127,15 +127,15 @@ NativeWidgetMacNSWindow* BridgedNativeWidgetHostImpl::GetLocalNSWindow() const { ...@@ -127,15 +127,15 @@ NativeWidgetMacNSWindow* BridgedNativeWidgetHostImpl::GetLocalNSWindow() const {
return local_window_.get(); return local_window_.get();
} }
gfx::NativeViewAccessible BridgedNativeWidgetHostImpl::GetParentViewAccessible() gfx::NativeViewAccessible
const { BridgedNativeWidgetHostImpl::GetNativeViewAccessibleForNSView() const {
if (bridge_impl_) if (bridge_impl_)
return bridge_impl_->ns_view(); return bridge_impl_->ns_view();
return remote_view_accessible_.get(); return remote_view_accessible_.get();
} }
gfx::NativeViewAccessible BridgedNativeWidgetHostImpl::GetWindowAccessible() gfx::NativeViewAccessible
const { BridgedNativeWidgetHostImpl::GetNativeViewAccessibleForNSWindow() const {
if (bridge_impl_) if (bridge_impl_)
return bridge_impl_->ns_window(); return bridge_impl_->ns_window();
return remote_window_accessible_.get(); return remote_window_accessible_.get();
......
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