| 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_android.h" | 5 #include "content/browser/accessibility/browser_accessibility_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_registrar.h" |
| 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 12 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 9 #include "content/common/accessibility_messages.h" | 13 #include "content/common/accessibility_messages.h" |
| 10 #include "content/common/accessibility_node_data.h" | 14 #include "content/common/accessibility_node_data.h" |
| 11 | 15 |
| 16 using base::android::ScopedJavaLocalRef; |
| 17 |
| 12 namespace content { | 18 namespace content { |
| 13 | 19 |
| 14 // static | 20 // static |
| 15 BrowserAccessibility* BrowserAccessibility::Create() { | 21 BrowserAccessibility* BrowserAccessibility::Create() { |
| 16 return new BrowserAccessibilityAndroid(); | 22 return new BrowserAccessibilityAndroid(); |
| 17 } | 23 } |
| 18 | 24 |
| 19 BrowserAccessibilityAndroid::BrowserAccessibilityAndroid() { | 25 BrowserAccessibilityAndroid::BrowserAccessibilityAndroid() { |
| 20 first_time_ = true; | 26 first_time_ = true; |
| 21 } | 27 } |
| 22 | 28 |
| 23 bool BrowserAccessibilityAndroid::IsNative() const { | 29 bool BrowserAccessibilityAndroid::IsNative() const { |
| 24 return true; | 30 return true; |
| 25 } | 31 } |
| 26 | 32 |
| 27 bool BrowserAccessibilityAndroid::IsLeaf() const { | 33 // |
| 28 if (child_count() == 0) | 34 // Actions, called from Java. |
| 29 return true; | 35 // |
| 30 | 36 |
| 31 // Iframes are always allowed to contain children. | 37 void BrowserAccessibilityAndroid::FocusJNI(JNIEnv* env, jobject obj) { |
| 32 if (IsIframe() || | 38 manager_->SetFocus(this, true); |
| 33 role() == AccessibilityNodeData::ROLE_ROOT_WEB_AREA || | 39 } |
| 34 role() == AccessibilityNodeData::ROLE_WEB_AREA) { | 40 |
| 35 return false; | 41 void BrowserAccessibilityAndroid::ClickJNI(JNIEnv* env, jobject obj) { |
| 42 manager_->DoDefaultAction(*this); |
| 43 } |
| 44 |
| 45 // |
| 46 // Const accessors, called from Java. |
| 47 // |
| 48 |
| 49 ScopedJavaLocalRef<jstring> |
| 50 BrowserAccessibilityAndroid::GetNameJNI(JNIEnv* env, jobject obj) const { |
| 51 return base::android::ConvertUTF16ToJavaString(env, ComputeName()); |
| 52 } |
| 53 |
| 54 ScopedJavaLocalRef<jobject> |
| 55 BrowserAccessibilityAndroid::GetAbsoluteRectJNI( |
| 56 JNIEnv* env, jobject obj) const { |
| 57 gfx::Rect rect = GetLocalBoundsRect(); |
| 58 |
| 59 // TODO(aboxhall): replace with non-stub implementation |
| 60 return ScopedJavaLocalRef<jobject>(env, NULL); |
| 61 } |
| 62 |
| 63 ScopedJavaLocalRef<jobject> |
| 64 BrowserAccessibilityAndroid::GetRectInParentJNI( |
| 65 JNIEnv* env, jobject obj) const { |
| 66 gfx::Rect rect = GetLocalBoundsRect(); |
| 67 if (parent()) { |
| 68 gfx::Rect parent_rect = parent()->GetLocalBoundsRect(); |
| 69 rect.Offset(-parent_rect.OffsetFromOrigin()); |
| 36 } | 70 } |
| 37 | 71 |
| 38 // If it has a focusable child, we definitely can't leave out children. | 72 // TODO(aboxhall): replace with non-stub implementation |
| 39 if (HasFocusableChild()) | 73 return ScopedJavaLocalRef<jobject>(env, NULL); |
| 40 return false; | |
| 41 | |
| 42 // Headings with text can drop their children. | |
| 43 string16 name = GetText(); | |
| 44 if (role() == AccessibilityNodeData::ROLE_HEADING && !name.empty()) | |
| 45 return true; | |
| 46 | |
| 47 // Focusable nodes with text can drop their children. | |
| 48 if (HasState(AccessibilityNodeData::STATE_FOCUSABLE) && !name.empty()) | |
| 49 return true; | |
| 50 | |
| 51 // Nodes with only static text as children can drop their children. | |
| 52 if (HasOnlyStaticTextChildren()) | |
| 53 return true; | |
| 54 | |
| 55 return false; | |
| 56 } | 74 } |
| 57 | 75 |
| 58 bool BrowserAccessibilityAndroid::IsCheckable() const { | 76 jboolean |
| 77 BrowserAccessibilityAndroid::IsFocusableJNI(JNIEnv* env, jobject obj) const { |
| 78 return static_cast<jboolean>(IsFocusable()); |
| 79 } |
| 80 |
| 81 jboolean |
| 82 BrowserAccessibilityAndroid::IsEditableTextJNI(JNIEnv* env, jobject obj) const { |
| 83 return IsEditableText(); |
| 84 } |
| 85 |
| 86 jint BrowserAccessibilityAndroid::GetParentJNI(JNIEnv* env, jobject obj) const { |
| 87 return static_cast<jint>(parent()->renderer_id()); |
| 88 } |
| 89 |
| 90 jint |
| 91 BrowserAccessibilityAndroid::GetChildCountJNI(JNIEnv* env, jobject obj) const { |
| 92 if (IsLeaf()) |
| 93 return 0; |
| 94 else |
| 95 return static_cast<jint>(child_count()); |
| 96 } |
| 97 |
| 98 jint BrowserAccessibilityAndroid::GetChildIdAtJNI(JNIEnv* env, |
| 99 jobject obj, |
| 100 jint child_index) const { |
| 101 return static_cast<jint>(GetChild(child_index)->renderer_id()); |
| 102 } |
| 103 |
| 104 jboolean |
| 105 BrowserAccessibilityAndroid::IsCheckableJNI(JNIEnv* env, jobject obj) const { |
| 59 bool checkable = false; | 106 bool checkable = false; |
| 60 bool is_aria_pressed_defined; | 107 bool is_aria_pressed_defined; |
| 61 bool is_mixed; | 108 bool is_mixed; |
| 62 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed); | 109 GetAriaTristate("aria-pressed", &is_aria_pressed_defined, &is_mixed); |
| 63 if (role() == AccessibilityNodeData::ROLE_CHECKBOX || | 110 if (role() == AccessibilityNodeData::ROLE_CHECKBOX || |
| 64 role() == AccessibilityNodeData::ROLE_RADIO_BUTTON || | 111 role() == AccessibilityNodeData::ROLE_RADIO_BUTTON || |
| 65 is_aria_pressed_defined) { | 112 is_aria_pressed_defined) { |
| 66 checkable = true; | 113 checkable = true; |
| 67 } | 114 } |
| 68 if (HasState(AccessibilityNodeData::STATE_CHECKED)) | 115 if (HasState(AccessibilityNodeData::STATE_CHECKED)) |
| 69 checkable = true; | 116 checkable = true; |
| 70 return checkable; | 117 return static_cast<jboolean>(checkable); |
| 71 } | 118 } |
| 72 | 119 |
| 73 bool BrowserAccessibilityAndroid::IsChecked() const { | 120 jboolean |
| 74 return HasState(AccessibilityNodeData::STATE_CHECKED); | 121 BrowserAccessibilityAndroid::IsCheckedJNI(JNIEnv* env, jobject obj) const { |
| 122 return static_cast<jboolean>( |
| 123 HasState(AccessibilityNodeData::STATE_CHECKED)); |
| 75 } | 124 } |
| 76 | 125 |
| 77 bool BrowserAccessibilityAndroid::IsClickable() const { | 126 base::android::ScopedJavaLocalRef<jstring> |
| 78 return (IsLeaf() && !GetText().empty()); | 127 BrowserAccessibilityAndroid::GetClassNameJNI(JNIEnv* env, jobject obj) const { |
| 79 } | |
| 80 | |
| 81 bool BrowserAccessibilityAndroid::IsEnabled() const { | |
| 82 return !HasState(AccessibilityNodeData::STATE_UNAVAILABLE); | |
| 83 } | |
| 84 | |
| 85 bool BrowserAccessibilityAndroid::IsFocusable() const { | |
| 86 bool focusable = HasState(AccessibilityNodeData::STATE_FOCUSABLE); | |
| 87 if (IsIframe() || | |
| 88 role() == AccessibilityNodeData::ROLE_WEB_AREA) { | |
| 89 focusable = false; | |
| 90 } | |
| 91 return focusable; | |
| 92 } | |
| 93 | |
| 94 bool BrowserAccessibilityAndroid::IsFocused() const { | |
| 95 return manager()->GetFocus(manager()->GetRoot()) == this; | |
| 96 } | |
| 97 | |
| 98 bool BrowserAccessibilityAndroid::IsPassword() const { | |
| 99 return HasState(AccessibilityNodeData::STATE_PROTECTED); | |
| 100 } | |
| 101 | |
| 102 bool BrowserAccessibilityAndroid::IsScrollable() const { | |
| 103 int dummy; | |
| 104 return GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &dummy); | |
| 105 } | |
| 106 | |
| 107 bool BrowserAccessibilityAndroid::IsSelected() const { | |
| 108 return HasState(AccessibilityNodeData::STATE_SELECTED); | |
| 109 } | |
| 110 | |
| 111 bool BrowserAccessibilityAndroid::IsVisibleToUser() const { | |
| 112 return !HasState(AccessibilityNodeData::STATE_INVISIBLE); | |
| 113 } | |
| 114 | |
| 115 const char* BrowserAccessibilityAndroid::GetClassName() const { | |
| 116 const char* class_name = NULL; | 128 const char* class_name = NULL; |
| 117 | 129 |
| 118 switch(role()) { | 130 switch(role()) { |
| 119 case AccessibilityNodeData::ROLE_EDITABLE_TEXT: | 131 case AccessibilityNodeData::ROLE_EDITABLE_TEXT: |
| 120 case AccessibilityNodeData::ROLE_SPIN_BUTTON: | 132 case AccessibilityNodeData::ROLE_SPIN_BUTTON: |
| 121 case AccessibilityNodeData::ROLE_TEXTAREA: | 133 case AccessibilityNodeData::ROLE_TEXTAREA: |
| 122 case AccessibilityNodeData::ROLE_TEXT_FIELD: | 134 case AccessibilityNodeData::ROLE_TEXT_FIELD: |
| 123 class_name = "android.widget.EditText"; | 135 class_name = "android.widget.EditText"; |
| 124 break; | 136 break; |
| 125 case AccessibilityNodeData::ROLE_SLIDER: | 137 case AccessibilityNodeData::ROLE_SLIDER: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 break; | 170 break; |
| 159 case AccessibilityNodeData::ROLE_LIST: | 171 case AccessibilityNodeData::ROLE_LIST: |
| 160 case AccessibilityNodeData::ROLE_LISTBOX: | 172 case AccessibilityNodeData::ROLE_LISTBOX: |
| 161 class_name = "android.widget.ListView"; | 173 class_name = "android.widget.ListView"; |
| 162 break; | 174 break; |
| 163 default: | 175 default: |
| 164 class_name = "android.view.View"; | 176 class_name = "android.view.View"; |
| 165 break; | 177 break; |
| 166 } | 178 } |
| 167 | 179 |
| 168 return class_name; | 180 return base::android::ConvertUTF8ToJavaString(env, class_name); |
| 169 } | 181 } |
| 170 | 182 |
| 171 string16 BrowserAccessibilityAndroid::GetText() const { | 183 jboolean |
| 172 if (IsIframe() || | 184 BrowserAccessibilityAndroid::IsEnabledJNI(JNIEnv* env, jobject obj) const { |
| 173 role() == AccessibilityNodeData::ROLE_WEB_AREA) { | 185 return static_cast<jboolean>( |
| 174 return string16(); | 186 !HasState(AccessibilityNodeData::STATE_UNAVAILABLE)); |
| 175 } | |
| 176 | |
| 177 string16 description; | |
| 178 GetStringAttribute(AccessibilityNodeData::ATTR_DESCRIPTION, &description); | |
| 179 | |
| 180 string16 text; | |
| 181 if (!name().empty()) | |
| 182 text = name(); | |
| 183 else if (!description.empty()) | |
| 184 text = description; | |
| 185 else if (!value().empty()) | |
| 186 text = value(); | |
| 187 | |
| 188 if (text.empty() && HasOnlyStaticTextChildren()) { | |
| 189 for (uint32 i = 0; i < child_count(); i++) { | |
| 190 BrowserAccessibility* child = GetChild(i); | |
| 191 text += static_cast<BrowserAccessibilityAndroid*>(child)->GetText(); | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 switch(role()) { | |
| 196 case AccessibilityNodeData::ROLE_IMAGE_MAP_LINK: | |
| 197 case AccessibilityNodeData::ROLE_LINK: | |
| 198 case AccessibilityNodeData::ROLE_WEBCORE_LINK: | |
| 199 if (!text.empty()) | |
| 200 text += ASCIIToUTF16(" "); | |
| 201 text += ASCIIToUTF16("Link"); | |
| 202 break; | |
| 203 case AccessibilityNodeData::ROLE_HEADING: | |
| 204 // Only append "heading" if this node already has text. | |
| 205 if (!text.empty()) | |
| 206 text += ASCIIToUTF16(" Heading"); | |
| 207 break; | |
| 208 } | |
| 209 | |
| 210 return text; | |
| 211 } | 187 } |
| 212 | 188 |
| 213 int BrowserAccessibilityAndroid::GetItemIndex() const { | 189 jboolean |
| 190 BrowserAccessibilityAndroid::IsFocusedJNI(JNIEnv* env, jobject obj) const { |
| 191 return manager()->GetFocus(manager()->GetRoot()) == this; |
| 192 } |
| 193 |
| 194 jboolean |
| 195 BrowserAccessibilityAndroid::IsPasswordJNI(JNIEnv* env, jobject obj) const { |
| 196 return static_cast<jboolean>( |
| 197 HasState(AccessibilityNodeData::STATE_PROTECTED)); |
| 198 } |
| 199 |
| 200 jboolean |
| 201 BrowserAccessibilityAndroid::IsScrollableJNI(JNIEnv* env, jobject obj) const { |
| 202 int dummy; |
| 203 bool scrollable = GetIntAttribute( |
| 204 AccessibilityNodeData::ATTR_SCROLL_X_MAX, &dummy); |
| 205 return static_cast<jboolean>(scrollable); |
| 206 } |
| 207 |
| 208 jboolean |
| 209 BrowserAccessibilityAndroid::IsSelectedJNI(JNIEnv* env, jobject obj) const { |
| 210 return static_cast<jboolean>( |
| 211 HasState(AccessibilityNodeData::STATE_SELECTED)); |
| 212 } |
| 213 |
| 214 jboolean |
| 215 BrowserAccessibilityAndroid::IsVisibleJNI(JNIEnv* env, jobject obj) const { |
| 216 return static_cast<jboolean>( |
| 217 !HasState(AccessibilityNodeData::STATE_INVISIBLE)); |
| 218 } |
| 219 |
| 220 base::android::ScopedJavaLocalRef<jstring> |
| 221 BrowserAccessibilityAndroid::GetAriaLiveJNI(JNIEnv* env, jobject obj) const { |
| 222 return base::android::ConvertUTF16ToJavaString(env, GetAriaLive()); |
| 223 } |
| 224 |
| 225 jint BrowserAccessibilityAndroid::GetItemIndexJNI( |
| 226 JNIEnv* env, jobject obj) const { |
| 214 int index = 0; | 227 int index = 0; |
| 215 switch(role()) { | 228 switch(role()) { |
| 216 case AccessibilityNodeData::ROLE_LIST_ITEM: | 229 case AccessibilityNodeData::ROLE_LIST_ITEM: |
| 217 case AccessibilityNodeData::ROLE_LISTBOX_OPTION: | 230 case AccessibilityNodeData::ROLE_LISTBOX_OPTION: |
| 218 index = index_in_parent(); | 231 index = index_in_parent(); |
| 219 break; | 232 break; |
| 220 case AccessibilityNodeData::ROLE_SLIDER: | 233 case AccessibilityNodeData::ROLE_SLIDER: |
| 221 case AccessibilityNodeData::ROLE_PROGRESS_INDICATOR: { | 234 case AccessibilityNodeData::ROLE_PROGRESS_INDICATOR: { |
| 222 float value_for_range; | 235 float value_for_range; |
| 223 if (GetFloatAttribute( | 236 if (GetFloatAttribute( |
| 224 AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &value_for_range)) { | 237 AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &value_for_range)) { |
| 225 index = static_cast<int>(value_for_range); | 238 index = static_cast<int>(value_for_range); |
| 226 } | 239 } |
| 227 break; | 240 break; |
| 228 } | 241 } |
| 229 } | 242 } |
| 230 return index; | 243 return static_cast<jint>(index); |
| 231 } | 244 } |
| 232 | 245 |
| 233 int BrowserAccessibilityAndroid::GetItemCount() const { | 246 jint |
| 247 BrowserAccessibilityAndroid::GetItemCountJNI(JNIEnv* env, jobject obj) const { |
| 234 int count = 0; | 248 int count = 0; |
| 235 switch(role()) { | 249 switch(role()) { |
| 236 case AccessibilityNodeData::ROLE_LIST: | 250 case AccessibilityNodeData::ROLE_LIST: |
| 237 case AccessibilityNodeData::ROLE_LISTBOX: | 251 case AccessibilityNodeData::ROLE_LISTBOX: |
| 238 count = child_count(); | 252 count = child_count(); |
| 239 break; | 253 break; |
| 240 case AccessibilityNodeData::ROLE_SLIDER: | 254 case AccessibilityNodeData::ROLE_SLIDER: |
| 241 case AccessibilityNodeData::ROLE_PROGRESS_INDICATOR: { | 255 case AccessibilityNodeData::ROLE_PROGRESS_INDICATOR: { |
| 242 float max_value_for_range; | 256 float max_value_for_range; |
| 243 if (GetFloatAttribute(AccessibilityNodeData::ATTR_MAX_VALUE_FOR_RANGE, | 257 if (GetFloatAttribute(AccessibilityNodeData::ATTR_MAX_VALUE_FOR_RANGE, |
| 244 &max_value_for_range)) { | 258 &max_value_for_range)) { |
| 245 count = static_cast<int>(max_value_for_range); | 259 count = static_cast<int>(max_value_for_range); |
| 246 } | 260 } |
| 247 break; | 261 break; |
| 248 } | 262 } |
| 249 } | 263 } |
| 250 return count; | 264 return static_cast<jint>(count); |
| 251 } | 265 } |
| 252 | 266 |
| 253 int BrowserAccessibilityAndroid::GetScrollX() const { | 267 jint |
| 268 BrowserAccessibilityAndroid::GetScrollXJNI(JNIEnv* env, jobject obj) const { |
| 254 int value = 0; | 269 int value = 0; |
| 255 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &value); | 270 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &value); |
| 256 return value; | 271 return static_cast<jint>(value); |
| 257 } | 272 } |
| 258 | 273 |
| 259 int BrowserAccessibilityAndroid::GetScrollY() const { | 274 jint |
| 275 BrowserAccessibilityAndroid::GetScrollYJNI(JNIEnv* env, jobject obj) const { |
| 260 int value = 0; | 276 int value = 0; |
| 261 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &value); | 277 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &value); |
| 262 return value; | 278 return static_cast<jint>(value); |
| 263 } | 279 } |
| 264 | 280 |
| 265 int BrowserAccessibilityAndroid::GetMaxScrollX() const { | 281 jint |
| 282 BrowserAccessibilityAndroid::GetMaxScrollXJNI(JNIEnv* env, jobject obj) const { |
| 266 int value = 0; | 283 int value = 0; |
| 267 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &value); | 284 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X_MAX, &value); |
| 268 return value; | 285 return static_cast<jint>(value); |
| 269 } | 286 } |
| 270 | 287 |
| 271 int BrowserAccessibilityAndroid::GetMaxScrollY() const { | 288 jint |
| 289 BrowserAccessibilityAndroid::GetMaxScrollYJNI(JNIEnv* env, jobject obj) const { |
| 272 int value = 0; | 290 int value = 0; |
| 273 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y_MAX, &value); | 291 GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y_MAX, &value); |
| 274 return value; | 292 return static_cast<jint>(value); |
| 275 } | 293 } |
| 276 | 294 |
| 277 int BrowserAccessibilityAndroid::GetTextChangeFromIndex() const { | 295 jboolean |
| 296 BrowserAccessibilityAndroid::GetClickableJNI(JNIEnv* env, jobject obj) const { |
| 297 return (IsLeaf() && !ComputeName().empty()); |
| 298 } |
| 299 |
| 300 jint BrowserAccessibilityAndroid::GetSelectionStartJNI(JNIEnv* env, jobject obj) |
| 301 const { |
| 302 int sel_start = 0; |
| 303 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_START, &sel_start); |
| 304 return sel_start; |
| 305 } |
| 306 |
| 307 jint BrowserAccessibilityAndroid::GetSelectionEndJNI(JNIEnv* env, jobject obj) |
| 308 const { |
| 309 int sel_end = 0; |
| 310 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &sel_end); |
| 311 return sel_end; |
| 312 } |
| 313 |
| 314 jint BrowserAccessibilityAndroid::GetEditableTextLengthJNI( |
| 315 JNIEnv* env, jobject obj) const { |
| 316 return value().length(); |
| 317 } |
| 318 |
| 319 int BrowserAccessibilityAndroid::GetTextChangeFromIndexJNI( |
| 320 JNIEnv* env, jobject obj) const { |
| 278 size_t index = 0; | 321 size_t index = 0; |
| 279 while (index < old_value_.length() && | 322 while (index < old_value_.length() && |
| 280 index < new_value_.length() && | 323 index < new_value_.length() && |
| 281 old_value_[index] == new_value_[index]) { | 324 old_value_[index] == new_value_[index]) { |
| 282 index++; | 325 index++; |
| 283 } | 326 } |
| 284 return index; | 327 return index; |
| 285 } | 328 } |
| 286 | 329 |
| 287 int BrowserAccessibilityAndroid::GetTextChangeAddedCount() const { | 330 jint BrowserAccessibilityAndroid::GetTextChangeAddedCountJNI( |
| 331 JNIEnv* env, jobject obj) const { |
| 288 size_t old_len = old_value_.length(); | 332 size_t old_len = old_value_.length(); |
| 289 size_t new_len = new_value_.length(); | 333 size_t new_len = new_value_.length(); |
| 290 size_t left = 0; | 334 size_t left = 0; |
| 291 while (left < old_len && | 335 while (left < old_len && |
| 292 left < new_len && | 336 left < new_len && |
| 293 old_value_[left] == new_value_[left]) { | 337 old_value_[left] == new_value_[left]) { |
| 294 left++; | 338 left++; |
| 295 } | 339 } |
| 296 size_t right = 0; | 340 size_t right = 0; |
| 297 while (right < old_len && | 341 while (right < old_len && |
| 298 right < new_len && | 342 right < new_len && |
| 299 old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) { | 343 old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) { |
| 300 right++; | 344 right++; |
| 301 } | 345 } |
| 302 return (new_len - left - right); | 346 return (new_len - left - right); |
| 303 } | 347 } |
| 304 | 348 |
| 305 int BrowserAccessibilityAndroid::GetTextChangeRemovedCount() const { | 349 jint BrowserAccessibilityAndroid::GetTextChangeRemovedCountJNI( |
| 350 JNIEnv* env, jobject obj) const { |
| 306 size_t old_len = old_value_.length(); | 351 size_t old_len = old_value_.length(); |
| 307 size_t new_len = new_value_.length(); | 352 size_t new_len = new_value_.length(); |
| 308 size_t left = 0; | 353 size_t left = 0; |
| 309 while (left < old_len && | 354 while (left < old_len && |
| 310 left < new_len && | 355 left < new_len && |
| 311 old_value_[left] == new_value_[left]) { | 356 old_value_[left] == new_value_[left]) { |
| 312 left++; | 357 left++; |
| 313 } | 358 } |
| 314 size_t right = 0; | 359 size_t right = 0; |
| 315 while (right < old_len && | 360 while (right < old_len && |
| 316 right < new_len && | 361 right < new_len && |
| 317 old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) { | 362 old_value_[old_len - right - 1] == new_value_[new_len - right - 1]) { |
| 318 right++; | 363 right++; |
| 319 } | 364 } |
| 320 return (old_len - left - right); | 365 return (old_len - left - right); |
| 321 } | 366 } |
| 322 | 367 |
| 323 string16 BrowserAccessibilityAndroid::GetTextChangeBeforeText() const { | 368 base::android::ScopedJavaLocalRef<jstring> |
| 324 return old_value_; | 369 BrowserAccessibilityAndroid::GetTextChangeBeforeTextJNI( |
| 370 JNIEnv* env, jobject obj) const { |
| 371 return base::android::ConvertUTF16ToJavaString(env, old_value_); |
| 325 } | 372 } |
| 326 | 373 |
| 327 int BrowserAccessibilityAndroid::GetSelectionStart() const { | 374 string16 BrowserAccessibilityAndroid::ComputeName() const { |
| 328 int sel_start = 0; | 375 if (IsIframe() || |
| 329 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_START, &sel_start); | 376 role() == AccessibilityNodeData::ROLE_WEB_AREA) { |
| 330 return sel_start; | 377 return string16(); |
| 378 } |
| 379 |
| 380 string16 description; |
| 381 GetStringAttribute(AccessibilityNodeData::ATTR_DESCRIPTION, |
| 382 &description); |
| 383 |
| 384 string16 text; |
| 385 if (!name().empty()) |
| 386 text = name(); |
| 387 else if (!description.empty()) |
| 388 text = description; |
| 389 else if (!value().empty()) |
| 390 text = value(); |
| 391 |
| 392 if (text.empty() && HasOnlyStaticTextChildren()) { |
| 393 for (uint32 i = 0; i < child_count(); i++) { |
| 394 BrowserAccessibility* child = GetChild(i); |
| 395 text += static_cast<BrowserAccessibilityAndroid*>(child)->ComputeName(); |
| 396 } |
| 397 } |
| 398 |
| 399 switch(role()) { |
| 400 case AccessibilityNodeData::ROLE_IMAGE_MAP_LINK: |
| 401 case AccessibilityNodeData::ROLE_LINK: |
| 402 case AccessibilityNodeData::ROLE_WEBCORE_LINK: |
| 403 if (!text.empty()) |
| 404 text += ASCIIToUTF16(" "); |
| 405 text += ASCIIToUTF16("Link"); |
| 406 break; |
| 407 case AccessibilityNodeData::ROLE_HEADING: |
| 408 // Only append "heading" if this node already has text. |
| 409 if (!text.empty()) |
| 410 text += ASCIIToUTF16(" Heading"); |
| 411 break; |
| 412 } |
| 413 |
| 414 return text; |
| 331 } | 415 } |
| 332 | 416 |
| 333 int BrowserAccessibilityAndroid::GetSelectionEnd() const { | 417 string16 BrowserAccessibilityAndroid::GetAriaLive() const { |
| 334 int sel_end = 0; | 418 string16 aria_live; |
| 335 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &sel_end); | 419 if (GetStringAttribute(AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, |
| 336 return sel_end; | 420 &aria_live)) { |
| 337 } | 421 return aria_live; |
| 338 | 422 } |
| 339 int BrowserAccessibilityAndroid::GetEditableTextLength() const { | 423 return string16(); |
| 340 return value().length(); | |
| 341 } | 424 } |
| 342 | 425 |
| 343 bool BrowserAccessibilityAndroid::HasFocusableChild() const { | 426 bool BrowserAccessibilityAndroid::HasFocusableChild() const { |
| 344 for (uint32 i = 0; i < child_count(); i++) { | 427 for (uint32 i = 0; i < child_count(); i++) { |
| 345 BrowserAccessibility* child = GetChild(i); | 428 BrowserAccessibility* child = GetChild(i); |
| 346 if (child->HasState(AccessibilityNodeData::STATE_FOCUSABLE)) | 429 if (child->HasState(AccessibilityNodeData::STATE_FOCUSABLE)) |
| 347 return true; | 430 return true; |
| 348 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild()) | 431 if (static_cast<BrowserAccessibilityAndroid*>(child)->HasFocusableChild()) |
| 349 return true; | 432 return true; |
| 350 } | 433 } |
| 351 return false; | 434 return false; |
| 352 } | 435 } |
| 353 | 436 |
| 354 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { | 437 bool BrowserAccessibilityAndroid::HasOnlyStaticTextChildren() const { |
| 355 for (uint32 i = 0; i < child_count(); i++) { | 438 for (uint32 i = 0; i < child_count(); i++) { |
| 356 BrowserAccessibility* child = GetChild(i); | 439 BrowserAccessibility* child = GetChild(i); |
| 357 if (child->role() != AccessibilityNodeData::ROLE_STATIC_TEXT) | 440 if (child->role() != AccessibilityNodeData::ROLE_STATIC_TEXT) |
| 358 return false; | 441 return false; |
| 359 } | 442 } |
| 360 return true; | 443 return true; |
| 361 } | 444 } |
| 362 | 445 |
| 363 bool BrowserAccessibilityAndroid::IsIframe() const { | 446 bool BrowserAccessibilityAndroid::IsIframe() const { |
| 364 string16 html_tag; | 447 string16 html_tag; |
| 365 GetStringAttribute(AccessibilityNodeData::ATTR_HTML_TAG, &html_tag); | 448 GetStringAttribute(AccessibilityNodeData::ATTR_HTML_TAG, &html_tag); |
| 366 return html_tag == ASCIIToUTF16("iframe"); | 449 return html_tag == ASCIIToUTF16("iframe"); |
| 367 } | 450 } |
| 368 | 451 |
| 452 bool BrowserAccessibilityAndroid::IsFocusable() const { |
| 453 bool focusable = HasState(AccessibilityNodeData::STATE_FOCUSABLE); |
| 454 if (IsIframe() || |
| 455 role() == AccessibilityNodeData::ROLE_WEB_AREA) { |
| 456 focusable = false; |
| 457 } |
| 458 return focusable; |
| 459 } |
| 460 |
| 461 bool BrowserAccessibilityAndroid::IsLeaf() const { |
| 462 if (child_count() == 0) |
| 463 return true; |
| 464 |
| 465 // Iframes are always allowed to contain children. |
| 466 if (IsIframe() || |
| 467 role() == AccessibilityNodeData::ROLE_ROOT_WEB_AREA || |
| 468 role() == AccessibilityNodeData::ROLE_WEB_AREA) { |
| 469 return false; |
| 470 } |
| 471 |
| 472 // If it has a focusable child, we definitely can't leave out children. |
| 473 if (HasFocusableChild()) |
| 474 return false; |
| 475 |
| 476 // Headings with text can drop their children. |
| 477 string16 name = ComputeName(); |
| 478 if (role() == AccessibilityNodeData::ROLE_HEADING && !name.empty()) |
| 479 return true; |
| 480 |
| 481 // Focusable nodes with text can drop their children. |
| 482 if (HasState(AccessibilityNodeData::STATE_FOCUSABLE) && !name.empty()) |
| 483 return true; |
| 484 |
| 485 // Nodes with only static text as children can drop their children. |
| 486 if (HasOnlyStaticTextChildren()) |
| 487 return true; |
| 488 |
| 489 return false; |
| 490 } |
| 491 |
| 369 void BrowserAccessibilityAndroid::PostInitialize() { | 492 void BrowserAccessibilityAndroid::PostInitialize() { |
| 370 BrowserAccessibility::PostInitialize(); | 493 BrowserAccessibility::PostInitialize(); |
| 371 | 494 |
| 372 if (IsEditableText()) { | 495 if (IsEditableText()) { |
| 373 if (value_ != new_value_) { | 496 if (value_ != new_value_) { |
| 374 old_value_ = new_value_; | 497 old_value_ = new_value_; |
| 375 new_value_ = value_; | 498 new_value_ = value_; |
| 376 } | 499 } |
| 377 } | 500 } |
| 378 | 501 |
| 379 if (role_ == AccessibilityNodeData::ROLE_ALERT && first_time_) | 502 if (role_ == AccessibilityNodeData::ROLE_ALERT && first_time_) |
| 380 manager_->NotifyAccessibilityEvent(AccessibilityNotificationAlert, this); | 503 manager_->NotifyAccessibilityEvent(AccessibilityNotificationAlert, this); |
| 381 | 504 |
| 382 string16 live; | 505 string16 live; |
| 383 if (GetStringAttribute(AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, | 506 if (GetStringAttribute(AccessibilityNodeData::ATTR_CONTAINER_LIVE_STATUS, |
| 384 &live)) { | 507 &live)) { |
| 385 NotifyLiveRegionUpdate(live); | 508 NotifyLiveRegionUpdate(live); |
| 386 } | 509 } |
| 387 | 510 |
| 388 first_time_ = false; | 511 first_time_ = false; |
| 389 } | 512 } |
| 390 | 513 |
| 391 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) { | 514 void BrowserAccessibilityAndroid::NotifyLiveRegionUpdate(string16& aria_live) { |
| 392 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && | 515 if (!EqualsASCII(aria_live, aria_strings::kAriaLivePolite) && |
| 393 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) | 516 !EqualsASCII(aria_live, aria_strings::kAriaLiveAssertive)) |
| 394 return; | 517 return; |
| 395 | 518 |
| 396 string16 text = GetText(); | 519 string16 text = ComputeName(); |
| 397 if (cached_text_ != text) { | 520 if (cached_text_ != text) { |
| 398 if (!text.empty()) { | 521 if (!text.empty()) { |
| 399 manager_->NotifyAccessibilityEvent(AccessibilityNotificationObjectShow, | 522 manager_->NotifyAccessibilityEvent(AccessibilityNotificationObjectShow, |
| 400 this); | 523 this); |
| 401 } | 524 } |
| 402 cached_text_ = text; | 525 cached_text_ = text; |
| 403 } | 526 } |
| 404 } | 527 } |
| 405 | 528 |
| 529 bool RegisterBrowserAccessibility(JNIEnv* env) { |
| 530 // TODO(aboxhall): replace with non-stub implementation |
| 531 return false; |
| 532 } |
| 533 |
| 406 } // namespace content | 534 } // namespace content |
| OLD | NEW |