blob: fe819f1bb084f5bbfe940ed38082d2c1c8786d97 [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"
tfarina3b0452d2014-12-31 15:20:0919#include "ui/gfx/geometry/rect.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
27// A compact representation of the accessibility information for a
dmazzoni329fd012015-10-22 20:05:3528// single accessible object, in a form that can be serialized and sent from
[email protected]4b02bbca2013-11-22 08:59:0329// one process to another.
30struct AX_EXPORT AXNodeData {
[email protected]4b02bbca2013-11-22 08:59:0331 AXNodeData();
32 virtual ~AXNodeData();
33
dmazzoni729443ae2016-02-29 21:17:1234 AXNodeData(const AXNodeData& other);
35 AXNodeData& operator=(AXNodeData other);
36
dmazzoni53e922ab2015-06-03 23:02:2537 // Accessing accessibility attributes:
38 //
39 // There are dozens of possible attributes for an accessibility node,
40 // but only a few tend to apply to any one object, so we store them
41 // in sparse arrays of <attribute id, attribute value> pairs, organized
42 // by type (bool, int, float, string, int list).
43 //
44 // There are three accessors for each type of attribute: one that returns
45 // true if the attribute is present and false if not, one that takes a
46 // pointer argument and returns true if the attribute is present (if you
47 // need to distinguish between the default value and a missing attribute),
48 // and another that returns the default value for that type if the
49 // attribute is not present. In addition, strings can be returned as
50 // either std::string or base::string16, for convenience.
51
52 bool HasBoolAttribute(AXBoolAttribute attr) const;
53 bool GetBoolAttribute(AXBoolAttribute attr) const;
54 bool GetBoolAttribute(AXBoolAttribute attr, bool* value) const;
55
56 bool HasFloatAttribute(AXFloatAttribute attr) const;
57 float GetFloatAttribute(AXFloatAttribute attr) const;
58 bool GetFloatAttribute(AXFloatAttribute attr, float* value) const;
59
60 bool HasIntAttribute(AXIntAttribute attribute) const;
61 int GetIntAttribute(AXIntAttribute attribute) const;
62 bool GetIntAttribute(AXIntAttribute attribute, int* value) const;
63
64 bool HasStringAttribute(
65 AXStringAttribute attribute) const;
66 const std::string& GetStringAttribute(AXStringAttribute attribute) const;
67 bool GetStringAttribute(AXStringAttribute attribute,
68 std::string* value) const;
69
70 bool GetString16Attribute(AXStringAttribute attribute,
71 base::string16* value) const;
72 base::string16 GetString16Attribute(
73 AXStringAttribute attribute) const;
74
75 bool HasIntListAttribute(AXIntListAttribute attribute) const;
avi9c81217b2015-12-24 23:40:0576 const std::vector<int32_t>& GetIntListAttribute(
dmazzoni53e922ab2015-06-03 23:02:2577 AXIntListAttribute attribute) const;
78 bool GetIntListAttribute(AXIntListAttribute attribute,
avi9c81217b2015-12-24 23:40:0579 std::vector<int32_t>* value) const;
dmazzoni53e922ab2015-06-03 23:02:2580
81 bool GetHtmlAttribute(const char* attr, base::string16* value) const;
82 bool GetHtmlAttribute(const char* attr, std::string* value) const;
83
84 // Setting accessibility attributes.
[email protected]5eec2f52014-01-06 22:30:5485 void AddStringAttribute(AXStringAttribute attribute,
[email protected]4b02bbca2013-11-22 08:59:0386 const std::string& value);
[email protected]5eec2f52014-01-06 22:30:5487 void AddIntAttribute(AXIntAttribute attribute, int value);
88 void AddFloatAttribute(AXFloatAttribute attribute, float value);
89 void AddBoolAttribute(AXBoolAttribute attribute, bool value);
90 void AddIntListAttribute(AXIntListAttribute attribute,
avi9c81217b2015-12-24 23:40:0591 const std::vector<int32_t>& value);
[email protected]4b02bbca2013-11-22 08:59:0392
93 // Convenience functions, mainly for writing unit tests.
94 // Equivalent to AddStringAttribute(ATTR_NAME, name).
ki.stfue0013b82015-09-23 18:14:5395 void SetName(const std::string& name);
[email protected]4b02bbca2013-11-22 08:59:0396 // Equivalent to AddStringAttribute(ATTR_VALUE, value).
ki.stfue0013b82015-09-23 18:14:5397 void SetValue(const std::string& value);
[email protected]4b02bbca2013-11-22 08:59:0398
[email protected]5eec2f52014-01-06 22:30:5499 // Return a string representation of this data, for debugging.
dmazzoniac6cdd02015-08-04 21:07:06100 virtual std::string ToString() const;
101
dmazzoni729443ae2016-02-29 21:17:12102 // As much as possible this should behave as a simple, serializable,
103 // copyable struct.
avi9c81217b2015-12-24 23:40:05104 int32_t id;
[email protected]4b02bbca2013-11-22 08:59:03105 AXRole role;
avi9c81217b2015-12-24 23:40:05106 uint32_t state;
patricialorc32a66d2016-07-01 00:29:18107 std::vector<std::pair<AXStringAttribute, std::string>> string_attributes;
avi9c81217b2015-12-24 23:40:05108 std::vector<std::pair<AXIntAttribute, int32_t>> int_attributes;
patricialorc32a66d2016-07-01 00:29:18109 std::vector<std::pair<AXFloatAttribute, float>> float_attributes;
110 std::vector<std::pair<AXBoolAttribute, bool>> bool_attributes;
avi9c81217b2015-12-24 23:40:05111 std::vector<std::pair<AXIntListAttribute, std::vector<int32_t>>>
[email protected]4b02bbca2013-11-22 08:59:03112 intlist_attributes;
anand.ratna85c48c2014-09-23 16:50:21113 base::StringPairs html_attributes;
avi9c81217b2015-12-24 23:40:05114 std::vector<int32_t> child_ids;
dmazzoni0aec3862016-03-28 19:06:56115
116 // The object's location relative to its window or frame.
117 gfx::Rect location;
118
119 // An additional transform to apply to position this object and its subtree.
dcheng18ec0b542016-04-26 19:28:53120 // NOTE: this member is a std::unique_ptr because it's rare and gfx::Transform
dmazzoni0aec3862016-03-28 19:06:56121 // takes up a fair amount of space. The assignment operator and copy
122 // constructor both make a duplicate of the owned pointer, so it acts more
123 // like a member than a pointer.
danakj25c52c32016-04-12 21:51:08124 std::unique_ptr<gfx::Transform> transform;
[email protected]4b02bbca2013-11-22 08:59:03125};
126
127} // namespace ui
128
129#endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_