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

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

Issue 15741009: Native Android accessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split RendererAccessibilityFocusOnly fix into separate changelist Created 7 years, 6 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 <cmath> 7 #include <cmath>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "content/browser/accessibility/browser_accessibility_android.h" 14 #include "content/browser/accessibility/browser_accessibility_android.h"
15 #include "content/common/accessibility_messages.h" 15 #include "content/common/accessibility_messages.h"
16 #include "jni/BrowserAccessibilityManager_jni.h"
16 17
17 using base::android::AttachCurrentThread; 18 using base::android::AttachCurrentThread;
18 using base::android::ScopedJavaLocalRef; 19 using base::android::ScopedJavaLocalRef;
19 20
20 namespace { 21 namespace {
21 22
22 // Restricts |val| to the range [min, max]. 23 // Restricts |val| to the range [min, max].
23 int Clamp(int val, int min, int max) { 24 int Clamp(int val, int min, int max) {
24 return std::min(std::max(val, min), max); 25 return std::min(std::max(val, min), max);
25 } 26 }
(...skipping 18 matching lines...) Expand all
44 45
45 BrowserAccessibilityManagerAndroid::BrowserAccessibilityManagerAndroid( 46 BrowserAccessibilityManagerAndroid::BrowserAccessibilityManagerAndroid(
46 ScopedJavaLocalRef<jobject> content_view_core, 47 ScopedJavaLocalRef<jobject> content_view_core,
47 const AccessibilityNodeData& src, 48 const AccessibilityNodeData& src,
48 BrowserAccessibilityDelegate* delegate, 49 BrowserAccessibilityDelegate* delegate,
49 BrowserAccessibilityFactory* factory) 50 BrowserAccessibilityFactory* factory)
50 : BrowserAccessibilityManager(src, delegate, factory) { 51 : BrowserAccessibilityManager(src, delegate, factory) {
51 if (content_view_core.is_null()) 52 if (content_view_core.is_null())
52 return; 53 return;
53 54
54 // TODO(aboxhall): set up Java references 55 JNIEnv* env = AttachCurrentThread();
56 java_ref_ = JavaObjectWeakGlobalRef(
57 env, Java_BrowserAccessibilityManager_create(
58 env, reinterpret_cast<jint>(this), content_view_core.obj()).obj());
55 } 59 }
56 60
57 BrowserAccessibilityManagerAndroid::~BrowserAccessibilityManagerAndroid() { 61 BrowserAccessibilityManagerAndroid::~BrowserAccessibilityManagerAndroid() {
58 JNIEnv* env = base::android::AttachCurrentThread(); 62 JNIEnv* env = AttachCurrentThread();
59 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 63 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
60 if (obj.is_null()) 64 if (obj.is_null())
61 return; 65 return;
62 66
63 // TODO(aboxhall): tear down Java references 67 Java_BrowserAccessibilityManager_onNativeObjectDestroyed(env, obj.obj());
64 } 68 }
65 69
66 // static 70 // static
67 AccessibilityNodeData BrowserAccessibilityManagerAndroid::GetEmptyDocument() { 71 AccessibilityNodeData BrowserAccessibilityManagerAndroid::GetEmptyDocument() {
68 AccessibilityNodeData empty_document; 72 AccessibilityNodeData empty_document;
69 empty_document.id = 0; 73 empty_document.id = 0;
70 empty_document.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; 74 empty_document.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA;
71 empty_document.state = 1 << AccessibilityNodeData::STATE_READONLY; 75 empty_document.state = 1 << AccessibilityNodeData::STATE_READONLY;
72 return empty_document; 76 return empty_document;
73 } 77 }
74 78
75 void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent( 79 void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent(
76 int type, 80 int type,
77 BrowserAccessibility* node) { 81 BrowserAccessibility* node) {
78 JNIEnv* env = base::android::AttachCurrentThread(); 82 JNIEnv* env = AttachCurrentThread();
79 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 83 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
80 if (obj.is_null()) 84 if (obj.is_null())
81 return; 85 return;
82 86
83 // TODO(aboxhall): call into appropriate Java method for each type of 87 switch (type) {
84 // notification 88 case AccessibilityNotificationLoadComplete:
bulach 2013/06/19 10:26:53 not quite clear where these enum is coming from, b
dmazzoni 2013/06/19 19:54:41 It's been around for a while and that used to be a
89 Java_BrowserAccessibilityManager_handlePageLoaded(
90 env, obj.obj(), focus_->renderer_id());
91 break;
92 case AccessibilityNotificationFocusChanged:
93 Java_BrowserAccessibilityManager_handleFocusChanged(
94 env, obj.obj(), node->renderer_id());
95 break;
96 case AccessibilityNotificationCheckStateChanged:
97 Java_BrowserAccessibilityManager_handleCheckStateChanged(
98 env, obj.obj(), node->renderer_id());
99 break;
100 case AccessibilityNotificationScrolledToAnchor:
101 Java_BrowserAccessibilityManager_handleScrolledToAnchor(
102 env, obj.obj(), node->renderer_id());
103 break;
104 case AccessibilityNotificationAlert:
105 Java_BrowserAccessibilityManager_announceObjectShow(
106 env, obj.obj(), node->renderer_id(), JNI_TRUE);
bulach 2013/06/19 10:26:53 nit: missing break, is it intentional? if it is, p
dmazzoni 2013/06/19 19:54:41 Thanks, this was a bug.
107 case AccessibilityNotificationObjectShow:
108 Java_BrowserAccessibilityManager_announceObjectShow(
109 env, obj.obj(), node->renderer_id(), JNI_FALSE);
bulach 2013/06/19 10:26:53 ditto
dmazzoni 2013/06/19 19:54:41 Done.
110 case AccessibilityNotificationSelectedTextChanged:
111 Java_BrowserAccessibilityManager_handleTextSelectionChanged(
112 env, obj.obj(), node->renderer_id());
113 break;
114 case AccessibilityNotificationChildrenChanged:
115 case AccessibilityNotificationTextChanged:
116 case AccessibilityNotificationValueChanged:
117 if (node->IsEditableText()) {
118 Java_BrowserAccessibilityManager_handleEditableTextChanged(
119 env, obj.obj(), node->renderer_id());
120 } else {
121 Java_BrowserAccessibilityManager_handleContentChanged(
122 env, obj.obj(), node->renderer_id());
123 }
124 break;
125 default:
126 break;
bulach 2013/06/19 10:26:53 nit: NOTREACHED() ?
dmazzoni 2013/06/19 19:54:41 I don't want this, but I added a comment.
127 }
85 } 128 }
86 129
87 jint BrowserAccessibilityManagerAndroid::GetRootId(JNIEnv* env, jobject obj) { 130 jint BrowserAccessibilityManagerAndroid::GetRootId(JNIEnv* env, jobject obj) {
88 return static_cast<jint>(root_->renderer_id()); 131 return static_cast<jint>(root_->renderer_id());
89 } 132 }
90 133
91 jint BrowserAccessibilityManagerAndroid::HitTest( 134 jint BrowserAccessibilityManagerAndroid::HitTest(
92 JNIEnv* env, jobject obj, jint x, jint y) { 135 JNIEnv* env, jobject obj, jint x, jint y) {
93 BrowserAccessibilityAndroid* result = 136 BrowserAccessibilityAndroid* result =
94 static_cast<BrowserAccessibilityAndroid*>( 137 static_cast<BrowserAccessibilityAndroid*>(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 int dy = std::abs(y - nearest_y); 204 int dy = std::abs(y - nearest_y);
162 return dx * dx + dy * dy; 205 return dx * dx + dy * dy;
163 } 206 }
164 207
165 jint BrowserAccessibilityManagerAndroid::GetNativeNodeById( 208 jint BrowserAccessibilityManagerAndroid::GetNativeNodeById(
166 JNIEnv* env, jobject obj, jint id) { 209 JNIEnv* env, jobject obj, jint id) {
167 return reinterpret_cast<jint>(GetFromRendererID(id)); 210 return reinterpret_cast<jint>(GetFromRendererID(id));
168 } 211 }
169 212
170 void BrowserAccessibilityManagerAndroid::NotifyRootChanged() { 213 void BrowserAccessibilityManagerAndroid::NotifyRootChanged() {
171 // TODO(aboxhall): non-stub implementation 214 JNIEnv* env = AttachCurrentThread();
215 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
216 if (obj.is_null())
217 return;
218
219 Java_BrowserAccessibilityManager_handleNavigate(env, obj.obj());
172 } 220 }
173 221
174 bool 222 bool
175 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() { 223 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() {
176 // The Java layer handles the root scroll offset. 224 // The Java layer handles the root scroll offset.
177 return false; 225 return false;
178 } 226 }
179 227
180 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { 228 bool RegisterBrowserAccessibilityManager(JNIEnv* env) {
181 // TODO(aboxhall): non-stub implementation 229 return RegisterNativesImpl(env);
182 return false;
183 } 230 }
184 231
185 } // namespace content 232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698