Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: ui/views/accessibility/native_view_accessibility.cc

Issue 2715543003: Views a11y: Implement AXPlatformNode::FromNativeViewAccessible on all platforms. (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/accessibility/native_view_accessibility.h" 5 #include "ui/views/accessibility/native_view_accessibility.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/accessibility/platform/ax_platform_node.h"
9 #include "ui/events/event_utils.h" 10 #include "ui/events/event_utils.h"
10 #include "ui/gfx/native_widget_types.h" 11 #include "ui/gfx/native_widget_types.h"
11 #include "ui/views/controls/native/native_view_host.h" 12 #include "ui/views/controls/native/native_view_host.h"
12 #include "ui/views/view.h" 13 #include "ui/views/view.h"
13 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
14 15
15 namespace views { 16 namespace views {
16 17
17 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
18 // static 18 // static
19 std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create( 19 std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::CreateForView(
20 View* view) { 20 View* view) {
21 // Use WrapUnique over MakeUnique to invoke the protected constructor. 21 return base::WrapUnique(Create(view));
22 return base::WrapUnique<NativeViewAccessibility>(
23 new NativeViewAccessibility(view));
24 } 22 }
25 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
26 23
27 NativeViewAccessibility::NativeViewAccessibility(View* view) 24 NativeViewAccessibility::NativeViewAccessibility(View* view)
28 : view_(view), 25 : view_(view),
29 parent_widget_(nullptr), 26 parent_widget_(nullptr),
30 ax_node_(nullptr) { 27 ax_node_(nullptr) {
31 ax_node_ = ui::AXPlatformNode::Create(this); 28 ax_node_ = ui::AXPlatformNode::Create(this);
32 } 29 }
33 30
34 NativeViewAccessibility::~NativeViewAccessibility() { 31 NativeViewAccessibility::~NativeViewAccessibility() {
35 if (ax_node_) 32 if (ax_node_)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 115 }
119 116
120 gfx::NativeWindow NativeViewAccessibility::GetTopLevelWidget() { 117 gfx::NativeWindow NativeViewAccessibility::GetTopLevelWidget() {
121 if (view_->GetWidget()) 118 if (view_->GetWidget())
122 return view_->GetWidget()->GetTopLevelWidget()->GetNativeWindow(); 119 return view_->GetWidget()->GetTopLevelWidget()->GetNativeWindow();
123 return nullptr; 120 return nullptr;
124 } 121 }
125 122
126 gfx::NativeViewAccessible NativeViewAccessibility::GetParent() { 123 gfx::NativeViewAccessible NativeViewAccessibility::GetParent() {
127 if (view_->parent()) 124 if (view_->parent())
128 return view_->parent()->GetNativeViewAccessible(); 125 return view_->parent()->GetNativeViewAccessible();
tapted 2017/03/06 01:43:09 I think this is where we need GetForView? Except G
Patti Lor 2017/03/13 03:03:25 Unfortunately I think we need this for GetChildCou
tapted 2017/03/13 04:07:02 It's possible we need GetChildCount on CrOS.. (but
Patti Lor 2017/03/19 23:10:26 Thanks for your giant refactor Trent! It took a bi
129 126
130 if (parent_widget_) 127 if (parent_widget_)
131 return parent_widget_->GetRootView()->GetNativeViewAccessible(); 128 return parent_widget_->GetRootView()->GetNativeViewAccessible();
132 129
133 return nullptr; 130 return nullptr;
134 } 131 }
135 132
136 gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() { 133 gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() {
137 return gfx::Vector2d(0, 0); // location is already in screen coordinates. 134 return gfx::Vector2d(0, 0); // location is already in screen coordinates.
138 } 135 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 231 }
235 } 232 }
236 233
237 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { 234 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) {
238 if (parent_widget_) 235 if (parent_widget_)
239 parent_widget_->RemoveObserver(this); 236 parent_widget_->RemoveObserver(this);
240 parent_widget_ = parent_widget; 237 parent_widget_ = parent_widget;
241 parent_widget_->AddObserver(this); 238 parent_widget_->AddObserver(this);
242 } 239 }
243 240
241 // static
242 NativeViewAccessibility* NativeViewAccessibility::GetForView(View* view) {
243 #if defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
244 // Retrieving the gfx::NativeViewAccessible also ensures that a
245 // NativeViewAccessibility exists for the given View.
246 gfx::NativeViewAccessible native_object = view->GetNativeViewAccessible();
247 ui::AXPlatformNode* node =
248 ui::AXPlatformNode::FromNativeViewAccessible(native_object);
249 DCHECK(node);
250 return static_cast<NativeViewAccessibility*>(node->GetDelegate());
251 #else
252 // Platforms (currently ChromeOS) without a native implementation also have no
253 // gfx::NativeViewAccessible, so make sure a NativeViewAccessibility exists
254 // and return the instance belonging to |view|.
255 view->GetNativeViewAccessible();
256 return view->native_view_accessibility_.get();
tapted 2017/03/06 01:43:09 The CL description needs to be clear why this is n
Patti Lor 2017/03/13 03:03:25 Updated the description with why we need a fallbac
257 #endif
258 }
259
260 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
261 // static
262 NativeViewAccessibility* NativeViewAccessibility::Create(View* view) {
263 return new NativeViewAccessibility(view);
264 }
265 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
266
244 void NativeViewAccessibility::PopulateChildWidgetVector( 267 void NativeViewAccessibility::PopulateChildWidgetVector(
245 std::vector<Widget*>* result_child_widgets) { 268 std::vector<Widget*>* result_child_widgets) {
246 // Only attach child widgets to the root view. 269 // Only attach child widgets to the root view.
247 Widget* widget = view_->GetWidget(); 270 Widget* widget = view_->GetWidget();
248 if (!widget || widget->GetRootView() != view_) 271 if (!widget || widget->GetRootView() != view_)
249 return; 272 return;
250 273
251 std::set<Widget*> child_widgets; 274 std::set<Widget*> child_widgets;
252 Widget::GetAllOwnedWidgets(widget->GetNativeView(), &child_widgets); 275 Widget::GetAllOwnedWidgets(widget->GetNativeView(), &child_widgets);
253 for (auto iter = child_widgets.begin(); iter != child_widgets.end(); ++iter) { 276 for (auto iter = child_widgets.begin(); iter != child_widgets.end(); ++iter) {
(...skipping 16 matching lines...) Expand all
270 child_widget_platform_node->GetDelegate()); 293 child_widget_platform_node->GetDelegate());
271 if (child_widget_view_accessibility->parent_widget() != widget) 294 if (child_widget_view_accessibility->parent_widget() != widget)
272 child_widget_view_accessibility->SetParentWidget(widget); 295 child_widget_view_accessibility->SetParentWidget(widget);
273 } 296 }
274 297
275 result_child_widgets->push_back(child_widget); 298 result_child_widgets->push_back(child_widget);
276 } 299 }
277 } 300 }
278 301
279 } // namespace views 302 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698