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

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

Issue 2811803002: Fixes accessibility navigation out of autofill popup. (Closed)
Patch Set: Renames OnAutofillPopupAccessibilityFocusCleared to GetIdForElementAfterElementHostingAutofillPopup. Created 3 years, 8 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 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return iter->second; 116 return iter->second;
117 117
118 // If we don't recognize the selector, return any element that a 118 // If we don't recognize the selector, return any element that a
119 // screen reader should navigate to. 119 // screen reader should navigate to.
120 return AllInterestingNodesPredicate; 120 return AllInterestingNodesPredicate;
121 } 121 }
122 122
123 // The element in the document for which we may be displaying an autofill popup. 123 // The element in the document for which we may be displaying an autofill popup.
124 int32_t g_element_hosting_autofill_popup_unique_id = -1; 124 int32_t g_element_hosting_autofill_popup_unique_id = -1;
125 125
126 // The element in the document that is the next element after
127 // |g_element_hosting_autofill_popup_unique_id|.
128 int32_t g_element_after_element_hosting_autofill_popup_unique_id = -1;
129
126 // Autofill popup will not be part of the |AXTree| that is sent by renderer. 130 // Autofill popup will not be part of the |AXTree| that is sent by renderer.
127 // Hence, we need a proxy |AXNode| to represent the autofill popup. 131 // Hence, we need a proxy |AXNode| to represent the autofill popup.
128 BrowserAccessibility* g_autofill_popup_proxy_node = nullptr; 132 BrowserAccessibility* g_autofill_popup_proxy_node = nullptr;
129 ui::AXNode* g_autofill_popup_proxy_node_ax_node = nullptr; 133 ui::AXNode* g_autofill_popup_proxy_node_ax_node = nullptr;
130 134
131 void DeleteAutofillPopupProxy() { 135 void DeleteAutofillPopupProxy() {
132 if (g_autofill_popup_proxy_node) { 136 if (g_autofill_popup_proxy_node) {
133 g_autofill_popup_proxy_node->Destroy(); 137 g_autofill_popup_proxy_node->Destroy();
134 delete g_autofill_popup_proxy_node_ax_node; 138 delete g_autofill_popup_proxy_node_ax_node;
135 g_autofill_popup_proxy_node = nullptr; 139 g_autofill_popup_proxy_node = nullptr;
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 env, obj, android_node->unique_id()); 762 env, obj, android_node->unique_id());
759 } 763 }
760 } 764 }
761 765
762 jint BrowserAccessibilityManagerAndroid::FindElementType( 766 jint BrowserAccessibilityManagerAndroid::FindElementType(
763 JNIEnv* env, 767 JNIEnv* env,
764 const JavaParamRef<jobject>& obj, 768 const JavaParamRef<jobject>& obj,
765 jint start_id, 769 jint start_id,
766 const JavaParamRef<jstring>& element_type_str, 770 const JavaParamRef<jstring>& element_type_str,
767 jboolean forwards) { 771 jboolean forwards) {
768 // Navigate forwards to the autofill popup's proxy node if focus is currently
769 // on the element hosting the autofill popup. Once within the popup, a back
770 // press will navigate back to the element hosting the popup.
771 if (forwards && start_id == g_element_hosting_autofill_popup_unique_id &&
772 g_autofill_popup_proxy_node) {
773 return g_autofill_popup_proxy_node->unique_id();
774 }
775
776 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); 772 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id);
777 if (!start_node) 773 if (!start_node)
778 return 0; 774 return 0;
779 775
780 BrowserAccessibilityManager* root_manager = GetRootManager(); 776 BrowserAccessibilityManager* root_manager = GetRootManager();
781 if (!root_manager) 777 if (!root_manager)
782 return 0; 778 return 0;
783 779
784 BrowserAccessibility* root = root_manager->GetRoot(); 780 BrowserAccessibility* root = root_manager->GetRoot();
785 if (!root) 781 if (!root)
786 return 0; 782 return 0;
787 783
788 AccessibilityMatchPredicate predicate = PredicateForSearchKey( 784 AccessibilityMatchPredicate predicate = PredicateForSearchKey(
789 base::android::ConvertJavaStringToUTF16(env, element_type_str)); 785 base::android::ConvertJavaStringToUTF16(env, element_type_str));
790 786
791 OneShotAccessibilityTreeSearch tree_search(root); 787 OneShotAccessibilityTreeSearch tree_search(root);
792 tree_search.SetStartNode(start_node); 788 tree_search.SetStartNode(start_node);
793 tree_search.SetDirection( 789 tree_search.SetDirection(
794 forwards ? 790 forwards ?
795 OneShotAccessibilityTreeSearch::FORWARDS : 791 OneShotAccessibilityTreeSearch::FORWARDS :
796 OneShotAccessibilityTreeSearch::BACKWARDS); 792 OneShotAccessibilityTreeSearch::BACKWARDS);
797 tree_search.SetResultLimit(1); 793 tree_search.SetResultLimit(1);
798 tree_search.SetImmediateDescendantsOnly(false); 794 tree_search.SetImmediateDescendantsOnly(false);
799 tree_search.SetVisibleOnly(false); 795 tree_search.SetVisibleOnly(false);
800 tree_search.AddPredicate(predicate); 796 tree_search.AddPredicate(predicate);
801 797
802 if (tree_search.CountMatches() == 0) 798 if (tree_search.CountMatches() == 0)
803 return 0; 799 return 0;
804 800
805 return tree_search.GetMatchAtIndex(0)->unique_id(); 801 int32_t element_id = tree_search.GetMatchAtIndex(0)->unique_id();
802
803 // Navigate forwards to the autofill popup's proxy node if focus is currently
804 // on the element hosting the autofill popup. Once within the popup, a back
805 // press will navigate back to the element hosting the popup. If user swipes
806 // past last suggestion in the popup, or swipes left from the first suggestion
807 // in the popup, we will navigate to the element that is the next element in
808 // the document after the element hosting the popup.
809 if (forwards && start_id == g_element_hosting_autofill_popup_unique_id &&
810 g_autofill_popup_proxy_node) {
811 g_element_after_element_hosting_autofill_popup_unique_id = element_id;
812 return g_autofill_popup_proxy_node->unique_id();
813 }
814
815 return element_id;
806 } 816 }
807 817
808 jboolean BrowserAccessibilityManagerAndroid::NextAtGranularity( 818 jboolean BrowserAccessibilityManagerAndroid::NextAtGranularity(
809 JNIEnv* env, 819 JNIEnv* env,
810 const JavaParamRef<jobject>& obj, 820 const JavaParamRef<jobject>& obj,
811 jint granularity, 821 jint granularity,
812 jboolean extend_selection, 822 jboolean extend_selection,
813 jint id, 823 jint id,
814 jint cursor_index) { 824 jint cursor_index) {
815 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); 825 BrowserAccessibilityAndroid* node = GetFromUniqueID(id);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 g_autofill_popup_proxy_node_ax_node->SetData(ax_node_data); 997 g_autofill_popup_proxy_node_ax_node->SetData(ax_node_data);
988 g_autofill_popup_proxy_node->Init(this, g_autofill_popup_proxy_node_ax_node); 998 g_autofill_popup_proxy_node->Init(this, g_autofill_popup_proxy_node_ax_node);
989 999
990 g_element_hosting_autofill_popup_unique_id = current_focus->unique_id(); 1000 g_element_hosting_autofill_popup_unique_id = current_focus->unique_id();
991 } 1001 }
992 1002
993 void BrowserAccessibilityManagerAndroid::OnAutofillPopupDismissed( 1003 void BrowserAccessibilityManagerAndroid::OnAutofillPopupDismissed(
994 JNIEnv* env, 1004 JNIEnv* env,
995 const JavaParamRef<jobject>& obj) { 1005 const JavaParamRef<jobject>& obj) {
996 g_element_hosting_autofill_popup_unique_id = -1; 1006 g_element_hosting_autofill_popup_unique_id = -1;
1007 g_element_after_element_hosting_autofill_popup_unique_id = -1;
997 DeleteAutofillPopupProxy(); 1008 DeleteAutofillPopupProxy();
998 } 1009 }
999 1010
1011 jint BrowserAccessibilityManagerAndroid::
1012 GetIdForElementAfterElementHostingAutofillPopup(
1013 JNIEnv* env,
1014 const JavaParamRef<jobject>& obj) {
1015 if (!base::FeatureList::IsEnabled(features::kAndroidAutofillAccessibility) ||
1016 g_element_after_element_hosting_autofill_popup_unique_id == -1 ||
1017 GetFromUniqueID(
1018 g_element_after_element_hosting_autofill_popup_unique_id) == nullptr)
1019 return 0;
1020
1021 return g_element_after_element_hosting_autofill_popup_unique_id;
1022 }
1023
1000 jboolean BrowserAccessibilityManagerAndroid::IsAutofillPopupNode( 1024 jboolean BrowserAccessibilityManagerAndroid::IsAutofillPopupNode(
1001 JNIEnv* env, 1025 JNIEnv* env,
1002 const JavaParamRef<jobject>& obj, 1026 const JavaParamRef<jobject>& obj,
1003 jint id) { 1027 jint id) {
1004 return g_autofill_popup_proxy_node && 1028 return g_autofill_popup_proxy_node &&
1005 g_autofill_popup_proxy_node->unique_id() == id; 1029 g_autofill_popup_proxy_node->unique_id() == id;
1006 } 1030 }
1007 1031
1008 bool BrowserAccessibilityManagerAndroid::Scroll( 1032 bool BrowserAccessibilityManagerAndroid::Scroll(
1009 JNIEnv* env, 1033 JNIEnv* env,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 1080
1057 JNIEnv* env = AttachCurrentThread(); 1081 JNIEnv* env = AttachCurrentThread();
1058 return root_manager->java_ref().get(env); 1082 return root_manager->java_ref().get(env);
1059 } 1083 }
1060 1084
1061 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { 1085 bool RegisterBrowserAccessibilityManager(JNIEnv* env) {
1062 return RegisterNativesImpl(env); 1086 return RegisterNativesImpl(env);
1063 } 1087 }
1064 1088
1065 } // namespace content 1089 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698