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/accessibility/ax_enums.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(
26 AccessibilityControlInfo
* info
);
28 void SendMenuAccessibilityNotification(
30 AccessibilityMenuInfo
* info
);
32 void SendWindowAccessibilityNotification(
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 static text passed to onControlFocused
108 // and onControlAction event listeners.
109 class AccessibilityStaticTextInfo
: public AccessibilityControlInfo
{
111 AccessibilityStaticTextInfo(Profile
* profile
,
112 const std::string
& text
,
113 const std::string
& context
);
115 virtual const char* type() const OVERRIDE
;
118 // Accessibility information about a hyperlink passed to onControlFocused
119 // and onControlAction event listeners.
120 class AccessibilityLinkInfo
: public AccessibilityControlInfo
{
122 AccessibilityLinkInfo(Profile
* profile
,
123 const std::string
& link_name
,
124 const std::string
& context
);
126 virtual const char* type() const OVERRIDE
;
129 // Accessibility information about a radio button passed to onControlFocused
130 // and onControlAction event listeners.
131 class AccessibilityRadioButtonInfo
: public AccessibilityControlInfo
{
133 AccessibilityRadioButtonInfo(Profile
* profile
,
134 const std::string
& name
,
135 const std::string
& context
,
140 virtual const char* type() const OVERRIDE
;
142 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
144 void SetChecked(bool checked
) { checked_
= checked
; }
146 int item_index() const { return item_index_
; }
147 int item_count() const { return item_count_
; }
148 bool checked() const { return checked_
; }
152 // The 0-based index of this radio button and number of buttons in the group.
157 // Accessibility information about a checkbox passed to onControlFocused
158 // and onControlAction event listeners.
159 class AccessibilityCheckboxInfo
: public AccessibilityControlInfo
{
161 AccessibilityCheckboxInfo(Profile
* profile
,
162 const std::string
& name
,
163 const std::string
& context
,
166 virtual const char* type() const OVERRIDE
;
168 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
170 void SetChecked(bool checked
) { checked_
= checked
; }
172 bool checked() const { return checked_
; }
178 // Accessibility information about a tab passed to onControlFocused
179 // and onControlAction event listeners.
180 class AccessibilityTabInfo
: public AccessibilityControlInfo
{
182 AccessibilityTabInfo(Profile
* profile
,
183 const std::string
& tab_name
,
184 const std::string
& context
,
188 virtual const char* type() const OVERRIDE
;
190 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
192 void SetTab(int tab_index
, std::string tab_name
) {
193 tab_index_
= tab_index
;
197 int tab_index() const { return tab_index_
; }
198 int tab_count() const { return tab_count_
; }
201 // The 0-based index of this tab and number of tabs in the group.
206 // Accessibility information about a combo box passed to onControlFocused
207 // and onControlAction event listeners.
208 class AccessibilityComboBoxInfo
: public AccessibilityControlInfo
{
210 AccessibilityComboBoxInfo(Profile
* profile
,
211 const std::string
& name
,
212 const std::string
& context
,
213 const std::string
& value
,
217 virtual const char* type() const OVERRIDE
;
219 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
221 void SetValue(int item_index
, const std::string
& value
) {
222 item_index_
= item_index
;
226 int item_index() const { return item_index_
; }
227 int item_count() const { return item_count_
; }
228 const std::string
& value() const { return value_
; }
232 // The 0-based index of the current item and the number of total items.
233 // If the value is not one of the drop-down options, |item_index_| should
240 // Accessibility information about a text box, passed to onControlFocused,
241 // onControlAction, and onTextChanged event listeners.
242 class AccessibilityTextBoxInfo
: public AccessibilityControlInfo
{
244 AccessibilityTextBoxInfo(Profile
* profile
,
245 const std::string
& name
,
246 const std::string
& context
,
249 virtual const char* type() const OVERRIDE
;
251 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
254 const std::string
& value
, int selection_start
, int selection_end
) {
256 selection_start_
= selection_start
;
257 selection_end_
= selection_end
;
260 const std::string
& value() const { return value_
; }
261 bool password() const { return password_
; }
262 int selection_start() const { return selection_start_
; }
263 int selection_end() const { return selection_end_
; }
268 int selection_start_
;
272 // Accessibility information about a combo box passed to onControlFocused
273 // and onControlAction event listeners.
274 class AccessibilityListBoxInfo
: public AccessibilityControlInfo
{
276 AccessibilityListBoxInfo(Profile
* profile
,
277 const std::string
& name
,
278 const std::string
& context
,
279 const std::string
& value
,
283 virtual const char* type() const OVERRIDE
;
285 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
287 void SetValue(int item_index
, std::string value
) {
288 item_index_
= item_index
;
292 int item_index() const { return item_index_
; }
293 int item_count() const { return item_count_
; }
294 const std::string
& value() const { return value_
; }
298 // The 0-based index of the current item and the number of total items.
299 // If the value is not one of the drop-down options, |item_index_| should
305 // Accessibility information about a menu; this class is used by
306 // onMenuOpened, onMenuClosed, and onControlFocused event listeners.
307 class AccessibilityMenuInfo
: public AccessibilityControlInfo
{
309 AccessibilityMenuInfo(Profile
* profile
, const std::string
& menu_name
);
311 virtual const char* type() const OVERRIDE
;
314 // Accessibility information about a menu item; this class is used by
315 // onControlFocused event listeners.
316 class AccessibilityMenuItemInfo
: public AccessibilityControlInfo
{
318 AccessibilityMenuItemInfo(Profile
* profile
,
319 const std::string
& name
,
320 const std::string
& context
,
325 virtual const char* type() const OVERRIDE
;
327 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
329 int item_index() const { return item_index_
; }
330 int item_count() const { return item_count_
; }
331 bool has_submenu() const { return has_submenu_
; }
335 // The 0-based index of the current item and the number of total items.
340 // Accessibility information about a tree; this class is used by
341 // onControlFocused event listeners.
342 class AccessibilityTreeInfo
: public AccessibilityControlInfo
{
344 AccessibilityTreeInfo(Profile
* profile
, const std::string
& menu_name
);
346 virtual const char* type() const OVERRIDE
;
349 // Accessibility information about a tree item; this class is used by
350 // onControlFocused event listeners.
351 class AccessibilityTreeItemInfo
: public AccessibilityControlInfo
{
353 AccessibilityTreeItemInfo(Profile
* profile
,
354 const std::string
& name
,
355 const std::string
& context
,
362 virtual const char* type() const OVERRIDE
;
364 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
366 int item_depth() const { return item_depth_
; }
367 int item_index() const { return item_index_
; }
368 int item_count() const { return item_count_
; }
369 int children_count() const { return children_count_
; }
370 bool is_expanded() const { return is_expanded_
; }
373 // 0-based item depth.
375 // The 0-based index of the current item and the number of total items at the
378 // Count of items at the current depth.
380 // Count of children of the current item.
382 // True if the node is expanded.
386 // Accessibility information about a slider passed to onControlFocused
387 // and onControlAction event listeners.
388 class AccessibilitySliderInfo
: public AccessibilityControlInfo
{
390 AccessibilitySliderInfo(Profile
* profile
,
391 const std::string
& name
,
392 const std::string
& context
,
393 const std::string
& value
);
395 virtual const char* type() const OVERRIDE
;
397 virtual void SerializeToDict(base::DictionaryValue
* dict
) const OVERRIDE
;
399 const std::string
& value() const { return value_
; }
405 // Accessibility information about an alert passed to onControlAction event.
406 class AccessibilityAlertInfo
: public AccessibilityControlInfo
{
408 AccessibilityAlertInfo(Profile
* profile
, const std::string
& name
);
410 virtual const char* type() const OVERRIDE
;
413 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_