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

Side by Side Diff: ui/accessibility/platform/ax_platform_node.cc

Issue 420653003: MacViews: Accessibility bridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2nd draft, based on 423513005 Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/accessibility/platform/ax_platform_node.h" 5 #include "ui/accessibility/platform/ax_platform_node.h"
6
7 #include "ui/accessibility/ax_node_data.h"
6 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 8 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
7 9
8 namespace ui { 10 namespace ui {
9 11
10 #if !defined(OS_WIN) 12 #if !defined(OS_MACOSX)
11 // static 13 // static
12 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { 14 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) {
13 AXPlatformNode* node = new AXPlatformNode(); 15 return NULL;
14 node->Init(delegate);
15 return node;
16 } 16 }
17 #endif 17 #endif
18 18
19 AXPlatformNode::AXPlatformNode() { 19 AXPlatformNode::AXPlatformNode() {
20 } 20 }
21 21
22 AXPlatformNode::~AXPlatformNode() { 22 AXPlatformNode::~AXPlatformNode() {
23 } 23 }
24 24
25 void AXPlatformNode::Init(AXPlatformNodeDelegate* delegate) { 25 void AXPlatformNode::Init(AXPlatformNodeDelegate* delegate) {
26 delegate_ = delegate; 26 delegate_ = delegate;
27 } 27 }
28 28
29 void AXPlatformNode::Detach() { 29 void AXPlatformNode::Detach() {
30 delegate_ = NULL; 30 delegate_ = NULL;
31 } 31 }
32 32
33 gfx::NativeViewAccessible AXPlatformNode::GetNativeViewAccessible() { 33 AXRole AXPlatformNode::GetRole() const {
34 return NULL; 34 return delegate_ ? delegate_->GetData()->role : AX_ROLE_UNKNOWN;
35 } 35 }
36 36
37 AXPlatformNode* AXPlatformNode::NextSibling() { 37 gfx::Rect AXPlatformNode::GetBoundsInScreen() const {
38 if (!delegate_) 38 gfx::Rect bounds = delegate_->GetData()->location;
dmazzoni 2014/07/29 06:35:14 Check delegate_ for NULL everywhere
Andre 2014/07/29 21:58:56 Done.
39 return NULL; 39 bounds.Offset(delegate_->GetGlobalCoordinateOffset());
40 40 return bounds;
41 AXPlatformNode* parent = delegate_->GetParent();
42 if (!parent)
43 return NULL;
44
45 int next_index = delegate_->GetIndexInParent() + 1;
46 if (next_index >= 0 && next_index < parent->GetChildCount())
47 return parent->ChildAtIndex(next_index);
48
49 return NULL;
50 } 41 }
51 42
52 AXPlatformNode* AXPlatformNode::PreviousSibling() { 43 gfx::NativeViewAccessible AXPlatformNode::GetParent() {
53 if (!delegate_) 44 return delegate_ ? delegate_->GetParent() : NULL;
54 return NULL;
55
56 AXPlatformNode* parent = delegate_->GetParent();
57 if (!parent)
58 return NULL;
59
60 int previous_index = delegate_->GetIndexInParent() - 1;
61 if (previous_index >= 0 && previous_index < parent->GetChildCount())
62 return parent->ChildAtIndex(previous_index);
63
64 return NULL;
65 } 45 }
66 46
67 bool AXPlatformNode::HasBoolAttribute( 47 int AXPlatformNode::GetChildCount() {
68 ui::AXBoolAttribute attribute) const { 48 return delegate_ ? delegate_->GetChildCount() : 0;
69 ui::AXNodeData* data = delegate_->GetData();
70 if (!data)
71 return false;
72
73 for (size_t i = 0; i < data.bool_attributes.size(); ++i) {
74 if (data.bool_attributes[i].first == attribute)
75 return true;
76 }
77
78 return false;
79 } 49 }
80 50
81 51 gfx::NativeViewAccessible AXPlatformNode::ChildAtIndex(int index) {
82 bool AXPlatformNode::GetBoolAttribute( 52 return delegate_ ? delegate_->ChildAtIndex(index) : NULL;
83 ui::AXBoolAttribute attribute) const {
84 ui::AXNodeData* data = delegate_->GetData();
85 if (!data)
86 return false;
87
88 for (size_t i = 0; i < data.bool_attributes.size(); ++i) {
89 if (data.bool_attributes[i].first == attribute)
90 return data.bool_attributes[i].second;
91 }
92
93 return false;
94 }
95
96 bool AXPlatformNode::GetBoolAttribute(
97 ui::AXBoolAttribute attribute, bool* value) const {
98 ui::AXNodeData* data = delegate_->GetData();
99 if (!data)
100 return false;
101
102 for (size_t i = 0; i < data.bool_attributes.size(); ++i) {
103 if (data.bool_attributes[i].first == attribute) {
104 *value = data.bool_attributes[i].second;
105 return true;
106 }
107 }
108
109 return false;
110 }
111
112 bool AXPlatformNode::HasFloatAttribute(
113 ui::AXFloatAttribute attribute) const {
114 ui::AXNodeData* data = delegate_->GetData();
115 if (!data)
116 return false;
117
118 for (size_t i = 0; i < data.float_attributes.size(); ++i) {
119 if (data.float_attributes[i].first == attribute)
120 return true;
121 }
122
123 return false;
124 }
125
126 float AXPlatformNode::GetFloatAttribute(
127 ui::AXFloatAttribute attribute) const {
128 ui::AXNodeData* data = delegate_->GetData();
129 if (!data)
130 return false;
131
132 for (size_t i = 0; i < data.float_attributes.size(); ++i) {
133 if (data.float_attributes[i].first == attribute)
134 return data.float_attributes[i].second;
135 }
136
137 return 0.0;
138 }
139
140 bool AXPlatformNode::GetFloatAttribute(
141 ui::AXFloatAttribute attribute, float* value) const {
142 ui::AXNodeData* data = delegate_->GetData();
143 if (!data)
144 return false;
145
146 for (size_t i = 0; i < data.float_attributes.size(); ++i) {
147 if (data.float_attributes[i].first == attribute) {
148 *value = data.float_attributes[i].second;
149 return true;
150 }
151 }
152
153 return false;
154 }
155
156 bool AXPlatformNode::HasIntAttribute(
157 ui::AXIntAttribute attribute) const {
158 ui::AXNodeData* data = delegate_->GetData();
159 if (!data)
160 return false;
161
162 for (size_t i = 0; i < data.int_attributes.size(); ++i) {
163 if (data.int_attributes[i].first == attribute)
164 return true;
165 }
166
167 return false;
168 }
169
170 int AXPlatformNode::GetIntAttribute(ui::AXIntAttribute attribute) const {
171 ui::AXNodeData* data = delegate_->GetData();
172 if (!data)
173 return false;
174
175 for (size_t i = 0; i < data.int_attributes.size(); ++i) {
176 if (data.int_attributes[i].first == attribute)
177 return data.int_attributes[i].second;
178 }
179
180 return 0;
181 }
182
183 bool AXPlatformNode::GetIntAttribute(
184 ui::AXIntAttribute attribute, int* value) const {
185 ui::AXNodeData* data = delegate_->GetData();
186 if (!data)
187 return false;
188
189 for (size_t i = 0; i < data.int_attributes.size(); ++i) {
190 if (data.int_attributes[i].first == attribute) {
191 *value = data.int_attributes[i].second;
192 return true;
193 }
194 }
195
196 return false;
197 }
198
199 bool AXPlatformNode::HasStringAttribute(
200 ui::AXStringAttribute attribute) const {
201 ui::AXNodeData* data = delegate_->GetData();
202 if (!data)
203 return false;
204
205 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
206 if (data.string_attributes[i].first == attribute)
207 return true;
208 }
209
210 return false;
211 }
212
213 const std::string& AXPlatformNode::GetStringAttribute(
214 ui::AXStringAttribute attribute) const {
215 ui::AXNodeData* data = delegate_->GetData();
216 if (!data)
217 return false;
218
219 CR_DEFINE_STATIC_LOCAL(std::string, empty_string, ());
220 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
221 if (data.string_attributes[i].first == attribute)
222 return data.string_attributes[i].second;
223 }
224
225 return empty_string;
226 }
227
228 bool AXPlatformNode::GetStringAttribute(
229 ui::AXStringAttribute attribute, std::string* value) const {
230 ui::AXNodeData* data = delegate_->GetData();
231 if (!data)
232 return false;
233
234 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
235 if (data.string_attributes[i].first == attribute) {
236 *value = data.string_attributes[i].second;
237 return true;
238 }
239 }
240
241 return false;
242 }
243
244 base::string16 AXPlatformNode::GetString16Attribute(
245 ui::AXStringAttribute attribute) const {
246 std::string value_utf8;
247 if (!GetStringAttribute(attribute, &value_utf8))
248 return base::string16();
249 return base::UTF8ToUTF16(value_utf8);
250 }
251
252 bool AXPlatformNode::GetString16Attribute(
253 ui::AXStringAttribute attribute,
254 base::string16* value) const {
255 std::string value_utf8;
256 if (!GetStringAttribute(attribute, &value_utf8))
257 return false;
258 *value = base::UTF8ToUTF16(value_utf8);
259 return true;
260 }
261
262 bool AXPlatformNode::HasIntListAttribute(
263 ui::AXIntListAttribute attribute) const {
264 ui::AXNodeData* data = delegate_->GetData();
265 if (!data)
266 return false;
267
268 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
269 if (data.intlist_attributes[i].first == attribute)
270 return true;
271 }
272
273 return false;
274 }
275
276 const std::vector<int32>& AXPlatformNode::GetIntListAttribute(
277 ui::AXIntListAttribute attribute) const {
278 ui::AXNodeData* data = delegate_->GetData();
279 if (!data)
280 return false;
281
282 CR_DEFINE_STATIC_LOCAL(std::vector<int32>, empty_vector, ());
283 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
284 if (data.intlist_attributes[i].first == attribute)
285 return data.intlist_attributes[i].second;
286 }
287
288 return empty_vector;
289 }
290
291 bool AXPlatformNode::GetIntListAttribute(
292 ui::AXIntListAttribute attribute,
293 std::vector<int32>* value) const {
294 ui::AXNodeData* data = delegate_->GetData();
295 if (!data)
296 return false;
297
298 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
299 if (data.intlist_attributes[i].first == attribute) {
300 *value = data.intlist_attributes[i].second;
301 return true;
302 }
303 }
304
305 return false;
306 }
307
308 bool AXPlatformNode::GetHtmlAttribute(
309 const char* html_attr, std::string* value) const {
310 for (size_t i = 0; i < GetHtmlAttributes().size(); ++i) {
311 const std::string& attr = GetHtmlAttributes()[i].first;
312 if (LowerCaseEqualsASCII(attr, html_attr)) {
313 *value = GetHtmlAttributes()[i].second;
314 return true;
315 }
316 }
317
318 return false;
319 }
320
321 bool AXPlatformNode::GetHtmlAttribute(
322 const char* html_attr, base::string16* value) const {
323 std::string value_utf8;
324 if (!GetHtmlAttribute(html_attr, &value_utf8))
325 return false;
326 *value = base::UTF8ToUTF16(value_utf8);
327 return true;
328 } 53 }
329 54
330 } // namespace ui 55 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698