Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_android.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 InitSearchKeyToPredicateMapIfNeeded(); | 110 InitSearchKeyToPredicateMapIfNeeded(); |
| 111 const auto& iter = g_search_key_to_predicate_map.Get().find(element_type); | 111 const auto& iter = g_search_key_to_predicate_map.Get().find(element_type); |
| 112 if (iter != g_search_key_to_predicate_map.Get().end()) | 112 if (iter != g_search_key_to_predicate_map.Get().end()) |
| 113 return iter->second; | 113 return iter->second; |
| 114 | 114 |
| 115 // If we don't recognize the selector, return any element that a | 115 // If we don't recognize the selector, return any element that a |
| 116 // screen reader should navigate to. | 116 // screen reader should navigate to. |
| 117 return AllInterestingNodesPredicate; | 117 return AllInterestingNodesPredicate; |
| 118 } | 118 } |
| 119 | 119 |
| 120 static int32_t potential_popup_unique_id_ = -1; | |
| 121 static int32_t current_unique_id_ = -1; | |
| 122 static BrowserAccessibility* popup_node_ = nullptr; | |
| 123 static ui::AXNode* popup_node_ax_node_ = nullptr; | |
| 124 | |
| 120 } // anonymous namespace | 125 } // anonymous namespace |
| 121 | 126 |
| 122 namespace aria_strings { | 127 namespace aria_strings { |
| 123 const char kAriaLivePolite[] = "polite"; | 128 const char kAriaLivePolite[] = "polite"; |
| 124 const char kAriaLiveAssertive[] = "assertive"; | 129 const char kAriaLiveAssertive[] = "assertive"; |
| 125 } | 130 } |
| 126 | 131 |
| 127 // static | 132 // static |
| 128 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( | 133 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( |
| 129 const ui::AXTreeUpdate& initial_tree, | 134 const ui::AXTreeUpdate& initial_tree, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 } | 325 } |
| 321 | 326 |
| 322 base::android::ScopedJavaLocalRef<jstring> | 327 base::android::ScopedJavaLocalRef<jstring> |
| 323 BrowserAccessibilityManagerAndroid::GetSupportedHtmlElementTypes( | 328 BrowserAccessibilityManagerAndroid::GetSupportedHtmlElementTypes( |
| 324 JNIEnv* env, | 329 JNIEnv* env, |
| 325 const JavaParamRef<jobject>& obj) { | 330 const JavaParamRef<jobject>& obj) { |
| 326 InitSearchKeyToPredicateMapIfNeeded(); | 331 InitSearchKeyToPredicateMapIfNeeded(); |
| 327 return base::android::ConvertUTF16ToJavaString(env, g_all_search_keys.Get()); | 332 return base::android::ConvertUTF16ToJavaString(env, g_all_search_keys.Get()); |
| 328 } | 333 } |
| 329 | 334 |
| 335 void BrowserAccessibilityManagerAndroid::OnAutofillPopupDisplayed( | |
| 336 JNIEnv* env, | |
| 337 const JavaParamRef<jobject>& obj) { | |
| 338 if (popup_node_) { | |
| 339 LOG(INFO) << "BrowserAccessibilityManagerAndroid::OnAutofillPopupDisplayed " | |
| 340 "popup_node_->unique_id()=" | |
| 341 << popup_node_->unique_id(); | |
| 342 } else { | |
| 343 popup_node_ = BrowserAccessibility::Create(); | |
|
dmazzoni
2017/03/22 16:13:54
Maybe this should be called popup_dialog_proxy_nod
csashi
2017/03/24 01:32:23
Done.
| |
| 344 popup_node_ax_node_ = new ui::AXNode(nullptr, -1, -1); | |
| 345 ui::AXNodeData ax_node_data; | |
| 346 ax_node_data.role = ui::AX_ROLE_MENU; | |
| 347 ax_node_data.SetName("Autofill"); | |
| 348 ax_node_data.state = 0; | |
| 349 ax_node_data.state |= 1 << ui::AX_STATE_READ_ONLY; | |
| 350 ax_node_data.state |= 1 << ui::AX_STATE_FOCUSABLE; | |
| 351 ax_node_data.state |= 1 << ui::AX_STATE_SELECTABLE; | |
| 352 popup_node_ax_node_->SetData(ax_node_data); | |
| 353 popup_node_->Init(this, popup_node_ax_node_); | |
| 354 } | |
| 355 LOG(INFO) << "current_unique_id_=" << current_unique_id_ | |
| 356 << ", popup_node_->unique_id()=" << popup_node_->unique_id(); | |
| 357 potential_popup_unique_id_ = current_unique_id_; | |
|
dmazzoni
2017/03/22 16:13:54
To clarify, is "potential popup" the node that's t
csashi
2017/03/24 01:32:23
Done.
| |
| 358 } | |
| 359 void BrowserAccessibilityManagerAndroid::OnAutofillPopupDismissed( | |
| 360 JNIEnv* env, | |
| 361 const JavaParamRef<jobject>& obj) { | |
| 362 if (potential_popup_unique_id_ != -1) { | |
| 363 LOG(INFO) << "Clearing potential_popup_unique_id_=" | |
| 364 << potential_popup_unique_id_; | |
| 365 potential_popup_unique_id_ = -1; | |
| 366 } | |
| 367 if (popup_node_) { | |
| 368 popup_node_->Destroy(); | |
| 369 delete popup_node_ax_node_; | |
| 370 popup_node_ = nullptr; | |
| 371 } | |
| 372 } | |
| 330 jint BrowserAccessibilityManagerAndroid::GetRootId( | 373 jint BrowserAccessibilityManagerAndroid::GetRootId( |
| 331 JNIEnv* env, | 374 JNIEnv* env, |
| 332 const JavaParamRef<jobject>& obj) { | 375 const JavaParamRef<jobject>& obj) { |
| 333 if (GetRoot()) | 376 if (GetRoot()) |
| 334 return static_cast<jint>(GetRoot()->unique_id()); | 377 return static_cast<jint>(GetRoot()->unique_id()); |
| 335 else | 378 else |
| 336 return -1; | 379 return -1; |
| 337 } | 380 } |
| 338 | 381 |
| 339 jboolean BrowserAccessibilityManagerAndroid::IsNodeValid( | 382 jboolean BrowserAccessibilityManagerAndroid::IsNodeValid( |
| 340 JNIEnv* env, | 383 JNIEnv* env, |
| 341 const JavaParamRef<jobject>& obj, | 384 const JavaParamRef<jobject>& obj, |
| 342 jint id) { | 385 jint id) { |
| 343 return GetFromUniqueID(id) != NULL; | 386 return GetFromUniqueID(id) != NULL || |
| 387 (popup_node_ && id == popup_node_->unique_id()); | |
| 344 } | 388 } |
| 345 | 389 |
| 346 void BrowserAccessibilityManagerAndroid::HitTest( | 390 void BrowserAccessibilityManagerAndroid::HitTest( |
| 347 JNIEnv* env, | 391 JNIEnv* env, |
| 348 const JavaParamRef<jobject>& obj, | 392 const JavaParamRef<jobject>& obj, |
| 349 jint x, | 393 jint x, |
| 350 jint y) { | 394 jint y) { |
| 351 BrowserAccessibilityManager::HitTest(gfx::Point(x, y)); | 395 BrowserAccessibilityManager::HitTest(gfx::Point(x, y)); |
| 352 } | 396 } |
| 353 | 397 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 return true; | 555 return true; |
| 512 } | 556 } |
| 513 | 557 |
| 514 jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityEvent( | 558 jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityEvent( |
| 515 JNIEnv* env, | 559 JNIEnv* env, |
| 516 const JavaParamRef<jobject>& obj, | 560 const JavaParamRef<jobject>& obj, |
| 517 const JavaParamRef<jobject>& event, | 561 const JavaParamRef<jobject>& event, |
| 518 jint id, | 562 jint id, |
| 519 jint event_type) { | 563 jint event_type) { |
| 520 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); | 564 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 565 LOG(INFO) | |
| 566 << "BrowserAccessibilityManagerAndroid::PopulateAccessibilityEvent id=" | |
| 567 << id << ", event_type=" << event_type | |
| 568 << ", node->unique_id()=" << (node ? node->unique_id() : -1) | |
| 569 << ", node->GetId()=" << (node ? node->GetId() : -1) | |
| 570 << ", node->node()->id()=" << (node ? node->node()->id() : -1); | |
| 521 if (!node) | 571 if (!node) |
| 522 return false; | 572 return false; |
| 523 | 573 |
| 524 Java_BrowserAccessibilityManager_setAccessibilityEventBooleanAttributes( | 574 Java_BrowserAccessibilityManager_setAccessibilityEventBooleanAttributes( |
| 525 env, obj, event, | 575 env, obj, event, |
| 526 node->IsChecked(), | 576 node->IsChecked(), |
| 527 node->IsEnabled(), | 577 node->IsEnabled(), |
| 528 node->IsPassword(), | 578 node->IsPassword(), |
| 529 node->IsScrollable()); | 579 node->IsScrollable()); |
| 530 Java_BrowserAccessibilityManager_setAccessibilityEventClassName( | 580 Java_BrowserAccessibilityManager_setAccessibilityEventClassName( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 node->RangeCurrentValue()); | 650 node->RangeCurrentValue()); |
| 601 } | 651 } |
| 602 | 652 |
| 603 return true; | 653 return true; |
| 604 } | 654 } |
| 605 | 655 |
| 606 void BrowserAccessibilityManagerAndroid::Click(JNIEnv* env, | 656 void BrowserAccessibilityManagerAndroid::Click(JNIEnv* env, |
| 607 const JavaParamRef<jobject>& obj, | 657 const JavaParamRef<jobject>& obj, |
| 608 jint id) { | 658 jint id) { |
| 609 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); | 659 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 660 LOG(INFO) << "BrowserAccessibilityManagerAndroid::Click id=" << id | |
| 661 << ", node->unique_id()=" << (node ? node->unique_id() : -1) | |
| 662 << ", node->GetId()=" << (node ? node->GetId() : -1) | |
| 663 << ", node->node()->id()=" << (node ? node->node()->id() : -1); | |
| 610 if (node) | 664 if (node) |
| 611 node->manager()->DoDefaultAction(*node); | 665 node->manager()->DoDefaultAction(*node); |
| 612 } | 666 } |
| 613 | 667 |
| 614 void BrowserAccessibilityManagerAndroid::Focus(JNIEnv* env, | 668 void BrowserAccessibilityManagerAndroid::Focus(JNIEnv* env, |
| 615 const JavaParamRef<jobject>& obj, | 669 const JavaParamRef<jobject>& obj, |
| 616 jint id) { | 670 jint id) { |
| 617 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); | 671 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 618 if (node) | 672 if (node) |
| 619 node->manager()->SetFocus(*node); | 673 node->manager()->SetFocus(*node); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 env, obj, android_node->unique_id()); | 790 env, obj, android_node->unique_id()); |
| 737 } | 791 } |
| 738 } | 792 } |
| 739 | 793 |
| 740 jint BrowserAccessibilityManagerAndroid::FindElementType( | 794 jint BrowserAccessibilityManagerAndroid::FindElementType( |
| 741 JNIEnv* env, | 795 JNIEnv* env, |
| 742 const JavaParamRef<jobject>& obj, | 796 const JavaParamRef<jobject>& obj, |
| 743 jint start_id, | 797 jint start_id, |
| 744 const JavaParamRef<jstring>& element_type_str, | 798 const JavaParamRef<jstring>& element_type_str, |
| 745 jboolean forwards) { | 799 jboolean forwards) { |
| 800 if (start_id == potential_popup_unique_id_) { | |
| 801 LOG(INFO) << "FindElementType start_id=" << start_id | |
| 802 << ", popup_node_->unique_id()=" << popup_node_->unique_id(); | |
| 803 return popup_node_->unique_id(); | |
| 804 } | |
| 805 if (popup_node_ && start_id == popup_node_->unique_id()) { | |
| 806 LOG(INFO) << "FindElementType start_id=" << start_id | |
| 807 << ", popup_node_->unique_id()=" << popup_node_->unique_id() | |
| 808 << ", potential_popup_unique_id_ = " | |
| 809 << potential_popup_unique_id_; | |
| 810 start_id = potential_popup_unique_id_; | |
| 811 } | |
| 746 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); | 812 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); |
| 747 if (!start_node) | 813 if (!start_node) |
| 748 return 0; | 814 return 0; |
| 749 | 815 |
| 750 BrowserAccessibilityManager* root_manager = GetRootManager(); | 816 BrowserAccessibilityManager* root_manager = GetRootManager(); |
| 751 if (!root_manager) | 817 if (!root_manager) |
| 752 return 0; | 818 return 0; |
| 753 | 819 |
| 754 BrowserAccessibility* root = root_manager->GetRoot(); | 820 BrowserAccessibility* root = root_manager->GetRoot(); |
| 755 if (!root) | 821 if (!root) |
| 756 return 0; | 822 return 0; |
| 757 | 823 |
| 758 AccessibilityMatchPredicate predicate = PredicateForSearchKey( | 824 AccessibilityMatchPredicate predicate = PredicateForSearchKey( |
| 759 base::android::ConvertJavaStringToUTF16(env, element_type_str)); | 825 base::android::ConvertJavaStringToUTF16(env, element_type_str)); |
| 760 | 826 |
| 761 OneShotAccessibilityTreeSearch tree_search(root); | 827 OneShotAccessibilityTreeSearch tree_search(root); |
| 762 tree_search.SetStartNode(start_node); | 828 tree_search.SetStartNode(start_node); |
| 763 tree_search.SetDirection( | 829 tree_search.SetDirection( |
| 764 forwards ? | 830 forwards ? |
| 765 OneShotAccessibilityTreeSearch::FORWARDS : | 831 OneShotAccessibilityTreeSearch::FORWARDS : |
| 766 OneShotAccessibilityTreeSearch::BACKWARDS); | 832 OneShotAccessibilityTreeSearch::BACKWARDS); |
| 767 tree_search.SetResultLimit(1); | 833 tree_search.SetResultLimit(1); |
| 768 tree_search.SetImmediateDescendantsOnly(false); | 834 tree_search.SetImmediateDescendantsOnly(false); |
| 769 tree_search.SetVisibleOnly(false); | 835 tree_search.SetVisibleOnly(false); |
| 770 tree_search.AddPredicate(predicate); | 836 tree_search.AddPredicate(predicate); |
| 771 | 837 |
| 772 if (tree_search.CountMatches() == 0) | 838 if (tree_search.CountMatches() == 0) |
| 773 return 0; | 839 return 0; |
| 774 | 840 |
| 775 return tree_search.GetMatchAtIndex(0)->unique_id(); | 841 jint return_id = tree_search.GetMatchAtIndex(0)->unique_id(); |
| 842 current_unique_id_ = return_id; | |
| 843 return return_id; | |
| 776 } | 844 } |
| 777 | 845 |
| 778 jboolean BrowserAccessibilityManagerAndroid::NextAtGranularity( | 846 jboolean BrowserAccessibilityManagerAndroid::NextAtGranularity( |
| 779 JNIEnv* env, | 847 JNIEnv* env, |
| 780 const JavaParamRef<jobject>& obj, | 848 const JavaParamRef<jobject>& obj, |
| 781 jint granularity, | 849 jint granularity, |
| 782 jboolean extend_selection, | 850 jboolean extend_selection, |
| 783 jint id, | 851 jint id, |
| 784 jint cursor_index) { | 852 jint cursor_index) { |
| 785 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); | 853 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 911 } | 979 } |
| 912 | 980 |
| 913 return true; | 981 return true; |
| 914 } | 982 } |
| 915 | 983 |
| 916 void BrowserAccessibilityManagerAndroid::SetAccessibilityFocus( | 984 void BrowserAccessibilityManagerAndroid::SetAccessibilityFocus( |
| 917 JNIEnv* env, | 985 JNIEnv* env, |
| 918 const JavaParamRef<jobject>& obj, | 986 const JavaParamRef<jobject>& obj, |
| 919 jint id) { | 987 jint id) { |
| 920 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); | 988 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 989 LOG(INFO) << "BrowserAccessibilityManagerAndroid::SetAccessibilityFocus id=" | |
| 990 << id << ", node->unique_id()=" << (node ? node->unique_id() : -1) | |
| 991 << ", node->GetId()=" << (node ? node->GetId() : -1) | |
| 992 << ", node->node()->id()=" << (node ? node->node()->id() : -1); | |
| 921 if (!node) | 993 if (!node) |
| 922 return; | 994 return; |
| 923 | 995 |
| 924 node->manager()->SetAccessibilityFocus(*node); | 996 node->manager()->SetAccessibilityFocus(*node); |
| 925 } | 997 } |
| 926 | 998 |
| 927 bool BrowserAccessibilityManagerAndroid::IsSlider( | 999 bool BrowserAccessibilityManagerAndroid::IsSlider( |
| 928 JNIEnv* env, | 1000 JNIEnv* env, |
| 929 const JavaParamRef<jobject>& obj, | 1001 const JavaParamRef<jobject>& obj, |
| 930 jint id) { | 1002 jint id) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 | 1058 |
| 987 JNIEnv* env = AttachCurrentThread(); | 1059 JNIEnv* env = AttachCurrentThread(); |
| 988 return root_manager->java_ref().get(env); | 1060 return root_manager->java_ref().get(env); |
| 989 } | 1061 } |
| 990 | 1062 |
| 991 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 1063 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
| 992 return RegisterNativesImpl(env); | 1064 return RegisterNativesImpl(env); |
| 993 } | 1065 } |
| 994 | 1066 |
| 995 } // namespace content | 1067 } // namespace content |
| OLD | NEW |