accessibility_events.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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_EVENTS_H_ 6#define CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_ 7 8#include <string> 9 10#include "base/values.h" 11 12class AccessibilityControlInfo; 13class NotificationType; 14class Profile; 15 16// Use the NotificationService to post the given accessibility 17// notification type with AccessibilityControlInfo details to any 18// listeners. Will not send if the profile's pause level is nonzero 19// (using profile->PauseAccessibilityEvents). 20void SendAccessibilityNotification( 21 NotificationType type, AccessibilityControlInfo* info); 22 23// Abstract parent class for accessibility information about a control 24// passed to event listeners. 25class AccessibilityControlInfo { 26 public: 27 virtual ~AccessibilityControlInfo() { } 28 29 // Serialize this class as a DictionaryValue that can be converted to 30 // a JavaScript object. 31 virtual void SerializeToDict(DictionaryValue *dict) const; 32 33 Profile* profile() const { return profile_; } 34 35 const std::string& name() const { return name_; } 36 37 protected: 38 // The constructor can only be called by subclasses. 39 AccessibilityControlInfo(Profile* profile, std::string control_name) 40 : profile_(profile), name_(control_name) { } 41 42 // The profile this control belongs to. 43 Profile* profile_; 44 45 // The name of the control, like "OK" or "Password". 46 std::string name_; 47}; 48 49// Accessibility information about a window passed to onWindowOpened 50// and onWindowClosed event listeners. 51class AccessibilityWindowInfo : public AccessibilityControlInfo { 52 public: 53 AccessibilityWindowInfo(Profile* profile, std::string window_name) 54 : AccessibilityControlInfo(profile, window_name) { } 55 56 virtual void SerializeToDict(DictionaryValue *dict) const; 57}; 58 59// Accessibility information about a push button passed to onControlFocused 60// and onControlAction event listeners. 61class AccessibilityButtonInfo : public AccessibilityControlInfo { 62 public: 63 AccessibilityButtonInfo(Profile* profile, std::string button_name) 64 : AccessibilityControlInfo(profile, button_name) { } 65 66 virtual void SerializeToDict(DictionaryValue *dict) const; 67}; 68 69// Accessibility information about a hyperlink passed to onControlFocused 70// and onControlAction event listeners. 71class AccessibilityLinkInfo : public AccessibilityControlInfo { 72 public: 73 AccessibilityLinkInfo(Profile* profile, std::string link_name) 74 : AccessibilityControlInfo(profile, link_name) { } 75 76 virtual void SerializeToDict(DictionaryValue *dict) const; 77}; 78 79// Accessibility information about a radio button passed to onControlFocused 80// and onControlAction event listeners. 81class AccessibilityRadioButtonInfo : public AccessibilityControlInfo { 82 public: 83 AccessibilityRadioButtonInfo(Profile* profile, 84 std::string name, 85 bool checked, 86 int item_index, 87 int item_count) 88 : AccessibilityControlInfo(profile, name), 89 checked_(checked), 90 item_index_(item_index), 91 item_count_(item_count) { 92 } 93 94 virtual void SerializeToDict(DictionaryValue *dict) const; 95 96 void SetChecked(bool checked) { checked_ = checked; } 97 98 private: 99 bool checked_; 100 // The 0-based index of this radio button and number of buttons in the group. 101 int item_index_; 102 int item_count_; 103}; 104 105// Accessibility information about a checkbox passed to onControlFocused 106// and onControlAction event listeners. 107class AccessibilityCheckboxInfo : public AccessibilityControlInfo { 108 public: 109 AccessibilityCheckboxInfo(Profile* profile, 110 std::string name, 111 bool checked) 112 : AccessibilityControlInfo(profile, name), 113 checked_(checked) { 114 } 115 116 virtual void SerializeToDict(DictionaryValue *dict) const; 117 118 void SetChecked(bool checked) { checked_ = checked; } 119 120 private: 121 bool checked_; 122}; 123 124// Accessibility information about a tab passed to onControlFocused 125// and onControlAction event listeners. 126class AccessibilityTabInfo : public AccessibilityControlInfo { 127 public: 128 AccessibilityTabInfo(Profile* profile, 129 std::string tab_name, 130 int tab_index, 131 int tab_count) 132 : AccessibilityControlInfo(profile, tab_name), 133 tab_index_(tab_index), 134 tab_count_(tab_count) { 135 } 136 137 virtual void SerializeToDict(DictionaryValue *dict) const; 138 139 void SetTab(int tab_index, std::string tab_name) { 140 tab_index_ = tab_index; 141 name_ = tab_name; 142 } 143 144 private: 145 // The 0-based index of this tab and number of tabs in the group. 146 int tab_index_; 147 int tab_count_; 148}; 149 150// Accessibility information about a combo box passed to onControlFocused 151// and onControlAction event listeners. 152class AccessibilityComboBoxInfo : public AccessibilityControlInfo { 153 public: 154 AccessibilityComboBoxInfo(Profile* profile, 155 std::string name, 156 std::string value, 157 int item_index, 158 int item_count) 159 : AccessibilityControlInfo(profile, name), 160 value_(value), 161 item_index_(item_index), 162 item_count_(item_count) { 163 } 164 165 virtual void SerializeToDict(DictionaryValue *dict) const; 166 167 void SetValue(int item_index, std::string value) { 168 item_index_ = item_index; 169 value_ = value; 170 } 171 172 private: 173 std::string value_; 174 // The 0-based index of the current item and the number of total items. 175 // If the value is not one of the drop-down options, |item_index_| should 176 // be -1. 177 int item_index_; 178 int item_count_; 179}; 180 181// Accessibility information about a text box, passed to onControlFocused, 182// onControlAction, and onTextChanged event listeners. 183class AccessibilityTextBoxInfo : public AccessibilityControlInfo { 184 public: 185 AccessibilityTextBoxInfo(Profile* profile, 186 std::string name, 187 bool password) 188 : AccessibilityControlInfo(profile, name), 189 value_(""), 190 password_(password), 191 selection_start_(0), 192 selection_end_(0) { 193 } 194 195 virtual void SerializeToDict(DictionaryValue *dict) const; 196 197 void SetValue(std::string value, int selection_start, int selection_end) { 198 value_ = value; 199 selection_start_ = selection_start; 200 selection_end_ = selection_end; 201 } 202 203 private: 204 std::string value_; 205 bool password_; 206 int selection_start_; 207 int selection_end_; 208}; 209 210// Accessibility information about a combo box passed to onControlFocused 211// and onControlAction event listeners. 212class AccessibilityListBoxInfo : public AccessibilityControlInfo { 213 public: 214 AccessibilityListBoxInfo(Profile* profile, 215 std::string name, 216 std::string value, 217 int item_index, 218 int item_count) 219 : AccessibilityControlInfo(profile, name), 220 value_(value), 221 item_index_(item_index), 222 item_count_(item_count) { 223 } 224 225 virtual void SerializeToDict(DictionaryValue *dict) const; 226 227 void SetValue(int item_index, std::string value) { 228 item_index_ = item_index; 229 value_ = value; 230 } 231 232 private: 233 std::string value_; 234 // The 0-based index of the current item and the number of total items. 235 // If the value is not one of the drop-down options, |item_index_| should 236 // be -1. 237 int item_index_; 238 int item_count_; 239}; 240 241// Accessibility information about a menu; this class is used by 242// onMenuOpened, onMenuClosed, and onControlFocused event listeners. 243class AccessibilityMenuInfo : public AccessibilityControlInfo { 244 public: 245 AccessibilityMenuInfo(Profile* profile, std::string menu_name) 246 : AccessibilityControlInfo(profile, menu_name) { } 247 248 virtual void SerializeToDict(DictionaryValue *dict) const; 249}; 250 251// Accessibility information about a menu item; this class is used by 252// onControlFocused event listeners. 253class AccessibilityMenuItemInfo : public AccessibilityControlInfo { 254 public: 255 AccessibilityMenuItemInfo(Profile* profile, 256 std::string name, 257 bool has_submenu, 258 int item_index, 259 int item_count) 260 : AccessibilityControlInfo(profile, name), 261 has_submenu_(has_submenu), 262 item_index_(item_index), 263 item_count_(item_count) { 264 } 265 266 virtual void SerializeToDict(DictionaryValue *dict) const; 267 268 private: 269 bool has_submenu_; 270 // The 0-based index of the current item and the number of total items. 271 int item_index_; 272 int item_count_; 273}; 274 275#endif // CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_ 276