| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" | |
| 6 | |
| 7 #include <atk/atk.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "content/browser/accessibility/browser_accessibility_gtk.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, | |
| 19 base::DictionaryValue* dict) { | |
| 20 BrowserAccessibilityGtk* node_gtk = | |
| 21 const_cast<BrowserAccessibility*>(&node)->ToBrowserAccessibilityGtk(); | |
| 22 AtkObject* atk_object = node_gtk->GetAtkObject(); | |
| 23 AtkRole role = atk_object_get_role(atk_object); | |
| 24 if (role != ATK_ROLE_UNKNOWN) | |
| 25 dict->SetString("role", atk_role_get_name(role)); | |
| 26 dict->SetString("name", atk_object_get_name(atk_object)); | |
| 27 dict->SetString("description", atk_object_get_description(atk_object)); | |
| 28 AtkStateSet* state_set = | |
| 29 atk_object_ref_state_set(atk_object); | |
| 30 base::ListValue* states = new base::ListValue; | |
| 31 for (int i = ATK_STATE_INVALID; i < ATK_STATE_LAST_DEFINED; i++) { | |
| 32 AtkStateType state_type = static_cast<AtkStateType>(i); | |
| 33 if (atk_state_set_contains_state(state_set, state_type)) | |
| 34 states->AppendString(atk_state_type_get_name(state_type)); | |
| 35 } | |
| 36 dict->Set("states", states); | |
| 37 dict->SetInteger("id", node.GetId()); | |
| 38 } | |
| 39 | |
| 40 base::string16 AccessibilityTreeFormatter::ToString( | |
| 41 const base::DictionaryValue& node, | |
| 42 const base::string16& indent) { | |
| 43 base::string16 line; | |
| 44 std::string role_value; | |
| 45 node.GetString("role", &role_value); | |
| 46 if (!role_value.empty()) { | |
| 47 WriteAttribute(true, | |
| 48 base::StringPrintf("[%s]", role_value.c_str()), &line); | |
| 49 } | |
| 50 | |
| 51 std::string name_value; | |
| 52 node.GetString("name", &name_value); | |
| 53 WriteAttribute(true, base::StringPrintf("name='%s'", name_value.c_str()), | |
| 54 &line); | |
| 55 | |
| 56 std::string description_value; | |
| 57 node.GetString("description", &description_value); | |
| 58 WriteAttribute(false, | |
| 59 base::StringPrintf("description='%s'", | |
| 60 description_value.c_str()), | |
| 61 &line); | |
| 62 | |
| 63 const base::ListValue* states_value; | |
| 64 node.GetList("states", &states_value); | |
| 65 for (base::ListValue::const_iterator it = states_value->begin(); | |
| 66 it != states_value->end(); | |
| 67 ++it) { | |
| 68 std::string state_value; | |
| 69 if ((*it)->GetAsString(&state_value)) | |
| 70 WriteAttribute(true, state_value, &line); | |
| 71 } | |
| 72 | |
| 73 int id_value; | |
| 74 node.GetInteger("id", &id_value); | |
| 75 WriteAttribute(false, | |
| 76 base::StringPrintf("id=%d", id_value), | |
| 77 &line); | |
| 78 | |
| 79 return indent + line + base::ASCIIToUTF16("\n"); | |
| 80 } | |
| 81 | |
| 82 void AccessibilityTreeFormatter::Initialize() {} | |
| 83 | |
| 84 // static | |
| 85 const base::FilePath::StringType | |
| 86 AccessibilityTreeFormatter::GetActualFileSuffix() { | |
| 87 return FILE_PATH_LITERAL("-actual-gtk.txt"); | |
| 88 } | |
| 89 | |
| 90 // static | |
| 91 const base::FilePath::StringType | |
| 92 AccessibilityTreeFormatter::GetExpectedFileSuffix() { | |
| 93 return FILE_PATH_LITERAL("-expected-gtk.txt"); | |
| 94 } | |
| 95 | |
| 96 // static | |
| 97 const std::string AccessibilityTreeFormatter::GetAllowEmptyString() { | |
| 98 return "@GTK-ALLOW-EMPTY:"; | |
| 99 } | |
| 100 | |
| 101 // static | |
| 102 const std::string AccessibilityTreeFormatter::GetAllowString() { | |
| 103 return "@GTK-ALLOW:"; | |
| 104 } | |
| 105 | |
| 106 // static | |
| 107 const std::string AccessibilityTreeFormatter::GetDenyString() { | |
| 108 return "@GTK-DENY:"; | |
| 109 } | |
| 110 | |
| 111 } | |
| OLD | NEW |