Chromium Code Reviews| 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" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 // caught so we can add accessibility extension API support. | 168 // caught so we can add accessibility extension API support. |
| 169 NOTREACHED(); | 169 NOTREACHED(); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 void AccessibilityEventRouterViews::SendButtonNotification( | 173 void AccessibilityEventRouterViews::SendButtonNotification( |
| 174 views::View* view, | 174 views::View* view, |
| 175 int type, | 175 int type, |
| 176 Profile* profile) { | 176 Profile* profile) { |
| 177 AccessibilityButtonInfo info(profile, GetViewName(view)); | 177 AccessibilityButtonInfo info(profile, GetViewName(view)); |
| 178 AddContextInfo(view, &info); | |
| 178 SendAccessibilityNotification(type, &info); | 179 SendAccessibilityNotification(type, &info); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void AccessibilityEventRouterViews::SendLinkNotification( | 182 void AccessibilityEventRouterViews::SendLinkNotification( |
| 182 views::View* view, | 183 views::View* view, |
| 183 int type, | 184 int type, |
| 184 Profile* profile) { | 185 Profile* profile) { |
| 185 AccessibilityLinkInfo info(profile, GetViewName(view)); | 186 AccessibilityLinkInfo info(profile, GetViewName(view)); |
| 187 AddContextInfo(view, &info); | |
| 186 SendAccessibilityNotification(type, &info); | 188 SendAccessibilityNotification(type, &info); |
| 187 } | 189 } |
| 188 | 190 |
| 189 void AccessibilityEventRouterViews::SendMenuNotification( | 191 void AccessibilityEventRouterViews::SendMenuNotification( |
| 190 views::View* view, | 192 views::View* view, |
| 191 int type, | 193 int type, |
| 192 Profile* profile) { | 194 Profile* profile) { |
| 193 AccessibilityMenuInfo info(profile, GetViewName(view)); | 195 AccessibilityMenuInfo info(profile, GetViewName(view)); |
| 196 AddContextInfo(view, &info); | |
| 194 SendAccessibilityNotification(type, &info); | 197 SendAccessibilityNotification(type, &info); |
| 195 } | 198 } |
| 196 | 199 |
| 197 void AccessibilityEventRouterViews::SendMenuItemNotification( | 200 void AccessibilityEventRouterViews::SendMenuItemNotification( |
| 198 views::View* view, | 201 views::View* view, |
| 199 int type, | 202 int type, |
| 200 Profile* profile) { | 203 Profile* profile) { |
| 201 std::string name = GetViewName(view); | 204 std::string name = GetViewName(view); |
| 202 | 205 |
| 203 bool has_submenu = false; | 206 bool has_submenu = false; |
| 204 int index = -1; | 207 int index = -1; |
| 205 int count = -1; | 208 int count = -1; |
| 206 | 209 |
| 207 if (view->GetClassName() == views::MenuItemView::kViewClassName) | 210 if (view->GetClassName() == views::MenuItemView::kViewClassName) |
| 208 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); | 211 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); |
| 209 | 212 |
| 210 views::View* parent_menu = view->parent(); | 213 views::View* parent_menu = view->parent(); |
| 211 while (parent_menu != NULL && parent_menu->GetClassName() != | 214 while (parent_menu != NULL && parent_menu->GetClassName() != |
| 212 views::SubmenuView::kViewClassName) { | 215 views::SubmenuView::kViewClassName) { |
| 213 parent_menu = parent_menu->parent(); | 216 parent_menu = parent_menu->parent(); |
| 214 } | 217 } |
| 215 if (parent_menu) { | 218 if (parent_menu) { |
| 216 count = 0; | 219 count = 0; |
| 217 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); | 220 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); |
| 218 } | 221 } |
| 219 | 222 |
| 220 AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count); | 223 AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count); |
| 224 AddContextInfo(view, &info); | |
| 221 SendAccessibilityNotification(type, &info); | 225 SendAccessibilityNotification(type, &info); |
| 222 } | 226 } |
| 223 | 227 |
| 224 void AccessibilityEventRouterViews::SendTextfieldNotification( | 228 void AccessibilityEventRouterViews::SendTextfieldNotification( |
| 225 views::View* view, | 229 views::View* view, |
| 226 int type, | 230 int type, |
| 227 Profile* profile) { | 231 Profile* profile) { |
| 228 ui::AccessibleViewState state; | 232 ui::AccessibleViewState state; |
| 229 view->GetAccessibleState(&state); | 233 view->GetAccessibleState(&state); |
| 230 std::string name = UTF16ToUTF8(state.name); | 234 std::string name = UTF16ToUTF8(state.name); |
| 231 bool password = | 235 bool password = |
| 232 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; | 236 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; |
| 233 AccessibilityTextBoxInfo info(profile, name, password); | 237 AccessibilityTextBoxInfo info(profile, name, password); |
| 234 std::string value = UTF16ToUTF8(state.value); | 238 std::string value = UTF16ToUTF8(state.value); |
| 235 info.SetValue(value, state.selection_start, state.selection_end); | 239 info.SetValue(value, state.selection_start, state.selection_end); |
| 240 AddContextInfo(view, &info); | |
| 236 SendAccessibilityNotification(type, &info); | 241 SendAccessibilityNotification(type, &info); |
| 237 } | 242 } |
| 238 | 243 |
| 239 void AccessibilityEventRouterViews::SendComboboxNotification( | 244 void AccessibilityEventRouterViews::SendComboboxNotification( |
| 240 views::View* view, | 245 views::View* view, |
| 241 int type, | 246 int type, |
| 242 Profile* profile) { | 247 Profile* profile) { |
| 243 ui::AccessibleViewState state; | 248 ui::AccessibleViewState state; |
| 244 view->GetAccessibleState(&state); | 249 view->GetAccessibleState(&state); |
| 245 std::string name = UTF16ToUTF8(state.name); | 250 std::string name = UTF16ToUTF8(state.name); |
| 246 std::string value = UTF16ToUTF8(state.value); | 251 std::string value = UTF16ToUTF8(state.value); |
| 247 AccessibilityComboBoxInfo info( | 252 AccessibilityComboBoxInfo info( |
| 248 profile, name, value, state.index, state.count); | 253 profile, name, value, state.index, state.count); |
| 254 AddContextInfo(view, &info); | |
| 249 SendAccessibilityNotification(type, &info); | 255 SendAccessibilityNotification(type, &info); |
| 250 } | 256 } |
| 251 | 257 |
| 252 void AccessibilityEventRouterViews::SendCheckboxNotification( | 258 void AccessibilityEventRouterViews::SendCheckboxNotification( |
| 253 views::View* view, | 259 views::View* view, |
| 254 int type, | 260 int type, |
| 255 Profile* profile) { | 261 Profile* profile) { |
| 256 ui::AccessibleViewState state; | 262 ui::AccessibleViewState state; |
| 257 view->GetAccessibleState(&state); | 263 view->GetAccessibleState(&state); |
| 258 std::string name = UTF16ToUTF8(state.name); | 264 std::string name = UTF16ToUTF8(state.name); |
| 259 std::string value = UTF16ToUTF8(state.value); | 265 std::string value = UTF16ToUTF8(state.value); |
| 260 AccessibilityCheckboxInfo info( | 266 AccessibilityCheckboxInfo info( |
| 261 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); | 267 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); |
| 268 AddContextInfo(view, &info); | |
| 262 SendAccessibilityNotification(type, &info); | 269 SendAccessibilityNotification(type, &info); |
| 263 } | 270 } |
| 264 | 271 |
| 265 void AccessibilityEventRouterViews::SendWindowNotification( | 272 void AccessibilityEventRouterViews::SendWindowNotification( |
| 266 views::View* view, | 273 views::View* view, |
| 267 int type, | 274 int type, |
| 268 Profile* profile) { | 275 Profile* profile) { |
| 269 ui::AccessibleViewState state; | 276 ui::AccessibleViewState state; |
| 270 view->GetAccessibleState(&state); | 277 view->GetAccessibleState(&state); |
| 271 std::string window_text; | 278 std::string window_text; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 282 AccessibilityWindowInfo info(profile, window_text); | 289 AccessibilityWindowInfo info(profile, window_text); |
| 283 SendAccessibilityNotification(type, &info); | 290 SendAccessibilityNotification(type, &info); |
| 284 } | 291 } |
| 285 | 292 |
| 286 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { | 293 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { |
| 287 ui::AccessibleViewState state; | 294 ui::AccessibleViewState state; |
| 288 view->GetAccessibleState(&state); | 295 view->GetAccessibleState(&state); |
| 289 return UTF16ToUTF8(state.name); | 296 return UTF16ToUTF8(state.name); |
| 290 } | 297 } |
| 291 | 298 |
| 299 void AccessibilityEventRouterViews::AddContextInfo( | |
|
sky
2011/12/07 22:01:55
Order should match header.
dmazzoni
2011/12/07 23:13:49
Done.
| |
| 300 views::View* view, AccessibilityControlInfo* info) { | |
| 301 for (views::View* parent = view->parent(); | |
| 302 parent; | |
| 303 parent = parent->parent()) { | |
| 304 ui::AccessibleViewState state; | |
| 305 parent->GetAccessibleState(&state); | |
| 306 | |
| 307 // Two cases are handled right now. More could be added in the future | |
| 308 // depending on how the UI evolves. | |
| 309 | |
| 310 // A control in a toolbar should use the toolbar's accessible name | |
| 311 // as the context. | |
| 312 if (state.role == ui::AccessibilityTypes::ROLE_TOOLBAR && | |
| 313 !state.name.empty()) { | |
| 314 info->set_context(UTF16ToUTF8(state.name)); | |
| 315 return; | |
| 316 } | |
| 317 | |
| 318 // A control inside of an alert (like an infobar) should grab the | |
| 319 // first static text descendant as the context; that's the prompt. | |
| 320 if (state.role == ui::AccessibilityTypes::ROLE_ALERT) { | |
| 321 views::View* static_text_child = FindDescendantWithAccessibleRole( | |
| 322 parent, ui::AccessibilityTypes::ROLE_STATICTEXT); | |
| 323 if (static_text_child) { | |
|
sky
2011/12/07 22:01:55
I don't know this code well enough, so this might
dmazzoni
2011/12/07 23:13:49
That should never happen (multiple ALERTs in the p
| |
| 324 ui::AccessibleViewState state; | |
| 325 static_text_child->GetAccessibleState(&state); | |
| 326 if (!state.name.empty()) { | |
| 327 info->set_context(UTF16ToUTF8(state.name)); | |
| 328 return; | |
| 329 } | |
| 330 } | |
| 331 } | |
| 332 } | |
| 333 } | |
| 334 | |
| 335 views::View* AccessibilityEventRouterViews::FindDescendantWithAccessibleRole( | |
|
sky
2011/12/07 22:01:55
Neither of these methods look like they need any s
dmazzoni
2011/12/07 23:13:49
Done - made a few more methods static too.
| |
| 336 views::View* view, ui::AccessibilityTypes::Role role) { | |
| 337 ui::AccessibleViewState state; | |
| 338 view->GetAccessibleState(&state); | |
| 339 if (state.role == role) | |
| 340 return view; | |
| 341 | |
| 342 for (int i = 0; i < view->child_count(); i++) { | |
| 343 views::View* child = view->child_at(i); | |
| 344 views::View* result = FindDescendantWithAccessibleRole(child, role); | |
| 345 if (result) | |
| 346 return result; | |
| 347 } | |
| 348 | |
| 349 return NULL; | |
| 350 } | |
| 351 | |
| 292 bool AccessibilityEventRouterViews::IsMenuEvent( | 352 bool AccessibilityEventRouterViews::IsMenuEvent( |
| 293 views::View* view, | 353 views::View* view, |
| 294 int type) { | 354 int type) { |
| 295 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || | 355 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || |
| 296 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) | 356 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) |
| 297 return true; | 357 return true; |
| 298 | 358 |
| 299 while (view) { | 359 while (view) { |
| 300 ui::AccessibleViewState state; | 360 ui::AccessibleViewState state; |
| 301 view->GetAccessibleState(&state); | 361 view->GetAccessibleState(&state); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 return UTF16ToUTF8(state.name); | 400 return UTF16ToUTF8(state.name); |
| 341 | 401 |
| 342 for (int i = 0; i < view->child_count(); ++i) { | 402 for (int i = 0; i < view->child_count(); ++i) { |
| 343 views::View* child = view->child_at(i); | 403 views::View* child = view->child_at(i); |
| 344 std::string result = RecursiveGetStaticText(child); | 404 std::string result = RecursiveGetStaticText(child); |
| 345 if (!result.empty()) | 405 if (!result.empty()) |
| 346 return result; | 406 return result; |
| 347 } | 407 } |
| 348 return std::string(); | 408 return std::string(); |
| 349 } | 409 } |
| OLD | NEW |