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.
5 #include "chrome/browser/accessibility/accessibility_events.h"
7 #include "base/values.h"
8 #include "chrome/browser/accessibility/accessibility_extension_api.h"
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"
16 namespace keys
= extension_accessibility_api_constants
;
18 void SendControlAccessibilityNotification(
19 ui::AccessibilityTypes::Event event
,
20 AccessibilityControlInfo
* info
) {
21 Profile
*profile
= info
->profile();
22 if (profile
->ShouldSendAccessibilityEvents()) {
23 ExtensionAccessibilityEventRouter::GetInstance()->HandleControlEvent(
29 void SendMenuAccessibilityNotification(
30 ui::AccessibilityTypes::Event event
,
31 AccessibilityMenuInfo
* info
) {
32 Profile
*profile
= info
->profile();
33 if (profile
->ShouldSendAccessibilityEvents()) {
34 ExtensionAccessibilityEventRouter::GetInstance()->HandleMenuEvent(
40 void SendWindowAccessibilityNotification(
41 ui::AccessibilityTypes::Event event
,
42 AccessibilityWindowInfo
* info
) {
43 Profile
*profile
= info
->profile();
44 if (profile
->ShouldSendAccessibilityEvents()) {
45 ExtensionAccessibilityEventRouter::GetInstance()->HandleWindowEvent(
52 AccessibilityControlInfo::AccessibilityControlInfo(
53 Profile
* profile
, const std::string
& name
)
54 : AccessibilityEventInfo(profile
),
58 AccessibilityControlInfo::~AccessibilityControlInfo() {
61 void AccessibilityControlInfo::SerializeToDict(DictionaryValue
*dict
) const {
62 dict
->SetString(keys::kNameKey
, name_
);
63 dict
->SetString(keys::kTypeKey
, type());
64 if (!context_
.empty())
65 dict
->SetString(keys::kContextKey
, context_
);
68 AccessibilityWindowInfo::AccessibilityWindowInfo(Profile
* profile
,
69 const std::string
& window_name
)
70 : AccessibilityControlInfo(profile
, window_name
) {
73 const char* AccessibilityWindowInfo::type() const {
74 return keys::kTypeWindow
;
77 AccessibilityButtonInfo::AccessibilityButtonInfo(Profile
* profile
,
78 const std::string
& button_name
,
79 const std::string
& context
)
80 : AccessibilityControlInfo(profile
, button_name
) {
84 const char* AccessibilityButtonInfo::type() const {
85 return keys::kTypeButton
;
88 AccessibilityLinkInfo::AccessibilityLinkInfo(Profile
* profile
,
89 const std::string
& link_name
,
90 const std::string
& context
)
91 : AccessibilityControlInfo(profile
, link_name
) {
95 const char* AccessibilityLinkInfo::type() const {
96 return keys::kTypeLink
;
99 AccessibilityRadioButtonInfo::AccessibilityRadioButtonInfo(
101 const std::string
& name
,
102 const std::string
& context
,
106 : AccessibilityControlInfo(profile
, name
),
108 item_index_(item_index
),
109 item_count_(item_count
) {
110 set_context(context
);
113 const char* AccessibilityRadioButtonInfo::type() const {
114 return keys::kTypeRadioButton
;
117 void AccessibilityRadioButtonInfo::SerializeToDict(
118 DictionaryValue
*dict
) const {
119 AccessibilityControlInfo::SerializeToDict(dict
);
120 dict
->SetBoolean(keys::kCheckedKey
, checked_
);
121 dict
->SetInteger(keys::kItemIndexKey
, item_index_
);
122 dict
->SetInteger(keys::kItemCountKey
, item_count_
);
125 AccessibilityCheckboxInfo::AccessibilityCheckboxInfo(Profile
* profile
,
126 const std::string
& name
,
127 const std::string
& context
,
129 : AccessibilityControlInfo(profile
, name
),
131 set_context(context
);
134 const char* AccessibilityCheckboxInfo::type() const {
135 return keys::kTypeCheckbox
;
138 void AccessibilityCheckboxInfo::SerializeToDict(DictionaryValue
*dict
) const {
139 AccessibilityControlInfo::SerializeToDict(dict
);
140 dict
->SetBoolean(keys::kCheckedKey
, checked_
);
143 AccessibilityTabInfo::AccessibilityTabInfo(Profile
* profile
,
144 const std::string
& tab_name
,
145 const std::string
& context
,
148 : AccessibilityControlInfo(profile
, tab_name
),
149 tab_index_(tab_index
),
150 tab_count_(tab_count
) {
151 set_context(context
);
154 const char* AccessibilityTabInfo::type() const {
155 return keys::kTypeTab
;
158 void AccessibilityTabInfo::SerializeToDict(DictionaryValue
*dict
) const {
159 AccessibilityControlInfo::SerializeToDict(dict
);
160 dict
->SetInteger(keys::kItemIndexKey
, tab_index_
);
161 dict
->SetInteger(keys::kItemCountKey
, tab_count_
);
164 AccessibilityComboBoxInfo::AccessibilityComboBoxInfo(Profile
* profile
,
165 const std::string
& name
,
166 const std::string
& context
,
167 const std::string
& value
,
170 : AccessibilityControlInfo(profile
, name
),
172 item_index_(item_index
),
173 item_count_(item_count
) {
174 set_context(context
);
177 const char* AccessibilityComboBoxInfo::type() const {
178 return keys::kTypeComboBox
;
181 void AccessibilityComboBoxInfo::SerializeToDict(DictionaryValue
*dict
) const {
182 AccessibilityControlInfo::SerializeToDict(dict
);
183 dict
->SetString(keys::kValueKey
, value_
);
184 dict
->SetInteger(keys::kItemIndexKey
, item_index_
);
185 dict
->SetInteger(keys::kItemCountKey
, item_count_
);
188 AccessibilityTextBoxInfo::AccessibilityTextBoxInfo(Profile
* profile
,
189 const std::string
& name
,
190 const std::string
& context
,
192 : AccessibilityControlInfo(profile
, name
),
196 set_context(context
);
199 const char* AccessibilityTextBoxInfo::type() const {
200 return keys::kTypeTextBox
;
203 void AccessibilityTextBoxInfo::SerializeToDict(DictionaryValue
*dict
) const {
204 AccessibilityControlInfo::SerializeToDict(dict
);
205 dict
->SetString(keys::kValueKey
, value_
);
206 dict
->SetBoolean(keys::kPasswordKey
, password_
);
207 dict
->SetInteger(keys::kSelectionStartKey
, selection_start_
);
208 dict
->SetInteger(keys::kSelectionEndKey
, selection_end_
);
211 AccessibilityListBoxInfo::AccessibilityListBoxInfo(Profile
* profile
,
212 const std::string
& name
,
213 const std::string
& context
,
214 const std::string
& value
,
217 : AccessibilityControlInfo(profile
, name
),
219 item_index_(item_index
),
220 item_count_(item_count
) {
221 set_context(context
);
224 const char* AccessibilityListBoxInfo::type() const {
225 return keys::kTypeListBox
;
228 void AccessibilityListBoxInfo::SerializeToDict(DictionaryValue
*dict
) const {
229 AccessibilityControlInfo::SerializeToDict(dict
);
230 dict
->SetString(keys::kValueKey
, value_
);
231 dict
->SetInteger(keys::kItemIndexKey
, item_index_
);
232 dict
->SetInteger(keys::kItemCountKey
, item_count_
);
235 AccessibilityMenuInfo::AccessibilityMenuInfo(Profile
* profile
,
236 const std::string
& menu_name
)
237 : AccessibilityControlInfo(profile
, menu_name
) {
240 const char* AccessibilityMenuInfo::type() const {
241 return keys::kTypeMenu
;
244 AccessibilityMenuItemInfo::AccessibilityMenuItemInfo(Profile
* profile
,
245 const std::string
& name
,
246 const std::string
& context
,
250 : AccessibilityControlInfo(profile
, name
),
251 has_submenu_(has_submenu
),
252 item_index_(item_index
),
253 item_count_(item_count
) {
254 set_context(context
);
257 const char* AccessibilityMenuItemInfo::type() const {
258 return keys::kTypeMenuItem
;
261 void AccessibilityMenuItemInfo::SerializeToDict(DictionaryValue
*dict
) const {
262 AccessibilityControlInfo::SerializeToDict(dict
);
263 dict
->SetBoolean(keys::kHasSubmenuKey
, has_submenu_
);
264 dict
->SetInteger(keys::kItemIndexKey
, item_index_
);
265 dict
->SetInteger(keys::kItemCountKey
, item_count_
);
268 AccessibilityTreeInfo::AccessibilityTreeInfo(Profile
* profile
,
269 const std::string
& menu_name
)
270 : AccessibilityControlInfo(profile
, menu_name
) {
273 const char* AccessibilityTreeInfo::type() const {
274 return keys::kTypeTree
;
277 AccessibilityTreeItemInfo::AccessibilityTreeItemInfo(Profile
* profile
,
278 const std::string
& name
,
279 const std::string
& context
,
285 : AccessibilityControlInfo(profile
, name
),
286 item_depth_(item_depth
),
287 item_index_(item_index
),
288 item_count_(item_count
),
289 children_count_(children_count
),
290 is_expanded_(is_expanded
) {
291 set_context(context
);
294 const char* AccessibilityTreeItemInfo::type() const {
295 return keys::kTypeTreeItem
;
298 void AccessibilityTreeItemInfo::SerializeToDict(DictionaryValue
*dict
) const {
299 AccessibilityControlInfo::SerializeToDict(dict
);
300 dict
->SetInteger(keys::kItemDepthKey
, item_depth_
);
301 dict
->SetInteger(keys::kItemIndexKey
, item_index_
);
302 dict
->SetInteger(keys::kItemCountKey
, item_count_
);
303 dict
->SetInteger(keys::kChildrenCountKey
, children_count_
);
304 dict
->SetBoolean(keys::kItemExpandedKey
, is_expanded_
);
307 AccessibilitySliderInfo::AccessibilitySliderInfo(Profile
* profile
,
308 const std::string
& name
,
309 const std::string
& context
,
310 const std::string
& value
)
311 : AccessibilityControlInfo(profile
, name
),
313 set_context(context
);
316 const char* AccessibilitySliderInfo::type() const {
317 return keys::kTypeSlider
;
320 void AccessibilitySliderInfo::SerializeToDict(DictionaryValue
*dict
) const {
321 AccessibilityControlInfo::SerializeToDict(dict
);
322 dict
->SetString(keys::kStringValueKey
, value_
);
325 AccessibilityAlertInfo::AccessibilityAlertInfo(Profile
* profile
,
326 const std::string
& name
)
327 : AccessibilityControlInfo(profile
, name
) {
330 const char* AccessibilityAlertInfo::type() const {
331 return keys::kTypeAlert
;