| 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/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 16 #include "content/common/notification_type.h" | 17 #include "content/common/notification_type.h" |
| 17 #include "ui/base/models/combobox_model.h" | 18 #include "ui/base/models/combobox_model.h" |
| 18 #include "ui/base/accessibility/accessible_view_state.h" | 19 #include "ui/base/accessibility/accessible_view_state.h" |
| 19 #include "views/controls/button/checkbox.h" | 20 #include "views/controls/button/checkbox.h" |
| 20 #include "views/controls/button/custom_button.h" | 21 #include "views/controls/button/custom_button.h" |
| 21 #include "views/controls/button/menu_button.h" | 22 #include "views/controls/button/menu_button.h" |
| 22 #include "views/controls/button/native_button.h" | 23 #include "views/controls/button/native_button.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 AccessibilityEventRouterViews::~AccessibilityEventRouterViews() { | 41 AccessibilityEventRouterViews::~AccessibilityEventRouterViews() { |
| 41 } | 42 } |
| 42 | 43 |
| 43 // static | 44 // static |
| 44 AccessibilityEventRouterViews* AccessibilityEventRouterViews::GetInstance() { | 45 AccessibilityEventRouterViews* AccessibilityEventRouterViews::GetInstance() { |
| 45 return Singleton<AccessibilityEventRouterViews>::get(); | 46 return Singleton<AccessibilityEventRouterViews>::get(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void AccessibilityEventRouterViews::HandleAccessibilityEvent( | 49 void AccessibilityEventRouterViews::HandleAccessibilityEvent( |
| 49 views::View* view, ui::AccessibilityTypes::Event event_type) { | 50 views::View* view, ui::AccessibilityTypes::Event event_type) { |
| 50 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | |
| 51 IsAccessibilityEnabled()) { | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 switch (event_type) { | 51 switch (event_type) { |
| 56 case ui::AccessibilityTypes::EVENT_FOCUS: | 52 case ui::AccessibilityTypes::EVENT_FOCUS: |
| 57 DispatchAccessibilityNotification( | 53 DispatchAccessibilityNotification( |
| 58 view, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); | 54 view, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); |
| 59 break; | 55 break; |
| 60 case ui::AccessibilityTypes::EVENT_MENUSTART: | 56 case ui::AccessibilityTypes::EVENT_MENUSTART: |
| 61 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: | 57 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: |
| 62 DispatchAccessibilityNotification( | 58 DispatchAccessibilityNotification( |
| 63 view, NotificationType::ACCESSIBILITY_MENU_OPENED); | 59 view, NotificationType::ACCESSIBILITY_MENU_OPENED); |
| 64 break; | 60 break; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 break; | 81 break; |
| 86 } | 82 } |
| 87 } | 83 } |
| 88 | 84 |
| 89 void AccessibilityEventRouterViews::HandleMenuItemFocused( | 85 void AccessibilityEventRouterViews::HandleMenuItemFocused( |
| 90 const std::wstring& menu_name, | 86 const std::wstring& menu_name, |
| 91 const std::wstring& menu_item_name, | 87 const std::wstring& menu_item_name, |
| 92 int item_index, | 88 int item_index, |
| 93 int item_count, | 89 int item_count, |
| 94 bool has_submenu) { | 90 bool has_submenu) { |
| 95 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | 91 if (!most_recent_profile_) |
| 96 IsAccessibilityEnabled()) { | 92 return; |
| 93 |
| 94 if (!most_recent_profile_->GetExtensionService()-> |
| 95 accessibility_event_router()->IsAccessibilityEnabled()) { |
| 97 return; | 96 return; |
| 98 } | 97 } |
| 99 | 98 |
| 100 if (!most_recent_profile_) | |
| 101 return; | |
| 102 | |
| 103 AccessibilityMenuItemInfo info( | 99 AccessibilityMenuItemInfo info( |
| 104 most_recent_profile_, | 100 most_recent_profile_, |
| 105 WideToUTF8(menu_item_name), | 101 WideToUTF8(menu_item_name), |
| 106 has_submenu, | 102 has_submenu, |
| 107 item_index, | 103 item_index, |
| 108 item_count); | 104 item_count); |
| 109 SendAccessibilityNotification( | 105 SendAccessibilityNotification( |
| 110 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, &info); | 106 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, &info); |
| 111 } | 107 } |
| 112 | 108 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 134 } | 130 } |
| 135 if (!profile) | 131 if (!profile) |
| 136 profile = most_recent_profile_; | 132 profile = most_recent_profile_; |
| 137 if (!profile) | 133 if (!profile) |
| 138 profile = g_browser_process->profile_manager()->GetDefaultProfile(); | 134 profile = g_browser_process->profile_manager()->GetDefaultProfile(); |
| 139 if (!profile) { | 135 if (!profile) { |
| 140 NOTREACHED(); | 136 NOTREACHED(); |
| 141 return; | 137 return; |
| 142 } | 138 } |
| 143 | 139 |
| 140 if (!profile->GetExtensionService()->accessibility_event_router()-> |
| 141 IsAccessibilityEnabled()) { |
| 142 return; |
| 143 } |
| 144 |
| 144 most_recent_profile_ = profile; | 145 most_recent_profile_ = profile; |
| 145 std::string class_name = view->GetClassName(); | 146 std::string class_name = view->GetClassName(); |
| 146 | 147 |
| 147 if (class_name == views::Checkbox::kViewClassName) { | 148 if (class_name == views::Checkbox::kViewClassName) { |
| 148 SendCheckboxNotification(view, type, profile); | 149 SendCheckboxNotification(view, type, profile); |
| 149 } else if (class_name == views::MenuButton::kViewClassName || | 150 } else if (class_name == views::MenuButton::kViewClassName || |
| 150 type == NotificationType::ACCESSIBILITY_MENU_OPENED || | 151 type == NotificationType::ACCESSIBILITY_MENU_OPENED || |
| 151 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) { | 152 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) { |
| 152 SendMenuNotification(view, type, profile); | 153 SendMenuNotification(view, type, profile); |
| 153 } else if (IsMenuEvent(view, type)) { | 154 } else if (IsMenuEvent(view, type)) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 void AccessibilityEventRouterViews::SendCheckboxNotification( | 288 void AccessibilityEventRouterViews::SendCheckboxNotification( |
| 288 views::View* view, NotificationType type, Profile* profile) { | 289 views::View* view, NotificationType type, Profile* profile) { |
| 289 ui::AccessibleViewState state; | 290 ui::AccessibleViewState state; |
| 290 view->GetAccessibleState(&state); | 291 view->GetAccessibleState(&state); |
| 291 std::string name = UTF16ToUTF8(state.name); | 292 std::string name = UTF16ToUTF8(state.name); |
| 292 std::string value = UTF16ToUTF8(state.value); | 293 std::string value = UTF16ToUTF8(state.value); |
| 293 AccessibilityCheckboxInfo info( | 294 AccessibilityCheckboxInfo info( |
| 294 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); | 295 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); |
| 295 SendAccessibilityNotification(type, &info); | 296 SendAccessibilityNotification(type, &info); |
| 296 } | 297 } |
| 297 | |
| OLD | NEW |