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

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

Issue 2323043002: Too many accessible nodes were marked as clickable on Android (Closed)
Patch Set: Fix item markers Created 4 years, 2 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 case ui::AX_ROLE_MAIN: 47 case ui::AX_ROLE_MAIN:
48 case ui::AX_ROLE_NAVIGATION: 48 case ui::AX_ROLE_NAVIGATION:
49 case ui::AX_ROLE_SEARCH: 49 case ui::AX_ROLE_SEARCH:
50 case ui::AX_ROLE_REGION: 50 case ui::AX_ROLE_REGION:
51 return true; 51 return true;
52 default: 52 default:
53 return false; 53 return false;
54 } 54 }
55 } 55 }
56 56
57 bool AllInterestingNodesPredicate(
58 BrowserAccessibility* start, BrowserAccessibility* node) {
59 // Focusable nodes should never be skipped. Note that IsFocusable()
60 // already skips over things like iframes and child frames that are
61 // technically focusable but shouldn't be exposed as focusable on Android.
62 BrowserAccessibilityAndroid* android_node =
63 static_cast<BrowserAccessibilityAndroid*>(node);
64 if (android_node->IsFocusable())
65 return true;
66
67 // If it's not focusable but has a control role, then it's interesting.
68 if (android_node->IsControl())
69 return true;
70
71 // Otherwise, the interesting nodes are leaf nodes with text.
72 return node->PlatformIsLeaf() && !node->GetText().empty();
73 }
74
57 void AddToPredicateMap(const char* search_key_ascii, 75 void AddToPredicateMap(const char* search_key_ascii,
58 AccessibilityMatchPredicate predicate) { 76 AccessibilityMatchPredicate predicate) {
59 base::string16 search_key_utf16 = base::ASCIIToUTF16(search_key_ascii); 77 base::string16 search_key_utf16 = base::ASCIIToUTF16(search_key_ascii);
60 g_search_key_to_predicate_map.Get()[search_key_utf16] = predicate; 78 g_search_key_to_predicate_map.Get()[search_key_utf16] = predicate;
61 if (!g_all_search_keys.Get().empty()) 79 if (!g_all_search_keys.Get().empty())
62 g_all_search_keys.Get() += base::ASCIIToUTF16(","); 80 g_all_search_keys.Get() += base::ASCIIToUTF16(",");
63 g_all_search_keys.Get() += search_key_utf16; 81 g_all_search_keys.Get() += search_key_utf16;
64 } 82 }
65 83
66 // These are special unofficial strings sent from TalkBack/BrailleBack 84 // These are special unofficial strings sent from TalkBack/BrailleBack
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 AddToPredicateMap("VISITED_LINK", AccessibilityVisitedLinkPredicate); 116 AddToPredicateMap("VISITED_LINK", AccessibilityVisitedLinkPredicate);
99 } 117 }
100 118
101 AccessibilityMatchPredicate PredicateForSearchKey( 119 AccessibilityMatchPredicate PredicateForSearchKey(
102 const base::string16& element_type) { 120 const base::string16& element_type) {
103 InitSearchKeyToPredicateMapIfNeeded(); 121 InitSearchKeyToPredicateMapIfNeeded();
104 const auto& iter = g_search_key_to_predicate_map.Get().find(element_type); 122 const auto& iter = g_search_key_to_predicate_map.Get().find(element_type);
105 if (iter != g_search_key_to_predicate_map.Get().end()) 123 if (iter != g_search_key_to_predicate_map.Get().end())
106 return iter->second; 124 return iter->second;
107 125
108 // If we don't recognize the selector, return any element that's clickable. 126 // If we don't recognize the selector, return any element that a
109 // We mark all focusable nodes and leaf nodes as clickable because it's 127 // screen reader should navigate to.
110 // impossible to know whether a web node has a click handler or not, so 128 return AllInterestingNodesPredicate;
111 // to be safe we have to allow accessibility services to click on nearly
112 // anything that could possibly respond to a click.
113 return [](BrowserAccessibility* start, BrowserAccessibility* node) {
114 return static_cast<BrowserAccessibilityAndroid*>(node)->IsClickable();
115 };
116 } 129 }
117 130
118 } // anonymous namespace 131 } // anonymous namespace
119 132
120 namespace aria_strings { 133 namespace aria_strings {
121 const char kAriaLivePolite[] = "polite"; 134 const char kAriaLivePolite[] = "polite";
122 const char kAriaLiveAssertive[] = "assertive"; 135 const char kAriaLiveAssertive[] = "assertive";
123 } 136 }
124 137
125 // static 138 // static
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 968
956 JNIEnv* env = AttachCurrentThread(); 969 JNIEnv* env = AttachCurrentThread();
957 return root_manager->java_ref().get(env); 970 return root_manager->java_ref().get(env);
958 } 971 }
959 972
960 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { 973 bool RegisterBrowserAccessibilityManager(JNIEnv* env) {
961 return RegisterNativesImpl(env); 974 return RegisterNativesImpl(env);
962 } 975 }
963 976
964 } // namespace content 977 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698