| 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/accessibility_tree_formatter.h" | 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 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/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_android.h" | 16 #include "content/browser/accessibility/browser_accessibility_android.h" |
| 17 #include "content/common/accessibility_node_data.h" | 17 #include "content/common/accessibility_node_data.h" |
| 18 | 18 |
| 19 using base::StringPrintf; | 19 using base::StringPrintf; |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 const char* BOOL_ATTRIBUTES[] = { | 24 const char* BOOL_ATTRIBUTES[] = { |
| 25 "checkable", | 25 "checkable", |
| 26 "checked", | 26 "checked", |
| 27 "clickable", | 27 "clickable", |
| 28 "collection", |
| 29 "collection_item", |
| 30 "content_invalid", |
| 28 "disabled", | 31 "disabled", |
| 32 "dismissable", |
| 29 "editable_text", | 33 "editable_text", |
| 30 "focusable", | 34 "focusable", |
| 31 "focused", | 35 "focused", |
| 36 "heading", |
| 37 "hierarchical", |
| 32 "invisible", | 38 "invisible", |
| 39 "multiline", |
| 33 "password", | 40 "password", |
| 41 "range", |
| 34 "scrollable", | 42 "scrollable", |
| 35 "selected" | 43 "selected" |
| 36 }; | 44 }; |
| 37 | 45 |
| 38 const char* STRING_ATTRIBUTES[] = { | 46 const char* STRING_ATTRIBUTES[] = { |
| 39 "name" | 47 "name" |
| 40 }; | 48 }; |
| 41 | 49 |
| 42 const char* INT_ATTRIBUTES[] = { | 50 const char* INT_ATTRIBUTES[] = { |
| 43 "item_index", | 51 "item_index", |
| 44 "item_count" | 52 "item_count", |
| 53 "row_count", |
| 54 "column_count", |
| 55 "row_index", |
| 56 "row_span", |
| 57 "column_index", |
| 58 "column_span", |
| 59 "input_type", |
| 60 "live_region_type", |
| 61 "range_min", |
| 62 "range_max", |
| 63 "range_current_value", |
| 45 }; | 64 }; |
| 46 } | 65 } |
| 47 | 66 |
| 48 void AccessibilityTreeFormatter::Initialize() { | 67 void AccessibilityTreeFormatter::Initialize() { |
| 49 } | 68 } |
| 50 | 69 |
| 51 void AccessibilityTreeFormatter::AddProperties( | 70 void AccessibilityTreeFormatter::AddProperties( |
| 52 const BrowserAccessibility& node, DictionaryValue* dict) { | 71 const BrowserAccessibility& node, DictionaryValue* dict) { |
| 53 const BrowserAccessibilityAndroid* android_node = | 72 const BrowserAccessibilityAndroid* android_node = |
| 54 static_cast<const BrowserAccessibilityAndroid*>(&node); | 73 static_cast<const BrowserAccessibilityAndroid*>(&node); |
| 55 | 74 |
| 56 // Class name. | 75 // Class name. |
| 57 dict->SetString("class", android_node->GetClassName()); | 76 dict->SetString("class", android_node->GetClassName()); |
| 58 | 77 |
| 59 // Bool attributes. | 78 // Bool attributes. |
| 79 dict->SetBoolean("checkable", android_node->IsCheckable()); |
| 80 dict->SetBoolean("checked", android_node->IsChecked()); |
| 81 dict->SetBoolean("clickable", android_node->IsClickable()); |
| 82 dict->SetBoolean("collection", android_node->IsCollection()); |
| 83 dict->SetBoolean("collection_item", android_node->IsCollectionItem()); |
| 84 dict->SetBoolean("disabled", !android_node->IsEnabled()); |
| 85 dict->SetBoolean("dismissable", android_node->IsDismissable()); |
| 86 dict->SetBoolean("editable_text", android_node->IsEditableText()); |
| 60 dict->SetBoolean("focusable", android_node->IsFocusable()); | 87 dict->SetBoolean("focusable", android_node->IsFocusable()); |
| 61 dict->SetBoolean("focused", android_node->IsFocused()); | 88 dict->SetBoolean("focused", android_node->IsFocused()); |
| 62 dict->SetBoolean("clickable", android_node->IsClickable()); | 89 dict->SetBoolean("heading", android_node->IsHeading()); |
| 63 dict->SetBoolean("editable_text", android_node->IsEditableText()); | 90 dict->SetBoolean("hierarchical", android_node->IsHierarchical()); |
| 64 dict->SetBoolean("checkable", android_node->IsCheckable()); | 91 dict->SetBoolean("invisible", !android_node->IsVisibleToUser()); |
| 65 dict->SetBoolean("checked", android_node->IsChecked()); | 92 dict->SetBoolean("multiline", android_node->IsMultiLine()); |
| 66 dict->SetBoolean("disabled", !android_node->IsEnabled()); | 93 dict->SetBoolean("range", android_node->IsRangeType()); |
| 94 dict->SetBoolean("password", android_node->IsPassword()); |
| 67 dict->SetBoolean("scrollable", android_node->IsScrollable()); | 95 dict->SetBoolean("scrollable", android_node->IsScrollable()); |
| 68 dict->SetBoolean("password", android_node->IsPassword()); | |
| 69 dict->SetBoolean("selected", android_node->IsSelected()); | 96 dict->SetBoolean("selected", android_node->IsSelected()); |
| 70 dict->SetBoolean("invisible", !android_node->IsVisibleToUser()); | |
| 71 | 97 |
| 72 // String attributes. | 98 // String attributes. |
| 73 dict->SetString("name", android_node->GetText()); | 99 dict->SetString("name", android_node->GetText()); |
| 74 | 100 |
| 75 // Int attributes. | 101 // Int attributes. |
| 76 dict->SetInteger("item_index", android_node->GetItemIndex()); | 102 dict->SetInteger("item_index", android_node->GetItemIndex()); |
| 77 dict->SetInteger("item_count", android_node->GetItemCount()); | 103 dict->SetInteger("item_count", android_node->GetItemCount()); |
| 104 dict->SetInteger("row_count", android_node->RowCount()); |
| 105 dict->SetInteger("column_count", android_node->ColumnCount()); |
| 106 dict->SetInteger("row_index", android_node->RowIndex()); |
| 107 dict->SetInteger("row_span", android_node->RowSpan()); |
| 108 dict->SetInteger("column_index", android_node->ColumnIndex()); |
| 109 dict->SetInteger("column_span", android_node->ColumnSpan()); |
| 110 dict->SetInteger("input_type", android_node->AndroidInputType()); |
| 111 dict->SetInteger("live_region_type", android_node->AndroidLiveRegionType()); |
| 112 dict->SetInteger("range_min", static_cast<int>(android_node->RangeMin())); |
| 113 dict->SetInteger("range_max", static_cast<int>(android_node->RangeMax())); |
| 114 dict->SetInteger("range_current_value", |
| 115 static_cast<int>(android_node->RangeCurrentValue())); |
| 78 } | 116 } |
| 79 | 117 |
| 80 base::string16 AccessibilityTreeFormatter::ToString( | 118 base::string16 AccessibilityTreeFormatter::ToString( |
| 81 const DictionaryValue& dict, | 119 const DictionaryValue& dict, |
| 82 const base::string16& indent) { | 120 const base::string16& indent) { |
| 83 base::string16 line; | 121 base::string16 line; |
| 84 | 122 |
| 85 base::string16 class_value; | 123 base::string16 class_value; |
| 86 dict.GetString("class", &class_value); | 124 dict.GetString("class", &class_value); |
| 87 WriteAttribute(true, UTF16ToUTF8(class_value), &line); | 125 WriteAttribute(true, UTF16ToUTF8(class_value), &line); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 const std::string AccessibilityTreeFormatter::GetAllowString() { | 175 const std::string AccessibilityTreeFormatter::GetAllowString() { |
| 138 return "@ANDROID-ALLOW:"; | 176 return "@ANDROID-ALLOW:"; |
| 139 } | 177 } |
| 140 | 178 |
| 141 // static | 179 // static |
| 142 const std::string AccessibilityTreeFormatter::GetDenyString() { | 180 const std::string AccessibilityTreeFormatter::GetDenyString() { |
| 143 return "@ANDROID-DENY:"; | 181 return "@ANDROID-DENY:"; |
| 144 } | 182 } |
| 145 | 183 |
| 146 } // namespace content | 184 } // namespace content |
| OLD | NEW |