• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SendAccessibilityNotification(NotificationType type,AccessibilityControlInfo * info)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 
AccessibilityControlInfo(Profile * profile,const std::string & control_name)27 AccessibilityControlInfo::AccessibilityControlInfo(
28     Profile* profile, const std::string& control_name)
29     : profile_(profile), name_(control_name) {
30 }
31 
~AccessibilityControlInfo()32 AccessibilityControlInfo::~AccessibilityControlInfo() {
33 }
34 
SerializeToDict(DictionaryValue * dict) const35 void AccessibilityControlInfo::SerializeToDict(DictionaryValue *dict) const {
36   dict->SetString(keys::kNameKey, name_);
37   dict->SetString(keys::kTypeKey, type());
38 }
39 
AccessibilityWindowInfo(Profile * profile,const std::string & window_name)40 AccessibilityWindowInfo::AccessibilityWindowInfo(Profile* profile,
41                                                  const std::string& window_name)
42     : AccessibilityControlInfo(profile, window_name) {
43 }
44 
type() const45 const char* AccessibilityWindowInfo::type() const {
46   return keys::kTypeWindow;
47 }
48 
AccessibilityButtonInfo(Profile * profile,const std::string & button_name)49 AccessibilityButtonInfo::AccessibilityButtonInfo(Profile* profile,
50                                                  const std::string& button_name)
51     : AccessibilityControlInfo(profile, button_name) {
52 }
53 
type() const54 const char* AccessibilityButtonInfo::type() const {
55   return keys::kTypeButton;
56 }
57 
AccessibilityLinkInfo(Profile * profile,const std::string & link_name)58 AccessibilityLinkInfo::AccessibilityLinkInfo(Profile* profile,
59                                              const std::string& link_name)
60       : AccessibilityControlInfo(profile, link_name) { }
61 
type() const62 const char* AccessibilityLinkInfo::type() const {
63   return keys::kTypeLink;
64 }
65 
AccessibilityRadioButtonInfo(Profile * profile,const std::string & name,bool checked,int item_index,int item_count)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 
type() const78 const char* AccessibilityRadioButtonInfo::type() const {
79   return keys::kTypeRadioButton;
80 }
81 
SerializeToDict(DictionaryValue * dict) const82 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 
AccessibilityCheckboxInfo(Profile * profile,const std::string & name,bool checked)90 AccessibilityCheckboxInfo::AccessibilityCheckboxInfo(Profile* profile,
91                                                      const std::string& name,
92                                                      bool checked)
93     : AccessibilityControlInfo(profile, name),
94       checked_(checked) {
95 }
96 
type() const97 const char* AccessibilityCheckboxInfo::type() const {
98   return keys::kTypeCheckbox;
99 }
100 
SerializeToDict(DictionaryValue * dict) const101 void AccessibilityCheckboxInfo::SerializeToDict(DictionaryValue *dict) const {
102   AccessibilityControlInfo::SerializeToDict(dict);
103   dict->SetBoolean(keys::kCheckedKey, checked_);
104 }
105 
AccessibilityTabInfo(Profile * profile,const std::string & tab_name,int tab_index,int tab_count)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 
type() const115 const char* AccessibilityTabInfo::type() const {
116   return keys::kTypeTab;
117 }
118 
SerializeToDict(DictionaryValue * dict) const119 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 
AccessibilityComboBoxInfo(Profile * profile,const std::string & name,const std::string & value,int item_index,int item_count)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 
type() const136 const char* AccessibilityComboBoxInfo::type() const {
137   return keys::kTypeComboBox;
138 }
139 
SerializeToDict(DictionaryValue * dict) const140 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 
AccessibilityTextBoxInfo(Profile * profile,const std::string & name,bool password)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 
type() const157 const char* AccessibilityTextBoxInfo::type() const {
158   return keys::kTypeTextBox;
159 }
160 
SerializeToDict(DictionaryValue * dict) const161 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 
AccessibilityListBoxInfo(Profile * profile,const std::string & name,const std::string & value,int item_index,int item_count)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 
type() const180 const char* AccessibilityListBoxInfo::type() const {
181   return keys::kTypeListBox;
182 }
183 
SerializeToDict(DictionaryValue * dict) const184 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 
AccessibilityMenuInfo(Profile * profile,const std::string & menu_name)191 AccessibilityMenuInfo::AccessibilityMenuInfo(Profile* profile,
192                                              const std::string& menu_name)
193     : AccessibilityControlInfo(profile, menu_name) {
194 }
195 
type() const196 const char* AccessibilityMenuInfo::type() const {
197   return keys::kTypeMenu;
198 }
199 
AccessibilityMenuItemInfo(Profile * profile,const std::string & name,bool has_submenu,int item_index,int item_count)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 
type() const211 const char* AccessibilityMenuItemInfo::type() const {
212   return keys::kTypeMenuItem;
213 }
214 
SerializeToDict(DictionaryValue * dict) const215 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