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