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