| 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> |
| 8 |
| 7 #include <cmath> | 9 #include <cmath> |
| 8 | 10 |
| 9 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 11 #include "base/i18n/char_iterator.h" | 13 #include "base/i18n/char_iterator.h" |
| 12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "content/browser/accessibility/browser_accessibility_android.h" | 17 #include "content/browser/accessibility/browser_accessibility_android.h" |
| 16 #include "content/common/accessibility_messages.h" | 18 #include "content/common/accessibility_messages.h" |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 Java_BrowserAccessibilityManager_finishGranularityMove( | 695 Java_BrowserAccessibilityManager_finishGranularityMove( |
| 694 env, obj, base::android::ConvertUTF16ToJavaString( | 696 env, obj, base::android::ConvertUTF16ToJavaString( |
| 695 env, node->GetText()).obj(), | 697 env, node->GetText()).obj(), |
| 696 extend_selection, start_index, end_index, false); | 698 extend_selection, start_index, end_index, false); |
| 697 return true; | 699 return true; |
| 698 } | 700 } |
| 699 return false; | 701 return false; |
| 700 } | 702 } |
| 701 | 703 |
| 702 bool BrowserAccessibilityManagerAndroid::NextAtGranularity( | 704 bool BrowserAccessibilityManagerAndroid::NextAtGranularity( |
| 703 int32 granularity, int32 cursor_index, | 705 int32_t granularity, |
| 704 BrowserAccessibilityAndroid* node, int32* start_index, int32* end_index) { | 706 int32_t cursor_index, |
| 707 BrowserAccessibilityAndroid* node, |
| 708 int32_t* start_index, |
| 709 int32_t* end_index) { |
| 705 switch (granularity) { | 710 switch (granularity) { |
| 706 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_CHARACTER: { | 711 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_CHARACTER: { |
| 707 base::string16 text = node->GetText(); | 712 base::string16 text = node->GetText(); |
| 708 if (cursor_index >= static_cast<int32>(text.length())) | 713 if (cursor_index >= static_cast<int32_t>(text.length())) |
| 709 return false; | 714 return false; |
| 710 base::i18n::UTF16CharIterator iter(text.data(), text.size()); | 715 base::i18n::UTF16CharIterator iter(text.data(), text.size()); |
| 711 while (!iter.end() && iter.array_pos() <= cursor_index) | 716 while (!iter.end() && iter.array_pos() <= cursor_index) |
| 712 iter.Advance(); | 717 iter.Advance(); |
| 713 *start_index = iter.array_pos(); | 718 *start_index = iter.array_pos(); |
| 714 *end_index = iter.array_pos(); | 719 *end_index = iter.array_pos(); |
| 715 break; | 720 break; |
| 716 } | 721 } |
| 717 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD: | 722 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD: |
| 718 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_LINE: { | 723 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_LINE: { |
| 719 std::vector<int32> starts; | 724 std::vector<int32_t> starts; |
| 720 std::vector<int32> ends; | 725 std::vector<int32_t> ends; |
| 721 node->GetGranularityBoundaries(granularity, &starts, &ends, 0); | 726 node->GetGranularityBoundaries(granularity, &starts, &ends, 0); |
| 722 if (starts.size() == 0) | 727 if (starts.size() == 0) |
| 723 return false; | 728 return false; |
| 724 | 729 |
| 725 size_t index = 0; | 730 size_t index = 0; |
| 726 while (index < starts.size() - 1 && starts[index] < cursor_index) | 731 while (index < starts.size() - 1 && starts[index] < cursor_index) |
| 727 index++; | 732 index++; |
| 728 | 733 |
| 729 if (starts[index] < cursor_index) | 734 if (starts[index] < cursor_index) |
| 730 return false; | 735 return false; |
| 731 | 736 |
| 732 *start_index = starts[index]; | 737 *start_index = starts[index]; |
| 733 *end_index = ends[index]; | 738 *end_index = ends[index]; |
| 734 break; | 739 break; |
| 735 } | 740 } |
| 736 default: | 741 default: |
| 737 NOTREACHED(); | 742 NOTREACHED(); |
| 738 } | 743 } |
| 739 | 744 |
| 740 return true; | 745 return true; |
| 741 } | 746 } |
| 742 | 747 |
| 743 bool BrowserAccessibilityManagerAndroid::PreviousAtGranularity( | 748 bool BrowserAccessibilityManagerAndroid::PreviousAtGranularity( |
| 744 int32 granularity, int32 cursor_index, | 749 int32_t granularity, |
| 745 BrowserAccessibilityAndroid* node, int32* start_index, int32* end_index) { | 750 int32_t cursor_index, |
| 751 BrowserAccessibilityAndroid* node, |
| 752 int32_t* start_index, |
| 753 int32_t* end_index) { |
| 746 switch (granularity) { | 754 switch (granularity) { |
| 747 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_CHARACTER: { | 755 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_CHARACTER: { |
| 748 if (cursor_index <= 0) | 756 if (cursor_index <= 0) |
| 749 return false; | 757 return false; |
| 750 base::string16 text = node->GetText(); | 758 base::string16 text = node->GetText(); |
| 751 base::i18n::UTF16CharIterator iter(text.data(), text.size()); | 759 base::i18n::UTF16CharIterator iter(text.data(), text.size()); |
| 752 int previous_index = 0; | 760 int previous_index = 0; |
| 753 while (!iter.end() && iter.array_pos() < cursor_index) { | 761 while (!iter.end() && iter.array_pos() < cursor_index) { |
| 754 previous_index = iter.array_pos(); | 762 previous_index = iter.array_pos(); |
| 755 iter.Advance(); | 763 iter.Advance(); |
| 756 } | 764 } |
| 757 *start_index = previous_index; | 765 *start_index = previous_index; |
| 758 *end_index = previous_index; | 766 *end_index = previous_index; |
| 759 break; | 767 break; |
| 760 } | 768 } |
| 761 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD: | 769 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD: |
| 762 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_LINE: { | 770 case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_LINE: { |
| 763 std::vector<int32> starts; | 771 std::vector<int32_t> starts; |
| 764 std::vector<int32> ends; | 772 std::vector<int32_t> ends; |
| 765 node->GetGranularityBoundaries(granularity, &starts, &ends, 0); | 773 node->GetGranularityBoundaries(granularity, &starts, &ends, 0); |
| 766 if (starts.size() == 0) | 774 if (starts.size() == 0) |
| 767 return false; | 775 return false; |
| 768 | 776 |
| 769 size_t index = starts.size() - 1; | 777 size_t index = starts.size() - 1; |
| 770 while (index > 0 && starts[index] >= cursor_index) | 778 while (index > 0 && starts[index] >= cursor_index) |
| 771 index--; | 779 index--; |
| 772 | 780 |
| 773 if (starts[index] >= cursor_index) | 781 if (starts[index] >= cursor_index) |
| 774 return false; | 782 return false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() { | 843 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() { |
| 836 // The Java layer handles the root scroll offset. | 844 // The Java layer handles the root scroll offset. |
| 837 return false; | 845 return false; |
| 838 } | 846 } |
| 839 | 847 |
| 840 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 848 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
| 841 return RegisterNativesImpl(env); | 849 return RegisterNativesImpl(env); |
| 842 } | 850 } |
| 843 | 851 |
| 844 } // namespace content | 852 } // namespace content |
| OLD | NEW |