Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / accessibility / accessibility_tree_formatter_android.cc
blob97cfc7f909a835ad495c7e788cb1bad8c747fccb
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
3 // found in the LICENSE file.
5 #include "content/browser/accessibility/accessibility_tree_formatter.h"
7 #include <string>
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/files/file_path.h"
12 #include "base/json/json_writer.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "content/browser/accessibility/browser_accessibility_android.h"
19 using base::StringPrintf;
21 namespace content {
23 namespace {
24 const char* BOOL_ATTRIBUTES[] = {
25 "checkable",
26 "checked",
27 "clickable",
28 "collection",
29 "collection_item",
30 "content_invalid",
31 "disabled",
32 "dismissable",
33 "editable_text",
34 "focusable",
35 "focused",
36 "heading",
37 "hierarchical",
38 "invisible",
39 "link",
40 "multiline",
41 "password",
42 "range",
43 "scrollable",
44 "selected"
47 const char* STRING_ATTRIBUTES[] = {
48 "name"
51 const char* INT_ATTRIBUTES[] = {
52 "item_index",
53 "item_count",
54 "row_count",
55 "column_count",
56 "row_index",
57 "row_span",
58 "column_index",
59 "column_span",
60 "input_type",
61 "live_region_type",
62 "range_min",
63 "range_max",
64 "range_current_value",
68 void AccessibilityTreeFormatter::Initialize() {
71 void AccessibilityTreeFormatter::AddProperties(
72 const BrowserAccessibility& node, base::DictionaryValue* dict) {
73 dict->SetInteger("id", node.GetId());
75 const BrowserAccessibilityAndroid* android_node =
76 static_cast<const BrowserAccessibilityAndroid*>(&node);
78 // Class name.
79 dict->SetString("class", android_node->GetClassName());
81 // Bool attributes.
82 dict->SetBoolean("checkable", android_node->IsCheckable());
83 dict->SetBoolean("checked", android_node->IsChecked());
84 dict->SetBoolean("clickable", android_node->IsClickable());
85 dict->SetBoolean("collection", android_node->IsCollection());
86 dict->SetBoolean("collection_item", android_node->IsCollectionItem());
87 dict->SetBoolean("disabled", !android_node->IsEnabled());
88 dict->SetBoolean("dismissable", android_node->IsDismissable());
89 dict->SetBoolean("editable_text", android_node->IsEditableText());
90 dict->SetBoolean("focusable", android_node->IsFocusable());
91 dict->SetBoolean("focused", android_node->IsFocused());
92 dict->SetBoolean("heading", android_node->IsHeading());
93 dict->SetBoolean("hierarchical", android_node->IsHierarchical());
94 dict->SetBoolean("invisible", !android_node->IsVisibleToUser());
95 dict->SetBoolean("link", android_node->IsLink());
96 dict->SetBoolean("multiline", android_node->IsMultiLine());
97 dict->SetBoolean("range", android_node->IsRangeType());
98 dict->SetBoolean("password", android_node->IsPassword());
99 dict->SetBoolean("scrollable", android_node->IsScrollable());
100 dict->SetBoolean("selected", android_node->IsSelected());
102 // String attributes.
103 dict->SetString("name", android_node->GetText());
105 // Int attributes.
106 dict->SetInteger("item_index", android_node->GetItemIndex());
107 dict->SetInteger("item_count", android_node->GetItemCount());
108 dict->SetInteger("row_count", android_node->RowCount());
109 dict->SetInteger("column_count", android_node->ColumnCount());
110 dict->SetInteger("row_index", android_node->RowIndex());
111 dict->SetInteger("row_span", android_node->RowSpan());
112 dict->SetInteger("column_index", android_node->ColumnIndex());
113 dict->SetInteger("column_span", android_node->ColumnSpan());
114 dict->SetInteger("input_type", android_node->AndroidInputType());
115 dict->SetInteger("live_region_type", android_node->AndroidLiveRegionType());
116 dict->SetInteger("range_min", static_cast<int>(android_node->RangeMin()));
117 dict->SetInteger("range_max", static_cast<int>(android_node->RangeMax()));
118 dict->SetInteger("range_current_value",
119 static_cast<int>(android_node->RangeCurrentValue()));
122 base::string16 AccessibilityTreeFormatter::ToString(
123 const base::DictionaryValue& dict) {
124 base::string16 line;
126 if (show_ids_) {
127 int id_value;
128 dict.GetInteger("id", &id_value);
129 WriteAttribute(true, base::IntToString16(id_value), &line);
132 base::string16 class_value;
133 dict.GetString("class", &class_value);
134 WriteAttribute(true, base::UTF16ToUTF8(class_value), &line);
136 for (unsigned i = 0; i < arraysize(BOOL_ATTRIBUTES); i++) {
137 const char* attribute_name = BOOL_ATTRIBUTES[i];
138 bool value;
139 if (dict.GetBoolean(attribute_name, &value) && value)
140 WriteAttribute(true, attribute_name, &line);
143 for (unsigned i = 0; i < arraysize(STRING_ATTRIBUTES); i++) {
144 const char* attribute_name = STRING_ATTRIBUTES[i];
145 std::string value;
146 if (!dict.GetString(attribute_name, &value) || value.empty())
147 continue;
148 WriteAttribute(true,
149 StringPrintf("%s='%s'", attribute_name, value.c_str()),
150 &line);
153 for (unsigned i = 0; i < arraysize(INT_ATTRIBUTES); i++) {
154 const char* attribute_name = INT_ATTRIBUTES[i];
155 int value;
156 if (!dict.GetInteger(attribute_name, &value) || value == 0)
157 continue;
158 WriteAttribute(true,
159 StringPrintf("%s=%d", attribute_name, value),
160 &line);
163 return line;
166 // static
167 const base::FilePath::StringType
168 AccessibilityTreeFormatter::GetActualFileSuffix() {
169 return FILE_PATH_LITERAL("-actual-android.txt");
172 // static
173 const base::FilePath::StringType
174 AccessibilityTreeFormatter::GetExpectedFileSuffix() {
175 return FILE_PATH_LITERAL("-expected-android.txt");
178 // static
179 const std::string AccessibilityTreeFormatter::GetAllowEmptyString() {
180 return "@ANDROID-ALLOW-EMPTY:";
183 // static
184 const std::string AccessibilityTreeFormatter::GetAllowString() {
185 return "@ANDROID-ALLOW:";
188 // static
189 const std::string AccessibilityTreeFormatter::GetDenyString() {
190 return "@ANDROID-DENY:";
193 } // namespace content