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 #ifndef CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_
6 #define CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_
9 #include "base/compiler_specific.h"
10 #include "ui/base/accessibility/accessibility_types.h"
12 class AccessibilityControlInfo
;
13 class AccessibilityMenuInfo
;
14 class AccessibilityWindowInfo
;
18 class DictionaryValue
;
21 // Notify the ExtensionAccessibilityEventRouter of the given accessibility
22 // event and AccessibilityEventInfo details. Will not send if the profile's
23 // pause level is nonzero (using profile->PauseAccessibilityEvents).
24 void SendControlAccessibilityNotification(
25 ui::AccessibilityTypes::Event event
,
26 AccessibilityControlInfo
* info
);
28 void SendMenuAccessibilityNotification(
29 ui::AccessibilityTypes::Event event
,
30 AccessibilityMenuInfo
* info
);
32 void SendWindowAccessibilityNotification(
33 ui::AccessibilityTypes::Event event
,
34 AccessibilityWindowInfo
* info
);
36 // Abstract parent class for accessibility event information passed to event
38 class AccessibilityEventInfo
{
40 virtual ~AccessibilityEventInfo() {}
42 // Serialize this class as a DictionaryValue that can be converted to
43 // a JavaScript object.
44 virtual void SerializeToDict(base::DictionaryValue
* dict
) const = 0;
46 Profile
* profile() const { return profile_
; }
49 explicit AccessibilityEventInfo(Profile
* profile
) : profile_(profile
) {}
51 // The profile this control belongs to.
55 // Abstract parent class for accessibility information about a control
56 // passed to event listeners.
57 class AccessibilityControlInfo
: public AccessibilityEventInfo
{
59 virtual ~AccessibilityControlInfo();
61 // Serialize this class as a DictionaryValue that can be converted to
62 // a JavaScript object.
63 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
65 // Return the specific type of this control, which will be one of the
66 // string constants defined in extension_accessibility_api_constants.h.
67 virtual const char* type() const = 0;
69 const std::string
& name() const { return name_
; }
71 const std::string
& context() const { return context_
; }
74 AccessibilityControlInfo(Profile
* profile
,
75 const std::string
& name
);
77 void set_context(const std::string
& context
) { context_
= context
; }
79 // The name of the control, like "OK" or "Password".
82 // A string describing the context of the control, such as the name of
83 // the group or toolbar it's contained in.
87 // Accessibility information about a window passed to onWindowOpened
88 // and onWindowClosed event listeners.
89 class AccessibilityWindowInfo
: public AccessibilityControlInfo
{
91 AccessibilityWindowInfo(Profile
* profile
, const std::string
& window_name
);
93 virtual const char* type() const OVERRIDE
;
96 // Accessibility information about a push button passed to onControlFocused
97 // and onControlAction event listeners.
98 class AccessibilityButtonInfo
: public AccessibilityControlInfo
{
100 AccessibilityButtonInfo(Profile
* profile
,
101 const std::string
& button_name
,
102 const std::string
& context
);
104 virtual const char* type() const OVERRIDE
;
107 // Accessibility information about a hyperlink passed to onControlFocused
108 // and onControlAction event listeners.
109 class AccessibilityLinkInfo
: public AccessibilityControlInfo
{
111 AccessibilityLinkInfo(Profile
* profile
,
112 const std::string
& link_name
,
113 const std::string
& context
);
115 virtual const char* type() const OVERRIDE
;
118 // Accessibility information about a radio button passed to onControlFocused
119 // and onControlAction event listeners.
120 class AccessibilityRadioButtonInfo
: public AccessibilityControlInfo
{
122 AccessibilityRadioButtonInfo(Profile
* profile
,
123 const std::string
& name
,
124 const std::string
& context
,
129 virtual const char* type() const OVERRIDE
;
131 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
133 void SetChecked(bool checked
) { checked_
= checked
; }
135 int item_index() const { return item_index_
; }
136 int item_count() const { return item_count_
; }
137 bool checked() const { return checked_
; }
141 // The 0-based index of this radio button and number of buttons in the group.
146 // Accessibility information about a checkbox passed to onControlFocused
147 // and onControlAction event listeners.
148 class AccessibilityCheckboxInfo
: public AccessibilityControlInfo
{
150 AccessibilityCheckboxInfo(Profile
* profile
,
151 const std::string
& name
,
152 const std::string
& context
,
155 virtual const char* type() const OVERRIDE
;
157 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
159 void SetChecked(bool checked
) { checked_
= checked
; }
161 bool checked() const { return checked_
; }
167 // Accessibility information about a tab passed to onControlFocused
168 // and onControlAction event listeners.
169 class AccessibilityTabInfo
: public AccessibilityControlInfo
{
171 AccessibilityTabInfo(Profile
* profile
,
172 const std::string
& tab_name
,
173 const std::string
& context
,
177 virtual const char* type() const OVERRIDE
;
179 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
181 void SetTab(int tab_index
, std::string tab_name
) {
182 tab_index_
= tab_index
;
186 int tab_index() const { return tab_index_
; }
187 int tab_count() const { return tab_count_
; }
190 // The 0-based index of this tab and number of tabs in the group.
195 // Accessibility information about a combo box passed to onControlFocused
196 // and onControlAction event listeners.
197 class AccessibilityComboBoxInfo
: public AccessibilityControlInfo
{
199 AccessibilityComboBoxInfo(Profile
* profile
,
200 const std::string
& name
,
201 const std::string
& context
,
202 const std::string
& value
,
206 virtual const char* type() const OVERRIDE
;
208 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
210 void SetValue(int item_index
, const std::string
& value
) {
211 item_index_
= item_index
;
215 int item_index() const { return item_index_
; }
216 int item_count() const { return item_count_
; }
217 const std::string
& value() const { return value_
; }
221 // The 0-based index of the current item and the number of total items.
222 // If the value is not one of the drop-down options, |item_index_| should
229 // Accessibility information about a text box, passed to onControlFocused,
230 // onControlAction, and onTextChanged event listeners.
231 class AccessibilityTextBoxInfo
: public AccessibilityControlInfo
{
233 AccessibilityTextBoxInfo(Profile
* profile
,
234 const std::string
& name
,
235 const std::string
& context
,
238 virtual const char* type() const OVERRIDE
;
240 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
243 const std::string
& value
, int selection_start
, int selection_end
) {
245 selection_start_
= selection_start
;
246 selection_end_
= selection_end
;
249 const std::string
& value() const { return value_
; }
250 bool password() const { return password_
; }
251 int selection_start() const { return selection_start_
; }
252 int selection_end() const { return selection_end_
; }
257 int selection_start_
;
261 // Accessibility information about a combo box passed to onControlFocused
262 // and onControlAction event listeners.
263 class AccessibilityListBoxInfo
: public AccessibilityControlInfo
{
265 AccessibilityListBoxInfo(Profile
* profile
,
266 const std::string
& name
,
267 const std::string
& context
,
268 const std::string
& value
,
272 virtual const char* type() const OVERRIDE
;
274 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
276 void SetValue(int item_index
, std::string value
) {
277 item_index_
= item_index
;
281 int item_index() const { return item_index_
; }
282 int item_count() const { return item_count_
; }
283 const std::string
& value() const { return value_
; }
287 // The 0-based index of the current item and the number of total items.
288 // If the value is not one of the drop-down options, |item_index_| should
294 // Accessibility information about a menu; this class is used by
295 // onMenuOpened, onMenuClosed, and onControlFocused event listeners.
296 class AccessibilityMenuInfo
: public AccessibilityControlInfo
{
298 AccessibilityMenuInfo(Profile
* profile
, const std::string
& menu_name
);
300 virtual const char* type() const OVERRIDE
;
303 // Accessibility information about a menu item; this class is used by
304 // onControlFocused event listeners.
305 class AccessibilityMenuItemInfo
: public AccessibilityControlInfo
{
307 AccessibilityMenuItemInfo(Profile
* profile
,
308 const std::string
& name
,
309 const std::string
& context
,
314 virtual const char* type() const OVERRIDE
;
316 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
318 int item_index() const { return item_index_
; }
319 int item_count() const { return item_count_
; }
320 bool has_submenu() const { return has_submenu_
; }
324 // The 0-based index of the current item and the number of total items.
329 // Accessibility information about a tree; this class is used by
330 // onControlFocused event listeners.
331 class AccessibilityTreeInfo
: public AccessibilityControlInfo
{
333 AccessibilityTreeInfo(Profile
* profile
, const std::string
& menu_name
);
335 virtual const char* type() const OVERRIDE
;
338 // Accessibility information about a tree item; this class is used by
339 // onControlFocused event listeners.
340 class AccessibilityTreeItemInfo
: public AccessibilityControlInfo
{
342 AccessibilityTreeItemInfo(Profile
* profile
,
343 const std::string
& name
,
344 const std::string
& context
,
351 virtual const char* type() const OVERRIDE
;
353 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
355 int item_depth() const { return item_depth_
; }
356 int item_index() const { return item_index_
; }
357 int item_count() const { return item_count_
; }
358 int children_count() const { return children_count_
; }
359 bool is_expanded() const { return is_expanded_
; }
362 // 0-based item depth.
364 // The 0-based index of the current item and the number of total items at the
367 // Count of items at the current depth.
369 // Count of children of the current item.
371 // True if the node is expanded.
375 // Accessibility information about a slider passed to onControlFocused
376 // and onControlAction event listeners.
377 class AccessibilitySliderInfo
: public AccessibilityControlInfo
{
379 AccessibilitySliderInfo(Profile
* profile
,
380 const std::string
& name
,
381 const std::string
& context
,
382 const std::string
& value
);
384 virtual const char* type() const OVERRIDE
;
386 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
388 const std::string
& value() const { return value_
; }
394 // Accessibility information about an alert passed to onControlAction event.
395 class AccessibilityAlertInfo
: public AccessibilityControlInfo
{
397 AccessibilityAlertInfo(Profile
* profile
, const std::string
& name
);
399 virtual const char* type() const OVERRIDE
;
402 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_