blob: 9b517b16b50304527e251181f16c9243dfd7b6d4 [file] [log] [blame]
[email protected]4b02bbca2013-11-22 08:59:031// 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#ifndef UI_ACCESSIBILITY_AX_NODE_DATA_H_
6#define UI_ACCESSIBILITY_AX_NODE_DATA_H_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include "base/strings/string16.h"
anand.ratna85c48c2014-09-23 16:50:2113#include "base/strings/string_split.h"
[email protected]4b02bbca2013-11-22 08:59:0314#include "ui/accessibility/ax_enums.h"
15#include "ui/accessibility/ax_export.h"
tfarina3b0452d2014-12-31 15:20:0916#include "ui/gfx/geometry/rect.h"
[email protected]4b02bbca2013-11-22 08:59:0317
18namespace ui {
19
20// A compact representation of the accessibility information for a
21// single web object, in a form that can be serialized and sent from
22// one process to another.
23struct AX_EXPORT AXNodeData {
[email protected]4b02bbca2013-11-22 08:59:0324 AXNodeData();
25 virtual ~AXNodeData();
26
dmazzoni53e922ab2015-06-03 23:02:2527 // Accessing accessibility attributes:
28 //
29 // There are dozens of possible attributes for an accessibility node,
30 // but only a few tend to apply to any one object, so we store them
31 // in sparse arrays of <attribute id, attribute value> pairs, organized
32 // by type (bool, int, float, string, int list).
33 //
34 // There are three accessors for each type of attribute: one that returns
35 // true if the attribute is present and false if not, one that takes a
36 // pointer argument and returns true if the attribute is present (if you
37 // need to distinguish between the default value and a missing attribute),
38 // and another that returns the default value for that type if the
39 // attribute is not present. In addition, strings can be returned as
40 // either std::string or base::string16, for convenience.
41
42 bool HasBoolAttribute(AXBoolAttribute attr) const;
43 bool GetBoolAttribute(AXBoolAttribute attr) const;
44 bool GetBoolAttribute(AXBoolAttribute attr, bool* value) const;
45
46 bool HasFloatAttribute(AXFloatAttribute attr) const;
47 float GetFloatAttribute(AXFloatAttribute attr) const;
48 bool GetFloatAttribute(AXFloatAttribute attr, float* value) const;
49
50 bool HasIntAttribute(AXIntAttribute attribute) const;
51 int GetIntAttribute(AXIntAttribute attribute) const;
52 bool GetIntAttribute(AXIntAttribute attribute, int* value) const;
53
54 bool HasStringAttribute(
55 AXStringAttribute attribute) const;
56 const std::string& GetStringAttribute(AXStringAttribute attribute) const;
57 bool GetStringAttribute(AXStringAttribute attribute,
58 std::string* value) const;
59
60 bool GetString16Attribute(AXStringAttribute attribute,
61 base::string16* value) const;
62 base::string16 GetString16Attribute(
63 AXStringAttribute attribute) const;
64
65 bool HasIntListAttribute(AXIntListAttribute attribute) const;
66 const std::vector<int32>& GetIntListAttribute(
67 AXIntListAttribute attribute) const;
68 bool GetIntListAttribute(AXIntListAttribute attribute,
69 std::vector<int32>* value) const;
70
71 bool GetHtmlAttribute(const char* attr, base::string16* value) const;
72 bool GetHtmlAttribute(const char* attr, std::string* value) const;
73
74 // Setting accessibility attributes.
[email protected]5eec2f52014-01-06 22:30:5475 void AddStringAttribute(AXStringAttribute attribute,
[email protected]4b02bbca2013-11-22 08:59:0376 const std::string& value);
[email protected]5eec2f52014-01-06 22:30:5477 void AddIntAttribute(AXIntAttribute attribute, int value);
78 void AddFloatAttribute(AXFloatAttribute attribute, float value);
79 void AddBoolAttribute(AXBoolAttribute attribute, bool value);
80 void AddIntListAttribute(AXIntListAttribute attribute,
[email protected]4b02bbca2013-11-22 08:59:0381 const std::vector<int32>& value);
82
83 // Convenience functions, mainly for writing unit tests.
84 // Equivalent to AddStringAttribute(ATTR_NAME, name).
ki.stfue0013b82015-09-23 18:14:5385 void SetName(const std::string& name);
[email protected]4b02bbca2013-11-22 08:59:0386 // Equivalent to AddStringAttribute(ATTR_VALUE, value).
ki.stfue0013b82015-09-23 18:14:5387 void SetValue(const std::string& value);
[email protected]4b02bbca2013-11-22 08:59:0388
[email protected]5eec2f52014-01-06 22:30:5489 // Return a string representation of this data, for debugging.
dmazzoniac6cdd02015-08-04 21:07:0690 virtual std::string ToString() const;
91
92 bool IsRoot() const;
93 void SetRoot();
[email protected]5eec2f52014-01-06 22:30:5494
[email protected]4b02bbca2013-11-22 08:59:0395 // This is a simple serializable struct. All member variables should be
96 // public and copyable.
97 int32 id;
98 AXRole role;
99 uint32 state;
100 gfx::Rect location;
[email protected]5eec2f52014-01-06 22:30:54101 std::vector<std::pair<AXStringAttribute, std::string> > string_attributes;
102 std::vector<std::pair<AXIntAttribute, int32> > int_attributes;
103 std::vector<std::pair<AXFloatAttribute, float> > float_attributes;
104 std::vector<std::pair<AXBoolAttribute, bool> > bool_attributes;
105 std::vector<std::pair<AXIntListAttribute, std::vector<int32> > >
[email protected]4b02bbca2013-11-22 08:59:03106 intlist_attributes;
anand.ratna85c48c2014-09-23 16:50:21107 base::StringPairs html_attributes;
[email protected]4b02bbca2013-11-22 08:59:03108 std::vector<int32> child_ids;
109};
110
111} // namespace ui
112
113#endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_