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 #include "chrome/browser/accessibility/accessibility_events.h" 6 7 #include "base/values.h" 8 9 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" 10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_types.h" 15 16 namespace keys = extension_accessibility_api_constants; 17 18 void SendAccessibilityNotification(int type, AccessibilityEventInfo* info) { 19 Profile *profile = info->profile(); 20 if (profile->ShouldSendAccessibilityEvents()) { 21 content::NotificationService::current()->Notify( 22 type, 23 content::Source<Profile>(profile), 24 content::Details<AccessibilityEventInfo>(info)); 25 } 26 } 27 28 AccessibilityControlInfo::AccessibilityControlInfo( 29 Profile* profile, const std::string& name) 30 : AccessibilityEventInfo(profile), 31 name_(name) { 32 } 33 34 AccessibilityControlInfo::~AccessibilityControlInfo() { 35 } 36 37 void AccessibilityControlInfo::SerializeToDict(DictionaryValue *dict) const { 38 dict->SetString(keys::kNameKey, name_); 39 dict->SetString(keys::kTypeKey, type()); 40 if (!context_.empty()) 41 dict->SetString(keys::kContextKey, context_); 42 } 43 44 AccessibilityWindowInfo::AccessibilityWindowInfo(Profile* profile, 45 const std::string& window_name) 46 : AccessibilityControlInfo(profile, window_name) { 47 } 48 49 const char* AccessibilityWindowInfo::type() const { 50 return keys::kTypeWindow; 51 } 52 53 AccessibilityButtonInfo::AccessibilityButtonInfo(Profile* profile, 54 const std::string& button_name, 55 const std::string& context) 56 : AccessibilityControlInfo(profile, button_name) { 57 set_context(context); 58 } 59 60 const char* AccessibilityButtonInfo::type() const { 61 return keys::kTypeButton; 62 } 63 64 AccessibilityLinkInfo::AccessibilityLinkInfo(Profile* profile, 65 const std::string& link_name, 66 const std::string& context) 67 : AccessibilityControlInfo(profile, link_name) { 68 set_context(context); 69 } 70 71 const char* AccessibilityLinkInfo::type() const { 72 return keys::kTypeLink; 73 } 74 75 AccessibilityRadioButtonInfo::AccessibilityRadioButtonInfo( 76 Profile* profile, 77 const std::string& name, 78 const std::string& context, 79 bool checked, 80 int item_index, 81 int item_count) 82 : AccessibilityControlInfo(profile, name), 83 checked_(checked), 84 item_index_(item_index), 85 item_count_(item_count) { 86 set_context(context); 87 } 88 89 const char* AccessibilityRadioButtonInfo::type() const { 90 return keys::kTypeRadioButton; 91 } 92 93 void AccessibilityRadioButtonInfo::SerializeToDict( 94 DictionaryValue *dict) const { 95 AccessibilityControlInfo::SerializeToDict(dict); 96 dict->SetBoolean(keys::kCheckedKey, checked_); 97 dict->SetInteger(keys::kItemIndexKey, item_index_); 98 dict->SetInteger(keys::kItemCountKey, item_count_); 99 } 100 101 AccessibilityCheckboxInfo::AccessibilityCheckboxInfo(Profile* profile, 102 const std::string& name, 103 const std::string& context, 104 bool checked) 105 : AccessibilityControlInfo(profile, name), 106 checked_(checked) { 107 set_context(context); 108 } 109 110 const char* AccessibilityCheckboxInfo::type() const { 111 return keys::kTypeCheckbox; 112 } 113 114 void AccessibilityCheckboxInfo::SerializeToDict(DictionaryValue *dict) const { 115 AccessibilityControlInfo::SerializeToDict(dict); 116 dict->SetBoolean(keys::kCheckedKey, checked_); 117 } 118 119 AccessibilityTabInfo::AccessibilityTabInfo(Profile* profile, 120 const std::string& tab_name, 121 const std::string& context, 122 int tab_index, 123 int tab_count) 124 : AccessibilityControlInfo(profile, tab_name), 125 tab_index_(tab_index), 126 tab_count_(tab_count) { 127 set_context(context); 128 } 129 130 const char* AccessibilityTabInfo::type() const { 131 return keys::kTypeTab; 132 } 133 134 void AccessibilityTabInfo::SerializeToDict(DictionaryValue *dict) const { 135 AccessibilityControlInfo::SerializeToDict(dict); 136 dict->SetInteger(keys::kItemIndexKey, tab_index_); 137 dict->SetInteger(keys::kItemCountKey, tab_count_); 138 } 139 140 AccessibilityComboBoxInfo::AccessibilityComboBoxInfo(Profile* profile, 141 const std::string& name, 142 const std::string& context, 143 const std::string& value, 144 int item_index, 145 int item_count) 146 : AccessibilityControlInfo(profile, name), 147 value_(value), 148 item_index_(item_index), 149 item_count_(item_count) { 150 set_context(context); 151 } 152 153 const char* AccessibilityComboBoxInfo::type() const { 154 return keys::kTypeComboBox; 155 } 156 157 void AccessibilityComboBoxInfo::SerializeToDict(DictionaryValue *dict) const { 158 AccessibilityControlInfo::SerializeToDict(dict); 159 dict->SetString(keys::kValueKey, value_); 160 dict->SetInteger(keys::kItemIndexKey, item_index_); 161 dict->SetInteger(keys::kItemCountKey, item_count_); 162 } 163 164 AccessibilityTextBoxInfo::AccessibilityTextBoxInfo(Profile* profile, 165 const std::string& name, 166 const std::string& context, 167 bool password) 168 : AccessibilityControlInfo(profile, name), 169 password_(password), 170 selection_start_(0), 171 selection_end_(0) { 172 set_context(context); 173 } 174 175 const char* AccessibilityTextBoxInfo::type() const { 176 return keys::kTypeTextBox; 177 } 178 179 void AccessibilityTextBoxInfo::SerializeToDict(DictionaryValue *dict) const { 180 AccessibilityControlInfo::SerializeToDict(dict); 181 dict->SetString(keys::kValueKey, value_); 182 dict->SetBoolean(keys::kPasswordKey, password_); 183 dict->SetInteger(keys::kSelectionStartKey, selection_start_); 184 dict->SetInteger(keys::kSelectionEndKey, selection_end_); 185 } 186 187 AccessibilityListBoxInfo::AccessibilityListBoxInfo(Profile* profile, 188 const std::string& name, 189 const std::string& context, 190 const std::string& value, 191 int item_index, 192 int item_count) 193 : AccessibilityControlInfo(profile, name), 194 value_(value), 195 item_index_(item_index), 196 item_count_(item_count) { 197 set_context(context); 198 } 199 200 const char* AccessibilityListBoxInfo::type() const { 201 return keys::kTypeListBox; 202 } 203 204 void AccessibilityListBoxInfo::SerializeToDict(DictionaryValue *dict) const { 205 AccessibilityControlInfo::SerializeToDict(dict); 206 dict->SetString(keys::kValueKey, value_); 207 dict->SetInteger(keys::kItemIndexKey, item_index_); 208 dict->SetInteger(keys::kItemCountKey, item_count_); 209 } 210 211 AccessibilityMenuInfo::AccessibilityMenuInfo(Profile* profile, 212 const std::string& menu_name) 213 : AccessibilityControlInfo(profile, menu_name) { 214 } 215 216 const char* AccessibilityMenuInfo::type() const { 217 return keys::kTypeMenu; 218 } 219 220 AccessibilityMenuItemInfo::AccessibilityMenuItemInfo(Profile* profile, 221 const std::string& name, 222 const std::string& context, 223 bool has_submenu, 224 int item_index, 225 int item_count) 226 : AccessibilityControlInfo(profile, name), 227 has_submenu_(has_submenu), 228 item_index_(item_index), 229 item_count_(item_count) { 230 set_context(context); 231 } 232 233 const char* AccessibilityMenuItemInfo::type() const { 234 return keys::kTypeMenuItem; 235 } 236 237 void AccessibilityMenuItemInfo::SerializeToDict(DictionaryValue *dict) const { 238 AccessibilityControlInfo::SerializeToDict(dict); 239 dict->SetBoolean(keys::kHasSubmenuKey, has_submenu_); 240 dict->SetInteger(keys::kItemIndexKey, item_index_); 241 dict->SetInteger(keys::kItemCountKey, item_count_); 242 } 243 244 AccessibilitySliderInfo::AccessibilitySliderInfo(Profile* profile, 245 const std::string& name, 246 const std::string& context, 247 const std::string& value) 248 : AccessibilityControlInfo(profile, name), 249 value_(value) { 250 set_context(context); 251 } 252 253 const char* AccessibilitySliderInfo::type() const { 254 return keys::kTypeSlider; 255 } 256 257 void AccessibilitySliderInfo::SerializeToDict(DictionaryValue *dict) const { 258 AccessibilityControlInfo::SerializeToDict(dict); 259 dict->SetString(keys::kStringValueKey, value_); 260 } 261