1 // Copyright (c) 2015 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"
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_auralinux.h"
18 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility
& node
,
19 base::DictionaryValue
* dict
) {
20 dict
->SetInteger("id", node
.GetId());
21 BrowserAccessibilityAuraLinux
* acc_obj
=
22 const_cast<BrowserAccessibility
*>(&node
)
23 ->ToBrowserAccessibilityAuraLinux();
25 AtkObject
* atk_object
= acc_obj
->GetAtkObject();
26 AtkRole role
= acc_obj
->atk_role();
27 if (role
!= ATK_ROLE_UNKNOWN
)
28 dict
->SetString("role", atk_role_get_name(role
));
29 dict
->SetString("name", atk_object_get_name(atk_object
));
30 dict
->SetString("description", atk_object_get_description(atk_object
));
31 AtkStateSet
* state_set
= atk_object_ref_state_set(atk_object
);
32 base::ListValue
* states
= new base::ListValue
;
33 for (int i
= ATK_STATE_INVALID
; i
< ATK_STATE_LAST_DEFINED
; i
++) {
34 AtkStateType state_type
= static_cast<AtkStateType
>(i
);
35 if (atk_state_set_contains_state(state_set
, state_type
))
36 states
->AppendString(atk_state_type_get_name(state_type
));
38 dict
->Set("states", states
);
41 base::string16
AccessibilityTreeFormatter::ToString(
42 const base::DictionaryValue
& node
) {
44 std::string role_value
;
45 node
.GetString("role", &role_value
);
46 if (!role_value
.empty()) {
47 WriteAttribute(true, base::StringPrintf("[%s]", role_value
.c_str()), &line
);
50 std::string name_value
;
51 node
.GetString("name", &name_value
);
52 WriteAttribute(true, base::StringPrintf("name='%s'", name_value
.c_str()),
55 std::string description_value
;
56 node
.GetString("description", &description_value
);
58 false, base::StringPrintf("description='%s'", description_value
.c_str()),
61 const base::ListValue
* states_value
;
62 node
.GetList("states", &states_value
);
63 for (base::ListValue::const_iterator it
= states_value
->begin();
64 it
!= states_value
->end(); ++it
) {
65 std::string state_value
;
66 if ((*it
)->GetAsString(&state_value
))
67 WriteAttribute(true, state_value
, &line
);
71 node
.GetInteger("id", &id_value
);
72 WriteAttribute(false, base::StringPrintf("id=%d", id_value
), &line
);
74 return line
+ base::ASCIIToUTF16("\n");
77 void AccessibilityTreeFormatter::Initialize() {
81 const base::FilePath::StringType
82 AccessibilityTreeFormatter::GetActualFileSuffix() {
83 return FILE_PATH_LITERAL("-actual-auralinux.txt");
87 const base::FilePath::StringType
88 AccessibilityTreeFormatter::GetExpectedFileSuffix() {
89 return FILE_PATH_LITERAL("-expected-auralinux.txt");
93 const std::string
AccessibilityTreeFormatter::GetAllowEmptyString() {
94 return "@AURALINUX-ALLOW-EMPTY:";
98 const std::string
AccessibilityTreeFormatter::GetAllowString() {
99 return "@AURALINUX-ALLOW:";
103 const std::string
AccessibilityTreeFormatter::GetDenyString() {
104 return "@AURALINUX-DENY:";