1 // Copyright (c) 2012 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 CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_
6 #define CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_
12 #include "base/strings/string16.h"
13 #include "content/common/content_export.h"
14 #include "third_party/WebKit/public/web/WebAXEnums.h"
15 #include "ui/gfx/rect.h"
19 // A compact representation of the accessibility information for a
20 // single web object, in a form that can be serialized and sent from
21 // the renderer process to the browser process.
22 struct CONTENT_EXPORT AccessibilityNodeData
{
23 // Additional optional attributes that can be optionally attached to
25 enum StringAttribute
{
26 // Document attributes.
32 // Attributes that could apply to any node.
35 ATTR_CONTAINER_LIVE_RELEVANT
,
36 ATTR_CONTAINER_LIVE_STATUS
,
51 // Scrollable container attributes.
59 // Editable text attributes.
65 ATTR_TABLE_COLUMN_COUNT
,
68 // Table row attributes.
70 ATTR_TABLE_ROW_HEADER_ID
,
72 // Table column attributes.
73 ATTR_TABLE_COLUMN_INDEX
,
74 ATTR_TABLE_COLUMN_HEADER_ID
,
76 // Table cell attributes.
77 ATTR_TABLE_CELL_COLUMN_INDEX
,
78 ATTR_TABLE_CELL_COLUMN_SPAN
,
79 ATTR_TABLE_CELL_ROW_INDEX
,
80 ATTR_TABLE_CELL_ROW_SPAN
,
82 // Tree control attributes.
83 ATTR_HIERARCHICAL_LEVEL
,
85 // Relationships between this element and other elements.
86 ATTR_TITLE_UI_ELEMENT
,
88 // Color value for WebKit::WebAXRoleColorWell, each component is 0..255
90 ATTR_COLOR_VALUE_GREEN
,
95 // Document attributes.
96 ATTR_DOC_LOADING_PROGRESS
,
100 ATTR_MIN_VALUE_FOR_RANGE
,
101 ATTR_MAX_VALUE_FOR_RANGE
,
105 // Document attributes.
108 // True if a checkbox or radio button is in the "mixed" state.
111 // Live region attributes.
112 ATTR_CONTAINER_LIVE_ATOMIC
,
113 ATTR_CONTAINER_LIVE_BUSY
,
117 // ARIA readonly flag.
120 // Writeable attributes
123 // If this is set, all of the other fields in this struct should
124 // be ignored and only the locations should change.
125 ATTR_UPDATE_LOCATION_ONLY
,
127 // Set on a canvas element if it has fallback content.
128 ATTR_CANVAS_HAS_FALLBACK
,
131 enum IntListAttribute
{
132 // Ids of nodes that are children of this node logically, but are
133 // not children of this node in the tree structure. As an example,
134 // a table cell is a child of a row, and an 'indirect' child of a
136 ATTR_INDIRECT_CHILD_IDS
,
138 // Character indices where line breaks occur.
141 // For a table, the cell ids in row-major order, with duplicate entries
142 // when there's a rowspan or colspan, and with -1 for missing cells.
143 // There are always exactly rows * columns entries.
146 // For a table, the unique cell ids in row-major order of their first
151 AccessibilityNodeData();
152 virtual ~AccessibilityNodeData();
154 void AddStringAttribute(StringAttribute attribute
,
155 const std::string
& value
);
156 void AddIntAttribute(IntAttribute attribute
, int value
);
157 void AddFloatAttribute(FloatAttribute attribute
, float value
);
158 void AddBoolAttribute(BoolAttribute attribute
, bool value
);
159 void AddIntListAttribute(IntListAttribute attribute
,
160 const std::vector
<int32
>& value
);
162 // Convenience function, mainly for writing unit tests.
163 // Equivalent to AddStringAttribute(ATTR_NAME, name).
164 void SetName(std::string name
);
167 virtual std::string
DebugString(bool recursive
) const;
170 // This is a simple serializable struct. All member variables should be
171 // public and copyable.
173 WebKit::WebAXRole role
;
176 std::vector
<std::pair
<StringAttribute
, std::string
> > string_attributes
;
177 std::vector
<std::pair
<IntAttribute
, int32
> > int_attributes
;
178 std::vector
<std::pair
<FloatAttribute
, float> > float_attributes
;
179 std::vector
<std::pair
<BoolAttribute
, bool> > bool_attributes
;
180 std::vector
<std::pair
<IntListAttribute
, std::vector
<int32
> > >
182 std::vector
<std::pair
<std::string
, std::string
> > html_attributes
;
183 std::vector
<int32
> child_ids
;
186 // For testing and debugging only: this subclass of AccessibilityNodeData
187 // is used to represent a whole tree of accessibility nodes, where each
188 // node owns its children. This makes it easy to print the tree structure
189 // or search it recursively.
190 struct CONTENT_EXPORT AccessibilityNodeDataTreeNode
191 : public AccessibilityNodeData
{
192 AccessibilityNodeDataTreeNode();
193 virtual ~AccessibilityNodeDataTreeNode();
195 AccessibilityNodeDataTreeNode
& operator=(const AccessibilityNodeData
& src
);
198 virtual std::string
DebugString(bool recursive
) const OVERRIDE
;
201 std::vector
<AccessibilityNodeDataTreeNode
> children
;
204 // Given a vector of accessibility nodes that represent a complete
205 // accessibility tree, where each node appears before its children,
206 // build a tree of AccessibilityNodeDataTreeNode objects for easier
207 // testing and debugging, where each node contains its children.
208 // The |dst| argument will become the root of the new tree.
209 void MakeAccessibilityNodeDataTree(
210 const std::vector
<AccessibilityNodeData
>& src
,
211 AccessibilityNodeDataTreeNode
* dst
);
213 } // namespace content
215 #endif // CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_