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

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

Issue 1761633002: One accessibility tree per frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix is-richly-editable test Created 4 years, 9 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 BrowserAccessibilityDelegate* delegate, 139 BrowserAccessibilityDelegate* delegate,
140 BrowserAccessibilityFactory* factory) 140 BrowserAccessibilityFactory* factory)
141 : BrowserAccessibilityManager(delegate, factory), 141 : BrowserAccessibilityManager(delegate, factory),
142 prune_tree_for_screen_reader_(true) { 142 prune_tree_for_screen_reader_(true) {
143 Initialize(initial_tree); 143 Initialize(initial_tree);
144 SetContentViewCore(content_view_core); 144 SetContentViewCore(content_view_core);
145 } 145 }
146 146
147 BrowserAccessibilityManagerAndroid::~BrowserAccessibilityManagerAndroid() { 147 BrowserAccessibilityManagerAndroid::~BrowserAccessibilityManagerAndroid() {
148 JNIEnv* env = AttachCurrentThread(); 148 JNIEnv* env = AttachCurrentThread();
149 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 149 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager();
150 if (obj.is_null()) 150 if (obj.is_null())
151 return; 151 return;
152 152
153 Java_BrowserAccessibilityManager_onNativeObjectDestroyed(env, obj.obj()); 153 Java_BrowserAccessibilityManager_onNativeObjectDestroyed(env, obj.obj());
154 } 154 }
155 155
156 // static 156 // static
157 ui::AXTreeUpdate 157 ui::AXTreeUpdate
158 BrowserAccessibilityManagerAndroid::GetEmptyDocument() { 158 BrowserAccessibilityManagerAndroid::GetEmptyDocument() {
159 ui::AXNodeData empty_document; 159 ui::AXNodeData empty_document;
(...skipping 15 matching lines...) Expand all
175 java_ref_ = JavaObjectWeakGlobalRef( 175 java_ref_ = JavaObjectWeakGlobalRef(
176 env, Java_BrowserAccessibilityManager_create( 176 env, Java_BrowserAccessibilityManager_create(
177 env, reinterpret_cast<intptr_t>(this), 177 env, reinterpret_cast<intptr_t>(this),
178 content_view_core.obj()).obj()); 178 content_view_core.obj()).obj());
179 } 179 }
180 180
181 void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent( 181 void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent(
182 ui::AXEvent event_type, 182 ui::AXEvent event_type,
183 BrowserAccessibility* node) { 183 BrowserAccessibility* node) {
184 JNIEnv* env = AttachCurrentThread(); 184 JNIEnv* env = AttachCurrentThread();
185 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 185 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager();
186 if (obj.is_null()) 186 if (obj.is_null())
187 return; 187 return;
188 188
189 BrowserAccessibilityAndroid* android_node = 189 BrowserAccessibilityAndroid* android_node =
190 static_cast<BrowserAccessibilityAndroid*>(node); 190 static_cast<BrowserAccessibilityAndroid*>(node);
191 191
192 if (event_type == ui::AX_EVENT_HIDE) 192 if (event_type == ui::AX_EVENT_HIDE)
193 return; 193 return;
194 194
195 if (event_type == ui::AX_EVENT_TREE_CHANGED) 195 if (event_type == ui::AX_EVENT_TREE_CHANGED)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 268 }
269 } 269 }
270 270
271 void BrowserAccessibilityManagerAndroid::OnLocationChanges( 271 void BrowserAccessibilityManagerAndroid::OnLocationChanges(
272 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { 272 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
273 // Android is not very efficient at handling notifications, and location 273 // Android is not very efficient at handling notifications, and location
274 // changes in particular are frequent and not time-critical. If a lot of 274 // changes in particular are frequent and not time-critical. If a lot of
275 // nodes changed location, just send a single notification after a short 275 // nodes changed location, just send a single notification after a short
276 // delay (to batch them), rather than lots of individual notifications. 276 // delay (to batch them), rather than lots of individual notifications.
277 if (params.size() > 3) { 277 if (params.size() > 3) {
278 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager();
278 JNIEnv* env = AttachCurrentThread(); 279 JNIEnv* env = AttachCurrentThread();
279 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
280 if (obj.is_null()) 280 if (obj.is_null())
281 return; 281 return;
282 Java_BrowserAccessibilityManager_sendDelayedWindowContentChangedEvent( 282 Java_BrowserAccessibilityManager_sendDelayedWindowContentChangedEvent(
283 env, obj.obj()); 283 env, obj.obj());
284 return; 284 return;
285 } 285 }
286 286
287 BrowserAccessibilityManager::OnLocationChanges(params); 287 BrowserAccessibilityManager::OnLocationChanges(params);
288 } 288 }
289 289
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 BrowserAccessibilityManager::SetValue( 652 BrowserAccessibilityManager::SetValue(
653 *node, base::UTF8ToUTF16(base::DoubleToString(value))); 653 *node, base::UTF8ToUTF16(base::DoubleToString(value)));
654 return true; 654 return true;
655 } 655 }
656 return false; 656 return false;
657 } 657 }
658 658
659 void BrowserAccessibilityManagerAndroid::HandleHoverEvent( 659 void BrowserAccessibilityManagerAndroid::HandleHoverEvent(
660 BrowserAccessibility* node) { 660 BrowserAccessibility* node) {
661 JNIEnv* env = AttachCurrentThread(); 661 JNIEnv* env = AttachCurrentThread();
662 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 662 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager();
663 if (obj.is_null()) 663 if (obj.is_null())
664 return; 664 return;
665 665
666 BrowserAccessibilityAndroid* ancestor = 666 BrowserAccessibilityAndroid* ancestor =
667 static_cast<BrowserAccessibilityAndroid*>(node->GetParent()); 667 static_cast<BrowserAccessibilityAndroid*>(node->GetParent());
668 while (ancestor && ancestor != GetRoot()) { 668 while (ancestor && ancestor != GetRoot()) {
669 if (ancestor->PlatformIsLeaf() || 669 if (ancestor->PlatformIsLeaf() ||
670 (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) { 670 (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) {
671 node = ancestor; 671 node = ancestor;
672 // Don't break - we want the highest ancestor that's focusable or a 672 // Don't break - we want the highest ancestor that's focusable or a
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 if (!node) 889 if (!node)
890 return false; 890 return false;
891 891
892 return node->Scroll(direction); 892 return node->Scroll(direction);
893 } 893 }
894 894
895 void BrowserAccessibilityManagerAndroid::OnAtomicUpdateFinished( 895 void BrowserAccessibilityManagerAndroid::OnAtomicUpdateFinished(
896 ui::AXTree* tree, 896 ui::AXTree* tree,
897 bool root_changed, 897 bool root_changed,
898 const std::vector<ui::AXTreeDelegate::Change>& changes) { 898 const std::vector<ui::AXTreeDelegate::Change>& changes) {
899 BrowserAccessibilityManager::OnAtomicUpdateFinished(
900 tree, root_changed, changes);
901
899 if (root_changed) { 902 if (root_changed) {
900 JNIEnv* env = AttachCurrentThread(); 903 JNIEnv* env = AttachCurrentThread();
901 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 904 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager();
902 if (obj.is_null()) 905 if (obj.is_null())
903 return; 906 return;
904 907
905 Java_BrowserAccessibilityManager_handleNavigate(env, obj.obj()); 908 Java_BrowserAccessibilityManager_handleNavigate(env, obj.obj());
906 } 909 }
907 } 910 }
908 911
909 bool 912 bool
910 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() { 913 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() {
911 // The Java layer handles the root scroll offset. 914 // The Java layer handles the root scroll offset.
912 return false; 915 return false;
913 } 916 }
914 917
915 BrowserAccessibilityAndroid* 918 BrowserAccessibilityAndroid*
916 BrowserAccessibilityManagerAndroid::GetFromUniqueID(int32_t unique_id) { 919 BrowserAccessibilityManagerAndroid::GetFromUniqueID(int32_t unique_id) {
917 return static_cast<BrowserAccessibilityAndroid*>( 920 return static_cast<BrowserAccessibilityAndroid*>(
918 BrowserAccessibility::GetFromUniqueID(unique_id)); 921 BrowserAccessibility::GetFromUniqueID(unique_id));
919 } 922 }
920 923
924 ScopedJavaLocalRef<jobject>
925 BrowserAccessibilityManagerAndroid::GetJavaRefFromRootManager() {
926 BrowserAccessibilityManagerAndroid* root_manager =
927 static_cast<BrowserAccessibilityManagerAndroid*>(
928 GetRootManager());
929 if (!root_manager)
930 return ScopedJavaLocalRef<jobject>();
931
932 JNIEnv* env = AttachCurrentThread();
933 return root_manager->java_ref().get(env);
934 }
935
921 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { 936 bool RegisterBrowserAccessibilityManager(JNIEnv* env) {
922 return RegisterNativesImpl(env); 937 return RegisterNativesImpl(env);
923 } 938 }
924 939
925 } // namespace content 940 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698