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

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

Issue 2964313002: Converts accNavigate over to the AXPlatformNode code. (Closed)
Patch Set: are -> is Created 3 years, 5 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 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_base.h" 5 #include "ui/accessibility/platform/ax_platform_node_base.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_action_data.h" 8 #include "ui/accessibility/ax_action_data.h"
9 #include "ui/accessibility/ax_node_data.h" 9 #include "ui/accessibility/ax_node_data.h"
10 #include "ui/accessibility/ax_role_properties.h"
10 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 11 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
11 #include "ui/gfx/geometry/rect_conversions.h" 12 #include "ui/gfx/geometry/rect_conversions.h"
12 13
13 namespace ui { 14 namespace ui {
14 15
15 void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) { 16 void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) {
16 delegate_ = delegate; 17 delegate_ = delegate;
17 } 18 }
18 19
19 const AXNodeData& AXPlatformNodeBase::GetData() const { 20 const AXNodeData& AXPlatformNodeBase::GetData() const {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return GetData().GetString16Attribute(attribute); 183 return GetData().GetString16Attribute(attribute);
183 } 184 }
184 185
185 bool AXPlatformNodeBase::GetString16Attribute( 186 bool AXPlatformNodeBase::GetString16Attribute(
186 ui::AXStringAttribute attribute, 187 ui::AXStringAttribute attribute,
187 base::string16* value) const { 188 base::string16* value) const {
188 CHECK(delegate_); 189 CHECK(delegate_);
189 return GetData().GetString16Attribute(attribute, value); 190 return GetData().GetString16Attribute(attribute, value);
190 } 191 }
191 192
193 bool AXPlatformNodeBase::HasIntListAttribute(
194 ui::AXIntListAttribute attribute) const {
195 return GetData().HasIntListAttribute(attribute);
196 }
197
198 const std::vector<int32_t>& AXPlatformNodeBase::GetIntListAttribute(
199 ui::AXIntListAttribute attribute) const {
200 return GetData().GetIntListAttribute(attribute);
201 }
202
203 bool AXPlatformNodeBase::GetIntListAttribute(
204 ui::AXIntListAttribute attribute,
205 std::vector<int32_t>* value) const {
206 return GetData().GetIntListAttribute(attribute, value);
207 }
208
192 AXPlatformNodeBase::AXPlatformNodeBase() { 209 AXPlatformNodeBase::AXPlatformNodeBase() {
193 } 210 }
194 211
195 AXPlatformNodeBase::~AXPlatformNodeBase() { 212 AXPlatformNodeBase::~AXPlatformNodeBase() {
196 CHECK(!delegate_); 213 CHECK(!delegate_);
197 } 214 }
198 215
199 // static 216 // static
200 AXPlatformNodeBase* AXPlatformNodeBase::FromNativeViewAccessible( 217 AXPlatformNodeBase* AXPlatformNodeBase::FromNativeViewAccessible(
201 gfx::NativeViewAccessible accessible) { 218 gfx::NativeViewAccessible accessible) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 case ui::AX_ROLE_SPIN_BUTTON: 298 case ui::AX_ROLE_SPIN_BUTTON:
282 case ui::AX_ROLE_SCROLL_BAR: 299 case ui::AX_ROLE_SCROLL_BAR:
283 return true; 300 return true;
284 case ui::AX_ROLE_SPLITTER: 301 case ui::AX_ROLE_SPLITTER:
285 return GetData().HasState(ui::AX_STATE_FOCUSABLE); 302 return GetData().HasState(ui::AX_STATE_FOCUSABLE);
286 default: 303 default:
287 return false; 304 return false;
288 } 305 }
289 } 306 }
290 307
308 AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const {
309 AXPlatformNodeBase* table = const_cast<AXPlatformNodeBase*>(this);
310 while (table && !ui::IsTableLikeRole(table->GetData().role)) {
311 gfx::NativeViewAccessible parent_accessible = table->GetParent();
312 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible);
313
314 table = parent;
315 }
316 return table;
317 }
318
319 AXPlatformNodeBase* AXPlatformNodeBase::GetTableCell(int index) const {
320 DCHECK(delegate_);
321
322 if (!ui::IsTableLikeRole(GetData().role) &&
323 !ui::IsCellOrTableHeaderRole(GetData().role))
324 return nullptr;
325
326 AXPlatformNodeBase* table = GetTable();
327 if (!table)
328 return nullptr;
329 const std::vector<int32_t>& unique_cell_ids =
330 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS);
331 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size()))
332 return nullptr;
333
334 return static_cast<AXPlatformNodeBase*>(
335 table->delegate_->GetFromNodeID(unique_cell_ids[index]));
336 }
337
338 AXPlatformNodeBase* AXPlatformNodeBase::GetTableCell(int row,
339 int column) const {
340 if (!ui::IsTableLikeRole(GetData().role) &&
341 !ui::IsCellOrTableHeaderRole(GetData().role))
342 return nullptr;
343
344 if (row < 0 || row >= GetTableRowCount() || column < 0 ||
345 column >= GetTableColumnCount()) {
346 return nullptr;
347 }
348
349 AXPlatformNodeBase* table = GetTable();
350 if (!table)
351 return nullptr;
352
353 // In contrast to unique cell IDs, these are duplicated whenever a cell spans
354 // multiple columns or rows.
355 const std::vector<int32_t>& cell_ids =
356 table->GetIntListAttribute(ui::AX_ATTR_CELL_IDS);
357 DCHECK_EQ(GetTableRowCount() * GetTableColumnCount(),
358 static_cast<int>(cell_ids.size()));
359 int position = row * GetTableColumnCount() + column;
360 if (position < 0 || position >= static_cast<int>(cell_ids.size()))
361 return nullptr;
362
363 return static_cast<AXPlatformNodeBase*>(
364 table->delegate_->GetFromNodeID(cell_ids[position]));
365 }
366
367 int AXPlatformNodeBase::GetTableCellIndex() const {
368 if (!ui::IsCellOrTableHeaderRole(GetData().role))
369 return -1;
370
371 AXPlatformNodeBase* table = GetTable();
372 if (!table)
373 return -1;
374
375 const std::vector<int32_t>& unique_cell_ids =
376 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS);
377 auto iter =
378 std::find(unique_cell_ids.begin(), unique_cell_ids.end(), GetData().id);
379 if (iter == unique_cell_ids.end())
380 return -1;
381
382 return std::distance(unique_cell_ids.begin(), iter);
383 }
384
385 int AXPlatformNodeBase::GetTableColumn() const {
386 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX);
387 }
388
389 int AXPlatformNodeBase::GetTableColumnCount() const {
390 AXPlatformNodeBase* table = GetTable();
391 if (!table)
392 return 0;
393
394 return table->GetIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT);
395 }
396
397 int AXPlatformNodeBase::GetTableColumnSpan() const {
398 if (!ui::IsCellOrTableHeaderRole(GetData().role))
399 return 0;
400
401 int column_span;
402 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &column_span))
403 return column_span;
404 return 1;
405 }
406
407 int AXPlatformNodeBase::GetTableRow() const {
408 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX);
409 }
410
411 int AXPlatformNodeBase::GetTableRowCount() const {
412 AXPlatformNodeBase* table = GetTable();
413 if (!table)
414 return 0;
415
416 return table->GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT);
417 }
418
419 int AXPlatformNodeBase::GetTableRowSpan() const {
420 if (!ui::IsCellOrTableHeaderRole(GetData().role))
421 return 0;
422
423 int row_span;
424 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span))
425 return row_span;
426 return 1;
427 }
428
291 } // namespace ui 429 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_base.h ('k') | ui/accessibility/platform/ax_platform_node_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698