blob: 29e79987433afd6d147c8a08d57ea37a95e008d1 [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
avi9c81217b2015-12-24 23:40:058#include <stdint.h>
9
[email protected]4b02bbca2013-11-22 08:59:0310#include <map>
dcheng18ec0b542016-04-26 19:28:5311#include <memory>
[email protected]4b02bbca2013-11-22 08:59:0312#include <string>
13#include <vector>
14
15#include "base/strings/string16.h"
anand.ratna85c48c2014-09-23 16:50:2116#include "base/strings/string_split.h"
[email protected]4b02bbca2013-11-22 08:59:0317#include "ui/accessibility/ax_enums.h"
18#include "ui/accessibility/ax_export.h"
dmazzoni7535c4d82016-07-21 22:12:3919#include "ui/gfx/geometry/rect_f.h"
[email protected]4b02bbca2013-11-22 08:59:0320
dmazzoni0aec3862016-03-28 19:06:5621namespace gfx {
22class Transform;
23};
24
[email protected]4b02bbca2013-11-22 08:59:0325namespace ui {
26
dmazzonica0b1e82017-02-10 03:59:0927// Return true if |attr| should be interpreted as the id of another node
28// in the same tree.
29AX_EXPORT bool IsNodeIdIntAttribute(AXIntAttribute attr);
30
31// Return true if |attr| should be interpreted as a list of ids of
32// nodes in the same tree.
33AX_EXPORT bool IsNodeIdIntListAttribute(AXIntListAttribute attr);
34
[email protected]4b02bbca2013-11-22 08:59:0335// A compact representation of the accessibility information for a
dmazzoni329fd012015-10-22 20:05:3536// single accessible object, in a form that can be serialized and sent from
[email protected]4b02bbca2013-11-22 08:59:0337// one process to another.
38struct AX_EXPORT AXNodeData {
[email protected]4b02bbca2013-11-22 08:59:0339 AXNodeData();
40 virtual ~AXNodeData();
41
dmazzoni729443ae2016-02-29 21:17:1242 AXNodeData(const AXNodeData& other);
43 AXNodeData& operator=(AXNodeData other);
44
dmazzoni53e922ab2015-06-03 23:02:2545 // Accessing accessibility attributes:
46 //
47 // There are dozens of possible attributes for an accessibility node,
48 // but only a few tend to apply to any one object, so we store them
49 // in sparse arrays of <attribute id, attribute value> pairs, organized
50 // by type (bool, int, float, string, int list).
51 //
52 // There are three accessors for each type of attribute: one that returns
53 // true if the attribute is present and false if not, one that takes a
54 // pointer argument and returns true if the attribute is present (if you
55 // need to distinguish between the default value and a missing attribute),
56 // and another that returns the default value for that type if the
57 // attribute is not present. In addition, strings can be returned as
58 // either std::string or base::string16, for convenience.
59
60 bool HasBoolAttribute(AXBoolAttribute attr) const;
61 bool GetBoolAttribute(AXBoolAttribute attr) const;
62 bool GetBoolAttribute(AXBoolAttribute attr, bool* value) const;
63
64 bool HasFloatAttribute(AXFloatAttribute attr) const;
65 float GetFloatAttribute(AXFloatAttribute attr) const;
66 bool GetFloatAttribute(AXFloatAttribute attr, float* value) const;
67
68 bool HasIntAttribute(AXIntAttribute attribute) const;
69 int GetIntAttribute(AXIntAttribute attribute) const;
70 bool GetIntAttribute(AXIntAttribute attribute, int* value) const;
71
72 bool HasStringAttribute(
73 AXStringAttribute attribute) const;
74 const std::string& GetStringAttribute(AXStringAttribute attribute) const;
75 bool GetStringAttribute(AXStringAttribute attribute,
76 std::string* value) const;
77
78 bool GetString16Attribute(AXStringAttribute attribute,
79 base::string16* value) const;
80 base::string16 GetString16Attribute(
81 AXStringAttribute attribute) const;
82
83 bool HasIntListAttribute(AXIntListAttribute attribute) const;
avi9c81217b2015-12-24 23:40:0584 const std::vector<int32_t>& GetIntListAttribute(
dmazzoni53e922ab2015-06-03 23:02:2585 AXIntListAttribute attribute) const;
86 bool GetIntListAttribute(AXIntListAttribute attribute,
avi9c81217b2015-12-24 23:40:0587 std::vector<int32_t>* value) const;
dmazzoni53e922ab2015-06-03 23:02:2588
yawanob87aed42017-06-26 02:55:2989 bool HasStringListAttribute(AXStringListAttribute attribute) const;
90 const std::vector<std::string>& GetStringListAttribute(
91 AXStringListAttribute attribute) const;
92 bool GetStringListAttribute(AXStringListAttribute attribute,
93 std::vector<std::string>* value) const;
94
dmazzoni53e922ab2015-06-03 23:02:2595 bool GetHtmlAttribute(const char* attr, base::string16* value) const;
96 bool GetHtmlAttribute(const char* attr, std::string* value) const;
97
98 // Setting accessibility attributes.
[email protected]5eec2f52014-01-06 22:30:5499 void AddStringAttribute(AXStringAttribute attribute,
[email protected]4b02bbca2013-11-22 08:59:03100 const std::string& value);
[email protected]5eec2f52014-01-06 22:30:54101 void AddIntAttribute(AXIntAttribute attribute, int value);
102 void AddFloatAttribute(AXFloatAttribute attribute, float value);
103 void AddBoolAttribute(AXBoolAttribute attribute, bool value);
104 void AddIntListAttribute(AXIntListAttribute attribute,
avi9c81217b2015-12-24 23:40:05105 const std::vector<int32_t>& value);
yawanob87aed42017-06-26 02:55:29106 void AddStringListAttribute(AXStringListAttribute attribute,
107 const std::vector<std::string>& value);
[email protected]4b02bbca2013-11-22 08:59:03108
109 // Convenience functions, mainly for writing unit tests.
110 // Equivalent to AddStringAttribute(ATTR_NAME, name).
ki.stfue0013b82015-09-23 18:14:53111 void SetName(const std::string& name);
dmazzoni13e52582016-11-04 07:24:21112 void SetName(const base::string16& name);
[email protected]4b02bbca2013-11-22 08:59:03113 // Equivalent to AddStringAttribute(ATTR_VALUE, value).
ki.stfue0013b82015-09-23 18:14:53114 void SetValue(const std::string& value);
dmazzoni13e52582016-11-04 07:24:21115 void SetValue(const base::string16& value);
116
patricialor979beed2017-05-22 06:24:22117 // Returns true if the given enum bit is 1.
118 bool HasState(ui::AXState state_enum) const;
119 bool HasAction(ui::AXAction state_enum) const;
120
121 // Set bits in the given enum's corresponding bitfield.
122 void AddState(ui::AXState state_enum);
123 void AddAction(ui::AXAction action_enum);
[email protected]4b02bbca2013-11-22 08:59:03124
[email protected]5eec2f52014-01-06 22:30:54125 // Return a string representation of this data, for debugging.
dmazzoniac6cdd02015-08-04 21:07:06126 virtual std::string ToString() const;
127
dmazzoni729443ae2016-02-29 21:17:12128 // As much as possible this should behave as a simple, serializable,
129 // copyable struct.
avi9c81217b2015-12-24 23:40:05130 int32_t id;
[email protected]4b02bbca2013-11-22 08:59:03131 AXRole role;
avi9c81217b2015-12-24 23:40:05132 uint32_t state;
patricialor979beed2017-05-22 06:24:22133 uint32_t actions;
patricialorc32a66d2016-07-01 00:29:18134 std::vector<std::pair<AXStringAttribute, std::string>> string_attributes;
avi9c81217b2015-12-24 23:40:05135 std::vector<std::pair<AXIntAttribute, int32_t>> int_attributes;
patricialorc32a66d2016-07-01 00:29:18136 std::vector<std::pair<AXFloatAttribute, float>> float_attributes;
137 std::vector<std::pair<AXBoolAttribute, bool>> bool_attributes;
avi9c81217b2015-12-24 23:40:05138 std::vector<std::pair<AXIntListAttribute, std::vector<int32_t>>>
[email protected]4b02bbca2013-11-22 08:59:03139 intlist_attributes;
yawanob87aed42017-06-26 02:55:29140 std::vector<std::pair<AXStringListAttribute, std::vector<std::string>>>
141 stringlist_attributes;
anand.ratna85c48c2014-09-23 16:50:21142 base::StringPairs html_attributes;
avi9c81217b2015-12-24 23:40:05143 std::vector<int32_t> child_ids;
dmazzoni0aec3862016-03-28 19:06:56144
dmazzoni051715a2016-08-15 21:36:58145 // TODO(dmazzoni): replace the following three members with a single
146 // instance of AXRelativeBounds.
147
148 // The id of an ancestor node in the same AXTree that this object's
149 // bounding box is relative to, or -1 if there's no offset container.
150 int offset_container_id;
151
152 // The relative bounding box of this node.
dmazzoni7535c4d82016-07-21 22:12:39153 gfx::RectF location;
dmazzoni0aec3862016-03-28 19:06:56154
155 // An additional transform to apply to position this object and its subtree.
dcheng18ec0b542016-04-26 19:28:53156 // NOTE: this member is a std::unique_ptr because it's rare and gfx::Transform
dmazzoni0aec3862016-03-28 19:06:56157 // takes up a fair amount of space. The assignment operator and copy
158 // constructor both make a duplicate of the owned pointer, so it acts more
159 // like a member than a pointer.
danakj25c52c32016-04-12 21:51:08160 std::unique_ptr<gfx::Transform> transform;
[email protected]4b02bbca2013-11-22 08:59:03161};
162
163} // namespace ui
164
165#endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_