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"
11 #include "ui/gfx/rect.h"
13 class AccessibilityControlInfo
;
14 class AccessibilityMenuInfo
;
15 class AccessibilityWindowInfo
;
19 class DictionaryValue
;
22 // Notify the ExtensionAccessibilityEventRouter of the given accessibility
23 // event and AccessibilityEventInfo details. Will not send if the profile's
24 // pause level is nonzero (using profile->PauseAccessibilityEvents).
25 void SendControlAccessibilityNotification(
27 AccessibilityControlInfo
* info
);
29 void SendMenuAccessibilityNotification(
31 AccessibilityMenuInfo
* info
);
33 void SendWindowAccessibilityNotification(
35 AccessibilityWindowInfo
* info
);
37 // Abstract parent class for accessibility event information passed to event
39 class AccessibilityEventInfo
{
41 virtual ~AccessibilityEventInfo() {}
43 // Serialize this class as a DictionaryValue that can be converted to
44 // a JavaScript object.
45 virtual void SerializeToDict(base::DictionaryValue
* dict
) const = 0;
47 Profile
* profile() const { return profile_
; }
50 explicit AccessibilityEventInfo(Profile
* profile
) : profile_(profile
) {}
52 // The profile this control belongs to.
56 // Abstract parent class for accessibility information about a control
57 // passed to event listeners.
58 class AccessibilityControlInfo
: public AccessibilityEventInfo
{
60 virtual ~AccessibilityControlInfo();
62 // Serialize this class as a DictionaryValue that can be converted to
63 // a JavaScript object.
64 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
66 // Return the specific type of this control, which will be one of the
67 // string constants defined in extension_accessibility_api_constants.h.
68 virtual const char* type() const = 0;
70 const std::string
& name() const { return name_
; }
72 const std::string
& context() const { return context_
; }
74 void set_bounds(const gfx::Rect
& bounds
) { bounds_
= bounds
; }
75 const gfx::Rect
& bounds() const { return bounds_
; }
78 AccessibilityControlInfo(Profile
* profile
,
79 const std::string
& name
);
81 void set_context(const std::string
& context
) { context_
= context
; }
83 // The name of the control, like "OK" or "Password".
86 // A string describing the context of the control, such as the name of
87 // the group or toolbar it's contained in.
90 // The bounds of the control in global screen coordinates.
94 // Accessibility information about a window passed to onWindowOpened
95 // and onWindowClosed event listeners.
96 class AccessibilityWindowInfo
: public AccessibilityControlInfo
{
98 AccessibilityWindowInfo(Profile
* profile
, const std::string
& window_name
);
100 virtual const char* type() const override
;
103 // Accessibility information about a push button passed to onControlFocused
104 // and onControlAction event listeners.
105 class AccessibilityButtonInfo
: public AccessibilityControlInfo
{
107 AccessibilityButtonInfo(Profile
* profile
,
108 const std::string
& button_name
,
109 const std::string
& context
);
111 virtual const char* type() const override
;
114 // Accessibility information about static text passed to onControlFocused
115 // and onControlAction event listeners.
116 class AccessibilityStaticTextInfo
: public AccessibilityControlInfo
{
118 AccessibilityStaticTextInfo(Profile
* profile
,
119 const std::string
& text
,
120 const std::string
& context
);
122 virtual const char* type() const override
;
125 // Accessibility information about a hyperlink passed to onControlFocused
126 // and onControlAction event listeners.
127 class AccessibilityLinkInfo
: public AccessibilityControlInfo
{
129 AccessibilityLinkInfo(Profile
* profile
,
130 const std::string
& link_name
,
131 const std::string
& context
);
133 virtual const char* type() const override
;
136 // Accessibility information about a radio button passed to onControlFocused
137 // and onControlAction event listeners.
138 class AccessibilityRadioButtonInfo
: public AccessibilityControlInfo
{
140 AccessibilityRadioButtonInfo(Profile
* profile
,
141 const std::string
& name
,
142 const std::string
& context
,
147 virtual const char* type() const override
;
149 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
151 void SetChecked(bool checked
) { checked_
= checked
; }
153 int item_index() const { return item_index_
; }
154 int item_count() const { return item_count_
; }
155 bool checked() const { return checked_
; }
159 // The 0-based index of this radio button and number of buttons in the group.
164 // Accessibility information about a checkbox passed to onControlFocused
165 // and onControlAction event listeners.
166 class AccessibilityCheckboxInfo
: public AccessibilityControlInfo
{
168 AccessibilityCheckboxInfo(Profile
* profile
,
169 const std::string
& name
,
170 const std::string
& context
,
173 virtual const char* type() const override
;
175 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
177 void SetChecked(bool checked
) { checked_
= checked
; }
179 bool checked() const { return checked_
; }
185 // Accessibility information about a tab passed to onControlFocused
186 // and onControlAction event listeners.
187 class AccessibilityTabInfo
: public AccessibilityControlInfo
{
189 AccessibilityTabInfo(Profile
* profile
,
190 const std::string
& tab_name
,
191 const std::string
& context
,
195 virtual const char* type() const override
;
197 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
199 void SetTab(int tab_index
, std::string tab_name
) {
200 tab_index_
= tab_index
;
204 int tab_index() const { return tab_index_
; }
205 int tab_count() const { return tab_count_
; }
208 // The 0-based index of this tab and number of tabs in the group.
213 // Accessibility information about a combo box passed to onControlFocused
214 // and onControlAction event listeners.
215 class AccessibilityComboBoxInfo
: public AccessibilityControlInfo
{
217 AccessibilityComboBoxInfo(Profile
* profile
,
218 const std::string
& name
,
219 const std::string
& context
,
220 const std::string
& value
,
224 virtual const char* type() const override
;
226 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
228 void SetValue(int item_index
, const std::string
& value
) {
229 item_index_
= item_index
;
233 int item_index() const { return item_index_
; }
234 int item_count() const { return item_count_
; }
235 const std::string
& value() const { return value_
; }
239 // The 0-based index of the current item and the number of total items.
240 // If the value is not one of the drop-down options, |item_index_| should
247 // Accessibility information about a text box, passed to onControlFocused,
248 // onControlAction, and onTextChanged event listeners.
249 class AccessibilityTextBoxInfo
: public AccessibilityControlInfo
{
251 AccessibilityTextBoxInfo(Profile
* profile
,
252 const std::string
& name
,
253 const std::string
& context
,
256 virtual const char* type() const override
;
258 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
261 const std::string
& value
, int selection_start
, int selection_end
) {
263 selection_start_
= selection_start
;
264 selection_end_
= selection_end
;
267 const std::string
& value() const { return value_
; }
268 bool password() const { return password_
; }
269 int selection_start() const { return selection_start_
; }
270 int selection_end() const { return selection_end_
; }
275 int selection_start_
;
279 // Accessibility information about a combo box passed to onControlFocused
280 // and onControlAction event listeners.
281 class AccessibilityListBoxInfo
: public AccessibilityControlInfo
{
283 AccessibilityListBoxInfo(Profile
* profile
,
284 const std::string
& name
,
285 const std::string
& context
,
286 const std::string
& value
,
290 virtual const char* type() const override
;
292 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
294 void SetValue(int item_index
, std::string value
) {
295 item_index_
= item_index
;
299 int item_index() const { return item_index_
; }
300 int item_count() const { return item_count_
; }
301 const std::string
& value() const { return value_
; }
305 // The 0-based index of the current item and the number of total items.
306 // If the value is not one of the drop-down options, |item_index_| should
312 // Accessibility information about a menu; this class is used by
313 // onMenuOpened, onMenuClosed, and onControlFocused event listeners.
314 class AccessibilityMenuInfo
: public AccessibilityControlInfo
{
316 AccessibilityMenuInfo(Profile
* profile
, const std::string
& menu_name
);
318 virtual const char* type() const override
;
321 // Accessibility information about a menu item; this class is used by
322 // onControlFocused event listeners.
323 class AccessibilityMenuItemInfo
: public AccessibilityControlInfo
{
325 AccessibilityMenuItemInfo(Profile
* profile
,
326 const std::string
& name
,
327 const std::string
& context
,
332 virtual const char* type() const override
;
334 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
336 int item_index() const { return item_index_
; }
337 int item_count() const { return item_count_
; }
338 bool has_submenu() const { return has_submenu_
; }
342 // The 0-based index of the current item and the number of total items.
347 // Accessibility information about a tree; this class is used by
348 // onControlFocused event listeners.
349 class AccessibilityTreeInfo
: public AccessibilityControlInfo
{
351 AccessibilityTreeInfo(Profile
* profile
, const std::string
& menu_name
);
353 virtual const char* type() const override
;
356 // Accessibility information about a tree item; this class is used by
357 // onControlFocused event listeners.
358 class AccessibilityTreeItemInfo
: public AccessibilityControlInfo
{
360 AccessibilityTreeItemInfo(Profile
* profile
,
361 const std::string
& name
,
362 const std::string
& context
,
369 virtual const char* type() const override
;
371 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
373 int item_depth() const { return item_depth_
; }
374 int item_index() const { return item_index_
; }
375 int item_count() const { return item_count_
; }
376 int children_count() const { return children_count_
; }
377 bool is_expanded() const { return is_expanded_
; }
380 // 0-based item depth.
382 // The 0-based index of the current item and the number of total items at the
385 // Count of items at the current depth.
387 // Count of children of the current item.
389 // True if the node is expanded.
393 // Accessibility information about a slider passed to onControlFocused
394 // and onControlAction event listeners.
395 class AccessibilitySliderInfo
: public AccessibilityControlInfo
{
397 AccessibilitySliderInfo(Profile
* profile
,
398 const std::string
& name
,
399 const std::string
& context
,
400 const std::string
& value
);
402 virtual const char* type() const override
;
404 virtual void SerializeToDict(base::DictionaryValue
* dict
) const override
;
406 const std::string
& value() const { return value_
; }
412 // Accessibility information about an alert passed to onControlAction event.
413 class AccessibilityAlertInfo
: public AccessibilityControlInfo
{
415 AccessibilityAlertInfo(Profile
* profile
, const std::string
& name
);
417 virtual const char* type() const override
;
420 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_