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

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

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

Powered by Google App Engine
This is Rietveld 408576698