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

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 long lived NVA in test. 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 // Use WrapUnique over MakeUnique to invoke the protected constructor.
22 return base::WrapUnique<NativeViewAccessibility>(
23 new NativeViewAccessibility(view));
20 } 24 }
21 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) 25 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
22 26
23 NativeViewAccessibility::NativeViewAccessibility(View* view) 27 NativeViewAccessibility::NativeViewAccessibility(View* view)
24 : view_(view), 28 : view_(view),
25 parent_widget_(nullptr), 29 parent_widget_(nullptr),
26 ax_node_(nullptr) { 30 ax_node_(nullptr) {
27 ax_node_ = ui::AXPlatformNode::Create(this); 31 ax_node_ = ui::AXPlatformNode::Create(this);
28 } 32 }
29 33
30 NativeViewAccessibility::~NativeViewAccessibility() { 34 NativeViewAccessibility::~NativeViewAccessibility() {
31 if (ax_node_) 35 if (ax_node_)
32 ax_node_->Destroy(); 36 ax_node_->Destroy();
33 if (parent_widget_) 37 if (parent_widget_)
34 parent_widget_->RemoveObserver(this); 38 parent_widget_->RemoveObserver(this);
35 } 39 }
36 40
37 gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() { 41 gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() {
38 return ax_node_ ? ax_node_->GetNativeViewAccessible() : nullptr; 42 return ax_node_ ? ax_node_->GetNativeViewAccessible() : nullptr;
39 } 43 }
40 44
41 void NativeViewAccessibility::Destroy() {
42 delete this;
43 }
44
45 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { 45 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) {
46 if (ax_node_) 46 if (ax_node_)
47 ax_node_->NotifyAccessibilityEvent(event_type); 47 ax_node_->NotifyAccessibilityEvent(event_type);
48 } 48 }
49 49
50 bool NativeViewAccessibility::SetFocused(bool focused) { 50 bool NativeViewAccessibility::SetFocused(bool focused) {
51 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE)) 51 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE))
52 return false; 52 return false;
53 53
54 if (focused) 54 if (focused)
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 child_widget_platform_node->GetDelegate()); 270 child_widget_platform_node->GetDelegate());
271 if (child_widget_view_accessibility->parent_widget() != widget) 271 if (child_widget_view_accessibility->parent_widget() != widget)
272 child_widget_view_accessibility->SetParentWidget(widget); 272 child_widget_view_accessibility->SetParentWidget(widget);
273 } 273 }
274 274
275 result_child_widgets->push_back(child_widget); 275 result_child_widgets->push_back(child_widget);
276 } 276 }
277 } 277 }
278 278
279 } // namespace views 279 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.h ('k') | ui/views/accessibility/native_view_accessibility_auralinux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698