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

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager.cc

Issue 2410333005: Create AXAction and AXActionData as a way to simplify accessibility actions (Closed)
Patch Set: Fix Android compile Created 4 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility_manager.h" 5 #include "content/browser/accessibility/browser_accessibility_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 BrowserAccessibility* obj = GetFromID(hit_obj_id); 452 BrowserAccessibility* obj = GetFromID(hit_obj_id);
453 if (!obj || !obj->HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) 453 if (!obj || !obj->HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID))
454 return; 454 return;
455 455
456 BrowserAccessibilityManager* child_manager = 456 BrowserAccessibilityManager* child_manager =
457 BrowserAccessibilityManager::FromID( 457 BrowserAccessibilityManager::FromID(
458 obj->GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); 458 obj->GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID));
459 if (!child_manager || !child_manager->delegate()) 459 if (!child_manager || !child_manager->delegate())
460 return; 460 return;
461 461
462 return child_manager->delegate()->AccessibilityHitTest(point); 462 ui::AXActionData action_data;
463 action_data.target_point = point;
464 return child_manager->delegate()->AccessibilityPerformAction(
465 ui::AX_ACTION_HIT_TEST, action_data);
463 } 466 }
464 467
465 void BrowserAccessibilityManager::ActivateFindInPageResult( 468 void BrowserAccessibilityManager::ActivateFindInPageResult(
466 int request_id) { 469 int request_id) {
467 find_in_page_info_.active_request_id = request_id; 470 find_in_page_info_.active_request_id = request_id;
468 if (find_in_page_info_.request_id != request_id) 471 if (find_in_page_info_.request_id != request_id)
469 return; 472 return;
470 473
471 BrowserAccessibility* node = GetFromID(find_in_page_info_.start_id); 474 BrowserAccessibility* node = GetFromID(find_in_page_info_.start_id);
472 if (!node) 475 if (!node)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 BrowserAccessibilityManager::FromID( 553 BrowserAccessibilityManager::FromID(
551 obj->GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); 554 obj->GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID));
552 if (child_manager) 555 if (child_manager)
553 return child_manager->GetFocusFromThisOrDescendantFrame(); 556 return child_manager->GetFocusFromThisOrDescendantFrame();
554 } 557 }
555 558
556 return obj; 559 return obj;
557 } 560 }
558 561
559 void BrowserAccessibilityManager::SetFocus(const BrowserAccessibility& node) { 562 void BrowserAccessibilityManager::SetFocus(const BrowserAccessibility& node) {
560 if (delegate_) 563 if (!delegate_)
561 delegate_->AccessibilitySetFocus(node.GetId()); 564 return;
565
566 ui::AXActionData action_data;
567 action_data.target_node_id = node.GetId();
568 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SET_FOCUS, action_data);
562 } 569 }
563 570
564 void BrowserAccessibilityManager::SetFocusLocallyForTesting( 571 void BrowserAccessibilityManager::SetFocusLocallyForTesting(
565 BrowserAccessibility* node) { 572 BrowserAccessibility* node) {
566 ui::AXTreeData data = GetTreeData(); 573 ui::AXTreeData data = GetTreeData();
567 data.focus_id = node->GetId(); 574 data.focus_id = node->GetId();
568 tree_->UpdateData(data); 575 tree_->UpdateData(data);
569 } 576 }
570 577
571 // static 578 // static
572 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting( 579 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting(
573 const base::Closure& callback) { 580 const base::Closure& callback) {
574 g_focus_change_callback_for_testing.Get() = callback; 581 g_focus_change_callback_for_testing.Get() = callback;
575 } 582 }
576 583
577 void BrowserAccessibilityManager::DoDefaultAction( 584 void BrowserAccessibilityManager::DoDefaultAction(
578 const BrowserAccessibility& node) { 585 const BrowserAccessibility& node) {
579 if (delegate_) 586 if (!delegate_)
580 delegate_->AccessibilityDoDefaultAction(node.GetId()); 587 return;
588
589 ui::AXActionData action_data;
590 action_data.target_node_id = node.GetId();
591 delegate_->AccessibilityPerformAction(ui::AX_ACTION_DO_DEFAULT, action_data);
592 }
593
594 void BrowserAccessibilityManager::ShowContextMenu(
595 const BrowserAccessibility& node) {
596 if (!delegate_)
597 return;
598
599 ui::AXActionData action_data;
600 action_data.target_node_id = node.GetId();
601 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SHOW_CONTEXT_MENU,
602 action_data);
581 } 603 }
582 604
583 void BrowserAccessibilityManager::ScrollToMakeVisible( 605 void BrowserAccessibilityManager::ScrollToMakeVisible(
584 const BrowserAccessibility& node, gfx::Rect subfocus) { 606 const BrowserAccessibility& node, gfx::Rect subfocus) {
585 if (delegate_) { 607 if (!delegate_)
586 delegate_->AccessibilityScrollToMakeVisible(node.GetId(), subfocus); 608 return;
587 } 609
610 ui::AXActionData action_data;
611 action_data.target_node_id = node.GetId();
612 action_data.target_rect = subfocus;
613 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SCROLL_TO_MAKE_VISIBLE,
614 action_data);
588 } 615 }
589 616
590 void BrowserAccessibilityManager::ScrollToPoint( 617 void BrowserAccessibilityManager::ScrollToPoint(
591 const BrowserAccessibility& node, gfx::Point point) { 618 const BrowserAccessibility& node, gfx::Point point) {
592 if (delegate_) { 619 if (!delegate_)
593 delegate_->AccessibilityScrollToPoint(node.GetId(), point); 620 return;
594 } 621
622 ui::AXActionData action_data;
623 action_data.target_node_id = node.GetId();
624 action_data.target_point = point;
625 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SCROLL_TO_POINT,
626 action_data);
595 } 627 }
596 628
597 void BrowserAccessibilityManager::SetScrollOffset( 629 void BrowserAccessibilityManager::SetScrollOffset(
598 const BrowserAccessibility& node, gfx::Point offset) { 630 const BrowserAccessibility& node, gfx::Point offset) {
599 if (delegate_) { 631 if (!delegate_)
600 delegate_->AccessibilitySetScrollOffset(node.GetId(), offset); 632 return;
601 } 633
634 ui::AXActionData action_data;
635 action_data.target_node_id = node.GetId();
636 action_data.target_point = offset;
637 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SET_SCROLL_OFFSET,
638 action_data);
602 } 639 }
603 640
604 void BrowserAccessibilityManager::SetValue( 641 void BrowserAccessibilityManager::SetValue(
605 const BrowserAccessibility& node, 642 const BrowserAccessibility& node,
606 const base::string16& value) { 643 const base::string16& value) {
607 if (delegate_) 644 if (!delegate_)
608 delegate_->AccessibilitySetValue(node.GetId(), value); 645 return;
646
647 ui::AXActionData action_data;
648 action_data.target_node_id = node.GetId();
649 action_data.value = value;
650 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SET_VALUE, action_data);
609 } 651 }
610 652
611 void BrowserAccessibilityManager::SetTextSelection( 653 void BrowserAccessibilityManager::SetTextSelection(
612 const BrowserAccessibility& node, 654 const BrowserAccessibility& node,
613 int start_offset, 655 int start_offset,
614 int end_offset) { 656 int end_offset) {
615 if (delegate_) { 657 if (!delegate_)
616 delegate_->AccessibilitySetSelection(node.GetId(), start_offset, 658 return;
617 node.GetId(), end_offset); 659
618 } 660 ui::AXActionData action_data;
661 action_data.anchor_node_id = node.GetId();
662 action_data.anchor_offset = start_offset;
663 action_data.focus_node_id = node.GetId();
664 action_data.focus_offset = end_offset;
665 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SET_SELECTION,
666 action_data);
667 }
668
669 void BrowserAccessibilityManager::SetAccessibilityFocus(
670 const BrowserAccessibility& node) {
671 if (!delegate_)
672 return;
673
674 ui::AXActionData action_data;
675 action_data.target_node_id = node.GetId();
676 delegate_->AccessibilityPerformAction(ui::AX_ACTION_SET_ACCESSIBILITY_FOCUS,
677 action_data);
678 }
679
680 void BrowserAccessibilityManager::HitTest(const gfx::Point& point) {
681 if (!delegate_)
682 return;
683
684 ui::AXActionData action_data;
685 action_data.target_point = point;
686 delegate_->AccessibilityPerformAction(ui::AX_ACTION_HIT_TEST, action_data);
619 } 687 }
620 688
621 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { 689 gfx::Rect BrowserAccessibilityManager::GetViewBounds() {
622 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager(); 690 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager();
623 if (delegate) 691 if (delegate)
624 return delegate->AccessibilityGetViewBounds(); 692 return delegate->AccessibilityGetViewBounds();
625 return gfx::Rect(); 693 return gfx::Rect();
626 } 694 }
627 695
628 // static 696 // static
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 1163
1096 BrowserAccessibility* BrowserAccessibilityManager::CachingAsyncHitTest( 1164 BrowserAccessibility* BrowserAccessibilityManager::CachingAsyncHitTest(
1097 const gfx::Point& screen_point) { 1165 const gfx::Point& screen_point) {
1098 BrowserAccessibilityManager* root_manager = GetRootManager(); 1166 BrowserAccessibilityManager* root_manager = GetRootManager();
1099 if (root_manager && root_manager != this) 1167 if (root_manager && root_manager != this)
1100 return root_manager->CachingAsyncHitTest(screen_point); 1168 return root_manager->CachingAsyncHitTest(screen_point);
1101 1169
1102 if (delegate()) { 1170 if (delegate()) {
1103 // This triggers an asynchronous request to compute the true object that's 1171 // This triggers an asynchronous request to compute the true object that's
1104 // under |screen_point|. 1172 // under |screen_point|.
1105 gfx::Point local_point = screen_point - GetViewBounds().OffsetFromOrigin(); 1173 HitTest(screen_point - GetViewBounds().OffsetFromOrigin());
1106 delegate()->AccessibilityHitTest(local_point);
1107 1174
1108 // Unfortunately we still have to return an answer synchronously because 1175 // Unfortunately we still have to return an answer synchronously because
1109 // the APIs were designed that way. The best case scenario is that the 1176 // the APIs were designed that way. The best case scenario is that the
1110 // screen point is within the bounds of the last result we got from a 1177 // screen point is within the bounds of the last result we got from a
1111 // call to AccessibilityHitTest - in that case, we can return that object! 1178 // call to AccessibilityHitTest - in that case, we can return that object!
1112 if (last_hover_bounds_.Contains(screen_point)) { 1179 if (last_hover_bounds_.Contains(screen_point)) {
1113 BrowserAccessibilityManager* manager = 1180 BrowserAccessibilityManager* manager =
1114 BrowserAccessibilityManager::FromID(last_hover_ax_tree_id_); 1181 BrowserAccessibilityManager::FromID(last_hover_ax_tree_id_);
1115 if (manager) { 1182 if (manager) {
1116 BrowserAccessibility* node = manager->GetFromID(last_hover_node_id_); 1183 BrowserAccessibility* node = manager->GetFromID(last_hover_node_id_);
(...skipping 22 matching lines...) Expand all
1139 hit_test_result = parent; 1206 hit_test_result = parent;
1140 parent = parent->GetParent(); 1207 parent = parent->GetParent();
1141 } 1208 }
1142 1209
1143 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); 1210 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id();
1144 last_hover_node_id_ = hit_test_result->GetId(); 1211 last_hover_node_id_ = hit_test_result->GetId();
1145 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); 1212 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect();
1146 } 1213 }
1147 1214
1148 } // namespace content 1215 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698