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