accessibility_events.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 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#ifndef CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_
6#define CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_
7#pragma once
8
9#include <string>
10
11class AccessibilityControlInfo;
12class DictionaryValue;
13class NotificationType;
14class Profile;
15
16// Use the NotificationService to post the given accessibility
17// notification type with AccessibilityControlInfo details to any
18// listeners.  Will not send if the profile's pause level is nonzero
19// (using profile->PauseAccessibilityEvents).
20void SendAccessibilityNotification(
21    NotificationType type, AccessibilityControlInfo* info);
22
23// Abstract parent class for accessibility information about a control
24// passed to event listeners.
25class AccessibilityControlInfo {
26 public:
27  virtual ~AccessibilityControlInfo() { }
28
29  // Serialize this class as a DictionaryValue that can be converted to
30  // a JavaScript object.
31  virtual void SerializeToDict(DictionaryValue* dict) const;
32
33  // Return the specific type of this control, which will be one of the
34  // string constants defined in extension_accessibility_api_constants.h.
35  virtual const char* type() const = 0;
36
37  Profile* profile() const { return profile_; }
38
39  const std::string& name() const { return name_; }
40
41 protected:
42  // The constructor can only be called by subclasses.
43  AccessibilityControlInfo(Profile* profile, std::string control_name)
44      : profile_(profile), name_(control_name) { }
45
46  // The profile this control belongs to.
47  Profile* profile_;
48
49  // The name of the control, like "OK" or "Password".
50  std::string name_;
51};
52
53// Accessibility information about a window passed to onWindowOpened
54// and onWindowClosed event listeners.
55class AccessibilityWindowInfo : public AccessibilityControlInfo {
56 public:
57  AccessibilityWindowInfo(Profile* profile, std::string window_name)
58      : AccessibilityControlInfo(profile, window_name) { }
59
60  virtual const char* type() const;
61};
62
63// Accessibility information about a push button passed to onControlFocused
64// and onControlAction event listeners.
65class AccessibilityButtonInfo : public AccessibilityControlInfo {
66 public:
67  AccessibilityButtonInfo(Profile* profile, std::string button_name)
68      : AccessibilityControlInfo(profile, button_name) { }
69
70  virtual const char* type() const;
71};
72
73// Accessibility information about a hyperlink passed to onControlFocused
74// and onControlAction event listeners.
75class AccessibilityLinkInfo : public AccessibilityControlInfo {
76 public:
77  AccessibilityLinkInfo(Profile* profile, std::string link_name)
78      : AccessibilityControlInfo(profile, link_name) { }
79
80  virtual const char* type() const;
81};
82
83// Accessibility information about a radio button passed to onControlFocused
84// and onControlAction event listeners.
85class AccessibilityRadioButtonInfo : public AccessibilityControlInfo {
86 public:
87  AccessibilityRadioButtonInfo(Profile* profile,
88                               std::string name,
89                               bool checked,
90                               int item_index,
91                               int item_count)
92      : AccessibilityControlInfo(profile, name),
93        checked_(checked),
94        item_index_(item_index),
95        item_count_(item_count) {
96  }
97
98  virtual const char* type() const;
99
100  virtual void SerializeToDict(DictionaryValue* dict) const;
101
102  void SetChecked(bool checked) { checked_ = checked; }
103
104 private:
105  bool checked_;
106  // The 0-based index of this radio button and number of buttons in the group.
107  int item_index_;
108  int item_count_;
109};
110
111// Accessibility information about a checkbox passed to onControlFocused
112// and onControlAction event listeners.
113class AccessibilityCheckboxInfo : public AccessibilityControlInfo {
114 public:
115  AccessibilityCheckboxInfo(Profile* profile,
116                            std::string name,
117                            bool checked)
118      : AccessibilityControlInfo(profile, name),
119        checked_(checked) {
120  }
121
122  virtual const char* type() const;
123
124  virtual void SerializeToDict(DictionaryValue* dict) const;
125
126  void SetChecked(bool checked) { checked_ = checked; }
127
128 private:
129  bool checked_;
130};
131
132// Accessibility information about a tab passed to onControlFocused
133// and onControlAction event listeners.
134class AccessibilityTabInfo : public AccessibilityControlInfo {
135 public:
136  AccessibilityTabInfo(Profile* profile,
137                       std::string tab_name,
138                       int tab_index,
139                       int tab_count)
140      : AccessibilityControlInfo(profile, tab_name),
141        tab_index_(tab_index),
142        tab_count_(tab_count) {
143  }
144
145  virtual const char* type() const;
146
147  virtual void SerializeToDict(DictionaryValue* dict) const;
148
149  void SetTab(int tab_index, std::string tab_name) {
150    tab_index_ = tab_index;
151    name_ = tab_name;
152  }
153
154 private:
155  // The 0-based index of this tab and number of tabs in the group.
156  int tab_index_;
157  int tab_count_;
158};
159
160// Accessibility information about a combo box passed to onControlFocused
161// and onControlAction event listeners.
162class AccessibilityComboBoxInfo : public AccessibilityControlInfo {
163 public:
164  AccessibilityComboBoxInfo(Profile* profile,
165                            std::string name,
166                            std::string value,
167                            int item_index,
168                            int item_count)
169      : AccessibilityControlInfo(profile, name),
170        value_(value),
171        item_index_(item_index),
172        item_count_(item_count) {
173  }
174
175  virtual const char* type() const;
176
177  virtual void SerializeToDict(DictionaryValue* dict) const;
178
179  void SetValue(int item_index, std::string value) {
180    item_index_ = item_index;
181    value_ = value;
182  }
183
184 private:
185  std::string value_;
186  // The 0-based index of the current item and the number of total items.
187  // If the value is not one of the drop-down options, |item_index_| should
188  // be -1.
189  int item_index_;
190  int item_count_;
191};
192
193// Accessibility information about a text box, passed to onControlFocused,
194// onControlAction, and onTextChanged event listeners.
195class AccessibilityTextBoxInfo : public AccessibilityControlInfo {
196 public:
197  AccessibilityTextBoxInfo(Profile* profile,
198                           std::string name,
199                           bool password)
200      : AccessibilityControlInfo(profile, name),
201        value_(""),
202        password_(password),
203        selection_start_(0),
204        selection_end_(0) {
205  }
206
207  virtual const char* type() const;
208
209  virtual void SerializeToDict(DictionaryValue* dict) const;
210
211  void SetValue(std::string value, int selection_start, int selection_end) {
212    value_ = value;
213    selection_start_ = selection_start;
214    selection_end_ = selection_end;
215  }
216
217 private:
218  std::string value_;
219  bool password_;
220  int selection_start_;
221  int selection_end_;
222};
223
224// Accessibility information about a combo box passed to onControlFocused
225// and onControlAction event listeners.
226class AccessibilityListBoxInfo : public AccessibilityControlInfo {
227 public:
228  AccessibilityListBoxInfo(Profile* profile,
229                           std::string name,
230                           std::string value,
231                           int item_index,
232                           int item_count)
233      : AccessibilityControlInfo(profile, name),
234        value_(value),
235        item_index_(item_index),
236        item_count_(item_count) {
237  }
238
239  virtual const char* type() const;
240
241  virtual void SerializeToDict(DictionaryValue* dict) const;
242
243  void SetValue(int item_index, std::string value) {
244    item_index_ = item_index;
245    value_ = value;
246  }
247
248 private:
249  std::string value_;
250  // The 0-based index of the current item and the number of total items.
251  // If the value is not one of the drop-down options, |item_index_| should
252  // be -1.
253  int item_index_;
254  int item_count_;
255};
256
257// Accessibility information about a menu; this class is used by
258// onMenuOpened, onMenuClosed, and onControlFocused event listeners.
259class AccessibilityMenuInfo : public AccessibilityControlInfo {
260 public:
261  AccessibilityMenuInfo(Profile* profile, std::string menu_name)
262      : AccessibilityControlInfo(profile, menu_name) { }
263
264  virtual const char* type() const;
265};
266
267// Accessibility information about a menu item; this class is used by
268// onControlFocused event listeners.
269class AccessibilityMenuItemInfo : public AccessibilityControlInfo {
270 public:
271  AccessibilityMenuItemInfo(Profile* profile,
272                            std::string name,
273                            bool has_submenu,
274                            int item_index,
275                            int item_count)
276      : AccessibilityControlInfo(profile, name),
277        has_submenu_(has_submenu),
278        item_index_(item_index),
279        item_count_(item_count) {
280  }
281
282  virtual const char* type() const;
283
284  virtual void SerializeToDict(DictionaryValue* dict) const;
285
286 private:
287  bool has_submenu_;
288  // The 0-based index of the current item and the number of total items.
289  int item_index_;
290  int item_count_;
291};
292
293#endif  // CHROME_BROWSER_ACCESSIBILITY_EVENTS_H_
294