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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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( | 57 bool AllInterestingNodesPredicate( |
58 BrowserAccessibility* start, BrowserAccessibility* node) { | 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 = | 59 BrowserAccessibilityAndroid* android_node = |
63 static_cast<BrowserAccessibilityAndroid*>(node); | 60 static_cast<BrowserAccessibilityAndroid*>(node); |
64 if (android_node->IsFocusable()) | 61 return android_node->IsInterestingOnAndroid(); |
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 } | 62 } |
74 | 63 |
75 void AddToPredicateMap(const char* search_key_ascii, | 64 void AddToPredicateMap(const char* search_key_ascii, |
76 AccessibilityMatchPredicate predicate) { | 65 AccessibilityMatchPredicate predicate) { |
77 base::string16 search_key_utf16 = base::ASCIIToUTF16(search_key_ascii); | 66 base::string16 search_key_utf16 = base::ASCIIToUTF16(search_key_ascii); |
78 g_search_key_to_predicate_map.Get()[search_key_utf16] = predicate; | 67 g_search_key_to_predicate_map.Get()[search_key_utf16] = predicate; |
79 if (!g_all_search_keys.Get().empty()) | 68 if (!g_all_search_keys.Get().empty()) |
80 g_all_search_keys.Get() += base::ASCIIToUTF16(","); | 69 g_all_search_keys.Get() += base::ASCIIToUTF16(","); |
81 g_all_search_keys.Get() += search_key_utf16; | 70 g_all_search_keys.Get() += search_key_utf16; |
82 } | 71 } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 node->manager()->delegate()->AccessibilityShowContextMenu(node->GetId()); | 692 node->manager()->delegate()->AccessibilityShowContextMenu(node->GetId()); |
704 } | 693 } |
705 | 694 |
706 void BrowserAccessibilityManagerAndroid::HandleHoverEvent( | 695 void BrowserAccessibilityManagerAndroid::HandleHoverEvent( |
707 BrowserAccessibility* node) { | 696 BrowserAccessibility* node) { |
708 JNIEnv* env = AttachCurrentThread(); | 697 JNIEnv* env = AttachCurrentThread(); |
709 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); | 698 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); |
710 if (obj.is_null()) | 699 if (obj.is_null()) |
711 return; | 700 return; |
712 | 701 |
713 BrowserAccessibilityAndroid* ancestor = | 702 // First walk up to the nearest platform node, in case this node isn't |
714 static_cast<BrowserAccessibilityAndroid*>(node->GetParent()); | 703 // even exposed on the platform. |
715 while (ancestor && ancestor != GetRoot()) { | 704 node = node->GetClosestPlatformObject(); |
716 if (ancestor->PlatformIsLeaf() || | 705 |
717 (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) { | 706 // If this node is uninteresting and just a wrapper around an interesting |
718 node = ancestor; | 707 // child, prefer that child instead. |
719 // Don't break - we want the highest ancestor that's focusable or a | 708 const BrowserAccessibilityAndroid* android_node = |
720 // leaf node. | 709 static_cast<BrowserAccessibilityAndroid*>(node); |
721 } | 710 const BrowserAccessibilityAndroid* interesting_child = |
aboxhall
2016/10/18 21:03:24
Do we need to make sure the child matches the hit
dmazzoni
2016/10/18 22:09:36
Good thought, but I don't think so - the only plac
| |
722 ancestor = static_cast<BrowserAccessibilityAndroid*>(ancestor->GetParent()); | 711 android_node->GetInterestingChild(); |
712 if (interesting_child) | |
713 android_node = interesting_child; | |
714 | |
715 // Finally, if this node is still uninteresting, try to walk up to | |
716 // find an interesting parent. | |
717 while (android_node && !android_node->IsInterestingOnAndroid()) { | |
718 android_node = static_cast<BrowserAccessibilityAndroid*>( | |
719 android_node->GetParent()); | |
723 } | 720 } |
724 | 721 |
725 Java_BrowserAccessibilityManager_handleHover(env, obj, node->unique_id()); | 722 if (android_node) { |
723 Java_BrowserAccessibilityManager_handleHover( | |
724 env, obj, android_node->unique_id()); | |
725 } | |
726 } | 726 } |
727 | 727 |
728 jint BrowserAccessibilityManagerAndroid::FindElementType( | 728 jint BrowserAccessibilityManagerAndroid::FindElementType( |
729 JNIEnv* env, | 729 JNIEnv* env, |
730 const JavaParamRef<jobject>& obj, | 730 const JavaParamRef<jobject>& obj, |
731 jint start_id, | 731 jint start_id, |
732 const JavaParamRef<jstring>& element_type_str, | 732 const JavaParamRef<jstring>& element_type_str, |
733 jboolean forwards) { | 733 jboolean forwards) { |
734 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); | 734 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); |
735 if (!start_node) | 735 if (!start_node) |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 | 977 |
978 JNIEnv* env = AttachCurrentThread(); | 978 JNIEnv* env = AttachCurrentThread(); |
979 return root_manager->java_ref().get(env); | 979 return root_manager->java_ref().get(env); |
980 } | 980 } |
981 | 981 |
982 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 982 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
983 return RegisterNativesImpl(env); | 983 return RegisterNativesImpl(env); |
984 } | 984 } |
985 | 985 |
986 } // namespace content | 986 } // namespace content |
OLD | NEW |