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

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: Created 4 years, 3 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 // Otherwise, the interesting nodes are leaf nodes with text.
David Tseng 2016/10/12 20:28:35 If I have a <div role="button"> (no text content,
dmazzoni 2016/10/12 22:41:58 Good idea, I can have it return true if it's a con
68 return node->PlatformIsLeaf() && !node->GetText().empty();
69 }
70
57 void AddToPredicateMap(const char* search_key_ascii, 71 void AddToPredicateMap(const char* search_key_ascii,
58 AccessibilityMatchPredicate predicate) { 72 AccessibilityMatchPredicate predicate) {
59 base::string16 search_key_utf16 = base::ASCIIToUTF16(search_key_ascii); 73 base::string16 search_key_utf16 = base::ASCIIToUTF16(search_key_ascii);
60 g_search_key_to_predicate_map.Get()[search_key_utf16] = predicate; 74 g_search_key_to_predicate_map.Get()[search_key_utf16] = predicate;
61 if (!g_all_search_keys.Get().empty()) 75 if (!g_all_search_keys.Get().empty())
62 g_all_search_keys.Get() += base::ASCIIToUTF16(","); 76 g_all_search_keys.Get() += base::ASCIIToUTF16(",");
63 g_all_search_keys.Get() += search_key_utf16; 77 g_all_search_keys.Get() += search_key_utf16;
64 } 78 }
65 79
66 // These are special unofficial strings sent from TalkBack/BrailleBack 80 // 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); 112 AddToPredicateMap("VISITED_LINK", AccessibilityVisitedLinkPredicate);
99 } 113 }
100 114
101 AccessibilityMatchPredicate PredicateForSearchKey( 115 AccessibilityMatchPredicate PredicateForSearchKey(
102 const base::string16& element_type) { 116 const base::string16& element_type) {
103 InitSearchKeyToPredicateMapIfNeeded(); 117 InitSearchKeyToPredicateMapIfNeeded();
104 const auto& iter = g_search_key_to_predicate_map.Get().find(element_type); 118 const auto& iter = g_search_key_to_predicate_map.Get().find(element_type);
105 if (iter != g_search_key_to_predicate_map.Get().end()) 119 if (iter != g_search_key_to_predicate_map.Get().end())
106 return iter->second; 120 return iter->second;
107 121
108 // If we don't recognize the selector, return any element that's clickable. 122 // 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 123 // screen reader should navigate to.
110 // impossible to know whether a web node has a click handler or not, so 124 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 } 125 }
117 126
118 } // anonymous namespace 127 } // anonymous namespace
119 128
120 namespace aria_strings { 129 namespace aria_strings {
121 const char kAriaLivePolite[] = "polite"; 130 const char kAriaLivePolite[] = "polite";
122 const char kAriaLiveAssertive[] = "assertive"; 131 const char kAriaLiveAssertive[] = "assertive";
123 } 132 }
124 133
125 // static 134 // static
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 953
945 JNIEnv* env = AttachCurrentThread(); 954 JNIEnv* env = AttachCurrentThread();
946 return root_manager->java_ref().get(env); 955 return root_manager->java_ref().get(env);
947 } 956 }
948 957
949 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { 958 bool RegisterBrowserAccessibilityManager(JNIEnv* env) {
950 return RegisterNativesImpl(env); 959 return RegisterNativesImpl(env);
951 } 960 }
952 961
953 } // namespace content 962 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698