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

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

Issue 975113002: Resurrect Aura Linux accessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress clang warning Created 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/accessibility/native_view_accessibility_auralinux.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/memory/singleton.h"
11 #include "ui/accessibility/ax_enums.h"
12 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/accessibility/platform/ax_platform_node_auralinux.h"
14 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_observer.h"
18
19 namespace views {
20
21 namespace {
22
23 // ATK requires that we have a single root "application" object that's the
24 // owner of all other windows. This is a simple class that implements the
25 // AXPlatformNodeDelegate interface so we can create such an application
26 // object. Every time we create an accessibility object for a View, we add its
27 // top-level widget to a vector so we can return the list of all top-level
28 // windows as children of this application object.
29 class AuraLinuxApplication
30 : public ui::AXPlatformNodeDelegate,
31 public WidgetObserver {
32 public:
33 // Get the single instance of this class.
34 static AuraLinuxApplication* GetInstance() {
35 return Singleton<AuraLinuxApplication>::get();
36 }
37
38 // Called every time we create a new accessibility on a View.
39 // Add the top-level widget to our registry so that we can enumerate all
40 // top-level widgets.
41 void RegisterWidget(Widget* widget) {
42 if (!widget)
43 return;
44
45 widget = widget->GetTopLevelWidget();
46 if (std::find(widgets_.begin(), widgets_.end(), widget) != widgets_.end())
47 return;
48
49 widgets_.push_back(widget);
50 widget->AddObserver(this);
51 }
52
53 gfx::NativeViewAccessible GetNativeViewAccessible() {
54 return platform_node_->GetNativeViewAccessible();
55 }
56
57 //
58 // WidgetObserver overrides.
59 //
60
61 void OnWidgetDestroying(Widget* widget) override {
62 auto iter = std::find(widgets_.begin(), widgets_.end(), widget);
63 if (iter != widgets_.end())
64 widgets_.erase(iter);
65 }
66
67 //
68 // ui::AXPlatformNodeDelegate overrides.
69 //
70
71 const ui::AXNodeData& GetData() override {
72 return data_;
73 }
74
75 gfx::NativeViewAccessible GetParent() override {
76 return nullptr;
77 }
78
79 int GetChildCount() override {
80 return static_cast<int>(widgets_.size());
81 }
82
83 gfx::NativeViewAccessible ChildAtIndex(int index) override {
84 if (index < 0 && index >= GetChildCount())
Peter Lundblad 2015/03/11 14:58:21 Should be ||.
dmazzoni 2015/03/11 18:39:53 Good catch!
85 return nullptr;
86
87 Widget* widget = widgets_[index];
88 CHECK(widget);
89 View* root_view = widget->GetRootView();
90 if (!root_view)
91 return nullptr;
92 return root_view->GetNativeViewAccessible();
93 }
94
95 gfx::Vector2d GetGlobalCoordinateOffset() override {
96 return gfx::Vector2d();
97 }
98
99 gfx::NativeViewAccessible HitTestSync(int x, int y) override {
100 return nullptr;
101 }
102
103 gfx::NativeViewAccessible GetFocus() override {
104 return nullptr;
105 }
106
107 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override {
108 return gfx::kNullAcceleratedWidget;
109 }
110
111 void DoDefaultAction() override {
112 }
113
114 bool SetStringValue(const base::string16& new_value) override {
115 return false;
116 }
117
118 private:
119 friend struct DefaultSingletonTraits<AuraLinuxApplication>;
120
121 AuraLinuxApplication() {
122 data_.role = ui::AX_ROLE_APPLICATION;
123 data_.AddStringAttribute(ui::AX_ATTR_NAME, "Chrome");
Peter Lundblad 2015/03/11 14:58:21 Is this a UI string? If so, it should be set from
dmazzoni 2015/03/11 18:39:53 Not sure IDS_SHORT_PRODUCT_NAME is available from
124 platform_node_ = ui::AXPlatformNode::Create(this);
125 ui::AXPlatformNodeAuraLinux::SetApplication(platform_node_);
126 }
127
128 ~AuraLinuxApplication() override {
129 platform_node_->Destroy();
130 platform_node_ = nullptr;
131 }
132
133 ui::AXPlatformNode* platform_node_;
134 ui::AXNodeData data_;
135 std::vector<Widget*> widgets_;
136 };
137
138 } // namespace
139
140 // static
141 NativeViewAccessibility* NativeViewAccessibility::Create(View* view) {
142 AuraLinuxApplication::GetInstance()->RegisterWidget(view->GetWidget());
143 return new NativeViewAccessibilityAuraLinux(view);
144 }
145
146 NativeViewAccessibilityAuraLinux::NativeViewAccessibilityAuraLinux(View* view)
147 : NativeViewAccessibility(view) {
148 }
149
150 NativeViewAccessibilityAuraLinux::~NativeViewAccessibilityAuraLinux() {
151 }
152
153 gfx::NativeViewAccessible NativeViewAccessibilityAuraLinux::GetParent() {
154 gfx::NativeViewAccessible parent = NativeViewAccessibility::GetParent();
155 if (!parent)
156 parent = AuraLinuxApplication::GetInstance()->GetNativeViewAccessible();
157 return parent;
158 }
159
160 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698