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

Unified Diff: content/browser/accessibility/browser_accessibility_manager_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 side-by-side diff with in-line comments
Download patch
Index: content/browser/accessibility/browser_accessibility_manager_android.cc
diff --git a/content/browser/accessibility/browser_accessibility_manager_android.cc b/content/browser/accessibility/browser_accessibility_manager_android.cc
index 4a772dd885885f2e2df792d62e186d2d35a3b874..828c3c09de792ec5a5bb65eed1891b6337a03796 100644
--- a/content/browser/accessibility/browser_accessibility_manager_android.cc
+++ b/content/browser/accessibility/browser_accessibility_manager_android.cc
@@ -56,20 +56,9 @@ bool SectionPredicate(
bool AllInterestingNodesPredicate(
BrowserAccessibility* start, BrowserAccessibility* node) {
- // Focusable nodes should never be skipped. Note that IsFocusable()
- // already skips over things like iframes and child frames that are
- // technically focusable but shouldn't be exposed as focusable on Android.
BrowserAccessibilityAndroid* android_node =
static_cast<BrowserAccessibilityAndroid*>(node);
- if (android_node->IsFocusable())
- return true;
-
- // If it's not focusable but has a control role, then it's interesting.
- if (android_node->IsControl())
- return true;
-
- // Otherwise, the interesting nodes are leaf nodes with text.
- return node->PlatformIsLeaf() && !node->GetText().empty();
+ return android_node->IsInterestingOnAndroid();
}
void AddToPredicateMap(const char* search_key_ascii,
@@ -710,19 +699,30 @@ void BrowserAccessibilityManagerAndroid::HandleHoverEvent(
if (obj.is_null())
return;
- BrowserAccessibilityAndroid* ancestor =
- static_cast<BrowserAccessibilityAndroid*>(node->GetParent());
- while (ancestor && ancestor != GetRoot()) {
- if (ancestor->PlatformIsLeaf() ||
- (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) {
- node = ancestor;
- // Don't break - we want the highest ancestor that's focusable or a
- // leaf node.
- }
- ancestor = static_cast<BrowserAccessibilityAndroid*>(ancestor->GetParent());
+ // First walk up to the nearest platform node, in case this node isn't
+ // even exposed on the platform.
+ node = node->GetClosestPlatformObject();
+
+ // If this node is uninteresting and just a wrapper around a sole
+ // interesting descendant, prefer that descendant instead.
+ const BrowserAccessibilityAndroid* android_node =
+ static_cast<BrowserAccessibilityAndroid*>(node);
+ const BrowserAccessibilityAndroid* sole_interesting_node =
+ android_node->GetSoleInterestingNodeFromSubtree();
+ if (sole_interesting_node)
+ android_node = sole_interesting_node;
+
+ // Finally, if this node is still uninteresting, try to walk up to
+ // find an interesting parent.
+ while (android_node && !android_node->IsInterestingOnAndroid()) {
+ android_node = static_cast<BrowserAccessibilityAndroid*>(
+ android_node->GetParent());
}
- Java_BrowserAccessibilityManager_handleHover(env, obj, node->unique_id());
+ if (android_node) {
+ Java_BrowserAccessibilityManager_handleHover(
+ env, obj, android_node->unique_id());
+ }
}
jint BrowserAccessibilityManagerAndroid::FindElementType(

Powered by Google App Engine
This is Rietveld 408576698