| 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_number_conversions.h" | |
| 14 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/browser/accessibility/browser_accessibility_android.h" | 16 #include "content/browser/accessibility/browser_accessibility_android.h" |
| 18 | 17 |
| 19 using base::StringPrintf; | 18 using base::StringPrintf; |
| 20 | 19 |
| 21 namespace content { | 20 namespace content { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 "range_max", | 61 "range_max", |
| 63 "range_current_value", | 62 "range_current_value", |
| 64 }; | 63 }; |
| 65 } | 64 } |
| 66 | 65 |
| 67 void AccessibilityTreeFormatter::Initialize() { | 66 void AccessibilityTreeFormatter::Initialize() { |
| 68 } | 67 } |
| 69 | 68 |
| 70 void AccessibilityTreeFormatter::AddProperties( | 69 void AccessibilityTreeFormatter::AddProperties( |
| 71 const BrowserAccessibility& node, base::DictionaryValue* dict) { | 70 const BrowserAccessibility& node, base::DictionaryValue* dict) { |
| 72 dict->SetInteger("id", node.GetId()); | |
| 73 | |
| 74 const BrowserAccessibilityAndroid* android_node = | 71 const BrowserAccessibilityAndroid* android_node = |
| 75 static_cast<const BrowserAccessibilityAndroid*>(&node); | 72 static_cast<const BrowserAccessibilityAndroid*>(&node); |
| 76 | 73 |
| 77 // Class name. | 74 // Class name. |
| 78 dict->SetString("class", android_node->GetClassName()); | 75 dict->SetString("class", android_node->GetClassName()); |
| 79 | 76 |
| 80 // Bool attributes. | 77 // Bool attributes. |
| 81 dict->SetBoolean("checkable", android_node->IsCheckable()); | 78 dict->SetBoolean("checkable", android_node->IsCheckable()); |
| 82 dict->SetBoolean("checked", android_node->IsChecked()); | 79 dict->SetBoolean("checked", android_node->IsChecked()); |
| 83 dict->SetBoolean("clickable", android_node->IsClickable()); | 80 dict->SetBoolean("clickable", android_node->IsClickable()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 dict->SetInteger("column_span", android_node->ColumnSpan()); | 108 dict->SetInteger("column_span", android_node->ColumnSpan()); |
| 112 dict->SetInteger("input_type", android_node->AndroidInputType()); | 109 dict->SetInteger("input_type", android_node->AndroidInputType()); |
| 113 dict->SetInteger("live_region_type", android_node->AndroidLiveRegionType()); | 110 dict->SetInteger("live_region_type", android_node->AndroidLiveRegionType()); |
| 114 dict->SetInteger("range_min", static_cast<int>(android_node->RangeMin())); | 111 dict->SetInteger("range_min", static_cast<int>(android_node->RangeMin())); |
| 115 dict->SetInteger("range_max", static_cast<int>(android_node->RangeMax())); | 112 dict->SetInteger("range_max", static_cast<int>(android_node->RangeMax())); |
| 116 dict->SetInteger("range_current_value", | 113 dict->SetInteger("range_current_value", |
| 117 static_cast<int>(android_node->RangeCurrentValue())); | 114 static_cast<int>(android_node->RangeCurrentValue())); |
| 118 } | 115 } |
| 119 | 116 |
| 120 base::string16 AccessibilityTreeFormatter::ToString( | 117 base::string16 AccessibilityTreeFormatter::ToString( |
| 121 const base::DictionaryValue& dict) { | 118 const base::DictionaryValue& dict, |
| 119 const base::string16& indent) { |
| 122 base::string16 line; | 120 base::string16 line; |
| 123 | 121 |
| 124 if (show_ids_) { | |
| 125 int id_value; | |
| 126 dict.GetInteger("id", &id_value); | |
| 127 WriteAttribute(true, base::IntToString16(id_value), &line); | |
| 128 } | |
| 129 | |
| 130 base::string16 class_value; | 122 base::string16 class_value; |
| 131 dict.GetString("class", &class_value); | 123 dict.GetString("class", &class_value); |
| 132 WriteAttribute(true, base::UTF16ToUTF8(class_value), &line); | 124 WriteAttribute(true, base::UTF16ToUTF8(class_value), &line); |
| 133 | 125 |
| 134 for (unsigned i = 0; i < arraysize(BOOL_ATTRIBUTES); i++) { | 126 for (unsigned i = 0; i < arraysize(BOOL_ATTRIBUTES); i++) { |
| 135 const char* attribute_name = BOOL_ATTRIBUTES[i]; | 127 const char* attribute_name = BOOL_ATTRIBUTES[i]; |
| 136 bool value; | 128 bool value; |
| 137 if (dict.GetBoolean(attribute_name, &value) && value) | 129 if (dict.GetBoolean(attribute_name, &value) && value) |
| 138 WriteAttribute(true, attribute_name, &line); | 130 WriteAttribute(true, attribute_name, &line); |
| 139 } | 131 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 151 for (unsigned i = 0; i < arraysize(INT_ATTRIBUTES); i++) { | 143 for (unsigned i = 0; i < arraysize(INT_ATTRIBUTES); i++) { |
| 152 const char* attribute_name = INT_ATTRIBUTES[i]; | 144 const char* attribute_name = INT_ATTRIBUTES[i]; |
| 153 int value; | 145 int value; |
| 154 if (!dict.GetInteger(attribute_name, &value) || value == 0) | 146 if (!dict.GetInteger(attribute_name, &value) || value == 0) |
| 155 continue; | 147 continue; |
| 156 WriteAttribute(true, | 148 WriteAttribute(true, |
| 157 StringPrintf("%s=%d", attribute_name, value), | 149 StringPrintf("%s=%d", attribute_name, value), |
| 158 &line); | 150 &line); |
| 159 } | 151 } |
| 160 | 152 |
| 161 return line; | 153 return indent + line + base::ASCIIToUTF16("\n"); |
| 162 } | 154 } |
| 163 | 155 |
| 164 // static | 156 // static |
| 165 const base::FilePath::StringType | 157 const base::FilePath::StringType |
| 166 AccessibilityTreeFormatter::GetActualFileSuffix() { | 158 AccessibilityTreeFormatter::GetActualFileSuffix() { |
| 167 return FILE_PATH_LITERAL("-actual-android.txt"); | 159 return FILE_PATH_LITERAL("-actual-android.txt"); |
| 168 } | 160 } |
| 169 | 161 |
| 170 // static | 162 // static |
| 171 const base::FilePath::StringType | 163 const base::FilePath::StringType |
| (...skipping 10 matching lines...) Expand all Loading... |
| 182 const std::string AccessibilityTreeFormatter::GetAllowString() { | 174 const std::string AccessibilityTreeFormatter::GetAllowString() { |
| 183 return "@ANDROID-ALLOW:"; | 175 return "@ANDROID-ALLOW:"; |
| 184 } | 176 } |
| 185 | 177 |
| 186 // static | 178 // static |
| 187 const std::string AccessibilityTreeFormatter::GetDenyString() { | 179 const std::string AccessibilityTreeFormatter::GetDenyString() { |
| 188 return "@ANDROID-DENY:"; | 180 return "@ANDROID-DENY:"; |
| 189 } | 181 } |
| 190 | 182 |
| 191 } // namespace content | 183 } // namespace content |
| OLD | NEW |