[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 1 | // 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 | |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 10 | #include <map> |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame^] | 11 | #include <memory> |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include "base/strings/string16.h" |
anand.ratn | a85c48c | 2014-09-23 16:50:21 | [diff] [blame] | 16 | #include "base/strings/string_split.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 17 | #include "ui/accessibility/ax_enums.h" |
| 18 | #include "ui/accessibility/ax_export.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 19 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 20 | |
dmazzoni | 0aec386 | 2016-03-28 19:06:56 | [diff] [blame] | 21 | namespace gfx { |
| 22 | class Transform; |
| 23 | }; |
| 24 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 25 | namespace ui { |
| 26 | |
| 27 | // A compact representation of the accessibility information for a |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 28 | // single accessible object, in a form that can be serialized and sent from |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 29 | // one process to another. |
| 30 | struct AX_EXPORT AXNodeData { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 31 | AXNodeData(); |
| 32 | virtual ~AXNodeData(); |
| 33 | |
dmazzoni | 729443ae | 2016-02-29 21:17:12 | [diff] [blame] | 34 | AXNodeData(const AXNodeData& other); |
| 35 | AXNodeData& operator=(AXNodeData other); |
| 36 | |
dmazzoni | 53e922ab | 2015-06-03 23:02:25 | [diff] [blame] | 37 | // 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; |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 76 | const std::vector<int32_t>& GetIntListAttribute( |
dmazzoni | 53e922ab | 2015-06-03 23:02:25 | [diff] [blame] | 77 | AXIntListAttribute attribute) const; |
| 78 | bool GetIntListAttribute(AXIntListAttribute attribute, |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 79 | std::vector<int32_t>* value) const; |
dmazzoni | 53e922ab | 2015-06-03 23:02:25 | [diff] [blame] | 80 | |
| 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] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 85 | void AddStringAttribute(AXStringAttribute attribute, |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 86 | const std::string& value); |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 87 | 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, |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 91 | const std::vector<int32_t>& value); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 92 | |
| 93 | // Convenience functions, mainly for writing unit tests. |
| 94 | // Equivalent to AddStringAttribute(ATTR_NAME, name). |
ki.stfu | e0013b8 | 2015-09-23 18:14:53 | [diff] [blame] | 95 | void SetName(const std::string& name); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 96 | // Equivalent to AddStringAttribute(ATTR_VALUE, value). |
ki.stfu | e0013b8 | 2015-09-23 18:14:53 | [diff] [blame] | 97 | void SetValue(const std::string& value); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 98 | |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 99 | // Return a string representation of this data, for debugging. |
dmazzoni | ac6cdd0 | 2015-08-04 21:07:06 | [diff] [blame] | 100 | virtual std::string ToString() const; |
| 101 | |
dmazzoni | 729443ae | 2016-02-29 21:17:12 | [diff] [blame] | 102 | // As much as possible this should behave as a simple, serializable, |
| 103 | // copyable struct. |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 104 | int32_t id; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 105 | AXRole role; |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 106 | uint32_t state; |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 107 | std::vector<std::pair<AXStringAttribute, std::string> > string_attributes; |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 108 | std::vector<std::pair<AXIntAttribute, int32_t>> int_attributes; |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 109 | std::vector<std::pair<AXFloatAttribute, float> > float_attributes; |
| 110 | std::vector<std::pair<AXBoolAttribute, bool> > bool_attributes; |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 111 | std::vector<std::pair<AXIntListAttribute, std::vector<int32_t>>> |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 112 | intlist_attributes; |
anand.ratn | a85c48c | 2014-09-23 16:50:21 | [diff] [blame] | 113 | base::StringPairs html_attributes; |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 114 | std::vector<int32_t> child_ids; |
dmazzoni | 0aec386 | 2016-03-28 19:06:56 | [diff] [blame] | 115 | |
| 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. |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame^] | 120 | // NOTE: this member is a std::unique_ptr because it's rare and gfx::Transform |
dmazzoni | 0aec386 | 2016-03-28 19:06:56 | [diff] [blame] | 121 | // 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. |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 124 | std::unique_ptr<gfx::Transform> transform; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | } // namespace ui |
| 128 | |
| 129 | #endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_ |