OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/views/accessibility_event_router_views.h" | 5 #include "chrome/browser/ui/views/accessibility_event_router_views.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/extension_accessibility_api.h" | 12 #include "chrome/browser/extensions/extension_accessibility_api.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "content/common/notification_type.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "ui/base/accessibility/accessible_view_state.h" | 16 #include "ui/base/accessibility/accessible_view_state.h" |
17 #include "views/controls/button/text_button.h" | 17 #include "views/controls/button/text_button.h" |
18 #include "views/controls/menu/menu_item_view.h" | 18 #include "views/controls/menu/menu_item_view.h" |
19 #include "views/controls/menu/submenu_view.h" | 19 #include "views/controls/menu/submenu_view.h" |
20 #include "views/view.h" | 20 #include "views/view.h" |
21 #include "views/widget/widget.h" | 21 #include "views/widget/widget.h" |
22 | 22 |
23 using views::FocusManager; | 23 using views::FocusManager; |
24 | 24 |
25 AccessibilityEventRouterViews::AccessibilityEventRouterViews() | 25 AccessibilityEventRouterViews::AccessibilityEventRouterViews() |
(...skipping 12 matching lines...) Expand all Loading... |
38 void AccessibilityEventRouterViews::HandleAccessibilityEvent( | 38 void AccessibilityEventRouterViews::HandleAccessibilityEvent( |
39 views::View* view, ui::AccessibilityTypes::Event event_type) { | 39 views::View* view, ui::AccessibilityTypes::Event event_type) { |
40 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | 40 if (!ExtensionAccessibilityEventRouter::GetInstance()-> |
41 IsAccessibilityEnabled()) { | 41 IsAccessibilityEnabled()) { |
42 return; | 42 return; |
43 } | 43 } |
44 | 44 |
45 switch (event_type) { | 45 switch (event_type) { |
46 case ui::AccessibilityTypes::EVENT_FOCUS: | 46 case ui::AccessibilityTypes::EVENT_FOCUS: |
47 DispatchAccessibilityNotification( | 47 DispatchAccessibilityNotification( |
48 view, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); | 48 view, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED); |
49 break; | 49 break; |
50 case ui::AccessibilityTypes::EVENT_MENUSTART: | 50 case ui::AccessibilityTypes::EVENT_MENUSTART: |
51 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: | 51 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: |
52 DispatchAccessibilityNotification( | 52 DispatchAccessibilityNotification( |
53 view, NotificationType::ACCESSIBILITY_MENU_OPENED); | 53 view, chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED); |
54 break; | 54 break; |
55 case ui::AccessibilityTypes::EVENT_MENUEND: | 55 case ui::AccessibilityTypes::EVENT_MENUEND: |
56 case ui::AccessibilityTypes::EVENT_MENUPOPUPEND: | 56 case ui::AccessibilityTypes::EVENT_MENUPOPUPEND: |
57 DispatchAccessibilityNotification( | 57 DispatchAccessibilityNotification( |
58 view, NotificationType::ACCESSIBILITY_MENU_CLOSED); | 58 view, chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED); |
59 break; | 59 break; |
60 case ui::AccessibilityTypes::EVENT_TEXT_CHANGED: | 60 case ui::AccessibilityTypes::EVENT_TEXT_CHANGED: |
61 case ui::AccessibilityTypes::EVENT_SELECTION_CHANGED: | 61 case ui::AccessibilityTypes::EVENT_SELECTION_CHANGED: |
62 DispatchAccessibilityNotification( | 62 DispatchAccessibilityNotification( |
63 view, NotificationType::ACCESSIBILITY_TEXT_CHANGED); | 63 view, chrome::NOTIFICATION_ACCESSIBILITY_TEXT_CHANGED); |
64 break; | 64 break; |
65 case ui::AccessibilityTypes::EVENT_VALUE_CHANGED: | 65 case ui::AccessibilityTypes::EVENT_VALUE_CHANGED: |
66 DispatchAccessibilityNotification( | 66 DispatchAccessibilityNotification( |
67 view, NotificationType::ACCESSIBILITY_CONTROL_ACTION); | 67 view, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_ACTION); |
68 break; | 68 break; |
69 case ui::AccessibilityTypes::EVENT_ALERT: | 69 case ui::AccessibilityTypes::EVENT_ALERT: |
70 DispatchAccessibilityNotification( | 70 DispatchAccessibilityNotification( |
71 view, NotificationType::ACCESSIBILITY_WINDOW_OPENED); | 71 view, chrome::NOTIFICATION_ACCESSIBILITY_WINDOW_OPENED); |
72 break; | 72 break; |
73 case ui::AccessibilityTypes::EVENT_NAME_CHANGED: | 73 case ui::AccessibilityTypes::EVENT_NAME_CHANGED: |
74 NOTIMPLEMENTED(); | 74 NOTIMPLEMENTED(); |
75 break; | 75 break; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void AccessibilityEventRouterViews::HandleMenuItemFocused( | 79 void AccessibilityEventRouterViews::HandleMenuItemFocused( |
80 const std::wstring& menu_name, | 80 const std::wstring& menu_name, |
81 const std::wstring& menu_item_name, | 81 const std::wstring& menu_item_name, |
82 int item_index, | 82 int item_index, |
83 int item_count, | 83 int item_count, |
84 bool has_submenu) { | 84 bool has_submenu) { |
85 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | 85 if (!ExtensionAccessibilityEventRouter::GetInstance()-> |
86 IsAccessibilityEnabled()) { | 86 IsAccessibilityEnabled()) { |
87 return; | 87 return; |
88 } | 88 } |
89 | 89 |
90 if (!most_recent_profile_) | 90 if (!most_recent_profile_) |
91 return; | 91 return; |
92 | 92 |
93 AccessibilityMenuItemInfo info( | 93 AccessibilityMenuItemInfo info( |
94 most_recent_profile_, | 94 most_recent_profile_, |
95 WideToUTF8(menu_item_name), | 95 WideToUTF8(menu_item_name), |
96 has_submenu, | 96 has_submenu, |
97 item_index, | 97 item_index, |
98 item_count); | 98 item_count); |
99 SendAccessibilityNotification( | 99 SendAccessibilityNotification( |
100 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, &info); | 100 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, &info); |
101 } | 101 } |
102 | 102 |
103 // | 103 // |
104 // Private methods | 104 // Private methods |
105 // | 105 // |
106 | 106 |
107 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( | 107 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( |
108 views::View* view, NotificationType type) { | 108 views::View* view, int type) { |
109 // Get the profile associated with this view. If it's not found, use | 109 // Get the profile associated with this view. If it's not found, use |
110 // the most recent profile where accessibility events were sent, or | 110 // the most recent profile where accessibility events were sent, or |
111 // the default profile. | 111 // the default profile. |
112 Profile* profile = NULL; | 112 Profile* profile = NULL; |
113 views::Widget* widget = view->GetWidget(); | 113 views::Widget* widget = view->GetWidget(); |
114 if (widget) { | 114 if (widget) { |
115 profile = reinterpret_cast<Profile*>( | 115 profile = reinterpret_cast<Profile*>( |
116 widget->GetNativeWindowProperty(Profile::kProfileKey)); | 116 widget->GetNativeWindowProperty(Profile::kProfileKey)); |
117 } | 117 } |
118 if (!profile) | 118 if (!profile) |
119 profile = most_recent_profile_; | 119 profile = most_recent_profile_; |
120 if (!profile) | 120 if (!profile) |
121 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | 121 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); |
122 if (!profile) { | 122 if (!profile) { |
123 NOTREACHED(); | 123 NOTREACHED(); |
124 return; | 124 return; |
125 } | 125 } |
126 | 126 |
127 most_recent_profile_ = profile; | 127 most_recent_profile_ = profile; |
128 | 128 |
129 if (type == NotificationType::ACCESSIBILITY_MENU_OPENED || | 129 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || |
130 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) { | 130 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) { |
131 SendMenuNotification(view, type, profile); | 131 SendMenuNotification(view, type, profile); |
132 return; | 132 return; |
133 } | 133 } |
134 | 134 |
135 ui::AccessibleViewState state; | 135 ui::AccessibleViewState state; |
136 view->GetAccessibleState(&state); | 136 view->GetAccessibleState(&state); |
137 switch (state.role) { | 137 switch (state.role) { |
138 case ui::AccessibilityTypes::ROLE_ALERT: | 138 case ui::AccessibilityTypes::ROLE_ALERT: |
139 SendWindowNotification(view, type, profile); | 139 SendWindowNotification(view, type, profile); |
140 break; | 140 break; |
(...skipping 26 matching lines...) Expand all Loading... |
167 // Not used anymore? | 167 // Not used anymore? |
168 default: | 168 default: |
169 // If this is encountered, please file a bug with the role that wasn't | 169 // If this is encountered, please file a bug with the role that wasn't |
170 // caught so we can add accessibility extension API support. | 170 // caught so we can add accessibility extension API support. |
171 NOTREACHED(); | 171 NOTREACHED(); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 void AccessibilityEventRouterViews::SendButtonNotification( | 175 void AccessibilityEventRouterViews::SendButtonNotification( |
176 views::View* view, | 176 views::View* view, |
177 NotificationType type, | 177 int type, |
178 Profile* profile) { | 178 Profile* profile) { |
179 AccessibilityButtonInfo info(profile, GetViewName(view)); | 179 AccessibilityButtonInfo info(profile, GetViewName(view)); |
180 SendAccessibilityNotification(type, &info); | 180 SendAccessibilityNotification(type, &info); |
181 } | 181 } |
182 | 182 |
183 void AccessibilityEventRouterViews::SendLinkNotification( | 183 void AccessibilityEventRouterViews::SendLinkNotification( |
184 views::View* view, | 184 views::View* view, |
185 NotificationType type, | 185 int type, |
186 Profile* profile) { | 186 Profile* profile) { |
187 AccessibilityLinkInfo info(profile, GetViewName(view)); | 187 AccessibilityLinkInfo info(profile, GetViewName(view)); |
188 SendAccessibilityNotification(type, &info); | 188 SendAccessibilityNotification(type, &info); |
189 } | 189 } |
190 | 190 |
191 void AccessibilityEventRouterViews::SendMenuNotification( | 191 void AccessibilityEventRouterViews::SendMenuNotification( |
192 views::View* view, | 192 views::View* view, |
193 NotificationType type, | 193 int type, |
194 Profile* profile) { | 194 Profile* profile) { |
195 AccessibilityMenuInfo info(profile, GetViewName(view)); | 195 AccessibilityMenuInfo info(profile, GetViewName(view)); |
196 SendAccessibilityNotification(type, &info); | 196 SendAccessibilityNotification(type, &info); |
197 } | 197 } |
198 | 198 |
199 void AccessibilityEventRouterViews::SendMenuItemNotification( | 199 void AccessibilityEventRouterViews::SendMenuItemNotification( |
200 views::View* view, | 200 views::View* view, |
201 NotificationType type, | 201 int type, |
202 Profile* profile) { | 202 Profile* profile) { |
203 std::string name = GetViewName(view); | 203 std::string name = GetViewName(view); |
204 | 204 |
205 bool has_submenu = false; | 205 bool has_submenu = false; |
206 int index = -1; | 206 int index = -1; |
207 int count = -1; | 207 int count = -1; |
208 | 208 |
209 if (view->GetClassName() == views::MenuItemView::kViewClassName) | 209 if (view->GetClassName() == views::MenuItemView::kViewClassName) |
210 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); | 210 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); |
211 | 211 |
212 views::View* parent_menu = view->parent(); | 212 views::View* parent_menu = view->parent(); |
213 while (parent_menu != NULL && parent_menu->GetClassName() != | 213 while (parent_menu != NULL && parent_menu->GetClassName() != |
214 views::SubmenuView::kViewClassName) { | 214 views::SubmenuView::kViewClassName) { |
215 parent_menu = parent_menu->parent(); | 215 parent_menu = parent_menu->parent(); |
216 } | 216 } |
217 if (parent_menu) { | 217 if (parent_menu) { |
218 count = 0; | 218 count = 0; |
219 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); | 219 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); |
220 } | 220 } |
221 | 221 |
222 AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count); | 222 AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count); |
223 SendAccessibilityNotification(type, &info); | 223 SendAccessibilityNotification(type, &info); |
224 } | 224 } |
225 | 225 |
226 void AccessibilityEventRouterViews::SendTextfieldNotification( | 226 void AccessibilityEventRouterViews::SendTextfieldNotification( |
227 views::View* view, | 227 views::View* view, |
228 NotificationType type, | 228 int type, |
229 Profile* profile) { | 229 Profile* profile) { |
230 ui::AccessibleViewState state; | 230 ui::AccessibleViewState state; |
231 view->GetAccessibleState(&state); | 231 view->GetAccessibleState(&state); |
232 std::string name = UTF16ToUTF8(state.name); | 232 std::string name = UTF16ToUTF8(state.name); |
233 bool password = | 233 bool password = |
234 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; | 234 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; |
235 AccessibilityTextBoxInfo info(profile, name, password); | 235 AccessibilityTextBoxInfo info(profile, name, password); |
236 std::string value = UTF16ToUTF8(state.value); | 236 std::string value = UTF16ToUTF8(state.value); |
237 info.SetValue(value, state.selection_start, state.selection_end); | 237 info.SetValue(value, state.selection_start, state.selection_end); |
238 SendAccessibilityNotification(type, &info); | 238 SendAccessibilityNotification(type, &info); |
239 } | 239 } |
240 | 240 |
241 void AccessibilityEventRouterViews::SendComboboxNotification( | 241 void AccessibilityEventRouterViews::SendComboboxNotification( |
242 views::View* view, | 242 views::View* view, |
243 NotificationType type, | 243 int type, |
244 Profile* profile) { | 244 Profile* profile) { |
245 ui::AccessibleViewState state; | 245 ui::AccessibleViewState state; |
246 view->GetAccessibleState(&state); | 246 view->GetAccessibleState(&state); |
247 std::string name = UTF16ToUTF8(state.name); | 247 std::string name = UTF16ToUTF8(state.name); |
248 std::string value = UTF16ToUTF8(state.value); | 248 std::string value = UTF16ToUTF8(state.value); |
249 AccessibilityComboBoxInfo info( | 249 AccessibilityComboBoxInfo info( |
250 profile, name, value, state.index, state.count); | 250 profile, name, value, state.index, state.count); |
251 SendAccessibilityNotification(type, &info); | 251 SendAccessibilityNotification(type, &info); |
252 } | 252 } |
253 | 253 |
254 void AccessibilityEventRouterViews::SendCheckboxNotification( | 254 void AccessibilityEventRouterViews::SendCheckboxNotification( |
255 views::View* view, | 255 views::View* view, |
256 NotificationType type, | 256 int type, |
257 Profile* profile) { | 257 Profile* profile) { |
258 ui::AccessibleViewState state; | 258 ui::AccessibleViewState state; |
259 view->GetAccessibleState(&state); | 259 view->GetAccessibleState(&state); |
260 std::string name = UTF16ToUTF8(state.name); | 260 std::string name = UTF16ToUTF8(state.name); |
261 std::string value = UTF16ToUTF8(state.value); | 261 std::string value = UTF16ToUTF8(state.value); |
262 AccessibilityCheckboxInfo info( | 262 AccessibilityCheckboxInfo info( |
263 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); | 263 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); |
264 SendAccessibilityNotification(type, &info); | 264 SendAccessibilityNotification(type, &info); |
265 } | 265 } |
266 | 266 |
267 void AccessibilityEventRouterViews::SendWindowNotification( | 267 void AccessibilityEventRouterViews::SendWindowNotification( |
268 views::View* view, | 268 views::View* view, |
269 NotificationType type, | 269 int type, |
270 Profile* profile) { | 270 Profile* profile) { |
271 ui::AccessibleViewState state; | 271 ui::AccessibleViewState state; |
272 view->GetAccessibleState(&state); | 272 view->GetAccessibleState(&state); |
273 std::string window_text; | 273 std::string window_text; |
274 | 274 |
275 // If it's an alert, try to get the text from the contents of the | 275 // If it's an alert, try to get the text from the contents of the |
276 // static text, not the window title. | 276 // static text, not the window title. |
277 if (state.role == ui::AccessibilityTypes::ROLE_ALERT) | 277 if (state.role == ui::AccessibilityTypes::ROLE_ALERT) |
278 window_text = RecursiveGetStaticText(view); | 278 window_text = RecursiveGetStaticText(view); |
279 | 279 |
280 // Otherwise get it from the window's accessible name. | 280 // Otherwise get it from the window's accessible name. |
281 if (window_text.empty()) | 281 if (window_text.empty()) |
282 window_text = UTF16ToUTF8(state.name); | 282 window_text = UTF16ToUTF8(state.name); |
283 | 283 |
284 AccessibilityWindowInfo info(profile, window_text); | 284 AccessibilityWindowInfo info(profile, window_text); |
285 SendAccessibilityNotification(type, &info); | 285 SendAccessibilityNotification(type, &info); |
286 } | 286 } |
287 | 287 |
288 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { | 288 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { |
289 ui::AccessibleViewState state; | 289 ui::AccessibleViewState state; |
290 view->GetAccessibleState(&state); | 290 view->GetAccessibleState(&state); |
291 return UTF16ToUTF8(state.name); | 291 return UTF16ToUTF8(state.name); |
292 } | 292 } |
293 | 293 |
294 bool AccessibilityEventRouterViews::IsMenuEvent( | 294 bool AccessibilityEventRouterViews::IsMenuEvent( |
295 views::View* view, | 295 views::View* view, |
296 NotificationType type) { | 296 int type) { |
297 if (type == NotificationType::ACCESSIBILITY_MENU_OPENED || | 297 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || |
298 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) | 298 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) |
299 return true; | 299 return true; |
300 | 300 |
301 while (view) { | 301 while (view) { |
302 ui::AccessibleViewState state; | 302 ui::AccessibleViewState state; |
303 view->GetAccessibleState(&state); | 303 view->GetAccessibleState(&state); |
304 ui::AccessibilityTypes::Role role = state.role; | 304 ui::AccessibilityTypes::Role role = state.role; |
305 if (role == ui::AccessibilityTypes::ROLE_MENUITEM || | 305 if (role == ui::AccessibilityTypes::ROLE_MENUITEM || |
306 role == ui::AccessibilityTypes::ROLE_MENUPOPUP) { | 306 role == ui::AccessibilityTypes::ROLE_MENUPOPUP) { |
307 return true; | 307 return true; |
308 } | 308 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 return UTF16ToUTF8(state.name); | 342 return UTF16ToUTF8(state.name); |
343 | 343 |
344 for (int i = 0; i < view->child_count(); ++i) { | 344 for (int i = 0; i < view->child_count(); ++i) { |
345 views::View* child = view->GetChildViewAt(i); | 345 views::View* child = view->GetChildViewAt(i); |
346 std::string result = RecursiveGetStaticText(child); | 346 std::string result = RecursiveGetStaticText(child); |
347 if (!result.empty()) | 347 if (!result.empty()) |
348 return result; | 348 return result; |
349 } | 349 } |
350 return std::string(); | 350 return std::string(); |
351 } | 351 } |
OLD | NEW |