Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / accessibility / accessibility_events.cc
blob320b6f5ef05f1a946b3ff66d64ccdb08ec78bec1
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(
24 event,
25 info);
29 void SendMenuAccessibilityNotification(
30 ui::AccessibilityTypes::Event event,
31 AccessibilityMenuInfo* info) {
32 Profile *profile = info->profile();
33 if (profile->ShouldSendAccessibilityEvents()) {
34 ExtensionAccessibilityEventRouter::GetInstance()->HandleMenuEvent(
35 event,
36 info);
40 void SendWindowAccessibilityNotification(
41 ui::AccessibilityTypes::Event event,
42 AccessibilityWindowInfo* info) {
43 Profile *profile = info->profile();
44 if (profile->ShouldSendAccessibilityEvents()) {
45 ExtensionAccessibilityEventRouter::GetInstance()->HandleWindowEvent(
46 event,
47 info);
52 AccessibilityControlInfo::AccessibilityControlInfo(
53 Profile* profile, const std::string& name)
54 : AccessibilityEventInfo(profile),
55 name_(name) {
58 AccessibilityControlInfo::~AccessibilityControlInfo() {
61 void AccessibilityControlInfo::SerializeToDict(
62 base::DictionaryValue *dict) const {
63 dict->SetString(keys::kNameKey, name_);
64 dict->SetString(keys::kTypeKey, type());
65 if (!context_.empty())
66 dict->SetString(keys::kContextKey, context_);
69 AccessibilityWindowInfo::AccessibilityWindowInfo(Profile* profile,
70 const std::string& window_name)
71 : AccessibilityControlInfo(profile, window_name) {
74 const char* AccessibilityWindowInfo::type() const {
75 return keys::kTypeWindow;
78 AccessibilityButtonInfo::AccessibilityButtonInfo(Profile* profile,
79 const std::string& button_name,
80 const std::string& context)
81 : AccessibilityControlInfo(profile, button_name) {
82 set_context(context);
85 const char* AccessibilityButtonInfo::type() const {
86 return keys::kTypeButton;
89 AccessibilityLinkInfo::AccessibilityLinkInfo(Profile* profile,
90 const std::string& link_name,
91 const std::string& context)
92 : AccessibilityControlInfo(profile, link_name) {
93 set_context(context);
96 const char* AccessibilityLinkInfo::type() const {
97 return keys::kTypeLink;
100 AccessibilityRadioButtonInfo::AccessibilityRadioButtonInfo(
101 Profile* profile,
102 const std::string& name,
103 const std::string& context,
104 bool checked,
105 int item_index,
106 int item_count)
107 : AccessibilityControlInfo(profile, name),
108 checked_(checked),
109 item_index_(item_index),
110 item_count_(item_count) {
111 set_context(context);
114 const char* AccessibilityRadioButtonInfo::type() const {
115 return keys::kTypeRadioButton;
118 void AccessibilityRadioButtonInfo::SerializeToDict(
119 base::DictionaryValue *dict) const {
120 AccessibilityControlInfo::SerializeToDict(dict);
121 dict->SetBoolean(keys::kCheckedKey, checked_);
122 dict->SetInteger(keys::kItemIndexKey, item_index_);
123 dict->SetInteger(keys::kItemCountKey, item_count_);
126 AccessibilityCheckboxInfo::AccessibilityCheckboxInfo(Profile* profile,
127 const std::string& name,
128 const std::string& context,
129 bool checked)
130 : AccessibilityControlInfo(profile, name),
131 checked_(checked) {
132 set_context(context);
135 const char* AccessibilityCheckboxInfo::type() const {
136 return keys::kTypeCheckbox;
139 void AccessibilityCheckboxInfo::SerializeToDict(
140 base::DictionaryValue *dict) const {
141 AccessibilityControlInfo::SerializeToDict(dict);
142 dict->SetBoolean(keys::kCheckedKey, checked_);
145 AccessibilityTabInfo::AccessibilityTabInfo(Profile* profile,
146 const std::string& tab_name,
147 const std::string& context,
148 int tab_index,
149 int tab_count)
150 : AccessibilityControlInfo(profile, tab_name),
151 tab_index_(tab_index),
152 tab_count_(tab_count) {
153 set_context(context);
156 const char* AccessibilityTabInfo::type() const {
157 return keys::kTypeTab;
160 void AccessibilityTabInfo::SerializeToDict(base::DictionaryValue *dict) const {
161 AccessibilityControlInfo::SerializeToDict(dict);
162 dict->SetInteger(keys::kItemIndexKey, tab_index_);
163 dict->SetInteger(keys::kItemCountKey, tab_count_);
166 AccessibilityComboBoxInfo::AccessibilityComboBoxInfo(Profile* profile,
167 const std::string& name,
168 const std::string& context,
169 const std::string& value,
170 int item_index,
171 int item_count)
172 : AccessibilityControlInfo(profile, name),
173 value_(value),
174 item_index_(item_index),
175 item_count_(item_count) {
176 set_context(context);
179 const char* AccessibilityComboBoxInfo::type() const {
180 return keys::kTypeComboBox;
183 void AccessibilityComboBoxInfo::SerializeToDict(
184 base::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_);
191 AccessibilityTextBoxInfo::AccessibilityTextBoxInfo(Profile* profile,
192 const std::string& name,
193 const std::string& context,
194 bool password)
195 : AccessibilityControlInfo(profile, name),
196 password_(password),
197 selection_start_(0),
198 selection_end_(0) {
199 set_context(context);
202 const char* AccessibilityTextBoxInfo::type() const {
203 return keys::kTypeTextBox;
206 void AccessibilityTextBoxInfo::SerializeToDict(
207 base::DictionaryValue *dict) const {
208 AccessibilityControlInfo::SerializeToDict(dict);
209 dict->SetString(keys::kValueKey, value_);
210 dict->SetBoolean(keys::kPasswordKey, password_);
211 dict->SetInteger(keys::kSelectionStartKey, selection_start_);
212 dict->SetInteger(keys::kSelectionEndKey, selection_end_);
215 AccessibilityListBoxInfo::AccessibilityListBoxInfo(Profile* profile,
216 const std::string& name,
217 const std::string& context,
218 const std::string& value,
219 int item_index,
220 int item_count)
221 : AccessibilityControlInfo(profile, name),
222 value_(value),
223 item_index_(item_index),
224 item_count_(item_count) {
225 set_context(context);
228 const char* AccessibilityListBoxInfo::type() const {
229 return keys::kTypeListBox;
232 void AccessibilityListBoxInfo::SerializeToDict(
233 base::DictionaryValue *dict) const {
234 AccessibilityControlInfo::SerializeToDict(dict);
235 dict->SetString(keys::kValueKey, value_);
236 dict->SetInteger(keys::kItemIndexKey, item_index_);
237 dict->SetInteger(keys::kItemCountKey, item_count_);
240 AccessibilityMenuInfo::AccessibilityMenuInfo(Profile* profile,
241 const std::string& menu_name)
242 : AccessibilityControlInfo(profile, menu_name) {
245 const char* AccessibilityMenuInfo::type() const {
246 return keys::kTypeMenu;
249 AccessibilityMenuItemInfo::AccessibilityMenuItemInfo(Profile* profile,
250 const std::string& name,
251 const std::string& context,
252 bool has_submenu,
253 int item_index,
254 int item_count)
255 : AccessibilityControlInfo(profile, name),
256 has_submenu_(has_submenu),
257 item_index_(item_index),
258 item_count_(item_count) {
259 set_context(context);
262 const char* AccessibilityMenuItemInfo::type() const {
263 return keys::kTypeMenuItem;
266 void AccessibilityMenuItemInfo::SerializeToDict(
267 base::DictionaryValue *dict) const {
268 AccessibilityControlInfo::SerializeToDict(dict);
269 dict->SetBoolean(keys::kHasSubmenuKey, has_submenu_);
270 dict->SetInteger(keys::kItemIndexKey, item_index_);
271 dict->SetInteger(keys::kItemCountKey, item_count_);
274 AccessibilityTreeInfo::AccessibilityTreeInfo(Profile* profile,
275 const std::string& menu_name)
276 : AccessibilityControlInfo(profile, menu_name) {
279 const char* AccessibilityTreeInfo::type() const {
280 return keys::kTypeTree;
283 AccessibilityTreeItemInfo::AccessibilityTreeItemInfo(Profile* profile,
284 const std::string& name,
285 const std::string& context,
286 int item_depth,
287 int item_index,
288 int item_count,
289 int children_count,
290 bool is_expanded)
291 : AccessibilityControlInfo(profile, name),
292 item_depth_(item_depth),
293 item_index_(item_index),
294 item_count_(item_count),
295 children_count_(children_count),
296 is_expanded_(is_expanded) {
297 set_context(context);
300 const char* AccessibilityTreeItemInfo::type() const {
301 return keys::kTypeTreeItem;
304 void AccessibilityTreeItemInfo::SerializeToDict(
305 base::DictionaryValue *dict) const {
306 AccessibilityControlInfo::SerializeToDict(dict);
307 dict->SetInteger(keys::kItemDepthKey, item_depth_);
308 dict->SetInteger(keys::kItemIndexKey, item_index_);
309 dict->SetInteger(keys::kItemCountKey, item_count_);
310 dict->SetInteger(keys::kChildrenCountKey, children_count_);
311 dict->SetBoolean(keys::kItemExpandedKey, is_expanded_);
314 AccessibilitySliderInfo::AccessibilitySliderInfo(Profile* profile,
315 const std::string& name,
316 const std::string& context,
317 const std::string& value)
318 : AccessibilityControlInfo(profile, name),
319 value_(value) {
320 set_context(context);
323 const char* AccessibilitySliderInfo::type() const {
324 return keys::kTypeSlider;
327 void AccessibilitySliderInfo::SerializeToDict(
328 base::DictionaryValue *dict) const {
329 AccessibilityControlInfo::SerializeToDict(dict);
330 dict->SetString(keys::kStringValueKey, value_);
333 AccessibilityAlertInfo::AccessibilityAlertInfo(Profile* profile,
334 const std::string& name)
335 : AccessibilityControlInfo(profile, name) {
338 const char* AccessibilityAlertInfo::type() const {
339 return keys::kTypeAlert;