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. 4 5 #ifndef CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_ 6 #define CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 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" 16 17 namespace content { 18 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 24 // a node. 25 enum StringAttribute { 26 // Document attributes. 27 ATTR_DOC_URL, 28 ATTR_DOC_TITLE, 29 ATTR_DOC_MIMETYPE, 30 ATTR_DOC_DOCTYPE, 31 32 // Attributes that could apply to any node. 33 ATTR_ACCESS_KEY, 34 ATTR_ACTION, 35 ATTR_CONTAINER_LIVE_RELEVANT, 36 ATTR_CONTAINER_LIVE_STATUS, 37 ATTR_DESCRIPTION, 38 ATTR_DISPLAY, 39 ATTR_HELP, 40 ATTR_HTML_TAG, 41 ATTR_NAME, 42 ATTR_LIVE_RELEVANT, 43 ATTR_LIVE_STATUS, 44 ATTR_ROLE, 45 ATTR_SHORTCUT, 46 ATTR_URL, 47 ATTR_VALUE, 48 }; 49 50 enum IntAttribute { 51 // Scrollable container attributes. 52 ATTR_SCROLL_X, 53 ATTR_SCROLL_X_MIN, 54 ATTR_SCROLL_X_MAX, 55 ATTR_SCROLL_Y, 56 ATTR_SCROLL_Y_MIN, 57 ATTR_SCROLL_Y_MAX, 58 59 // Editable text attributes. 60 ATTR_TEXT_SEL_START, 61 ATTR_TEXT_SEL_END, 62 63 // Table attributes. 64 ATTR_TABLE_ROW_COUNT, 65 ATTR_TABLE_COLUMN_COUNT, 66 ATTR_TABLE_HEADER_ID, 67 68 // Table row attributes. 69 ATTR_TABLE_ROW_INDEX, 70 ATTR_TABLE_ROW_HEADER_ID, 71 72 // Table column attributes. 73 ATTR_TABLE_COLUMN_INDEX, 74 ATTR_TABLE_COLUMN_HEADER_ID, 75 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, 81 82 // Tree control attributes. 83 ATTR_HIERARCHICAL_LEVEL, 84 85 // Relationships between this element and other elements. 86 ATTR_TITLE_UI_ELEMENT, 87 88 // Color value for blink::WebAXRoleColorWell, each component is 0..255 89 ATTR_COLOR_VALUE_RED, 90 ATTR_COLOR_VALUE_GREEN, 91 ATTR_COLOR_VALUE_BLUE, 92 93 // Inline text attributes. 94 ATTR_TEXT_DIRECTION 95 }; 96 97 enum FloatAttribute { 98 // Document attributes. 99 ATTR_DOC_LOADING_PROGRESS, 100 101 // Range attributes. 102 ATTR_VALUE_FOR_RANGE, 103 ATTR_MIN_VALUE_FOR_RANGE, 104 ATTR_MAX_VALUE_FOR_RANGE, 105 }; 106 107 enum BoolAttribute { 108 // Document attributes. 109 ATTR_DOC_LOADED, 110 111 // True if a checkbox or radio button is in the "mixed" state. 112 ATTR_BUTTON_MIXED, 113 114 // Live region attributes. 115 ATTR_CONTAINER_LIVE_ATOMIC, 116 ATTR_CONTAINER_LIVE_BUSY, 117 ATTR_LIVE_ATOMIC, 118 ATTR_LIVE_BUSY, 119 120 // ARIA readonly flag. 121 ATTR_ARIA_READONLY, 122 123 // Writeable attributes 124 ATTR_CAN_SET_VALUE, 125 126 // If this is set, all of the other fields in this struct should 127 // be ignored and only the locations should change. 128 ATTR_UPDATE_LOCATION_ONLY, 129 130 // Set on a canvas element if it has fallback content. 131 ATTR_CANVAS_HAS_FALLBACK, 132 }; 133 134 enum IntListAttribute { 135 // Ids of nodes that are children of this node logically, but are 136 // not children of this node in the tree structure. As an example, 137 // a table cell is a child of a row, and an 'indirect' child of a 138 // column. 139 ATTR_INDIRECT_CHILD_IDS, 140 141 // Character indices where line breaks occur. 142 ATTR_LINE_BREAKS, 143 144 // For a table, the cell ids in row-major order, with duplicate entries 145 // when there's a rowspan or colspan, and with -1 for missing cells. 146 // There are always exactly rows * columns entries. 147 ATTR_CELL_IDS, 148 149 // For a table, the unique cell ids in row-major order of their first 150 // occurrence. 151 ATTR_UNIQUE_CELL_IDS, 152 153 // For inline text. This is the pixel position of the end of this 154 // character within the bounding rectangle of this object, in the 155 // direction given by ATTR_TEXT_DIRECTION. For example, for left-to-right 156 // text, the first offset is the right coordinate of the first character 157 // within the object's bounds, the second offset is the right coordinate 158 // of the second character, and so on. 159 ATTR_CHARACTER_OFFSETS, 160 161 // For inline text. These int lists must be the same size; they represent 162 // the start and end character index of each word within this text. 163 ATTR_WORD_STARTS, 164 ATTR_WORD_ENDS, 165 }; 166 167 AccessibilityNodeData(); 168 virtual ~AccessibilityNodeData(); 169 170 void AddStringAttribute(StringAttribute attribute, 171 const std::string& value); 172 void AddIntAttribute(IntAttribute attribute, int value); 173 void AddFloatAttribute(FloatAttribute attribute, float value); 174 void AddBoolAttribute(BoolAttribute attribute, bool value); 175 void AddIntListAttribute(IntListAttribute attribute, 176 const std::vector<int32>& value); 177 178 // Convenience functions, mainly for writing unit tests. 179 // Equivalent to AddStringAttribute(ATTR_NAME, name). 180 void SetName(std::string name); 181 // Equivalent to AddStringAttribute(ATTR_VALUE, value). 182 void SetValue(std::string value); 183 184 #ifndef NDEBUG 185 virtual std::string DebugString(bool recursive) const; 186 #endif 187 188 // This is a simple serializable struct. All member variables should be 189 // public and copyable. 190 int32 id; 191 blink::WebAXRole role; 192 uint32 state; 193 gfx::Rect location; 194 std::vector<std::pair<StringAttribute, std::string> > string_attributes; 195 std::vector<std::pair<IntAttribute, int32> > int_attributes; 196 std::vector<std::pair<FloatAttribute, float> > float_attributes; 197 std::vector<std::pair<BoolAttribute, bool> > bool_attributes; 198 std::vector<std::pair<IntListAttribute, std::vector<int32> > > 199 intlist_attributes; 200 std::vector<std::pair<std::string, std::string> > html_attributes; 201 std::vector<int32> child_ids; 202 }; 203 204 // For testing and debugging only: this subclass of AccessibilityNodeData 205 // is used to represent a whole tree of accessibility nodes, where each 206 // node owns its children. This makes it easy to print the tree structure 207 // or search it recursively. 208 struct CONTENT_EXPORT AccessibilityNodeDataTreeNode 209 : public AccessibilityNodeData { 210 AccessibilityNodeDataTreeNode(); 211 virtual ~AccessibilityNodeDataTreeNode(); 212 213 AccessibilityNodeDataTreeNode& operator=(const AccessibilityNodeData& src); 214 215 #ifndef NDEBUG 216 virtual std::string DebugString(bool recursive) const OVERRIDE; 217 #endif 218 219 std::vector<AccessibilityNodeDataTreeNode> children; 220 }; 221 222 // Given a vector of accessibility nodes that represent a complete 223 // accessibility tree, where each node appears before its children, 224 // build a tree of AccessibilityNodeDataTreeNode objects for easier 225 // testing and debugging, where each node contains its children. 226 // The |dst| argument will become the root of the new tree. 227 void MakeAccessibilityNodeDataTree( 228 const std::vector<AccessibilityNodeData>& src, 229 AccessibilityNodeDataTreeNode* dst); 230 231 } // namespace content 232 233 #endif // CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_ 234