summaryrefslogtreecommitdiffstats
path: root/content/browser/accessibility/accessibility_tree_formatter_auralinux.cc
blob: 8ceefe8699378940d4947e0f96ddc0c28b926a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/accessibility/accessibility_tree_formatter.h"

#include <atk/atk.h>

#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/accessibility/browser_accessibility_auralinux.h"

namespace content {

void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node,
                                               base::DictionaryValue* dict) {
  dict->SetInteger("id", node.GetId());
  BrowserAccessibilityAuraLinux* acc_obj =
      const_cast<BrowserAccessibility*>(&node)
          ->ToBrowserAccessibilityAuraLinux();

  AtkObject* atk_object = acc_obj->GetAtkObject();
  AtkRole role = acc_obj->atk_role();
  if (role != ATK_ROLE_UNKNOWN)
    dict->SetString("role", atk_role_get_name(role));
  dict->SetString("name", atk_object_get_name(atk_object));
  dict->SetString("description", atk_object_get_description(atk_object));
  AtkStateSet* state_set = atk_object_ref_state_set(atk_object);
  base::ListValue* states = new base::ListValue;
  for (int i = ATK_STATE_INVALID; i < ATK_STATE_LAST_DEFINED; i++) {
    AtkStateType state_type = static_cast<AtkStateType>(i);
    if (atk_state_set_contains_state(state_set, state_type))
      states->AppendString(atk_state_type_get_name(state_type));
  }
  dict->Set("states", states);
}

base::string16 AccessibilityTreeFormatter::ToString(
    const base::DictionaryValue& node) {
  base::string16 line;
  std::string role_value;
  node.GetString("role", &role_value);
  if (!role_value.empty()) {
    WriteAttribute(true, base::StringPrintf("[%s]", role_value.c_str()), &line);
  }

  std::string name_value;
  node.GetString("name", &name_value);
  WriteAttribute(true, base::StringPrintf("name='%s'", name_value.c_str()),
                 &line);

  std::string description_value;
  node.GetString("description", &description_value);
  WriteAttribute(
      false, base::StringPrintf("description='%s'", description_value.c_str()),
      &line);

  const base::ListValue* states_value;
  node.GetList("states", &states_value);
  for (base::ListValue::const_iterator it = states_value->begin();
       it != states_value->end(); ++it) {
    std::string state_value;
    if ((*it)->GetAsString(&state_value))
      WriteAttribute(true, state_value, &line);
  }

  int id_value;
  node.GetInteger("id", &id_value);
  WriteAttribute(false, base::StringPrintf("id=%d", id_value), &line);

  return line + base::ASCIIToUTF16("\n");
}

void AccessibilityTreeFormatter::Initialize() {
}

// static
const base::FilePath::StringType
AccessibilityTreeFormatter::GetActualFileSuffix() {
  return FILE_PATH_LITERAL("-actual-auralinux.txt");
}

// static
const base::FilePath::StringType
AccessibilityTreeFormatter::GetExpectedFileSuffix() {
  return FILE_PATH_LITERAL("-expected-auralinux.txt");
}

// static
const std::string AccessibilityTreeFormatter::GetAllowEmptyString() {
  return "@AURALINUX-ALLOW-EMPTY:";
}

// static
const std::string AccessibilityTreeFormatter::GetAllowString() {
  return "@AURALINUX-ALLOW:";
}

// static
const std::string AccessibilityTreeFormatter::GetDenyString() {
  return "@AURALINUX-DENY:";
}
}