| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/accessibility_event_router_views
.h" | 5 #include "chrome/browser/ui/views/accessibility/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/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/accessibility/accessibility_extension_api.h" | 12 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_source.h" | |
| 19 #include "ui/base/accessibility/accessible_view_state.h" | 18 #include "ui/base/accessibility/accessible_view_state.h" |
| 20 #include "ui/views/controls/menu/menu_item_view.h" | 19 #include "ui/views/controls/menu/menu_item_view.h" |
| 21 #include "ui/views/controls/menu/submenu_view.h" | 20 #include "ui/views/controls/menu/submenu_view.h" |
| 22 #include "ui/views/focus/view_storage.h" | 21 #include "ui/views/focus/view_storage.h" |
| 23 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 25 | 24 |
| 26 using views::FocusManager; | 25 using views::FocusManager; |
| 27 | 26 |
| 28 AccessibilityEventRouterViews::AccessibilityEventRouterViews() | 27 AccessibilityEventRouterViews::AccessibilityEventRouterViews() |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 return Singleton<AccessibilityEventRouterViews>::get(); | 40 return Singleton<AccessibilityEventRouterViews>::get(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void AccessibilityEventRouterViews::HandleAccessibilityEvent( | 43 void AccessibilityEventRouterViews::HandleAccessibilityEvent( |
| 45 views::View* view, ui::AccessibilityTypes::Event event_type) { | 44 views::View* view, ui::AccessibilityTypes::Event event_type) { |
| 46 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | 45 if (!ExtensionAccessibilityEventRouter::GetInstance()-> |
| 47 IsAccessibilityEnabled()) { | 46 IsAccessibilityEnabled()) { |
| 48 return; | 47 return; |
| 49 } | 48 } |
| 50 | 49 |
| 51 chrome::NotificationType notification_type; | 50 if (event_type == ui::AccessibilityTypes::EVENT_TEXT_CHANGED || |
| 52 switch (event_type) { | 51 event_type == ui::AccessibilityTypes::EVENT_SELECTION_CHANGED) { |
| 53 case ui::AccessibilityTypes::EVENT_FOCUS: | 52 // These two events should only be sent for views that have focus. This |
| 54 notification_type = chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED; | 53 // enforces the invariant that we fire events triggered by user action and |
| 55 break; | 54 // not by programmatic logic. For example, the location bar can be updated |
| 56 case ui::AccessibilityTypes::EVENT_MENUSTART: | 55 // by javascript while the user focus is within some other part of the |
| 57 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: | 56 // user interface. In contrast, the other supported events here do not |
| 58 notification_type = chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED; | 57 // depend on focus. For example, a menu within a menubar can open or close |
| 59 break; | 58 // while focus is within the location bar or anywhere else as a result of |
| 60 case ui::AccessibilityTypes::EVENT_MENUEND: | 59 // user action. Note that the below logic can at some point be removed if |
| 61 case ui::AccessibilityTypes::EVENT_MENUPOPUPEND: | 60 // we pass more information along to the listener such as focused state. |
| 62 notification_type = chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED; | 61 if (!view->GetFocusManager() || |
| 63 break; | 62 view->GetFocusManager()->GetFocusedView() != view) |
| 64 case ui::AccessibilityTypes::EVENT_TEXT_CHANGED: | |
| 65 case ui::AccessibilityTypes::EVENT_SELECTION_CHANGED: | |
| 66 // These two events should only be sent for views that have focus. This | |
| 67 // enforces the invariant that we fire events triggered by user action and | |
| 68 // not by programmatic logic. For example, the location bar can be updated | |
| 69 // by javascript while the user focus is within some other part of the | |
| 70 // user interface. In contrast, the other supported events here do not | |
| 71 // depend on focus. For example, a menu within a menubar can open or close | |
| 72 // while focus is within the location bar or anywhere else as a result of | |
| 73 // user action. Note that the below logic can at some point be removed if | |
| 74 // we pass more information along to the listener such as focused state. | |
| 75 if (!view->GetFocusManager() || | |
| 76 view->GetFocusManager()->GetFocusedView() != view) | |
| 77 return; | |
| 78 notification_type = chrome::NOTIFICATION_ACCESSIBILITY_TEXT_CHANGED; | |
| 79 break; | |
| 80 case ui::AccessibilityTypes::EVENT_VALUE_CHANGED: | |
| 81 notification_type = chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_ACTION; | |
| 82 break; | |
| 83 case ui::AccessibilityTypes::EVENT_ALERT: | |
| 84 notification_type = chrome::NOTIFICATION_ACCESSIBILITY_WINDOW_OPENED; | |
| 85 break; | |
| 86 case ui::AccessibilityTypes::EVENT_NAME_CHANGED: | |
| 87 default: | |
| 88 NOTIMPLEMENTED(); | |
| 89 return; | 63 return; |
| 90 } | 64 } |
| 91 | 65 |
| 92 // Don't dispatch the accessibility event until the next time through the | 66 // Don't dispatch the accessibility event until the next time through the |
| 93 // event loop, to handle cases where the view's state changes after | 67 // event loop, to handle cases where the view's state changes after |
| 94 // the call to post the event. It's safe to use base::Unretained(this) | 68 // the call to post the event. It's safe to use base::Unretained(this) |
| 95 // because AccessibilityEventRouterViews is a singleton. | 69 // because AccessibilityEventRouterViews is a singleton. |
| 96 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); | 70 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); |
| 97 int view_storage_id = view_storage->CreateStorageID(); | 71 int view_storage_id = view_storage->CreateStorageID(); |
| 98 view_storage->StoreView(view_storage_id, view); | 72 view_storage->StoreView(view_storage_id, view); |
| 99 base::MessageLoop::current()->PostTask( | 73 base::MessageLoop::current()->PostTask( |
| 100 FROM_HERE, | 74 FROM_HERE, |
| 101 base::Bind( | 75 base::Bind( |
| 102 &AccessibilityEventRouterViews::DispatchNotificationOnViewStorageId, | 76 &AccessibilityEventRouterViews::DispatchEventOnViewStorageId, |
| 103 view_storage_id, | 77 view_storage_id, |
| 104 notification_type)); | 78 event_type)); |
| 105 } | 79 } |
| 106 | 80 |
| 107 void AccessibilityEventRouterViews::HandleMenuItemFocused( | 81 void AccessibilityEventRouterViews::HandleMenuItemFocused( |
| 108 const string16& menu_name, | 82 const string16& menu_name, |
| 109 const string16& menu_item_name, | 83 const string16& menu_item_name, |
| 110 int item_index, | 84 int item_index, |
| 111 int item_count, | 85 int item_count, |
| 112 bool has_submenu) { | 86 bool has_submenu) { |
| 113 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | 87 if (!ExtensionAccessibilityEventRouter::GetInstance()-> |
| 114 IsAccessibilityEnabled()) { | 88 IsAccessibilityEnabled()) { |
| 115 return; | 89 return; |
| 116 } | 90 } |
| 117 | 91 |
| 118 if (!most_recent_profile_) | 92 if (!most_recent_profile_) |
| 119 return; | 93 return; |
| 120 | 94 |
| 121 AccessibilityMenuItemInfo info(most_recent_profile_, | 95 AccessibilityMenuItemInfo info(most_recent_profile_, |
| 122 UTF16ToUTF8(menu_item_name), | 96 UTF16ToUTF8(menu_item_name), |
| 123 UTF16ToUTF8(menu_name), | 97 UTF16ToUTF8(menu_name), |
| 124 has_submenu, | 98 has_submenu, |
| 125 item_index, | 99 item_index, |
| 126 item_count); | 100 item_count); |
| 127 SendAccessibilityNotification( | 101 SendControlAccessibilityNotification( |
| 128 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, &info); | 102 ui::AccessibilityTypes::EVENT_FOCUS, &info); |
| 129 } | 103 } |
| 130 | 104 |
| 131 void AccessibilityEventRouterViews::Observe( | 105 void AccessibilityEventRouterViews::Observe( |
| 132 int type, | 106 int type, |
| 133 const content::NotificationSource& source, | 107 const content::NotificationSource& source, |
| 134 const content::NotificationDetails& details) { | 108 const content::NotificationDetails& details) { |
| 135 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); | 109 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); |
| 136 Profile* profile = content::Source<Profile>(source).ptr(); | 110 Profile* profile = content::Source<Profile>(source).ptr(); |
| 137 if (profile == most_recent_profile_) | 111 if (profile == most_recent_profile_) |
| 138 most_recent_profile_ = NULL; | 112 most_recent_profile_ = NULL; |
| 139 } | 113 } |
| 140 | 114 |
| 141 // | 115 // |
| 142 // Private methods | 116 // Private methods |
| 143 // | 117 // |
| 144 | 118 |
| 145 void AccessibilityEventRouterViews::DispatchNotificationOnViewStorageId( | 119 void AccessibilityEventRouterViews::DispatchEventOnViewStorageId( |
| 146 int view_storage_id, | 120 int view_storage_id, |
| 147 chrome::NotificationType type) { | 121 ui::AccessibilityTypes::Event type) { |
| 148 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); | 122 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); |
| 149 views::View* view = view_storage->RetrieveView(view_storage_id); | 123 views::View* view = view_storage->RetrieveView(view_storage_id); |
| 150 view_storage->RemoveView(view_storage_id); | 124 view_storage->RemoveView(view_storage_id); |
| 151 if (!view) | 125 if (!view) |
| 152 return; | 126 return; |
| 153 | 127 |
| 154 AccessibilityEventRouterViews* instance = | 128 AccessibilityEventRouterViews* instance = |
| 155 AccessibilityEventRouterViews::GetInstance(); | 129 AccessibilityEventRouterViews::GetInstance(); |
| 156 instance->DispatchAccessibilityNotification(view, type); | 130 instance->DispatchAccessibilityEvent(view, type); |
| 157 } | 131 } |
| 158 | 132 |
| 159 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( | 133 void AccessibilityEventRouterViews::DispatchAccessibilityEvent( |
| 160 views::View* view, chrome::NotificationType type) { | 134 views::View* view, ui::AccessibilityTypes::Event type) { |
| 161 // Get the profile associated with this view. If it's not found, use | 135 // Get the profile associated with this view. If it's not found, use |
| 162 // the most recent profile where accessibility events were sent, or | 136 // the most recent profile where accessibility events were sent, or |
| 163 // the default profile. | 137 // the default profile. |
| 164 Profile* profile = NULL; | 138 Profile* profile = NULL; |
| 165 views::Widget* widget = view->GetWidget(); | 139 views::Widget* widget = view->GetWidget(); |
| 166 if (widget) { | 140 if (widget) { |
| 167 profile = reinterpret_cast<Profile*>( | 141 profile = reinterpret_cast<Profile*>( |
| 168 widget->GetNativeWindowProperty(Profile::kProfileKey)); | 142 widget->GetNativeWindowProperty(Profile::kProfileKey)); |
| 169 } | 143 } |
| 170 if (!profile) | 144 if (!profile) |
| 171 profile = most_recent_profile_; | 145 profile = most_recent_profile_; |
| 172 if (!profile) { | 146 if (!profile) { |
| 173 if (g_browser_process->profile_manager()) | 147 if (g_browser_process->profile_manager()) |
| 174 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | 148 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 175 } | 149 } |
| 176 if (!profile) { | 150 if (!profile) { |
| 177 LOG(WARNING) << "Accessibility notification but no profile"; | 151 LOG(WARNING) << "Accessibility notification but no profile"; |
| 178 return; | 152 return; |
| 179 } | 153 } |
| 180 | 154 |
| 181 most_recent_profile_ = profile; | 155 most_recent_profile_ = profile; |
| 182 | 156 |
| 183 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || | 157 if (type == ui::AccessibilityTypes::EVENT_MENUSTART || |
| 184 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) { | 158 type == ui::AccessibilityTypes::EVENT_MENUPOPUPSTART || |
| 159 type == ui::AccessibilityTypes::EVENT_MENUEND || |
| 160 type == ui::AccessibilityTypes::EVENT_MENUPOPUPEND) { |
| 185 SendMenuNotification(view, type, profile); | 161 SendMenuNotification(view, type, profile); |
| 186 return; | 162 return; |
| 187 } | 163 } |
| 188 | 164 |
| 189 ui::AccessibleViewState state; | 165 ui::AccessibleViewState state; |
| 190 view->GetAccessibleState(&state); | 166 view->GetAccessibleState(&state); |
| 191 | 167 |
| 192 switch (state.role) { | 168 switch (state.role) { |
| 193 case ui::AccessibilityTypes::ROLE_ALERT: | 169 case ui::AccessibilityTypes::ROLE_ALERT: |
| 194 case ui::AccessibilityTypes::ROLE_WINDOW: | 170 case ui::AccessibilityTypes::ROLE_WINDOW: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 default: | 203 default: |
| 228 // If this is encountered, please file a bug with the role that wasn't | 204 // If this is encountered, please file a bug with the role that wasn't |
| 229 // caught so we can add accessibility extension API support. | 205 // caught so we can add accessibility extension API support. |
| 230 NOTREACHED(); | 206 NOTREACHED(); |
| 231 } | 207 } |
| 232 } | 208 } |
| 233 | 209 |
| 234 // static | 210 // static |
| 235 void AccessibilityEventRouterViews::SendButtonNotification( | 211 void AccessibilityEventRouterViews::SendButtonNotification( |
| 236 views::View* view, | 212 views::View* view, |
| 237 int type, | 213 ui::AccessibilityTypes::Event event, |
| 238 Profile* profile) { | 214 Profile* profile) { |
| 239 AccessibilityButtonInfo info( | 215 AccessibilityButtonInfo info( |
| 240 profile, GetViewName(view), GetViewContext(view)); | 216 profile, GetViewName(view), GetViewContext(view)); |
| 241 SendAccessibilityNotification(type, &info); | 217 SendControlAccessibilityNotification(event, &info); |
| 242 } | 218 } |
| 243 | 219 |
| 244 // static | 220 // static |
| 245 void AccessibilityEventRouterViews::SendLinkNotification( | 221 void AccessibilityEventRouterViews::SendLinkNotification( |
| 246 views::View* view, | 222 views::View* view, |
| 247 int type, | 223 ui::AccessibilityTypes::Event event, |
| 248 Profile* profile) { | 224 Profile* profile) { |
| 249 AccessibilityLinkInfo info(profile, GetViewName(view), GetViewContext(view)); | 225 AccessibilityLinkInfo info(profile, GetViewName(view), GetViewContext(view)); |
| 250 SendAccessibilityNotification(type, &info); | 226 SendControlAccessibilityNotification(event, &info); |
| 251 } | 227 } |
| 252 | 228 |
| 253 // static | 229 // static |
| 254 void AccessibilityEventRouterViews::SendMenuNotification( | 230 void AccessibilityEventRouterViews::SendMenuNotification( |
| 255 views::View* view, | 231 views::View* view, |
| 256 int type, | 232 ui::AccessibilityTypes::Event event, |
| 257 Profile* profile) { | 233 Profile* profile) { |
| 258 AccessibilityMenuInfo info(profile, GetViewName(view)); | 234 AccessibilityMenuInfo info(profile, GetViewName(view)); |
| 259 SendAccessibilityNotification(type, &info); | 235 SendMenuAccessibilityNotification(event, &info); |
| 260 } | 236 } |
| 261 | 237 |
| 262 // static | 238 // static |
| 263 void AccessibilityEventRouterViews::SendMenuItemNotification( | 239 void AccessibilityEventRouterViews::SendMenuItemNotification( |
| 264 views::View* view, | 240 views::View* view, |
| 265 int type, | 241 ui::AccessibilityTypes::Event event, |
| 266 Profile* profile) { | 242 Profile* profile) { |
| 267 std::string name = GetViewName(view); | 243 std::string name = GetViewName(view); |
| 268 std::string context = GetViewContext(view); | 244 std::string context = GetViewContext(view); |
| 269 | 245 |
| 270 bool has_submenu = false; | 246 bool has_submenu = false; |
| 271 int index = -1; | 247 int index = -1; |
| 272 int count = -1; | 248 int count = -1; |
| 273 | 249 |
| 274 if (!strcmp(view->GetClassName(), views::MenuItemView::kViewClassName)) | 250 if (!strcmp(view->GetClassName(), views::MenuItemView::kViewClassName)) |
| 275 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); | 251 has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); |
| 276 | 252 |
| 277 views::View* parent_menu = view->parent(); | 253 views::View* parent_menu = view->parent(); |
| 278 while (parent_menu != NULL && strcmp(parent_menu->GetClassName(), | 254 while (parent_menu != NULL && strcmp(parent_menu->GetClassName(), |
| 279 views::SubmenuView::kViewClassName)) { | 255 views::SubmenuView::kViewClassName)) { |
| 280 parent_menu = parent_menu->parent(); | 256 parent_menu = parent_menu->parent(); |
| 281 } | 257 } |
| 282 if (parent_menu) { | 258 if (parent_menu) { |
| 283 count = 0; | 259 count = 0; |
| 284 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); | 260 RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); |
| 285 } | 261 } |
| 286 | 262 |
| 287 AccessibilityMenuItemInfo info( | 263 AccessibilityMenuItemInfo info( |
| 288 profile, name, context, has_submenu, index, count); | 264 profile, name, context, has_submenu, index, count); |
| 289 SendAccessibilityNotification(type, &info); | 265 SendControlAccessibilityNotification(event, &info); |
| 290 } | 266 } |
| 291 | 267 |
| 292 // static | 268 // static |
| 293 void AccessibilityEventRouterViews::SendTextfieldNotification( | 269 void AccessibilityEventRouterViews::SendTextfieldNotification( |
| 294 views::View* view, | 270 views::View* view, |
| 295 int type, | 271 ui::AccessibilityTypes::Event event, |
| 296 Profile* profile) { | 272 Profile* profile) { |
| 297 ui::AccessibleViewState state; | 273 ui::AccessibleViewState state; |
| 298 view->GetAccessibleState(&state); | 274 view->GetAccessibleState(&state); |
| 299 std::string name = UTF16ToUTF8(state.name); | 275 std::string name = UTF16ToUTF8(state.name); |
| 300 std::string context = GetViewContext(view); | 276 std::string context = GetViewContext(view); |
| 301 bool password = | 277 bool password = |
| 302 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; | 278 (state.state & ui::AccessibilityTypes::STATE_PROTECTED) != 0; |
| 303 AccessibilityTextBoxInfo info(profile, name, context, password); | 279 AccessibilityTextBoxInfo info(profile, name, context, password); |
| 304 std::string value = UTF16ToUTF8(state.value); | 280 std::string value = UTF16ToUTF8(state.value); |
| 305 info.SetValue(value, state.selection_start, state.selection_end); | 281 info.SetValue(value, state.selection_start, state.selection_end); |
| 306 SendAccessibilityNotification(type, &info); | 282 SendControlAccessibilityNotification(event, &info); |
| 307 } | 283 } |
| 308 | 284 |
| 309 // static | 285 // static |
| 310 void AccessibilityEventRouterViews::SendComboboxNotification( | 286 void AccessibilityEventRouterViews::SendComboboxNotification( |
| 311 views::View* view, | 287 views::View* view, |
| 312 int type, | 288 ui::AccessibilityTypes::Event event, |
| 313 Profile* profile) { | 289 Profile* profile) { |
| 314 ui::AccessibleViewState state; | 290 ui::AccessibleViewState state; |
| 315 view->GetAccessibleState(&state); | 291 view->GetAccessibleState(&state); |
| 316 std::string name = UTF16ToUTF8(state.name); | 292 std::string name = UTF16ToUTF8(state.name); |
| 317 std::string value = UTF16ToUTF8(state.value); | 293 std::string value = UTF16ToUTF8(state.value); |
| 318 std::string context = GetViewContext(view); | 294 std::string context = GetViewContext(view); |
| 319 AccessibilityComboBoxInfo info( | 295 AccessibilityComboBoxInfo info( |
| 320 profile, name, context, value, state.index, state.count); | 296 profile, name, context, value, state.index, state.count); |
| 321 SendAccessibilityNotification(type, &info); | 297 SendControlAccessibilityNotification(event, &info); |
| 322 } | 298 } |
| 323 | 299 |
| 324 // static | 300 // static |
| 325 void AccessibilityEventRouterViews::SendCheckboxNotification( | 301 void AccessibilityEventRouterViews::SendCheckboxNotification( |
| 326 views::View* view, | 302 views::View* view, |
| 327 int type, | 303 ui::AccessibilityTypes::Event event, |
| 328 Profile* profile) { | 304 Profile* profile) { |
| 329 ui::AccessibleViewState state; | 305 ui::AccessibleViewState state; |
| 330 view->GetAccessibleState(&state); | 306 view->GetAccessibleState(&state); |
| 331 std::string name = UTF16ToUTF8(state.name); | 307 std::string name = UTF16ToUTF8(state.name); |
| 332 std::string value = UTF16ToUTF8(state.value); | 308 std::string value = UTF16ToUTF8(state.value); |
| 333 std::string context = GetViewContext(view); | 309 std::string context = GetViewContext(view); |
| 334 AccessibilityCheckboxInfo info( | 310 AccessibilityCheckboxInfo info( |
| 335 profile, | 311 profile, |
| 336 name, | 312 name, |
| 337 context, | 313 context, |
| 338 state.state == ui::AccessibilityTypes::STATE_CHECKED); | 314 state.state == ui::AccessibilityTypes::STATE_CHECKED); |
| 339 SendAccessibilityNotification(type, &info); | 315 SendControlAccessibilityNotification(event, &info); |
| 340 } | 316 } |
| 341 | 317 |
| 342 // static | 318 // static |
| 343 void AccessibilityEventRouterViews::SendWindowNotification( | 319 void AccessibilityEventRouterViews::SendWindowNotification( |
| 344 views::View* view, | 320 views::View* view, |
| 345 int type, | 321 ui::AccessibilityTypes::Event event, |
| 346 Profile* profile) { | 322 Profile* profile) { |
| 347 ui::AccessibleViewState state; | 323 ui::AccessibleViewState state; |
| 348 view->GetAccessibleState(&state); | 324 view->GetAccessibleState(&state); |
| 349 std::string window_text; | 325 std::string window_text; |
| 350 | 326 |
| 351 // If it's an alert, try to get the text from the contents of the | 327 // If it's an alert, try to get the text from the contents of the |
| 352 // static text, not the window title. | 328 // static text, not the window title. |
| 353 if (state.role == ui::AccessibilityTypes::ROLE_ALERT) | 329 if (state.role == ui::AccessibilityTypes::ROLE_ALERT) |
| 354 window_text = RecursiveGetStaticText(view); | 330 window_text = RecursiveGetStaticText(view); |
| 355 | 331 |
| 356 // Otherwise get it from the window's accessible name. | 332 // Otherwise get it from the window's accessible name. |
| 357 if (window_text.empty()) | 333 if (window_text.empty()) |
| 358 window_text = UTF16ToUTF8(state.name); | 334 window_text = UTF16ToUTF8(state.name); |
| 359 | 335 |
| 360 AccessibilityWindowInfo info(profile, window_text); | 336 AccessibilityWindowInfo info(profile, window_text); |
| 361 SendAccessibilityNotification(type, &info); | 337 SendWindowAccessibilityNotification(event, &info); |
| 362 } | 338 } |
| 363 | 339 |
| 364 // static | 340 // static |
| 365 void AccessibilityEventRouterViews::SendSliderNotification( | 341 void AccessibilityEventRouterViews::SendSliderNotification( |
| 366 views::View* view, | 342 views::View* view, |
| 367 int type, | 343 ui::AccessibilityTypes::Event event, |
| 368 Profile* profile) { | 344 Profile* profile) { |
| 369 ui::AccessibleViewState state; | 345 ui::AccessibleViewState state; |
| 370 view->GetAccessibleState(&state); | 346 view->GetAccessibleState(&state); |
| 371 | 347 |
| 372 std::string name = UTF16ToUTF8(state.name); | 348 std::string name = UTF16ToUTF8(state.name); |
| 373 std::string value = UTF16ToUTF8(state.value); | 349 std::string value = UTF16ToUTF8(state.value); |
| 374 std::string context = GetViewContext(view); | 350 std::string context = GetViewContext(view); |
| 375 AccessibilitySliderInfo info( | 351 AccessibilitySliderInfo info( |
| 376 profile, | 352 profile, |
| 377 name, | 353 name, |
| 378 context, | 354 context, |
| 379 value); | 355 value); |
| 380 SendAccessibilityNotification(type, &info); | 356 SendControlAccessibilityNotification(event, &info); |
| 381 } | 357 } |
| 382 | 358 |
| 383 // static | 359 // static |
| 384 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { | 360 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { |
| 385 ui::AccessibleViewState state; | 361 ui::AccessibleViewState state; |
| 386 view->GetAccessibleState(&state); | 362 view->GetAccessibleState(&state); |
| 387 return UTF16ToUTF8(state.name); | 363 return UTF16ToUTF8(state.name); |
| 388 } | 364 } |
| 389 | 365 |
| 390 // static | 366 // static |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 views::View* child = view->child_at(i); | 413 views::View* child = view->child_at(i); |
| 438 views::View* result = FindDescendantWithAccessibleRole(child, role); | 414 views::View* result = FindDescendantWithAccessibleRole(child, role); |
| 439 if (result) | 415 if (result) |
| 440 return result; | 416 return result; |
| 441 } | 417 } |
| 442 | 418 |
| 443 return NULL; | 419 return NULL; |
| 444 } | 420 } |
| 445 | 421 |
| 446 // static | 422 // static |
| 447 bool AccessibilityEventRouterViews::IsMenuEvent( | |
| 448 views::View* view, | |
| 449 int type) { | |
| 450 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || | |
| 451 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) | |
| 452 return true; | |
| 453 | |
| 454 while (view) { | |
| 455 ui::AccessibleViewState state; | |
| 456 view->GetAccessibleState(&state); | |
| 457 ui::AccessibilityTypes::Role role = state.role; | |
| 458 if (role == ui::AccessibilityTypes::ROLE_MENUITEM || | |
| 459 role == ui::AccessibilityTypes::ROLE_MENUPOPUP) { | |
| 460 return true; | |
| 461 } | |
| 462 view = view->parent(); | |
| 463 } | |
| 464 | |
| 465 return false; | |
| 466 } | |
| 467 | |
| 468 // static | |
| 469 void AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( | 423 void AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( |
| 470 views::View* menu, | 424 views::View* menu, |
| 471 views::View* item, | 425 views::View* item, |
| 472 int* index, | 426 int* index, |
| 473 int* count) { | 427 int* count) { |
| 474 for (int i = 0; i < menu->child_count(); ++i) { | 428 for (int i = 0; i < menu->child_count(); ++i) { |
| 475 views::View* child = menu->child_at(i); | 429 views::View* child = menu->child_at(i); |
| 476 int previous_count = *count; | 430 int previous_count = *count; |
| 477 RecursiveGetMenuItemIndexAndCount(child, item, index, count); | 431 RecursiveGetMenuItemIndexAndCount(child, item, index, count); |
| 478 ui::AccessibleViewState state; | 432 ui::AccessibleViewState state; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 499 return UTF16ToUTF8(state.name); | 453 return UTF16ToUTF8(state.name); |
| 500 | 454 |
| 501 for (int i = 0; i < view->child_count(); ++i) { | 455 for (int i = 0; i < view->child_count(); ++i) { |
| 502 views::View* child = view->child_at(i); | 456 views::View* child = view->child_at(i); |
| 503 std::string result = RecursiveGetStaticText(child); | 457 std::string result = RecursiveGetStaticText(child); |
| 504 if (!result.empty()) | 458 if (!result.empty()) |
| 505 return result; | 459 return result; |
| 506 } | 460 } |
| 507 return std::string(); | 461 return std::string(); |
| 508 } | 462 } |
| OLD | NEW |