Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/gtk/accessibility_event_router_gtk.h

Issue 1585011: Add menu and menu item events to the accessibility extension api, and... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_GTK_ACCESSIBILITY_EVENT_ROUTER_GTK_H_ 5 #ifndef CHROME_BROWSER_GTK_ACCESSIBILITY_EVENT_ROUTER_GTK_H_
6 #define CHROME_BROWSER_GTK_ACCESSIBILITY_EVENT_ROUTER_GTK_H_ 6 #define CHROME_BROWSER_GTK_ACCESSIBILITY_EVENT_ROUTER_GTK_H_
7 7
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 18 matching lines...) Expand all
29 } // namespace __gnu_cxx 29 } // namespace __gnu_cxx
30 30
31 // Struct to keep track of event listener hook ids to remove them later. 31 // Struct to keep track of event listener hook ids to remove them later.
32 struct InstalledHook { 32 struct InstalledHook {
33 InstalledHook(guint _signal_id, gulong _hook_id) 33 InstalledHook(guint _signal_id, gulong _hook_id)
34 : signal_id(_signal_id), hook_id(_hook_id) { } 34 : signal_id(_signal_id), hook_id(_hook_id) { }
35 guint signal_id; 35 guint signal_id;
36 gulong hook_id; 36 gulong hook_id;
37 }; 37 };
38 38
39 // NOTE: This class is part of the Accessibility Extension API, which lets
40 // extensions receive accessibility events. It's distinct from code that
41 // implements platform accessibility APIs like MSAA or ATK.
42 //
39 // Singleton class that adds a signal emission hook to many gtk events, and 43 // Singleton class that adds a signal emission hook to many gtk events, and
40 // then sends an accessibility notification whenever a relevant event is 44 // then sends an accessibility notification whenever a relevant event is
41 // sent to an accessible control. 45 // sent to an accessible control.
42 // 46 //
43 // Gtk widgets are not accessible by default. When you register a root widget, 47 // Gtk widgets are not accessible by default. When you register a root widget,
44 // that widget and all of its descendants will start sending accessibility 48 // that widget and all of its descendants will start sending accessibility
45 // event notifications. You can then override the default behavior for 49 // event notifications. You can then override the default behavior for
46 // specific descendants using other methods. 50 // specific descendants using other methods.
47 // 51 //
48 // You can use Profile::PauseAccessibilityEvents to prevent a flurry 52 // You can use Profile::PauseAccessibilityEvents to prevent a flurry
49 // of accessibility events when a window is being created or initialized. 53 // of accessibility events when a window is being created or initialized.
50 class AccessibilityEventRouter { 54 class AccessibilityEventRouterGtk {
51 public: 55 public:
52 // Internal information about a particular widget to override the 56 // Internal information about a particular widget to override the
53 // information we get directly from gtk. 57 // information we get directly from gtk.
54 struct WidgetInfo { 58 struct WidgetInfo {
55 WidgetInfo() : ignore(false) { } 59 WidgetInfo() : ignore(false) { }
56 60
57 // If nonempty, will use this name instead of the widget's label. 61 // If nonempty, will use this name instead of the widget's label.
58 std::string name; 62 std::string name;
59 63
60 // If true, will ignore this widget and not send accessibility events. 64 // If true, will ignore this widget and not send accessibility events.
61 bool ignore; 65 bool ignore;
62 }; 66 };
63 67
64 // Get the single instance of this class. 68 // Get the single instance of this class.
65 static AccessibilityEventRouter* GetInstance(); 69 static AccessibilityEventRouterGtk* GetInstance();
66 70
67 // Start sending accessibility events for this widget and all of its 71 // Start sending accessibility events for this widget and all of its
68 // descendants. Notifications will go to the specified profile. 72 // descendants. Notifications will go to the specified profile.
69 void AddRootWidget(GtkWidget* root_widget, Profile* profile); 73 void AddRootWidget(GtkWidget* root_widget, Profile* profile);
70 74
71 // Stop sending accessibility events for this widget and all of its 75 // Stop sending accessibility events for this widget and all of its
72 // descendants. 76 // descendants.
73 void RemoveRootWidget(GtkWidget* root_widget); 77 void RemoveRootWidget(GtkWidget* root_widget);
74 78
75 // Don't send any events for this widget. 79 // Don't send any events for this widget.
76 void IgnoreWidget(GtkWidget* widget); 80 void IgnoreWidget(GtkWidget* widget);
77 81
78 // Use the following string as the name of this widget, instead of the 82 // Use the following string as the name of this widget, instead of the
79 // gtk label associated with the widget. 83 // gtk label associated with the widget.
80 void SetWidgetName(GtkWidget* widget, std::string name); 84 void SetWidgetName(GtkWidget* widget, std::string name);
81 85
82 // Forget all information about this widget. 86 // Forget all information about this widget.
83 void RemoveWidget(GtkWidget* widget); 87 void RemoveWidget(GtkWidget* widget);
84 88
85 // 89 //
86 // The following methods are only for use by gtk signal handlers. 90 // The following methods are only for use by gtk signal handlers.
87 // 91 //
88 92
89 // Returns true if this widget is a descendant of one of our registered
90 // root widgets and not in the set of ignored widgets. If |profile| is
91 // not null, return the profile where notifications associated with this
92 // widget should be sent.
93 bool IsWidgetAccessible(GtkWidget* widget, Profile** profile);
94
95 // Return the name of a widget.
96 std::string GetWidgetName(GtkWidget* widget);
97
98 // Called by the signal handler. Checks the type of the widget and 93 // Called by the signal handler. Checks the type of the widget and
99 // calls one of the more specific Send*Notification methods, below. 94 // calls one of the more specific Send*Notification methods, below.
100 void DispatchAccessibilityNotification( 95 void DispatchAccessibilityNotification(
101 GtkWidget* widget, NotificationType type); 96 GtkWidget* widget, NotificationType type);
102 97
103 // Post a task to call DispatchAccessibilityNotification the next time 98 // Post a task to call DispatchAccessibilityNotification the next time
104 // through the event loop. 99 // through the event loop.
105 void PostDispatchAccessibilityNotification( 100 void PostDispatchAccessibilityNotification(
106 GtkWidget* widget, NotificationType type); 101 GtkWidget* widget, NotificationType type);
107 102
103 private:
104 AccessibilityEventRouterGtk();
105 virtual ~AccessibilityEventRouterGtk();
106
107 // Given a widget, determine if it's the descendant of a root widget
108 // that's mapped to a profile and if so, if it's marked as accessible.
109 void FindWidget(GtkWidget* widget, Profile** profile, bool* is_accessible);
110
111 // Return the name of a widget.
112 std::string GetWidgetName(GtkWidget* widget);
113
108 // Each of these methods constructs an AccessibilityControlInfo object 114 // Each of these methods constructs an AccessibilityControlInfo object
109 // and sends a notification of a specific accessibility event. 115 // and sends a notification of a specific accessibility event.
110 void SendButtonNotification( 116 void SendButtonNotification(
111 GtkWidget* widget, NotificationType type, Profile* profile); 117 GtkWidget* widget, NotificationType type, Profile* profile);
112 void SendCheckboxNotification( 118 void SendCheckboxNotification(
113 GtkWidget* widget, NotificationType type, Profile* profile); 119 GtkWidget* widget, NotificationType type, Profile* profile);
114 void SendComboBoxNotification( 120 void SendComboBoxNotification(
115 GtkWidget* widget, NotificationType type, Profile* profile); 121 GtkWidget* widget, NotificationType type, Profile* profile);
116 void SendListBoxNotification( 122 void SendListBoxNotification(
117 GtkWidget* widget, NotificationType type, Profile* profile); 123 GtkWidget* widget, NotificationType type, Profile* profile);
124 void SendMenuItemNotification(
125 GtkWidget* widget, NotificationType type, Profile* profile);
118 void SendRadioButtonNotification( 126 void SendRadioButtonNotification(
119 GtkWidget* widget, NotificationType type, Profile* profile); 127 GtkWidget* widget, NotificationType type, Profile* profile);
120 void SendTabNotification( 128 void SendTabNotification(
121 GtkWidget* widget, NotificationType type, Profile* profile); 129 GtkWidget* widget, NotificationType type, Profile* profile);
122 void SendTextBoxNotification( 130 void SendTextBoxNotification(
123 GtkWidget* widget, NotificationType type, Profile* profile); 131 GtkWidget* widget, NotificationType type, Profile* profile);
124 132
125 void InstallEventListeners(); 133 void InstallEventListeners();
126 void RemoveEventListeners(); 134 void RemoveEventListeners();
127 135
128 // Start and stop listening to signals. 136 // Start and stop listening to signals.
129 void StartListening(); 137 void StartListening();
130 void StopListening(); 138 void StopListening();
131 139
132 private:
133 AccessibilityEventRouter();
134 virtual ~AccessibilityEventRouter();
135
136 // Add a signal emission hook for one particular signal name and 140 // Add a signal emission hook for one particular signal name and
137 // widget type, and save the hook_id in installed_hooks so we can 141 // widget type, and save the hook_id in installed_hooks so we can
138 // remove it later. 142 // remove it later.
139 void InstallEventListener( 143 void InstallEventListener(
140 const char *signal_name, 144 const char *signal_name,
141 GType widget_type, 145 GType widget_type,
142 GSignalEmissionHook hook_func); 146 GSignalEmissionHook hook_func);
143 147
144 friend struct DefaultSingletonTraits<AccessibilityEventRouter>; 148 friend struct DefaultSingletonTraits<AccessibilityEventRouterGtk>;
145 149
146 // The set of all root widgets; only descendants of these will generate 150 // The set of all root widgets; only descendants of these will generate
147 // accessibility notifications. 151 // accessibility notifications.
148 base::hash_map<GtkWidget*, Profile*> root_widget_profile_map_; 152 base::hash_map<GtkWidget*, Profile*> root_widget_profile_map_;
149 153
150 // Extra information about specific widgets. 154 // Extra information about specific widgets.
151 base::hash_map<GtkWidget*, WidgetInfo> widget_info_map_; 155 base::hash_map<GtkWidget*, WidgetInfo> widget_info_map_;
152 156
153 // Installed event listener hook ids so we can remove them later. 157 // Installed event listener hook ids so we can remove them later.
154 std::vector<InstalledHook> installed_hooks_; 158 std::vector<InstalledHook> installed_hooks_;
155 159
156 // True if we are currently listening to signals. 160 // True if we are currently listening to signals.
157 bool listening_; 161 bool listening_;
158 162
159 // Used to schedule invocations of StartListening(). 163 // The profile associated with the most recent window event - used to
160 ScopedRunnableMethodFactory<AccessibilityEventRouter> method_factory_; 164 // figure out where to route a few events that can't be directly traced
165 // to a window with a profile (like menu events).
166 Profile* most_recent_profile_;
167
168 // Used to schedule invocations of StartListening() and to defer handling
169 // of some events until the next time through the event loop.
170 ScopedRunnableMethodFactory<AccessibilityEventRouterGtk> method_factory_;
161 }; 171 };
162 172
163 #endif // CHROME_BROWSER_GTK_ACCESSIBILITY_EVENT_ROUTER_GTK_H_ 173 #endif // CHROME_BROWSER_GTK_ACCESSIBILITY_EVENT_ROUTER_GTK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698