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 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 return false; | 683 return false; |
695 } | 684 } |
696 | 685 |
697 void BrowserAccessibilityManagerAndroid::HandleHoverEvent( | 686 void BrowserAccessibilityManagerAndroid::HandleHoverEvent( |
698 BrowserAccessibility* node) { | 687 BrowserAccessibility* node) { |
699 JNIEnv* env = AttachCurrentThread(); | 688 JNIEnv* env = AttachCurrentThread(); |
700 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); | 689 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); |
701 if (obj.is_null()) | 690 if (obj.is_null()) |
702 return; | 691 return; |
703 | 692 |
704 BrowserAccessibilityAndroid* ancestor = | 693 // First walk up to the nearest platform node, in case this node isn't |
705 static_cast<BrowserAccessibilityAndroid*>(node->GetParent()); | 694 // even exposed on the platform. |
706 while (ancestor && ancestor != GetRoot()) { | 695 node = node->GetClosestPlatformObject(); |
707 if (ancestor->PlatformIsLeaf() || | 696 |
708 (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) { | 697 // If this node is uninteresting and just a wrapper around a sole |
709 node = ancestor; | 698 // interesting descendant, prefer that descendant instead. |
710 // Don't break - we want the highest ancestor that's focusable or a | 699 const BrowserAccessibilityAndroid* android_node = |
711 // leaf node. | 700 static_cast<BrowserAccessibilityAndroid*>(node); |
712 } | 701 const BrowserAccessibilityAndroid* sole_interesting_descendant = |
713 ancestor = static_cast<BrowserAccessibilityAndroid*>(ancestor->GetParent()); | 702 android_node->GetSoleInterestingDescendant(); |
| 703 if (sole_interesting_descendant) |
| 704 android_node = sole_interesting_descendant; |
| 705 |
| 706 // Finally, if this node is still uninteresting, try to walk up to |
| 707 // find an interesting parent. |
| 708 while (android_node && !android_node->IsInterestingOnAndroid()) { |
| 709 android_node = static_cast<BrowserAccessibilityAndroid*>( |
| 710 android_node->GetParent()); |
714 } | 711 } |
715 | 712 |
716 Java_BrowserAccessibilityManager_handleHover(env, obj, node->unique_id()); | 713 if (android_node) { |
| 714 Java_BrowserAccessibilityManager_handleHover( |
| 715 env, obj, android_node->unique_id()); |
| 716 } |
717 } | 717 } |
718 | 718 |
719 jint BrowserAccessibilityManagerAndroid::FindElementType( | 719 jint BrowserAccessibilityManagerAndroid::FindElementType( |
720 JNIEnv* env, | 720 JNIEnv* env, |
721 const JavaParamRef<jobject>& obj, | 721 const JavaParamRef<jobject>& obj, |
722 jint start_id, | 722 jint start_id, |
723 const JavaParamRef<jstring>& element_type_str, | 723 const JavaParamRef<jstring>& element_type_str, |
724 jboolean forwards) { | 724 jboolean forwards) { |
725 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); | 725 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); |
726 if (!start_node) | 726 if (!start_node) |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 | 968 |
969 JNIEnv* env = AttachCurrentThread(); | 969 JNIEnv* env = AttachCurrentThread(); |
970 return root_manager->java_ref().get(env); | 970 return root_manager->java_ref().get(env); |
971 } | 971 } |
972 | 972 |
973 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 973 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
974 return RegisterNativesImpl(env); | 974 return RegisterNativesImpl(env); |
975 } | 975 } |
976 | 976 |
977 } // namespace content | 977 } // namespace content |
OLD | NEW |