Add ICU message format support
[chromium-blink-merge.git] / ui / accessibility / ax_node_data.h
blob528b27b71325244727fc720639088614cc4d5cc2
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.
5 #ifndef UI_ACCESSIBILITY_AX_NODE_DATA_H_
6 #define UI_ACCESSIBILITY_AX_NODE_DATA_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/strings/string16.h"
13 #include "base/strings/string_split.h"
14 #include "ui/accessibility/ax_enums.h"
15 #include "ui/accessibility/ax_export.h"
16 #include "ui/gfx/geometry/rect.h"
18 namespace ui {
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 {
24 AXNodeData();
25 virtual ~AXNodeData();
27 // Accessing accessibility attributes:
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).
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.
42 bool HasBoolAttribute(AXBoolAttribute attr) const;
43 bool GetBoolAttribute(AXBoolAttribute attr) const;
44 bool GetBoolAttribute(AXBoolAttribute attr, bool* value) const;
46 bool HasFloatAttribute(AXFloatAttribute attr) const;
47 float GetFloatAttribute(AXFloatAttribute attr) const;
48 bool GetFloatAttribute(AXFloatAttribute attr, float* value) const;
50 bool HasIntAttribute(AXIntAttribute attribute) const;
51 int GetIntAttribute(AXIntAttribute attribute) const;
52 bool GetIntAttribute(AXIntAttribute attribute, int* value) const;
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;
60 bool GetString16Attribute(AXStringAttribute attribute,
61 base::string16* value) const;
62 base::string16 GetString16Attribute(
63 AXStringAttribute attribute) const;
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;
71 bool GetHtmlAttribute(const char* attr, base::string16* value) const;
72 bool GetHtmlAttribute(const char* attr, std::string* value) const;
74 // Setting accessibility attributes.
75 void AddStringAttribute(AXStringAttribute attribute,
76 const std::string& value);
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,
81 const std::vector<int32>& value);
83 // Convenience functions, mainly for writing unit tests.
84 // Equivalent to AddStringAttribute(ATTR_NAME, name).
85 void SetName(std::string name);
86 // Equivalent to AddStringAttribute(ATTR_VALUE, value).
87 void SetValue(std::string value);
89 // Return a string representation of this data, for debugging.
90 virtual std::string ToString() const;
92 bool IsRoot() const;
93 void SetRoot();
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;
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> > >
106 intlist_attributes;
107 base::StringPairs html_attributes;
108 std::vector<int32> child_ids;
111 } // namespace ui
113 #endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_