| OLD | NEW |
| 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 Loading... |
| 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 action_data.action = ui::AX_ACTION_HIT_TEST; |
| 465 return child_manager->delegate()->AccessibilityPerformAction(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 Loading... |
| 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.action = ui::AX_ACTION_SET_FOCUS; |
| 568 action_data.target_node_id = node.GetId(); |
| 569 delegate_->AccessibilityPerformAction(action_data); |
| 562 } | 570 } |
| 563 | 571 |
| 564 void BrowserAccessibilityManager::SetFocusLocallyForTesting( | 572 void BrowserAccessibilityManager::SetFocusLocallyForTesting( |
| 565 BrowserAccessibility* node) { | 573 BrowserAccessibility* node) { |
| 566 ui::AXTreeData data = GetTreeData(); | 574 ui::AXTreeData data = GetTreeData(); |
| 567 data.focus_id = node->GetId(); | 575 data.focus_id = node->GetId(); |
| 568 tree_->UpdateData(data); | 576 tree_->UpdateData(data); |
| 569 } | 577 } |
| 570 | 578 |
| 571 // static | 579 // static |
| 572 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting( | 580 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting( |
| 573 const base::Closure& callback) { | 581 const base::Closure& callback) { |
| 574 g_focus_change_callback_for_testing.Get() = callback; | 582 g_focus_change_callback_for_testing.Get() = callback; |
| 575 } | 583 } |
| 576 | 584 |
| 577 void BrowserAccessibilityManager::DoDefaultAction( | 585 void BrowserAccessibilityManager::DoDefaultAction( |
| 578 const BrowserAccessibility& node) { | 586 const BrowserAccessibility& node) { |
| 579 if (delegate_) | 587 if (!delegate_) |
| 580 delegate_->AccessibilityDoDefaultAction(node.GetId()); | 588 return; |
| 589 |
| 590 ui::AXActionData action_data; |
| 591 action_data.action = ui::AX_ACTION_DO_DEFAULT; |
| 592 action_data.target_node_id = node.GetId(); |
| 593 delegate_->AccessibilityPerformAction(action_data); |
| 594 } |
| 595 |
| 596 void BrowserAccessibilityManager::ShowContextMenu( |
| 597 const BrowserAccessibility& node) { |
| 598 if (!delegate_) |
| 599 return; |
| 600 |
| 601 ui::AXActionData action_data; |
| 602 action_data.action = ui::AX_ACTION_SHOW_CONTEXT_MENU; |
| 603 action_data.target_node_id = node.GetId(); |
| 604 delegate_->AccessibilityPerformAction(action_data); |
| 581 } | 605 } |
| 582 | 606 |
| 583 void BrowserAccessibilityManager::ScrollToMakeVisible( | 607 void BrowserAccessibilityManager::ScrollToMakeVisible( |
| 584 const BrowserAccessibility& node, gfx::Rect subfocus) { | 608 const BrowserAccessibility& node, gfx::Rect subfocus) { |
| 585 if (delegate_) { | 609 if (!delegate_) |
| 586 delegate_->AccessibilityScrollToMakeVisible(node.GetId(), subfocus); | 610 return; |
| 587 } | 611 |
| 612 ui::AXActionData action_data; |
| 613 action_data.target_node_id = node.GetId(); |
| 614 action_data.action = ui::AX_ACTION_SCROLL_TO_MAKE_VISIBLE; |
| 615 action_data.target_rect = subfocus; |
| 616 delegate_->AccessibilityPerformAction(action_data); |
| 588 } | 617 } |
| 589 | 618 |
| 590 void BrowserAccessibilityManager::ScrollToPoint( | 619 void BrowserAccessibilityManager::ScrollToPoint( |
| 591 const BrowserAccessibility& node, gfx::Point point) { | 620 const BrowserAccessibility& node, gfx::Point point) { |
| 592 if (delegate_) { | 621 if (!delegate_) |
| 593 delegate_->AccessibilityScrollToPoint(node.GetId(), point); | 622 return; |
| 594 } | 623 |
| 624 ui::AXActionData action_data; |
| 625 action_data.target_node_id = node.GetId(); |
| 626 action_data.action = ui::AX_ACTION_SCROLL_TO_POINT; |
| 627 action_data.target_point = point; |
| 628 delegate_->AccessibilityPerformAction(action_data); |
| 595 } | 629 } |
| 596 | 630 |
| 597 void BrowserAccessibilityManager::SetScrollOffset( | 631 void BrowserAccessibilityManager::SetScrollOffset( |
| 598 const BrowserAccessibility& node, gfx::Point offset) { | 632 const BrowserAccessibility& node, gfx::Point offset) { |
| 599 if (delegate_) { | 633 if (!delegate_) |
| 600 delegate_->AccessibilitySetScrollOffset(node.GetId(), offset); | 634 return; |
| 601 } | 635 |
| 636 ui::AXActionData action_data; |
| 637 action_data.target_node_id = node.GetId(); |
| 638 action_data.action = ui::AX_ACTION_SET_SCROLL_OFFSET; |
| 639 action_data.target_point = offset; |
| 640 delegate_->AccessibilityPerformAction(action_data); |
| 602 } | 641 } |
| 603 | 642 |
| 604 void BrowserAccessibilityManager::SetValue( | 643 void BrowserAccessibilityManager::SetValue( |
| 605 const BrowserAccessibility& node, | 644 const BrowserAccessibility& node, |
| 606 const base::string16& value) { | 645 const base::string16& value) { |
| 607 if (delegate_) | 646 if (!delegate_) |
| 608 delegate_->AccessibilitySetValue(node.GetId(), value); | 647 return; |
| 648 |
| 649 ui::AXActionData action_data; |
| 650 action_data.target_node_id = node.GetId(); |
| 651 action_data.action = ui::AX_ACTION_SET_VALUE; |
| 652 action_data.value = value; |
| 653 delegate_->AccessibilityPerformAction(action_data); |
| 609 } | 654 } |
| 610 | 655 |
| 611 void BrowserAccessibilityManager::SetTextSelection( | 656 void BrowserAccessibilityManager::SetTextSelection( |
| 612 const BrowserAccessibility& node, | 657 const BrowserAccessibility& node, |
| 613 int start_offset, | 658 int start_offset, |
| 614 int end_offset) { | 659 int end_offset) { |
| 615 if (delegate_) { | 660 if (!delegate_) |
| 616 delegate_->AccessibilitySetSelection(node.GetId(), start_offset, | 661 return; |
| 617 node.GetId(), end_offset); | 662 |
| 618 } | 663 ui::AXActionData action_data; |
| 664 action_data.anchor_node_id = node.GetId(); |
| 665 action_data.anchor_offset = start_offset; |
| 666 action_data.focus_node_id = node.GetId(); |
| 667 action_data.focus_offset = end_offset; |
| 668 action_data.action = ui::AX_ACTION_SET_SELECTION; |
| 669 delegate_->AccessibilityPerformAction(action_data); |
| 670 } |
| 671 |
| 672 void BrowserAccessibilityManager::SetAccessibilityFocus( |
| 673 const BrowserAccessibility& node) { |
| 674 if (!delegate_) |
| 675 return; |
| 676 |
| 677 ui::AXActionData action_data; |
| 678 action_data.action = ui::AX_ACTION_SET_ACCESSIBILITY_FOCUS; |
| 679 action_data.target_node_id = node.GetId(); |
| 680 delegate_->AccessibilityPerformAction(action_data); |
| 681 } |
| 682 |
| 683 void BrowserAccessibilityManager::HitTest(const gfx::Point& point) { |
| 684 if (!delegate_) |
| 685 return; |
| 686 |
| 687 ui::AXActionData action_data; |
| 688 action_data.action = ui::AX_ACTION_HIT_TEST; |
| 689 action_data.target_point = point; |
| 690 delegate_->AccessibilityPerformAction(action_data); |
| 619 } | 691 } |
| 620 | 692 |
| 621 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { | 693 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { |
| 622 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager(); | 694 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager(); |
| 623 if (delegate) | 695 if (delegate) |
| 624 return delegate->AccessibilityGetViewBounds(); | 696 return delegate->AccessibilityGetViewBounds(); |
| 625 return gfx::Rect(); | 697 return gfx::Rect(); |
| 626 } | 698 } |
| 627 | 699 |
| 628 // static | 700 // static |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 | 1167 |
| 1096 BrowserAccessibility* BrowserAccessibilityManager::CachingAsyncHitTest( | 1168 BrowserAccessibility* BrowserAccessibilityManager::CachingAsyncHitTest( |
| 1097 const gfx::Point& screen_point) { | 1169 const gfx::Point& screen_point) { |
| 1098 BrowserAccessibilityManager* root_manager = GetRootManager(); | 1170 BrowserAccessibilityManager* root_manager = GetRootManager(); |
| 1099 if (root_manager && root_manager != this) | 1171 if (root_manager && root_manager != this) |
| 1100 return root_manager->CachingAsyncHitTest(screen_point); | 1172 return root_manager->CachingAsyncHitTest(screen_point); |
| 1101 | 1173 |
| 1102 if (delegate()) { | 1174 if (delegate()) { |
| 1103 // This triggers an asynchronous request to compute the true object that's | 1175 // This triggers an asynchronous request to compute the true object that's |
| 1104 // under |screen_point|. | 1176 // under |screen_point|. |
| 1105 gfx::Point local_point = screen_point - GetViewBounds().OffsetFromOrigin(); | 1177 HitTest(screen_point - GetViewBounds().OffsetFromOrigin()); |
| 1106 delegate()->AccessibilityHitTest(local_point); | |
| 1107 | 1178 |
| 1108 // Unfortunately we still have to return an answer synchronously because | 1179 // Unfortunately we still have to return an answer synchronously because |
| 1109 // the APIs were designed that way. The best case scenario is that the | 1180 // 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 | 1181 // 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! | 1182 // call to AccessibilityHitTest - in that case, we can return that object! |
| 1112 if (last_hover_bounds_.Contains(screen_point)) { | 1183 if (last_hover_bounds_.Contains(screen_point)) { |
| 1113 BrowserAccessibilityManager* manager = | 1184 BrowserAccessibilityManager* manager = |
| 1114 BrowserAccessibilityManager::FromID(last_hover_ax_tree_id_); | 1185 BrowserAccessibilityManager::FromID(last_hover_ax_tree_id_); |
| 1115 if (manager) { | 1186 if (manager) { |
| 1116 BrowserAccessibility* node = manager->GetFromID(last_hover_node_id_); | 1187 BrowserAccessibility* node = manager->GetFromID(last_hover_node_id_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1139 hit_test_result = parent; | 1210 hit_test_result = parent; |
| 1140 parent = parent->GetParent(); | 1211 parent = parent->GetParent(); |
| 1141 } | 1212 } |
| 1142 | 1213 |
| 1143 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); | 1214 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); |
| 1144 last_hover_node_id_ = hit_test_result->GetId(); | 1215 last_hover_node_id_ = hit_test_result->GetId(); |
| 1145 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); | 1216 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); |
| 1146 } | 1217 } |
| 1147 | 1218 |
| 1148 } // namespace content | 1219 } // namespace content |
| OLD | NEW |