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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 OnAutofillPopupAccessibilityFocusCleared(JNIEnv* env, | |
| 1013 const JavaParamRef<jobject>& obj) { | |
| 1014 if (!base::FeatureList::IsEnabled(features::kAndroidAutofillAccessibility) || | |
| 1015 g_element_after_element_hosting_autofill_popup_unique_id == -1) | |
| 1016 return 0; | |
| 1017 return g_element_after_element_hosting_autofill_popup_unique_id; | |
|
dmazzoni
2017/04/10 17:39:06
It's possible that the user navigated away.
You s
csashi
2017/04/10 18:06:28
Done.
| |
| 1018 } | |
| 1019 | |
| 1000 jboolean BrowserAccessibilityManagerAndroid::IsAutofillPopupNode( | 1020 jboolean BrowserAccessibilityManagerAndroid::IsAutofillPopupNode( |
| 1001 JNIEnv* env, | 1021 JNIEnv* env, |
| 1002 const JavaParamRef<jobject>& obj, | 1022 const JavaParamRef<jobject>& obj, |
| 1003 jint id) { | 1023 jint id) { |
| 1004 return g_autofill_popup_proxy_node && | 1024 return g_autofill_popup_proxy_node && |
| 1005 g_autofill_popup_proxy_node->unique_id() == id; | 1025 g_autofill_popup_proxy_node->unique_id() == id; |
| 1006 } | 1026 } |
| 1007 | 1027 |
| 1008 bool BrowserAccessibilityManagerAndroid::Scroll( | 1028 bool BrowserAccessibilityManagerAndroid::Scroll( |
| 1009 JNIEnv* env, | 1029 JNIEnv* env, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 | 1076 |
| 1057 JNIEnv* env = AttachCurrentThread(); | 1077 JNIEnv* env = AttachCurrentThread(); |
| 1058 return root_manager->java_ref().get(env); | 1078 return root_manager->java_ref().get(env); |
| 1059 } | 1079 } |
| 1060 | 1080 |
| 1061 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 1081 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
| 1062 return RegisterNativesImpl(env); | 1082 return RegisterNativesImpl(env); |
| 1063 } | 1083 } |
| 1064 | 1084 |
| 1065 } // namespace content | 1085 } // namespace content |
| OLD | NEW |