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 CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_ 6 #define CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_ 7 8 #include <string> 9 #include "base/compiler_specific.h" 10 #include "ui/accessibility/ax_enums.h" 11 12 class AccessibilityControlInfo; 13 class AccessibilityMenuInfo; 14 class AccessibilityWindowInfo; 15 class Profile; 16 17 namespace base { 18 class DictionaryValue; 19 } 20 21 // Notify the ExtensionAccessibilityEventRouter of the given accessibility 22 // event and AccessibilityEventInfo details. Will not send if the profile's 23 // pause level is nonzero (using profile->PauseAccessibilityEvents). 24 void SendControlAccessibilityNotification( 25 ui::AXEvent event, 26 AccessibilityControlInfo* info); 27 28 void SendMenuAccessibilityNotification( 29 ui::AXEvent event, 30 AccessibilityMenuInfo* info); 31 32 void SendWindowAccessibilityNotification( 33 ui::AXEvent event, 34 AccessibilityWindowInfo* info); 35 36 // Abstract parent class for accessibility event information passed to event 37 // listeners. 38 class AccessibilityEventInfo { 39 public: 40 virtual ~AccessibilityEventInfo() {} 41 42 // Serialize this class as a DictionaryValue that can be converted to 43 // a JavaScript object. 44 virtual void SerializeToDict(base::DictionaryValue* dict) const = 0; 45 46 Profile* profile() const { return profile_; } 47 48 protected: 49 explicit AccessibilityEventInfo(Profile* profile) : profile_(profile) {} 50 51 // The profile this control belongs to. 52 Profile* profile_; 53 }; 54 55 // Abstract parent class for accessibility information about a control 56 // passed to event listeners. 57 class AccessibilityControlInfo : public AccessibilityEventInfo { 58 public: 59 virtual ~AccessibilityControlInfo(); 60 61 // Serialize this class as a DictionaryValue that can be converted to 62 // a JavaScript object. 63 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 64 65 // Return the specific type of this control, which will be one of the 66 // string constants defined in extension_accessibility_api_constants.h. 67 virtual const char* type() const = 0; 68 69 const std::string& name() const { return name_; } 70 71 const std::string& context() const { return context_; } 72 73 protected: 74 AccessibilityControlInfo(Profile* profile, 75 const std::string& name); 76 77 void set_context(const std::string& context) { context_ = context; } 78 79 // The name of the control, like "OK" or "Password". 80 std::string name_; 81 82 // A string describing the context of the control, such as the name of 83 // the group or toolbar it's contained in. 84 std::string context_; 85 }; 86 87 // Accessibility information about a window passed to onWindowOpened 88 // and onWindowClosed event listeners. 89 class AccessibilityWindowInfo : public AccessibilityControlInfo { 90 public: 91 AccessibilityWindowInfo(Profile* profile, const std::string& window_name); 92 93 virtual const char* type() const OVERRIDE; 94 }; 95 96 // Accessibility information about a push button passed to onControlFocused 97 // and onControlAction event listeners. 98 class AccessibilityButtonInfo : public AccessibilityControlInfo { 99 public: 100 AccessibilityButtonInfo(Profile* profile, 101 const std::string& button_name, 102 const std::string& context); 103 104 virtual const char* type() const OVERRIDE; 105 }; 106 107 // Accessibility information about a hyperlink passed to onControlFocused 108 // and onControlAction event listeners. 109 class AccessibilityLinkInfo : public AccessibilityControlInfo { 110 public: 111 AccessibilityLinkInfo(Profile* profile, 112 const std::string& link_name, 113 const std::string& context); 114 115 virtual const char* type() const OVERRIDE; 116 }; 117 118 // Accessibility information about a radio button passed to onControlFocused 119 // and onControlAction event listeners. 120 class AccessibilityRadioButtonInfo : public AccessibilityControlInfo { 121 public: 122 AccessibilityRadioButtonInfo(Profile* profile, 123 const std::string& name, 124 const std::string& context, 125 bool checked, 126 int item_index, 127 int item_count); 128 129 virtual const char* type() const OVERRIDE; 130 131 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 132 133 void SetChecked(bool checked) { checked_ = checked; } 134 135 int item_index() const { return item_index_; } 136 int item_count() const { return item_count_; } 137 bool checked() const { return checked_; } 138 139 private: 140 bool checked_; 141 // The 0-based index of this radio button and number of buttons in the group. 142 int item_index_; 143 int item_count_; 144 }; 145 146 // Accessibility information about a checkbox passed to onControlFocused 147 // and onControlAction event listeners. 148 class AccessibilityCheckboxInfo : public AccessibilityControlInfo { 149 public: 150 AccessibilityCheckboxInfo(Profile* profile, 151 const std::string& name, 152 const std::string& context, 153 bool checked); 154 155 virtual const char* type() const OVERRIDE; 156 157 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 158 159 void SetChecked(bool checked) { checked_ = checked; } 160 161 bool checked() const { return checked_; } 162 163 private: 164 bool checked_; 165 }; 166 167 // Accessibility information about a tab passed to onControlFocused 168 // and onControlAction event listeners. 169 class AccessibilityTabInfo : public AccessibilityControlInfo { 170 public: 171 AccessibilityTabInfo(Profile* profile, 172 const std::string& tab_name, 173 const std::string& context, 174 int tab_index, 175 int tab_count); 176 177 virtual const char* type() const OVERRIDE; 178 179 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 180 181 void SetTab(int tab_index, std::string tab_name) { 182 tab_index_ = tab_index; 183 name_ = tab_name; 184 } 185 186 int tab_index() const { return tab_index_; } 187 int tab_count() const { return tab_count_; } 188 189 private: 190 // The 0-based index of this tab and number of tabs in the group. 191 int tab_index_; 192 int tab_count_; 193 }; 194 195 // Accessibility information about a combo box passed to onControlFocused 196 // and onControlAction event listeners. 197 class AccessibilityComboBoxInfo : public AccessibilityControlInfo { 198 public: 199 AccessibilityComboBoxInfo(Profile* profile, 200 const std::string& name, 201 const std::string& context, 202 const std::string& value, 203 int item_index, 204 int item_count); 205 206 virtual const char* type() const OVERRIDE; 207 208 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 209 210 void SetValue(int item_index, const std::string& value) { 211 item_index_ = item_index; 212 value_ = value; 213 } 214 215 int item_index() const { return item_index_; } 216 int item_count() const { return item_count_; } 217 const std::string& value() const { return value_; } 218 219 private: 220 std::string value_; 221 // The 0-based index of the current item and the number of total items. 222 // If the value is not one of the drop-down options, |item_index_| should 223 // be -1. 224 int item_index_; 225 int item_count_; 226 }; 227 228 229 // Accessibility information about a text box, passed to onControlFocused, 230 // onControlAction, and onTextChanged event listeners. 231 class AccessibilityTextBoxInfo : public AccessibilityControlInfo { 232 public: 233 AccessibilityTextBoxInfo(Profile* profile, 234 const std::string& name, 235 const std::string& context, 236 bool password); 237 238 virtual const char* type() const OVERRIDE; 239 240 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 241 242 void SetValue( 243 const std::string& value, int selection_start, int selection_end) { 244 value_ = value; 245 selection_start_ = selection_start; 246 selection_end_ = selection_end; 247 } 248 249 const std::string& value() const { return value_; } 250 bool password() const { return password_; } 251 int selection_start() const { return selection_start_; } 252 int selection_end() const { return selection_end_; } 253 254 private: 255 std::string value_; 256 bool password_; 257 int selection_start_; 258 int selection_end_; 259 }; 260 261 // Accessibility information about a combo box passed to onControlFocused 262 // and onControlAction event listeners. 263 class AccessibilityListBoxInfo : public AccessibilityControlInfo { 264 public: 265 AccessibilityListBoxInfo(Profile* profile, 266 const std::string& name, 267 const std::string& context, 268 const std::string& value, 269 int item_index, 270 int item_count); 271 272 virtual const char* type() const OVERRIDE; 273 274 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 275 276 void SetValue(int item_index, std::string value) { 277 item_index_ = item_index; 278 value_ = value; 279 } 280 281 int item_index() const { return item_index_; } 282 int item_count() const { return item_count_; } 283 const std::string& value() const { return value_; } 284 285 private: 286 std::string value_; 287 // The 0-based index of the current item and the number of total items. 288 // If the value is not one of the drop-down options, |item_index_| should 289 // be -1. 290 int item_index_; 291 int item_count_; 292 }; 293 294 // Accessibility information about a menu; this class is used by 295 // onMenuOpened, onMenuClosed, and onControlFocused event listeners. 296 class AccessibilityMenuInfo : public AccessibilityControlInfo { 297 public: 298 AccessibilityMenuInfo(Profile* profile, const std::string& menu_name); 299 300 virtual const char* type() const OVERRIDE; 301 }; 302 303 // Accessibility information about a menu item; this class is used by 304 // onControlFocused event listeners. 305 class AccessibilityMenuItemInfo : public AccessibilityControlInfo { 306 public: 307 AccessibilityMenuItemInfo(Profile* profile, 308 const std::string& name, 309 const std::string& context, 310 bool has_submenu, 311 int item_index, 312 int item_count); 313 314 virtual const char* type() const OVERRIDE; 315 316 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 317 318 int item_index() const { return item_index_; } 319 int item_count() const { return item_count_; } 320 bool has_submenu() const { return has_submenu_; } 321 322 private: 323 bool has_submenu_; 324 // The 0-based index of the current item and the number of total items. 325 int item_index_; 326 int item_count_; 327 }; 328 329 // Accessibility information about a tree; this class is used by 330 // onControlFocused event listeners. 331 class AccessibilityTreeInfo : public AccessibilityControlInfo { 332 public: 333 AccessibilityTreeInfo(Profile* profile, const std::string& menu_name); 334 335 virtual const char* type() const OVERRIDE; 336 }; 337 338 // Accessibility information about a tree item; this class is used by 339 // onControlFocused event listeners. 340 class AccessibilityTreeItemInfo : public AccessibilityControlInfo { 341 public: 342 AccessibilityTreeItemInfo(Profile* profile, 343 const std::string& name, 344 const std::string& context, 345 int item_depth, 346 int item_index, 347 int item_count, 348 int children_count, 349 bool is_expanded); 350 351 virtual const char* type() const OVERRIDE; 352 353 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 354 355 int item_depth() const { return item_depth_; } 356 int item_index() const { return item_index_; } 357 int item_count() const { return item_count_; } 358 int children_count() const { return children_count_; } 359 bool is_expanded() const { return is_expanded_; } 360 361 private: 362 // 0-based item depth. 363 int item_depth_; 364 // The 0-based index of the current item and the number of total items at the 365 // current depth. 366 int item_index_; 367 // Count of items at the current depth. 368 int item_count_; 369 // Count of children of the current item. 370 int children_count_; 371 // True if the node is expanded. 372 bool is_expanded_; 373 }; 374 375 // Accessibility information about a slider passed to onControlFocused 376 // and onControlAction event listeners. 377 class AccessibilitySliderInfo : public AccessibilityControlInfo { 378 public: 379 AccessibilitySliderInfo(Profile* profile, 380 const std::string& name, 381 const std::string& context, 382 const std::string& value); 383 384 virtual const char* type() const OVERRIDE; 385 386 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE; 387 388 const std::string& value() const { return value_; } 389 390 private: 391 std::string value_; 392 }; 393 394 // Accessibility information about an alert passed to onControlAction event. 395 class AccessibilityAlertInfo : public AccessibilityControlInfo { 396 public: 397 AccessibilityAlertInfo(Profile* profile, const std::string& name); 398 399 virtual const char* type() const OVERRIDE; 400 }; 401 402 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_ 403