OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/web_contents_accessibility_android.h" | 5 #include "content/browser/accessibility/web_contents_accessibility_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 JNIEnv* env, | 557 JNIEnv* env, |
558 const JavaParamRef<jobject>& obj) { | 558 const JavaParamRef<jobject>& obj) { |
559 InitSearchKeyToPredicateMapIfNeeded(); | 559 InitSearchKeyToPredicateMapIfNeeded(); |
560 return base::android::ConvertUTF16ToJavaString(env, g_all_search_keys.Get()); | 560 return base::android::ConvertUTF16ToJavaString(env, g_all_search_keys.Get()); |
561 } | 561 } |
562 | 562 |
563 jint WebContentsAccessibilityAndroid::GetRootId( | 563 jint WebContentsAccessibilityAndroid::GetRootId( |
564 JNIEnv* env, | 564 JNIEnv* env, |
565 const JavaParamRef<jobject>& obj) { | 565 const JavaParamRef<jobject>& obj) { |
566 if (root_manager_) { | 566 if (root_manager_) { |
567 auto* root = root_manager_->GetRoot(); | 567 auto* root = |
| 568 static_cast<BrowserAccessibilityAndroid*>(root_manager_->GetRoot()); |
568 if (root) | 569 if (root) |
569 return static_cast<jint>(root->unique_id()); | 570 return static_cast<jint>(root->unique_id()); |
570 } | 571 } |
571 return -1; | 572 return -1; |
572 } | 573 } |
573 | 574 |
574 jboolean WebContentsAccessibilityAndroid::IsNodeValid( | 575 jboolean WebContentsAccessibilityAndroid::IsNodeValid( |
575 JNIEnv* env, | 576 JNIEnv* env, |
576 const JavaParamRef<jobject>& obj, | 577 const JavaParamRef<jobject>& obj, |
577 jint unique_id) { | 578 jint unique_id) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityNodeInfo( | 634 jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityNodeInfo( |
634 JNIEnv* env, | 635 JNIEnv* env, |
635 const JavaParamRef<jobject>& obj, | 636 const JavaParamRef<jobject>& obj, |
636 const JavaParamRef<jobject>& info, | 637 const JavaParamRef<jobject>& info, |
637 jint unique_id) { | 638 jint unique_id) { |
638 BrowserAccessibilityAndroid* node = GetAXFromUniqueID(unique_id); | 639 BrowserAccessibilityAndroid* node = GetAXFromUniqueID(unique_id); |
639 if (!node) | 640 if (!node) |
640 return false; | 641 return false; |
641 | 642 |
642 if (node->PlatformGetParent()) { | 643 if (node->PlatformGetParent()) { |
| 644 auto* android_node = |
| 645 static_cast<BrowserAccessibilityAndroid*>(node->PlatformGetParent()); |
643 Java_WebContentsAccessibility_setAccessibilityNodeInfoParent( | 646 Java_WebContentsAccessibility_setAccessibilityNodeInfoParent( |
644 env, obj, info, node->PlatformGetParent()->unique_id()); | 647 env, obj, info, android_node->unique_id()); |
645 } | 648 } |
646 for (unsigned i = 0; i < node->PlatformChildCount(); ++i) { | 649 for (unsigned i = 0; i < node->PlatformChildCount(); ++i) { |
| 650 auto* android_node = |
| 651 static_cast<BrowserAccessibilityAndroid*>(node->PlatformGetChild(i)); |
647 Java_WebContentsAccessibility_addAccessibilityNodeInfoChild( | 652 Java_WebContentsAccessibility_addAccessibilityNodeInfoChild( |
648 env, obj, info, node->PlatformGetChild(i)->unique_id()); | 653 env, obj, info, android_node->unique_id()); |
649 } | 654 } |
650 Java_WebContentsAccessibility_setAccessibilityNodeInfoBooleanAttributes( | 655 Java_WebContentsAccessibility_setAccessibilityNodeInfoBooleanAttributes( |
651 env, obj, info, unique_id, node->IsCheckable(), node->IsChecked(), | 656 env, obj, info, unique_id, node->IsCheckable(), node->IsChecked(), |
652 node->IsClickable(), node->IsEnabled(), node->IsFocusable(), | 657 node->IsClickable(), node->IsEnabled(), node->IsFocusable(), |
653 node->IsFocused(), node->IsPassword(), node->IsScrollable(), | 658 node->IsFocused(), node->IsPassword(), node->IsScrollable(), |
654 node->IsSelected(), node->IsVisibleToUser()); | 659 node->IsSelected(), node->IsVisibleToUser()); |
655 Java_WebContentsAccessibility_addAccessibilityNodeInfoActions( | 660 Java_WebContentsAccessibility_addAccessibilityNodeInfoActions( |
656 env, obj, info, unique_id, node->CanScrollForward(), | 661 env, obj, info, unique_id, node->CanScrollForward(), |
657 node->CanScrollBackward(), node->CanScrollUp(), node->CanScrollDown(), | 662 node->CanScrollBackward(), node->CanScrollUp(), node->CanScrollDown(), |
658 node->CanScrollLeft(), node->CanScrollRight(), node->IsClickable(), | 663 node->CanScrollLeft(), node->CanScrollRight(), node->IsClickable(), |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 ? OneShotAccessibilityTreeSearch::FORWARDS | 923 ? OneShotAccessibilityTreeSearch::FORWARDS |
919 : OneShotAccessibilityTreeSearch::BACKWARDS); | 924 : OneShotAccessibilityTreeSearch::BACKWARDS); |
920 tree_search.SetResultLimit(1); | 925 tree_search.SetResultLimit(1); |
921 tree_search.SetImmediateDescendantsOnly(false); | 926 tree_search.SetImmediateDescendantsOnly(false); |
922 tree_search.SetVisibleOnly(false); | 927 tree_search.SetVisibleOnly(false); |
923 tree_search.AddPredicate(predicate); | 928 tree_search.AddPredicate(predicate); |
924 | 929 |
925 if (tree_search.CountMatches() == 0) | 930 if (tree_search.CountMatches() == 0) |
926 return 0; | 931 return 0; |
927 | 932 |
928 int32_t element_id = tree_search.GetMatchAtIndex(0)->unique_id(); | 933 auto* android_node = |
| 934 static_cast<BrowserAccessibilityAndroid*>(tree_search.GetMatchAtIndex(0)); |
| 935 int32_t element_id = android_node->unique_id(); |
929 | 936 |
930 // Navigate forwards to the autofill popup's proxy node if focus is currently | 937 // Navigate forwards to the autofill popup's proxy node if focus is currently |
931 // on the element hosting the autofill popup. Once within the popup, a back | 938 // on the element hosting the autofill popup. Once within the popup, a back |
932 // press will navigate back to the element hosting the popup. If user swipes | 939 // press will navigate back to the element hosting the popup. If user swipes |
933 // past last suggestion in the popup, or swipes left from the first suggestion | 940 // past last suggestion in the popup, or swipes left from the first suggestion |
934 // in the popup, we will navigate to the element that is the next element in | 941 // in the popup, we will navigate to the element that is the next element in |
935 // the document after the element hosting the popup. | 942 // the document after the element hosting the popup. |
936 if (forwards && start_id == g_element_hosting_autofill_popup_unique_id && | 943 if (forwards && start_id == g_element_hosting_autofill_popup_unique_id && |
937 g_autofill_popup_proxy_node) { | 944 g_autofill_popup_proxy_node) { |
938 g_element_after_element_hosting_autofill_popup_unique_id = element_id; | 945 g_element_after_element_hosting_autofill_popup_unique_id = element_id; |
939 return g_autofill_popup_proxy_node->unique_id(); | 946 auto* android_node = |
| 947 static_cast<BrowserAccessibilityAndroid*>(g_autofill_popup_proxy_node); |
| 948 return android_node->unique_id(); |
940 } | 949 } |
941 | 950 |
942 return element_id; | 951 return element_id; |
943 } | 952 } |
944 | 953 |
945 jboolean WebContentsAccessibilityAndroid::NextAtGranularity( | 954 jboolean WebContentsAccessibilityAndroid::NextAtGranularity( |
946 JNIEnv* env, | 955 JNIEnv* env, |
947 const JavaParamRef<jobject>& obj, | 956 const JavaParamRef<jobject>& obj, |
948 jint granularity, | 957 jint granularity, |
949 jboolean extend_selection, | 958 jboolean extend_selection, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 ax_node_data.role = ui::AX_ROLE_MENU; | 1041 ax_node_data.role = ui::AX_ROLE_MENU; |
1033 ax_node_data.SetName("Autofill"); | 1042 ax_node_data.SetName("Autofill"); |
1034 ax_node_data.AddIntAttribute(ui::AX_ATTR_RESTRICTION, | 1043 ax_node_data.AddIntAttribute(ui::AX_ATTR_RESTRICTION, |
1035 ui::AX_RESTRICTION_READ_ONLY); | 1044 ui::AX_RESTRICTION_READ_ONLY); |
1036 ax_node_data.AddState(ui::AX_STATE_FOCUSABLE); | 1045 ax_node_data.AddState(ui::AX_STATE_FOCUSABLE); |
1037 ax_node_data.AddState(ui::AX_STATE_SELECTABLE); | 1046 ax_node_data.AddState(ui::AX_STATE_SELECTABLE); |
1038 g_autofill_popup_proxy_node_ax_node->SetData(ax_node_data); | 1047 g_autofill_popup_proxy_node_ax_node->SetData(ax_node_data); |
1039 g_autofill_popup_proxy_node->Init(root_manager_, | 1048 g_autofill_popup_proxy_node->Init(root_manager_, |
1040 g_autofill_popup_proxy_node_ax_node); | 1049 g_autofill_popup_proxy_node_ax_node); |
1041 | 1050 |
1042 g_element_hosting_autofill_popup_unique_id = current_focus->unique_id(); | 1051 auto* android_node = static_cast<BrowserAccessibilityAndroid*>(current_focus); |
| 1052 |
| 1053 g_element_hosting_autofill_popup_unique_id = android_node->unique_id(); |
1043 } | 1054 } |
1044 | 1055 |
1045 void WebContentsAccessibilityAndroid::OnAutofillPopupDismissed( | 1056 void WebContentsAccessibilityAndroid::OnAutofillPopupDismissed( |
1046 JNIEnv* env, | 1057 JNIEnv* env, |
1047 const JavaParamRef<jobject>& obj) { | 1058 const JavaParamRef<jobject>& obj) { |
1048 g_element_hosting_autofill_popup_unique_id = -1; | 1059 g_element_hosting_autofill_popup_unique_id = -1; |
1049 g_element_after_element_hosting_autofill_popup_unique_id = -1; | 1060 g_element_after_element_hosting_autofill_popup_unique_id = -1; |
1050 DeleteAutofillPopupProxy(); | 1061 DeleteAutofillPopupProxy(); |
1051 } | 1062 } |
1052 | 1063 |
1053 jint WebContentsAccessibilityAndroid:: | 1064 jint WebContentsAccessibilityAndroid:: |
1054 GetIdForElementAfterElementHostingAutofillPopup( | 1065 GetIdForElementAfterElementHostingAutofillPopup( |
1055 JNIEnv* env, | 1066 JNIEnv* env, |
1056 const JavaParamRef<jobject>& obj) { | 1067 const JavaParamRef<jobject>& obj) { |
1057 if (!base::FeatureList::IsEnabled(features::kAndroidAutofillAccessibility) || | 1068 if (!base::FeatureList::IsEnabled(features::kAndroidAutofillAccessibility) || |
1058 g_element_after_element_hosting_autofill_popup_unique_id == -1 || | 1069 g_element_after_element_hosting_autofill_popup_unique_id == -1 || |
1059 GetAXFromUniqueID( | 1070 GetAXFromUniqueID( |
1060 g_element_after_element_hosting_autofill_popup_unique_id) == nullptr) | 1071 g_element_after_element_hosting_autofill_popup_unique_id) == nullptr) |
1061 return 0; | 1072 return 0; |
1062 | 1073 |
1063 return g_element_after_element_hosting_autofill_popup_unique_id; | 1074 return g_element_after_element_hosting_autofill_popup_unique_id; |
1064 } | 1075 } |
1065 | 1076 |
1066 jboolean WebContentsAccessibilityAndroid::IsAutofillPopupNode( | 1077 jboolean WebContentsAccessibilityAndroid::IsAutofillPopupNode( |
1067 JNIEnv* env, | 1078 JNIEnv* env, |
1068 const JavaParamRef<jobject>& obj, | 1079 const JavaParamRef<jobject>& obj, |
1069 jint unique_id) { | 1080 jint unique_id) { |
1070 return g_autofill_popup_proxy_node && | 1081 auto* android_node = |
1071 g_autofill_popup_proxy_node->unique_id() == unique_id; | 1082 static_cast<BrowserAccessibilityAndroid*>(g_autofill_popup_proxy_node); |
| 1083 |
| 1084 return g_autofill_popup_proxy_node && android_node->unique_id() == unique_id; |
1072 } | 1085 } |
1073 | 1086 |
1074 bool WebContentsAccessibilityAndroid::Scroll(JNIEnv* env, | 1087 bool WebContentsAccessibilityAndroid::Scroll(JNIEnv* env, |
1075 const JavaParamRef<jobject>& obj, | 1088 const JavaParamRef<jobject>& obj, |
1076 jint unique_id, | 1089 jint unique_id, |
1077 int direction) { | 1090 int direction) { |
1078 BrowserAccessibilityAndroid* node = GetAXFromUniqueID(unique_id); | 1091 BrowserAccessibilityAndroid* node = GetAXFromUniqueID(unique_id); |
1079 if (!node) | 1092 if (!node) |
1080 return false; | 1093 return false; |
1081 | 1094 |
1082 return node->Scroll(direction); | 1095 return node->Scroll(direction); |
1083 } | 1096 } |
1084 | 1097 |
1085 BrowserAccessibilityAndroid* WebContentsAccessibilityAndroid::GetAXFromUniqueID( | 1098 BrowserAccessibilityAndroid* WebContentsAccessibilityAndroid::GetAXFromUniqueID( |
1086 int32_t unique_id) { | 1099 int32_t unique_id) { |
1087 return static_cast<BrowserAccessibilityAndroid*>( | 1100 return static_cast<BrowserAccessibilityAndroid*>( |
1088 BrowserAccessibility::GetFromUniqueID(unique_id)); | 1101 BrowserAccessibilityAndroid::GetFromUniqueId(unique_id)); |
1089 } | 1102 } |
1090 | 1103 |
1091 void WebContentsAccessibilityAndroid::UpdateFrameInfo() { | 1104 void WebContentsAccessibilityAndroid::UpdateFrameInfo() { |
1092 if (frame_info_initialized_) | 1105 if (frame_info_initialized_) |
1093 return; | 1106 return; |
1094 | 1107 |
1095 JNIEnv* env = AttachCurrentThread(); | 1108 JNIEnv* env = AttachCurrentThread(); |
1096 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1109 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
1097 if (obj.is_null()) | 1110 if (obj.is_null()) |
1098 return; | 1111 return; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 const JavaParamRef<jobject>& jweb_contents, | 1191 const JavaParamRef<jobject>& jweb_contents, |
1179 jboolean should_focus_on_page_load) { | 1192 jboolean should_focus_on_page_load) { |
1180 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1193 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
1181 DCHECK(web_contents); | 1194 DCHECK(web_contents); |
1182 | 1195 |
1183 return reinterpret_cast<intptr_t>(new WebContentsAccessibilityAndroid( | 1196 return reinterpret_cast<intptr_t>(new WebContentsAccessibilityAndroid( |
1184 env, obj, web_contents, should_focus_on_page_load)); | 1197 env, obj, web_contents, should_focus_on_page_load)); |
1185 } | 1198 } |
1186 | 1199 |
1187 } // namespace content | 1200 } // namespace content |
OLD | NEW |