[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / accessibility / accessibility_events.h
blob84ee2b07de0cef4d5d4af8b1a126af5086b72c0d
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_
8 #include <string>
9 #include "base/compiler_specific.h"
10 #include "ui/accessibility/ax_enums.h"
12 class AccessibilityControlInfo;
13 class AccessibilityMenuInfo;
14 class AccessibilityWindowInfo;
15 class Profile;
17 namespace base {
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::AXEvent event,
26 AccessibilityControlInfo* info);
28 void SendMenuAccessibilityNotification(
29 ui::AXEvent event,
30 AccessibilityMenuInfo* info);
32 void SendWindowAccessibilityNotification(
33 ui::AXEvent event,
34 AccessibilityWindowInfo* info);
36 // Abstract parent class for accessibility event information passed to event
37 // listeners.
38 class AccessibilityEventInfo {
39 public:
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_; }
48 protected:
49 explicit AccessibilityEventInfo(Profile* profile) : profile_(profile) {}
51 // The profile this control belongs to.
52 Profile* profile_;
55 // Abstract parent class for accessibility information about a control
56 // passed to event listeners.
57 class AccessibilityControlInfo : public AccessibilityEventInfo {
58 public:
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_; }
73 protected:
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".
80 std::string name_;
82 // A string describing the context of the control, such as the name of
83 // the group or toolbar it's contained in.
84 std::string context_;
87 // Accessibility information about a window passed to onWindowOpened
88 // and onWindowClosed event listeners.
89 class AccessibilityWindowInfo : public AccessibilityControlInfo {
90 public:
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 {
99 public:
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 {
110 public:
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 {
121 public:
122 AccessibilityRadioButtonInfo(Profile* profile,
123 const std::string& name,
124 const std::string& context,
125 bool checked,
126 int item_index,
127 int item_count);
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_; }
139 private:
140 bool checked_;
141 // The 0-based index of this radio button and number of buttons in the group.
142 int item_index_;
143 int item_count_;
146 // Accessibility information about a checkbox passed to onControlFocused
147 // and onControlAction event listeners.
148 class AccessibilityCheckboxInfo : public AccessibilityControlInfo {
149 public:
150 AccessibilityCheckboxInfo(Profile* profile,
151 const std::string& name,
152 const std::string& context,
153 bool checked);
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_; }
163 private:
164 bool checked_;
167 // Accessibility information about a tab passed to onControlFocused
168 // and onControlAction event listeners.
169 class AccessibilityTabInfo : public AccessibilityControlInfo {
170 public:
171 AccessibilityTabInfo(Profile* profile,
172 const std::string& tab_name,
173 const std::string& context,
174 int tab_index,
175 int tab_count);
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;
183 name_ = tab_name;
186 int tab_index() const { return tab_index_; }
187 int tab_count() const { return tab_count_; }
189 private:
190 // The 0-based index of this tab and number of tabs in the group.
191 int tab_index_;
192 int tab_count_;
195 // Accessibility information about a combo box passed to onControlFocused
196 // and onControlAction event listeners.
197 class AccessibilityComboBoxInfo : public AccessibilityControlInfo {
198 public:
199 AccessibilityComboBoxInfo(Profile* profile,
200 const std::string& name,
201 const std::string& context,
202 const std::string& value,
203 int item_index,
204 int item_count);
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;
212 value_ = value;
215 int item_index() const { return item_index_; }
216 int item_count() const { return item_count_; }
217 const std::string& value() const { return value_; }
219 private:
220 std::string 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
223 // be -1.
224 int item_index_;
225 int item_count_;
229 // Accessibility information about a text box, passed to onControlFocused,
230 // onControlAction, and onTextChanged event listeners.
231 class AccessibilityTextBoxInfo : public AccessibilityControlInfo {
232 public:
233 AccessibilityTextBoxInfo(Profile* profile,
234 const std::string& name,
235 const std::string& context,
236 bool password);
238 virtual const char* type() const OVERRIDE;
240 virtual void SerializeToDict(base::DictionaryValue* dict) const OVERRIDE;
242 void SetValue(
243 const std::string& value, int selection_start, int selection_end) {
244 value_ = value;
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_; }
254 private:
255 std::string value_;
256 bool password_;
257 int selection_start_;
258 int selection_end_;
261 // Accessibility information about a combo box passed to onControlFocused
262 // and onControlAction event listeners.
263 class AccessibilityListBoxInfo : public AccessibilityControlInfo {
264 public:
265 AccessibilityListBoxInfo(Profile* profile,
266 const std::string& name,
267 const std::string& context,
268 const std::string& value,
269 int item_index,
270 int item_count);
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;
278 value_ = value;
281 int item_index() const { return item_index_; }
282 int item_count() const { return item_count_; }
283 const std::string& value() const { return value_; }
285 private:
286 std::string 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
289 // be -1.
290 int item_index_;
291 int item_count_;
294 // Accessibility information about a menu; this class is used by
295 // onMenuOpened, onMenuClosed, and onControlFocused event listeners.
296 class AccessibilityMenuInfo : public AccessibilityControlInfo {
297 public:
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 {
306 public:
307 AccessibilityMenuItemInfo(Profile* profile,
308 const std::string& name,
309 const std::string& context,
310 bool has_submenu,
311 int item_index,
312 int item_count);
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_; }
322 private:
323 bool has_submenu_;
324 // The 0-based index of the current item and the number of total items.
325 int item_index_;
326 int item_count_;
329 // Accessibility information about a tree; this class is used by
330 // onControlFocused event listeners.
331 class AccessibilityTreeInfo : public AccessibilityControlInfo {
332 public:
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 {
341 public:
342 AccessibilityTreeItemInfo(Profile* profile,
343 const std::string& name,
344 const std::string& context,
345 int item_depth,
346 int item_index,
347 int item_count,
348 int children_count,
349 bool is_expanded);
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_; }
361 private:
362 // 0-based item depth.
363 int item_depth_;
364 // The 0-based index of the current item and the number of total items at the
365 // current depth.
366 int item_index_;
367 // Count of items at the current depth.
368 int item_count_;
369 // Count of children of the current item.
370 int children_count_;
371 // True if the node is expanded.
372 bool is_expanded_;
375 // Accessibility information about a slider passed to onControlFocused
376 // and onControlAction event listeners.
377 class AccessibilitySliderInfo : public AccessibilityControlInfo {
378 public:
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_; }
390 private:
391 std::string value_;
394 // Accessibility information about an alert passed to onControlAction event.
395 class AccessibilityAlertInfo : public AccessibilityControlInfo {
396 public:
397 AccessibilityAlertInfo(Profile* profile, const std::string& name);
399 virtual const char* type() const OVERRIDE;
402 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_