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 "ui/gfx/rect.h" 15 16 namespace content { 17 18 // A compact representation of the accessibility information for a 19 // single web object, in a form that can be serialized and sent from 20 // the renderer process to the browser process. 21 struct CONTENT_EXPORT AccessibilityNodeData { 22 // An enumeration of accessibility roles. 23 enum Role { 24 ROLE_UNKNOWN = 0, 25 26 // Used by Chromium to distinguish between the root of the tree 27 // for this page, and a web area for a frame within this page. 28 ROLE_ROOT_WEB_AREA, 29 30 // These roles all directly correspond to WebKit accessibility roles, 31 // keep these alphabetical. 32 ROLE_ALERT, 33 ROLE_ALERT_DIALOG, 34 ROLE_ANNOTATION, 35 ROLE_APPLICATION, 36 ROLE_ARTICLE, 37 ROLE_BROWSER, 38 ROLE_BUSY_INDICATOR, 39 ROLE_BUTTON, 40 ROLE_CANVAS, 41 ROLE_CANVAS_WITH_FALLBACK_CONTENT, 42 ROLE_CELL, 43 ROLE_CHECKBOX, 44 ROLE_COLOR_WELL, 45 ROLE_COLUMN, 46 ROLE_COLUMN_HEADER, 47 ROLE_COMBO_BOX, 48 ROLE_DEFINITION, 49 ROLE_DESCRIPTION_LIST_DETAIL, 50 ROLE_DESCRIPTION_LIST_TERM, 51 ROLE_DIALOG, 52 ROLE_DIRECTORY, 53 ROLE_DISCLOSURE_TRIANGLE, 54 ROLE_DIV, 55 ROLE_DOCUMENT, 56 ROLE_DRAWER, 57 ROLE_EDITABLE_TEXT, 58 ROLE_FOOTER, 59 ROLE_FORM, 60 ROLE_GRID, 61 ROLE_GROUP, 62 ROLE_GROW_AREA, 63 ROLE_HEADING, 64 ROLE_HELP_TAG, 65 ROLE_HORIZONTAL_RULE, 66 ROLE_IGNORED, 67 ROLE_IMAGE, 68 ROLE_IMAGE_MAP, 69 ROLE_IMAGE_MAP_LINK, 70 ROLE_INCREMENTOR, 71 ROLE_LABEL, 72 ROLE_LANDMARK_APPLICATION, 73 ROLE_LANDMARK_BANNER, 74 ROLE_LANDMARK_COMPLEMENTARY, 75 ROLE_LANDMARK_CONTENTINFO, 76 ROLE_LANDMARK_MAIN, 77 ROLE_LANDMARK_NAVIGATION, 78 ROLE_LANDMARK_SEARCH, 79 ROLE_LINK, 80 ROLE_LIST, 81 ROLE_LISTBOX, 82 ROLE_LISTBOX_OPTION, 83 ROLE_LIST_ITEM, 84 ROLE_LIST_MARKER, 85 ROLE_LOG, 86 ROLE_MARQUEE, 87 ROLE_MATH, 88 ROLE_MATTE, 89 ROLE_MENU, 90 ROLE_MENU_BAR, 91 ROLE_MENU_ITEM, 92 ROLE_MENU_BUTTON, 93 ROLE_MENU_LIST_OPTION, 94 ROLE_MENU_LIST_POPUP, 95 ROLE_NOTE, 96 ROLE_OUTLINE, 97 ROLE_PARAGRAPH, 98 ROLE_POPUP_BUTTON, 99 ROLE_PRESENTATIONAL, 100 ROLE_PROGRESS_INDICATOR, 101 ROLE_RADIO_BUTTON, 102 ROLE_RADIO_GROUP, 103 ROLE_REGION, 104 ROLE_ROW, 105 ROLE_ROW_HEADER, 106 ROLE_RULER, 107 ROLE_RULER_MARKER, 108 ROLE_SCROLLAREA, 109 ROLE_SCROLLBAR, 110 ROLE_SHEET, 111 ROLE_SLIDER, 112 ROLE_SLIDER_THUMB, 113 ROLE_SPIN_BUTTON, 114 ROLE_SPIN_BUTTON_PART, 115 ROLE_SPLITTER, 116 ROLE_SPLIT_GROUP, 117 ROLE_STATIC_TEXT, 118 ROLE_STATUS, 119 ROLE_SVG_ROOT, 120 ROLE_SYSTEM_WIDE, 121 ROLE_TAB, 122 ROLE_TABLE, 123 ROLE_TABLE_HEADER_CONTAINER, 124 ROLE_TAB_GROUP_UNUSED, // WebKit doesn't use (uses ROLE_TAB_LIST) 125 ROLE_TAB_LIST, 126 ROLE_TAB_PANEL, 127 ROLE_TEXTAREA, 128 ROLE_TEXT_FIELD, 129 ROLE_TIMER, 130 ROLE_TOGGLE_BUTTON, 131 ROLE_TOOLBAR, 132 ROLE_TOOLTIP, 133 ROLE_TREE, 134 ROLE_TREE_GRID, 135 ROLE_TREE_ITEM, 136 ROLE_VALUE_INDICATOR, 137 ROLE_WEBCORE_LINK, 138 ROLE_WEB_AREA, 139 ROLE_WINDOW, 140 NUM_ROLES 141 }; 142 143 // An alphabetical enumeration of accessibility states. 144 // A state bitmask is formed by shifting 1 to the left by each state, 145 // for example: 146 // int mask = (1 << STATE_CHECKED) | (1 << STATE_FOCUSED); 147 enum State { 148 STATE_BUSY, 149 STATE_CHECKED, 150 STATE_COLLAPSED, 151 STATE_EXPANDED, 152 STATE_FOCUSABLE, 153 STATE_FOCUSED, 154 STATE_HASPOPUP, 155 STATE_HOTTRACKED, 156 STATE_INDETERMINATE, 157 STATE_INVISIBLE, 158 STATE_LINKED, 159 STATE_MULTISELECTABLE, 160 STATE_OFFSCREEN, 161 STATE_PRESSED, 162 STATE_PROTECTED, 163 STATE_READONLY, 164 STATE_REQUIRED, 165 STATE_SELECTABLE, 166 STATE_SELECTED, 167 STATE_TRAVERSED, 168 STATE_UNAVAILABLE, 169 STATE_VERTICAL, 170 STATE_VISITED, 171 NUM_STATES 172 }; 173 174 COMPILE_ASSERT(NUM_STATES <= 31, state_enum_not_too_large); 175 176 // Additional optional attributes that can be optionally attached to 177 // a node. 178 enum StringAttribute { 179 // Document attributes. 180 ATTR_DOC_URL, 181 ATTR_DOC_TITLE, 182 ATTR_DOC_MIMETYPE, 183 ATTR_DOC_DOCTYPE, 184 185 // Attributes that could apply to any node. 186 ATTR_ACCESS_KEY, 187 ATTR_ACTION, 188 ATTR_CONTAINER_LIVE_RELEVANT, 189 ATTR_CONTAINER_LIVE_STATUS, 190 ATTR_DESCRIPTION, 191 ATTR_DISPLAY, 192 ATTR_HELP, 193 ATTR_HTML_TAG, 194 ATTR_LIVE_RELEVANT, 195 ATTR_LIVE_STATUS, 196 ATTR_ROLE, 197 ATTR_SHORTCUT, 198 ATTR_URL, 199 }; 200 201 enum IntAttribute { 202 // Scrollable container attributes. 203 ATTR_SCROLL_X, 204 ATTR_SCROLL_X_MIN, 205 ATTR_SCROLL_X_MAX, 206 ATTR_SCROLL_Y, 207 ATTR_SCROLL_Y_MIN, 208 ATTR_SCROLL_Y_MAX, 209 210 // Editable text attributes. 211 ATTR_TEXT_SEL_START, 212 ATTR_TEXT_SEL_END, 213 214 // Table attributes. 215 ATTR_TABLE_ROW_COUNT, 216 ATTR_TABLE_COLUMN_COUNT, 217 ATTR_TABLE_HEADER_ID, 218 219 // Table row attributes. 220 ATTR_TABLE_ROW_INDEX, 221 ATTR_TABLE_ROW_HEADER_ID, 222 223 // Table column attributes. 224 ATTR_TABLE_COLUMN_INDEX, 225 ATTR_TABLE_COLUMN_HEADER_ID, 226 227 // Table cell attributes. 228 ATTR_TABLE_CELL_COLUMN_INDEX, 229 ATTR_TABLE_CELL_COLUMN_SPAN, 230 ATTR_TABLE_CELL_ROW_INDEX, 231 ATTR_TABLE_CELL_ROW_SPAN, 232 233 // Tree control attributes. 234 ATTR_HIERARCHICAL_LEVEL, 235 236 // Relationships between this element and other elements. 237 ATTR_TITLE_UI_ELEMENT, 238 239 // Color value for ROLE_COLOR_WELL, each component is 0..255 240 ATTR_COLOR_VALUE_RED, 241 ATTR_COLOR_VALUE_GREEN, 242 ATTR_COLOR_VALUE_BLUE 243 }; 244 245 enum FloatAttribute { 246 // Document attributes. 247 ATTR_DOC_LOADING_PROGRESS, 248 249 // Range attributes. 250 ATTR_VALUE_FOR_RANGE, 251 ATTR_MIN_VALUE_FOR_RANGE, 252 ATTR_MAX_VALUE_FOR_RANGE, 253 }; 254 255 enum BoolAttribute { 256 // Document attributes. 257 ATTR_DOC_LOADED, 258 259 // True if a checkbox or radio button is in the "mixed" state. 260 ATTR_BUTTON_MIXED, 261 262 // Live region attributes. 263 ATTR_CONTAINER_LIVE_ATOMIC, 264 ATTR_CONTAINER_LIVE_BUSY, 265 ATTR_LIVE_ATOMIC, 266 ATTR_LIVE_BUSY, 267 268 // ARIA readonly flag. 269 ATTR_ARIA_READONLY, 270 271 // Writeable attributes 272 ATTR_CAN_SET_VALUE, 273 274 // If this is set, all of the other fields in this struct should 275 // be ignored and only the locations should change. 276 ATTR_UPDATE_LOCATION_ONLY, 277 }; 278 279 AccessibilityNodeData(); 280 virtual ~AccessibilityNodeData(); 281 282 #ifndef NDEBUG 283 virtual std::string DebugString(bool recursive) const; 284 #endif 285 286 // This is a simple serializable struct. All member variables should be 287 // public and copyable. 288 int32 id; 289 string16 name; 290 string16 value; 291 Role role; 292 uint32 state; 293 gfx::Rect location; 294 std::map<StringAttribute, string16> string_attributes; 295 std::map<IntAttribute, int32> int_attributes; 296 std::map<FloatAttribute, float> float_attributes; 297 std::map<BoolAttribute, bool> bool_attributes; 298 std::vector<int32> child_ids; 299 std::vector<int32> indirect_child_ids; 300 std::vector<std::pair<string16, string16> > html_attributes; 301 std::vector<int32> line_breaks; 302 303 // For a table, the cell ids in row-major order, with duplicate entries 304 // when there's a rowspan or colspan, and with -1 for missing cells. 305 // There are always exactly rows * columns entries. 306 std::vector<int32> cell_ids; 307 308 // For a table, the unique cell ids in row-major order of their first 309 // occurrence. 310 std::vector<int32> unique_cell_ids; 311 }; 312 313 // For testing and debugging only: this subclass of AccessibilityNodeData 314 // is used to represent a whole tree of accessibility nodes, where each 315 // node owns its children. This makes it easy to print the tree structure 316 // or search it recursively. 317 struct CONTENT_EXPORT AccessibilityNodeDataTreeNode 318 : public AccessibilityNodeData { 319 AccessibilityNodeDataTreeNode(); 320 virtual ~AccessibilityNodeDataTreeNode(); 321 322 AccessibilityNodeDataTreeNode& operator=(const AccessibilityNodeData& src); 323 324 #ifndef NDEBUG 325 virtual std::string DebugString(bool recursive) const OVERRIDE; 326 #endif 327 328 std::vector<AccessibilityNodeDataTreeNode> children; 329 }; 330 331 // Given a vector of accessibility nodes that represent a complete 332 // accessibility tree, where each node appears before its children, 333 // build a tree of AccessibilityNodeDataTreeNode objects for easier 334 // testing and debugging, where each node contains its children. 335 // The |dst| argument will become the root of the new tree. 336 void MakeAccessibilityNodeDataTree( 337 const std::vector<AccessibilityNodeData>& src, 338 AccessibilityNodeDataTreeNode* dst); 339 340 } // namespace content 341 342 #endif // CONTENT_COMMON_ACCESSIBILITY_NODE_DATA_H_ 343