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

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

Issue 2422773002: Improve Android accessible hit testing. (Closed)
Patch Set: Clarify that it can return |this| 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_android.h" 5 #include "content/browser/accessibility/browser_accessibility_android.h"
6 6
7 #include "base/i18n/break_iterator.h" 7 #include "base/i18n/break_iterator.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 bool BrowserAccessibilityAndroid::IsSlider() const { 272 bool BrowserAccessibilityAndroid::IsSlider() const {
273 return GetRole() == ui::AX_ROLE_SLIDER; 273 return GetRole() == ui::AX_ROLE_SLIDER;
274 } 274 }
275 275
276 bool BrowserAccessibilityAndroid::IsVisibleToUser() const { 276 bool BrowserAccessibilityAndroid::IsVisibleToUser() const {
277 return !HasState(ui::AX_STATE_INVISIBLE); 277 return !HasState(ui::AX_STATE_INVISIBLE);
278 } 278 }
279 279
280 bool BrowserAccessibilityAndroid::IsInterestingOnAndroid() const {
281 // Focusable nodes are always interesting. Note that IsFocusable()
282 // already skips over things like iframes and child frames that are
283 // technically focusable but shouldn't be exposed as focusable on Android.
284 if (IsFocusable())
285 return true;
286
287 // If it's not focusable but has a control role, then it's interesting.
288 if (IsControl())
289 return true;
290
291 // Otherwise, the interesting nodes are leaf nodes with text.
292 return PlatformIsLeaf() && !GetText().empty();
293 }
294
295 const BrowserAccessibilityAndroid*
296 BrowserAccessibilityAndroid::GetSoleInterestingNodeFromSubtree() const {
297 if (IsInterestingOnAndroid())
298 return this;
299
300 const BrowserAccessibilityAndroid* sole_interesting_node = nullptr;
aboxhall 2016/10/19 23:21:29 This is fine, of course, but I can't help pointing
301 for (uint32_t i = 0; i < PlatformChildCount(); ++i) {
302 const BrowserAccessibilityAndroid* interesting_node =
303 static_cast<const BrowserAccessibilityAndroid*>(PlatformGetChild(i))->
304 GetSoleInterestingNodeFromSubtree();
305 if (interesting_node && sole_interesting_node) {
306 // If there are two interesting nodes, return nullptr.
307 return nullptr;
308 } else if (interesting_node) {
309 sole_interesting_node = interesting_node;
310 }
311 }
312
313 return sole_interesting_node;
314 }
315
280 bool BrowserAccessibilityAndroid::CanOpenPopup() const { 316 bool BrowserAccessibilityAndroid::CanOpenPopup() const {
281 return HasState(ui::AX_STATE_HASPOPUP); 317 return HasState(ui::AX_STATE_HASPOPUP);
282 } 318 }
283 319
284 const char* BrowserAccessibilityAndroid::GetClassName() const { 320 const char* BrowserAccessibilityAndroid::GetClassName() const {
285 const char* class_name = NULL; 321 const char* class_name = NULL;
286 322
287 switch (GetRole()) { 323 switch (GetRole()) {
288 case ui::AX_ROLE_SEARCH_BOX: 324 case ui::AX_ROLE_SEARCH_BOX:
289 case ui::AX_ROLE_SPIN_BUTTON: 325 case ui::AX_ROLE_SPIN_BUTTON:
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const { 1464 int BrowserAccessibilityAndroid::CountChildrenWithRole(ui::AXRole role) const {
1429 int count = 0; 1465 int count = 0;
1430 for (uint32_t i = 0; i < PlatformChildCount(); i++) { 1466 for (uint32_t i = 0; i < PlatformChildCount(); i++) {
1431 if (PlatformGetChild(i)->GetRole() == role) 1467 if (PlatformGetChild(i)->GetRole() == role)
1432 count++; 1468 count++;
1433 } 1469 }
1434 return count; 1470 return count;
1435 } 1471 }
1436 1472
1437 } // namespace content 1473 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698