Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / accessibility / accessibility_events.h
blob05f3577ab00378a164ec6d1897476f5b8a5c1621
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"
11 #include "ui/gfx/rect.h"
13 class AccessibilityControlInfo;
14 class AccessibilityMenuInfo;
15 class AccessibilityWindowInfo;
16 class Profile;
18 namespace base {
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(
26 ui::AXEvent event,
27 AccessibilityControlInfo* info);
29 void SendMenuAccessibilityNotification(
30 ui::AXEvent event,
31 AccessibilityMenuInfo* info);
33 void SendWindowAccessibilityNotification(
34 ui::AXEvent event,
35 AccessibilityWindowInfo* info);
37 // Abstract parent class for accessibility event information passed to event
38 // listeners.
39 class AccessibilityEventInfo {
40 public:
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_; }
49 protected:
50 explicit AccessibilityEventInfo(Profile* profile) : profile_(profile) {}
52 // The profile this control belongs to.
53 Profile* profile_;
56 // Abstract parent class for accessibility information about a control
57 // passed to event listeners.
58 class AccessibilityControlInfo : public AccessibilityEventInfo {
59 public:
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_; }
77 protected:
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".
84 std::string name_;
86 // A string describing the context of the control, such as the name of
87 // the group or toolbar it's contained in.
88 std::string context_;
90 // The bounds of the control in global screen coordinates.
91 gfx::Rect bounds_;
94 // Accessibility information about a window passed to onWindowOpened
95 // and onWindowClosed event listeners.
96 class AccessibilityWindowInfo : public AccessibilityControlInfo {
97 public:
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 {
106 public:
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 {
117 public:
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 {
128 public:
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 {
139 public:
140 AccessibilityRadioButtonInfo(Profile* profile,
141 const std::string& name,
142 const std::string& context,
143 bool checked,
144 int item_index,
145 int item_count);
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_; }
157 private:
158 bool checked_;
159 // The 0-based index of this radio button and number of buttons in the group.
160 int item_index_;
161 int item_count_;
164 // Accessibility information about a checkbox passed to onControlFocused
165 // and onControlAction event listeners.
166 class AccessibilityCheckboxInfo : public AccessibilityControlInfo {
167 public:
168 AccessibilityCheckboxInfo(Profile* profile,
169 const std::string& name,
170 const std::string& context,
171 bool checked);
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_; }
181 private:
182 bool checked_;
185 // Accessibility information about a tab passed to onControlFocused
186 // and onControlAction event listeners.
187 class AccessibilityTabInfo : public AccessibilityControlInfo {
188 public:
189 AccessibilityTabInfo(Profile* profile,
190 const std::string& tab_name,
191 const std::string& context,
192 int tab_index,
193 int tab_count);
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;
201 name_ = tab_name;
204 int tab_index() const { return tab_index_; }
205 int tab_count() const { return tab_count_; }
207 private:
208 // The 0-based index of this tab and number of tabs in the group.
209 int tab_index_;
210 int tab_count_;
213 // Accessibility information about a combo box passed to onControlFocused
214 // and onControlAction event listeners.
215 class AccessibilityComboBoxInfo : public AccessibilityControlInfo {
216 public:
217 AccessibilityComboBoxInfo(Profile* profile,
218 const std::string& name,
219 const std::string& context,
220 const std::string& value,
221 int item_index,
222 int item_count);
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;
230 value_ = value;
233 int item_index() const { return item_index_; }
234 int item_count() const { return item_count_; }
235 const std::string& value() const { return value_; }
237 private:
238 std::string 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
241 // be -1.
242 int item_index_;
243 int item_count_;
247 // Accessibility information about a text box, passed to onControlFocused,
248 // onControlAction, and onTextChanged event listeners.
249 class AccessibilityTextBoxInfo : public AccessibilityControlInfo {
250 public:
251 AccessibilityTextBoxInfo(Profile* profile,
252 const std::string& name,
253 const std::string& context,
254 bool password);
256 virtual const char* type() const override;
258 virtual void SerializeToDict(base::DictionaryValue* dict) const override;
260 void SetValue(
261 const std::string& value, int selection_start, int selection_end) {
262 value_ = value;
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_; }
272 private:
273 std::string value_;
274 bool password_;
275 int selection_start_;
276 int selection_end_;
279 // Accessibility information about a combo box passed to onControlFocused
280 // and onControlAction event listeners.
281 class AccessibilityListBoxInfo : public AccessibilityControlInfo {
282 public:
283 AccessibilityListBoxInfo(Profile* profile,
284 const std::string& name,
285 const std::string& context,
286 const std::string& value,
287 int item_index,
288 int item_count);
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;
296 value_ = value;
299 int item_index() const { return item_index_; }
300 int item_count() const { return item_count_; }
301 const std::string& value() const { return value_; }
303 private:
304 std::string 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
307 // be -1.
308 int item_index_;
309 int item_count_;
312 // Accessibility information about a menu; this class is used by
313 // onMenuOpened, onMenuClosed, and onControlFocused event listeners.
314 class AccessibilityMenuInfo : public AccessibilityControlInfo {
315 public:
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 {
324 public:
325 AccessibilityMenuItemInfo(Profile* profile,
326 const std::string& name,
327 const std::string& context,
328 bool has_submenu,
329 int item_index,
330 int item_count);
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_; }
340 private:
341 bool has_submenu_;
342 // The 0-based index of the current item and the number of total items.
343 int item_index_;
344 int item_count_;
347 // Accessibility information about a tree; this class is used by
348 // onControlFocused event listeners.
349 class AccessibilityTreeInfo : public AccessibilityControlInfo {
350 public:
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 {
359 public:
360 AccessibilityTreeItemInfo(Profile* profile,
361 const std::string& name,
362 const std::string& context,
363 int item_depth,
364 int item_index,
365 int item_count,
366 int children_count,
367 bool is_expanded);
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_; }
379 private:
380 // 0-based item depth.
381 int item_depth_;
382 // The 0-based index of the current item and the number of total items at the
383 // current depth.
384 int item_index_;
385 // Count of items at the current depth.
386 int item_count_;
387 // Count of children of the current item.
388 int children_count_;
389 // True if the node is expanded.
390 bool is_expanded_;
393 // Accessibility information about a slider passed to onControlFocused
394 // and onControlAction event listeners.
395 class AccessibilitySliderInfo : public AccessibilityControlInfo {
396 public:
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_; }
408 private:
409 std::string value_;
412 // Accessibility information about an alert passed to onControlAction event.
413 class AccessibilityAlertInfo : public AccessibilityControlInfo {
414 public:
415 AccessibilityAlertInfo(Profile* profile, const std::string& name);
417 virtual const char* type() const override;
420 #endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EVENTS_H_