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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (content_view_core.is_null()) | 174 if (content_view_core.is_null()) |
175 return; | 175 return; |
176 | 176 |
177 JNIEnv* env = AttachCurrentThread(); | 177 JNIEnv* env = AttachCurrentThread(); |
178 java_ref_ = JavaObjectWeakGlobalRef( | 178 java_ref_ = JavaObjectWeakGlobalRef( |
179 env, Java_BrowserAccessibilityManager_create( | 179 env, Java_BrowserAccessibilityManager_create( |
180 env, reinterpret_cast<intptr_t>(this), | 180 env, reinterpret_cast<intptr_t>(this), |
181 content_view_core.obj()).obj()); | 181 content_view_core.obj()).obj()); |
182 } | 182 } |
183 | 183 |
| 184 bool BrowserAccessibilityManagerAndroid::ShouldExposePasswordText() { |
| 185 JNIEnv* env = AttachCurrentThread(); |
| 186 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); |
| 187 if (obj.is_null()) |
| 188 return false; |
| 189 |
| 190 return Java_BrowserAccessibilityManager_shouldExposePasswordText( |
| 191 env, obj.obj()); |
| 192 } |
| 193 |
184 void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent( | 194 void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent( |
185 ui::AXEvent event_type, | 195 ui::AXEvent event_type, |
186 BrowserAccessibility* node) { | 196 BrowserAccessibility* node) { |
187 JNIEnv* env = AttachCurrentThread(); | 197 JNIEnv* env = AttachCurrentThread(); |
188 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); | 198 ScopedJavaLocalRef<jobject> obj = GetJavaRefFromRootManager(); |
189 if (obj.is_null()) | 199 if (obj.is_null()) |
190 return; | 200 return; |
191 | 201 |
192 BrowserAccessibilityAndroid* android_node = | 202 BrowserAccessibilityAndroid* android_node = |
193 static_cast<BrowserAccessibilityAndroid*>(node); | 203 static_cast<BrowserAccessibilityAndroid*>(node); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 node->CanScrollLeft(), | 406 node->CanScrollLeft(), |
397 node->CanScrollRight(), | 407 node->CanScrollRight(), |
398 node->IsClickable(), | 408 node->IsClickable(), |
399 node->IsEditableText(), | 409 node->IsEditableText(), |
400 node->IsEnabled(), | 410 node->IsEnabled(), |
401 node->IsFocusable(), | 411 node->IsFocusable(), |
402 node->IsFocused()); | 412 node->IsFocused()); |
403 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoClassName( | 413 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoClassName( |
404 env, obj, info, | 414 env, obj, info, |
405 base::android::ConvertUTF8ToJavaString(env, node->GetClassName()).obj()); | 415 base::android::ConvertUTF8ToJavaString(env, node->GetClassName()).obj()); |
406 if (!node->IsPassword() || | 416 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoText( |
407 Java_BrowserAccessibilityManager_shouldExposePasswordText(env, obj)) { | 417 env, obj, info, |
408 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoContentDescription( | 418 base::android::ConvertUTF16ToJavaString(env, node->GetText()).obj(), |
409 env, obj, info, | 419 node->IsLink(), |
410 base::android::ConvertUTF16ToJavaString(env, node->GetText()).obj(), | 420 node->IsEditableText()); |
411 node->IsLink()); | |
412 } | |
413 base::string16 element_id; | 421 base::string16 element_id; |
414 if (node->GetHtmlAttribute("id", &element_id)) { | 422 if (node->GetHtmlAttribute("id", &element_id)) { |
415 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoViewIdResourceName( | 423 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoViewIdResourceName( |
416 env, obj, info, | 424 env, obj, info, |
417 base::android::ConvertUTF16ToJavaString(env, element_id).obj()); | 425 base::android::ConvertUTF16ToJavaString(env, element_id).obj()); |
418 } | 426 } |
419 | 427 |
420 gfx::Rect absolute_rect = node->GetLocalBoundsRect(); | 428 gfx::Rect absolute_rect = node->GetLocalBoundsRect(); |
421 gfx::Rect parent_relative_rect = absolute_rect; | 429 gfx::Rect parent_relative_rect = absolute_rect; |
422 if (node->GetParent()) { | 430 if (node->GetParent()) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 node->GetItemCount()); | 507 node->GetItemCount()); |
500 Java_BrowserAccessibilityManager_setAccessibilityEventScrollAttributes( | 508 Java_BrowserAccessibilityManager_setAccessibilityEventScrollAttributes( |
501 env, obj, event, | 509 env, obj, event, |
502 node->GetScrollX(), | 510 node->GetScrollX(), |
503 node->GetScrollY(), | 511 node->GetScrollY(), |
504 node->GetMaxScrollX(), | 512 node->GetMaxScrollX(), |
505 node->GetMaxScrollY()); | 513 node->GetMaxScrollY()); |
506 | 514 |
507 switch (event_type) { | 515 switch (event_type) { |
508 case ANDROID_ACCESSIBILITY_EVENT_TEXT_CHANGED: { | 516 case ANDROID_ACCESSIBILITY_EVENT_TEXT_CHANGED: { |
509 base::string16 before_text, text; | 517 base::string16 before_text = node->GetTextChangeBeforeText(); |
510 if (!node->IsPassword() || | 518 base::string16 text = node->GetText(); |
511 Java_BrowserAccessibilityManager_shouldExposePasswordText(env, obj)) { | |
512 before_text = node->GetTextChangeBeforeText(); | |
513 text = node->GetText(); | |
514 } | |
515 Java_BrowserAccessibilityManager_setAccessibilityEventTextChangedAttrs( | 519 Java_BrowserAccessibilityManager_setAccessibilityEventTextChangedAttrs( |
516 env, obj, event, | 520 env, obj, event, |
517 node->GetTextChangeFromIndex(), | 521 node->GetTextChangeFromIndex(), |
518 node->GetTextChangeAddedCount(), | 522 node->GetTextChangeAddedCount(), |
519 node->GetTextChangeRemovedCount(), | 523 node->GetTextChangeRemovedCount(), |
520 base::android::ConvertUTF16ToJavaString( | 524 base::android::ConvertUTF16ToJavaString( |
521 env, before_text).obj(), | 525 env, before_text).obj(), |
522 base::android::ConvertUTF16ToJavaString(env, text).obj()); | 526 base::android::ConvertUTF16ToJavaString(env, text).obj()); |
523 break; | 527 break; |
524 } | 528 } |
525 case ANDROID_ACCESSIBILITY_EVENT_TEXT_SELECTION_CHANGED: { | 529 case ANDROID_ACCESSIBILITY_EVENT_TEXT_SELECTION_CHANGED: { |
526 base::string16 text; | 530 base::string16 text = node->GetText(); |
527 if (!node->IsPassword() || | |
528 Java_BrowserAccessibilityManager_shouldExposePasswordText(env, obj)) { | |
529 text = node->GetText(); | |
530 } | |
531 Java_BrowserAccessibilityManager_setAccessibilityEventSelectionAttrs( | 531 Java_BrowserAccessibilityManager_setAccessibilityEventSelectionAttrs( |
532 env, obj, event, | 532 env, obj, event, |
533 node->GetSelectionStart(), | 533 node->GetSelectionStart(), |
534 node->GetSelectionEnd(), | 534 node->GetSelectionEnd(), |
535 node->GetEditableTextLength(), | 535 node->GetEditableTextLength(), |
536 base::android::ConvertUTF16ToJavaString(env, text).obj()); | 536 base::android::ConvertUTF16ToJavaString(env, text).obj()); |
537 break; | 537 break; |
538 } | 538 } |
539 default: | 539 default: |
540 break; | 540 break; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 jint id, | 737 jint id, |
738 jint cursor_index) { | 738 jint cursor_index) { |
739 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); | 739 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
740 if (!node) | 740 if (!node) |
741 return false; | 741 return false; |
742 | 742 |
743 jint start_index = -1; | 743 jint start_index = -1; |
744 int end_index = -1; | 744 int end_index = -1; |
745 if (NextAtGranularity(granularity, cursor_index, node, | 745 if (NextAtGranularity(granularity, cursor_index, node, |
746 &start_index, &end_index)) { | 746 &start_index, &end_index)) { |
747 base::string16 text; | 747 base::string16 text = node->GetText(); |
748 if (!node->IsPassword() || | |
749 Java_BrowserAccessibilityManager_shouldExposePasswordText(env, obj)) { | |
750 text = node->GetText(); | |
751 } | |
752 Java_BrowserAccessibilityManager_finishGranularityMove( | 748 Java_BrowserAccessibilityManager_finishGranularityMove( |
753 env, obj, base::android::ConvertUTF16ToJavaString( | 749 env, obj, base::android::ConvertUTF16ToJavaString( |
754 env, text).obj(), | 750 env, text).obj(), |
755 extend_selection, start_index, end_index, true); | 751 extend_selection, start_index, end_index, true); |
756 return true; | 752 return true; |
757 } | 753 } |
758 return false; | 754 return false; |
759 } | 755 } |
760 | 756 |
761 jboolean BrowserAccessibilityManagerAndroid::PreviousAtGranularity( | 757 jboolean BrowserAccessibilityManagerAndroid::PreviousAtGranularity( |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 | 939 |
944 JNIEnv* env = AttachCurrentThread(); | 940 JNIEnv* env = AttachCurrentThread(); |
945 return root_manager->java_ref().get(env); | 941 return root_manager->java_ref().get(env); |
946 } | 942 } |
947 | 943 |
948 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 944 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
949 return RegisterNativesImpl(env); | 945 return RegisterNativesImpl(env); |
950 } | 946 } |
951 | 947 |
952 } // namespace content | 948 } // namespace content |
OLD | NEW |