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

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

Issue 2718073003: Views a11y: Convert View's NativeViewAccessibility to a unique_ptr. (Closed)
Patch Set: Fix compile error. 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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
9 #include "ui/gfx/native_widget_types.h" 10 #include "ui/gfx/native_widget_types.h"
10 #include "ui/views/controls/native/native_view_host.h" 11 #include "ui/views/controls/native/native_view_host.h"
11 #include "ui/views/view.h" 12 #include "ui/views/view.h"
12 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
13 14
14 namespace views { 15 namespace views {
15 16
16 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) 17 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
17 // static 18 // static
18 NativeViewAccessibility* NativeViewAccessibility::Create(View* view) { 19 std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create(
19 return new NativeViewAccessibility(view); 20 View* view) {
21 return base::WrapUnique<NativeViewAccessibility>(
tapted 2017/02/28 06:29:12 nit: Comment here like // Use WrapUnique rather t
Patti Lor 2017/02/28 22:24:24 Done - sorry, I forgot :(
22 new NativeViewAccessibility(view));
20 } 23 }
21 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) 24 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
22 25
23 NativeViewAccessibility::NativeViewAccessibility(View* view) 26 NativeViewAccessibility::NativeViewAccessibility(View* view)
24 : view_(view), 27 : view_(view),
25 parent_widget_(nullptr), 28 parent_widget_(nullptr),
26 ax_node_(nullptr) { 29 ax_node_(nullptr) {
27 ax_node_ = ui::AXPlatformNode::Create(this); 30 ax_node_ = ui::AXPlatformNode::Create(this);
28 } 31 }
29 32
30 NativeViewAccessibility::~NativeViewAccessibility() { 33 NativeViewAccessibility::~NativeViewAccessibility() {
31 if (ax_node_) 34 if (ax_node_)
32 ax_node_->Destroy(); 35 ax_node_->Destroy();
33 if (parent_widget_) 36 if (parent_widget_)
34 parent_widget_->RemoveObserver(this); 37 parent_widget_->RemoveObserver(this);
35 } 38 }
36 39
37 gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() { 40 gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() {
38 return ax_node_ ? ax_node_->GetNativeViewAccessible() : nullptr; 41 return ax_node_ ? ax_node_->GetNativeViewAccessible() : nullptr;
39 } 42 }
40 43
41 void NativeViewAccessibility::Destroy() {
42 delete this;
43 }
44
45 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { 44 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) {
46 if (ax_node_) 45 if (ax_node_)
47 ax_node_->NotifyAccessibilityEvent(event_type); 46 ax_node_->NotifyAccessibilityEvent(event_type);
48 } 47 }
49 48
50 bool NativeViewAccessibility::SetFocused(bool focused) { 49 bool NativeViewAccessibility::SetFocused(bool focused) {
51 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE)) 50 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE))
52 return false; 51 return false;
53 52
54 if (focused) 53 if (focused)
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 child_widget_platform_node->GetDelegate()); 269 child_widget_platform_node->GetDelegate());
271 if (child_widget_view_accessibility->parent_widget() != widget) 270 if (child_widget_view_accessibility->parent_widget() != widget)
272 child_widget_view_accessibility->SetParentWidget(widget); 271 child_widget_view_accessibility->SetParentWidget(widget);
273 } 272 }
274 273
275 result_child_widgets->push_back(child_widget); 274 result_child_widgets->push_back(child_widget);
276 } 275 }
277 } 276 }
278 277
279 } // namespace views 278 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698