[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 | |
| 8 | #include <map> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/strings/string16.h" |
anand.ratn | a85c48c | 2014-09-23 16:50:21 | [diff] [blame] | 13 | #include "base/strings/string_split.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 14 | #include "ui/accessibility/ax_enums.h" |
| 15 | #include "ui/accessibility/ax_export.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 16 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 17 | |
| 18 | namespace 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. |
| 23 | struct AX_EXPORT AXNodeData { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 24 | AXNodeData(); |
| 25 | virtual ~AXNodeData(); |
| 26 | |
dmazzoni | 53e922ab | 2015-06-03 23:02:25 | [diff] [blame] | 27 | // 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] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 75 | void AddStringAttribute(AXStringAttribute attribute, |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 76 | const std::string& value); |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 77 | 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] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 81 | const std::vector<int32>& value); |
| 82 | |
| 83 | // Convenience functions, mainly for writing unit tests. |
| 84 | // Equivalent to AddStringAttribute(ATTR_NAME, name). |
ki.stfu | e0013b8 | 2015-09-23 18:14:53 | [diff] [blame^] | 85 | void SetName(const std::string& name); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 86 | // Equivalent to AddStringAttribute(ATTR_VALUE, value). |
ki.stfu | e0013b8 | 2015-09-23 18:14:53 | [diff] [blame^] | 87 | void SetValue(const std::string& value); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 88 | |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 89 | // Return a string representation of this data, for debugging. |
dmazzoni | ac6cdd0 | 2015-08-04 21:07:06 | [diff] [blame] | 90 | virtual std::string ToString() const; |
| 91 | |
| 92 | bool IsRoot() const; |
| 93 | void SetRoot(); |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 94 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 95 | // 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] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 101 | 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] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 106 | intlist_attributes; |
anand.ratn | a85c48c | 2014-09-23 16:50:21 | [diff] [blame] | 107 | base::StringPairs html_attributes; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 108 | std::vector<int32> child_ids; |
| 109 | }; |
| 110 | |
| 111 | } // namespace ui |
| 112 | |
| 113 | #endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_ |