blob: 5bb8c147ff5c1ab4532f47047e7c5a64faab6ff4 [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>
11#include <string>
12#include <vector>
13
14#include "base/strings/string16.h"
anand.ratna85c48c2014-09-23 16:50:2115#include "base/strings/string_split.h"
[email protected]4b02bbca2013-11-22 08:59:0316#include "ui/accessibility/ax_enums.h"
17#include "ui/accessibility/ax_export.h"
tfarina3b0452d2014-12-31 15:20:0918#include "ui/gfx/geometry/rect.h"
[email protected]4b02bbca2013-11-22 08:59:0319
20namespace ui {
21
22// A compact representation of the accessibility information for a
dmazzoni329fd012015-10-22 20:05:3523// single accessible object, in a form that can be serialized and sent from
[email protected]4b02bbca2013-11-22 08:59:0324// one process to another.
25struct AX_EXPORT AXNodeData {
[email protected]4b02bbca2013-11-22 08:59:0326 AXNodeData();
27 virtual ~AXNodeData();
28
dmazzoni53e922ab2015-06-03 23:02:2529 // Accessing accessibility attributes:
30 //
31 // There are dozens of possible attributes for an accessibility node,
32 // but only a few tend to apply to any one object, so we store them
33 // in sparse arrays of <attribute id, attribute value> pairs, organized
34 // by type (bool, int, float, string, int list).
35 //
36 // There are three accessors for each type of attribute: one that returns
37 // true if the attribute is present and false if not, one that takes a
38 // pointer argument and returns true if the attribute is present (if you
39 // need to distinguish between the default value and a missing attribute),
40 // and another that returns the default value for that type if the
41 // attribute is not present. In addition, strings can be returned as
42 // either std::string or base::string16, for convenience.
43
44 bool HasBoolAttribute(AXBoolAttribute attr) const;
45 bool GetBoolAttribute(AXBoolAttribute attr) const;
46 bool GetBoolAttribute(AXBoolAttribute attr, bool* value) const;
47
48 bool HasFloatAttribute(AXFloatAttribute attr) const;
49 float GetFloatAttribute(AXFloatAttribute attr) const;
50 bool GetFloatAttribute(AXFloatAttribute attr, float* value) const;
51
52 bool HasIntAttribute(AXIntAttribute attribute) const;
53 int GetIntAttribute(AXIntAttribute attribute) const;
54 bool GetIntAttribute(AXIntAttribute attribute, int* value) const;
55
56 bool HasStringAttribute(
57 AXStringAttribute attribute) const;
58 const std::string& GetStringAttribute(AXStringAttribute attribute) const;
59 bool GetStringAttribute(AXStringAttribute attribute,
60 std::string* value) const;
61
62 bool GetString16Attribute(AXStringAttribute attribute,
63 base::string16* value) const;
64 base::string16 GetString16Attribute(
65 AXStringAttribute attribute) const;
66
67 bool HasIntListAttribute(AXIntListAttribute attribute) const;
avi9c81217b2015-12-24 23:40:0568 const std::vector<int32_t>& GetIntListAttribute(
dmazzoni53e922ab2015-06-03 23:02:2569 AXIntListAttribute attribute) const;
70 bool GetIntListAttribute(AXIntListAttribute attribute,
avi9c81217b2015-12-24 23:40:0571 std::vector<int32_t>* value) const;
dmazzoni53e922ab2015-06-03 23:02:2572
73 bool GetHtmlAttribute(const char* attr, base::string16* value) const;
74 bool GetHtmlAttribute(const char* attr, std::string* value) const;
75
76 // Setting accessibility attributes.
[email protected]5eec2f52014-01-06 22:30:5477 void AddStringAttribute(AXStringAttribute attribute,
[email protected]4b02bbca2013-11-22 08:59:0378 const std::string& value);
[email protected]5eec2f52014-01-06 22:30:5479 void AddIntAttribute(AXIntAttribute attribute, int value);
80 void AddFloatAttribute(AXFloatAttribute attribute, float value);
81 void AddBoolAttribute(AXBoolAttribute attribute, bool value);
82 void AddIntListAttribute(AXIntListAttribute attribute,
avi9c81217b2015-12-24 23:40:0583 const std::vector<int32_t>& value);
[email protected]4b02bbca2013-11-22 08:59:0384
85 // Convenience functions, mainly for writing unit tests.
86 // Equivalent to AddStringAttribute(ATTR_NAME, name).
ki.stfue0013b82015-09-23 18:14:5387 void SetName(const std::string& name);
[email protected]4b02bbca2013-11-22 08:59:0388 // Equivalent to AddStringAttribute(ATTR_VALUE, value).
ki.stfue0013b82015-09-23 18:14:5389 void SetValue(const std::string& value);
[email protected]4b02bbca2013-11-22 08:59:0390
[email protected]5eec2f52014-01-06 22:30:5491 // Return a string representation of this data, for debugging.
dmazzoniac6cdd02015-08-04 21:07:0692 virtual std::string ToString() const;
93
94 bool IsRoot() const;
95 void SetRoot();
[email protected]5eec2f52014-01-06 22:30:5496
[email protected]4b02bbca2013-11-22 08:59:0397 // This is a simple serializable struct. All member variables should be
98 // public and copyable.
avi9c81217b2015-12-24 23:40:0599 int32_t id;
[email protected]4b02bbca2013-11-22 08:59:03100 AXRole role;
avi9c81217b2015-12-24 23:40:05101 uint32_t state;
[email protected]4b02bbca2013-11-22 08:59:03102 gfx::Rect location;
[email protected]5eec2f52014-01-06 22:30:54103 std::vector<std::pair<AXStringAttribute, std::string> > string_attributes;
avi9c81217b2015-12-24 23:40:05104 std::vector<std::pair<AXIntAttribute, int32_t>> int_attributes;
[email protected]5eec2f52014-01-06 22:30:54105 std::vector<std::pair<AXFloatAttribute, float> > float_attributes;
106 std::vector<std::pair<AXBoolAttribute, bool> > bool_attributes;
avi9c81217b2015-12-24 23:40:05107 std::vector<std::pair<AXIntListAttribute, std::vector<int32_t>>>
[email protected]4b02bbca2013-11-22 08:59:03108 intlist_attributes;
anand.ratna85c48c2014-09-23 16:50:21109 base::StringPairs html_attributes;
avi9c81217b2015-12-24 23:40:05110 std::vector<int32_t> child_ids;
[email protected]4b02bbca2013-11-22 08:59:03111};
112
113} // namespace ui
114
115#endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_