| 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" |
| 23 #include "views/controls/combobox/combobox.h" | 24 #include "views/controls/combobox/combobox.h" |
| 24 #include "views/controls/link.h" | 25 #include "views/controls/link.h" |
| 25 #include "views/controls/menu/menu_item_view.h" | 26 #include "views/controls/menu/menu_item_view.h" |
| 26 #include "views/controls/menu/submenu_view.h" | 27 #include "views/controls/menu/submenu_view.h" |
| 27 #include "views/controls/textfield/textfield.h" | 28 #include "views/controls/textfield/textfield.h" |
| 28 #include "views/view.h" | 29 #include "views/view.h" |
| 29 #include "views/widget/native_widget.h" | 30 #include "views/widget/native_widget.h" |
| 30 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
| 31 #include "views/window/window.h" | 32 #include "views/window/window.h" |
| 32 | 33 |
| 33 using views::FocusManager; | 34 using views::FocusManager; |
| 34 | 35 |
| 35 AccessibilityEventRouterViews::AccessibilityEventRouterViews() | 36 AccessibilityEventRouterViews::AccessibilityEventRouterViews() |
| 36 : most_recent_profile_(NULL), | 37 : most_recent_profile_(NULL), |
| 37 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 38 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 39 accessibility_enabled_overridden_for_testing_(false), |
| 40 accessibility_enabled_override_value_(false) { |
| 38 } | 41 } |
| 39 | 42 |
| 40 AccessibilityEventRouterViews::~AccessibilityEventRouterViews() { | 43 AccessibilityEventRouterViews::~AccessibilityEventRouterViews() { |
| 41 } | 44 } |
| 42 | 45 |
| 43 // static | 46 // static |
| 44 AccessibilityEventRouterViews* AccessibilityEventRouterViews::GetInstance() { | 47 AccessibilityEventRouterViews* AccessibilityEventRouterViews::GetInstance() { |
| 45 return Singleton<AccessibilityEventRouterViews>::get(); | 48 return Singleton<AccessibilityEventRouterViews>::get(); |
| 46 } | 49 } |
| 47 | 50 |
| 48 void AccessibilityEventRouterViews::HandleAccessibilityEvent( | 51 void AccessibilityEventRouterViews::HandleAccessibilityEvent( |
| 49 views::View* view, ui::AccessibilityTypes::Event event_type) { | 52 views::View* view, ui::AccessibilityTypes::Event event_type) { |
| 50 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | |
| 51 IsAccessibilityEnabled()) { | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 switch (event_type) { | 53 switch (event_type) { |
| 56 case ui::AccessibilityTypes::EVENT_FOCUS: | 54 case ui::AccessibilityTypes::EVENT_FOCUS: |
| 57 DispatchAccessibilityNotification( | 55 DispatchAccessibilityNotification( |
| 58 view, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); | 56 view, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); |
| 59 break; | 57 break; |
| 60 case ui::AccessibilityTypes::EVENT_MENUSTART: | 58 case ui::AccessibilityTypes::EVENT_MENUSTART: |
| 61 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: | 59 case ui::AccessibilityTypes::EVENT_MENUPOPUPSTART: |
| 62 DispatchAccessibilityNotification( | 60 DispatchAccessibilityNotification( |
| 63 view, NotificationType::ACCESSIBILITY_MENU_OPENED); | 61 view, NotificationType::ACCESSIBILITY_MENU_OPENED); |
| 64 break; | 62 break; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 break; | 83 break; |
| 86 } | 84 } |
| 87 } | 85 } |
| 88 | 86 |
| 89 void AccessibilityEventRouterViews::HandleMenuItemFocused( | 87 void AccessibilityEventRouterViews::HandleMenuItemFocused( |
| 90 const std::wstring& menu_name, | 88 const std::wstring& menu_name, |
| 91 const std::wstring& menu_item_name, | 89 const std::wstring& menu_item_name, |
| 92 int item_index, | 90 int item_index, |
| 93 int item_count, | 91 int item_count, |
| 94 bool has_submenu) { | 92 bool has_submenu) { |
| 95 if (!ExtensionAccessibilityEventRouter::GetInstance()-> | 93 if (!most_recent_profile_) |
| 96 IsAccessibilityEnabled()) { | 94 return; |
| 95 |
| 96 if (!IsAccessibilityEnabled(most_recent_profile_)) { |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 | 99 |
| 100 if (!most_recent_profile_) | |
| 101 return; | |
| 102 | |
| 103 AccessibilityMenuItemInfo info( | 100 AccessibilityMenuItemInfo info( |
| 104 most_recent_profile_, | 101 most_recent_profile_, |
| 105 WideToUTF8(menu_item_name), | 102 WideToUTF8(menu_item_name), |
| 106 has_submenu, | 103 has_submenu, |
| 107 item_index, | 104 item_index, |
| 108 item_count); | 105 item_count); |
| 109 SendAccessibilityNotification( | 106 SendAccessibilityNotification( |
| 110 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, &info); | 107 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, &info); |
| 111 } | 108 } |
| 112 | 109 |
| 113 // | 110 // |
| 114 // Private methods | 111 // Private methods |
| 115 // | 112 // |
| 116 | 113 |
| 114 bool AccessibilityEventRouterViews::IsAccessibilityEnabled(Profile* profile) { |
| 115 if (accessibility_enabled_overridden_for_testing_) { |
| 116 return accessibility_enabled_override_value_; |
| 117 } |
| 118 DCHECK(profile); |
| 119 return profile->GetExtensionService()->accessibility_event_router()-> |
| 120 IsAccessibilityEnabled(); |
| 121 } |
| 122 |
| 117 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { | 123 std::string AccessibilityEventRouterViews::GetViewName(views::View* view) { |
| 118 ui::AccessibleViewState state; | 124 ui::AccessibleViewState state; |
| 119 view->GetAccessibleState(&state); | 125 view->GetAccessibleState(&state); |
| 120 return UTF16ToUTF8(state.name); | 126 return UTF16ToUTF8(state.name); |
| 121 } | 127 } |
| 122 | 128 |
| 123 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( | 129 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( |
| 124 views::View* view, NotificationType type) { | 130 views::View* view, NotificationType type) { |
| 125 // Get the profile associated with this view. If it's not found, use | 131 // Get the profile associated with this view. If it's not found, use |
| 126 // the most recent profile where accessibility events were sent, or | 132 // the most recent profile where accessibility events were sent, or |
| 127 // the default profile. | 133 // the default profile. |
| 128 Profile* profile = NULL; | 134 Profile* profile = NULL; |
| 129 views::Window* window = view->GetWindow(); | 135 views::Window* window = view->GetWindow(); |
| 130 if (window) { | 136 if (window) { |
| 131 profile = reinterpret_cast<Profile*>( | 137 profile = reinterpret_cast<Profile*>( |
| 132 window->AsWidget()->native_widget()->GetNativeWindowProperty( | 138 window->AsWidget()->native_widget()->GetNativeWindowProperty( |
| 133 Profile::kProfileKey)); | 139 Profile::kProfileKey)); |
| 134 } | 140 } |
| 135 if (!profile) | 141 if (!profile) |
| 136 profile = most_recent_profile_; | 142 profile = most_recent_profile_; |
| 137 if (!profile) | 143 if (!profile) |
| 138 profile = g_browser_process->profile_manager()->GetDefaultProfile(); | 144 profile = g_browser_process->profile_manager()->GetDefaultProfile(); |
| 139 if (!profile) { | 145 if (!profile) { |
| 140 NOTREACHED(); | 146 NOTREACHED(); |
| 141 return; | 147 return; |
| 142 } | 148 } |
| 143 | 149 |
| 150 if (!IsAccessibilityEnabled(profile)) { |
| 151 return; |
| 152 } |
| 153 |
| 144 most_recent_profile_ = profile; | 154 most_recent_profile_ = profile; |
| 145 std::string class_name = view->GetClassName(); | 155 std::string class_name = view->GetClassName(); |
| 146 | 156 |
| 147 if (class_name == views::Checkbox::kViewClassName) { | 157 if (class_name == views::Checkbox::kViewClassName) { |
| 148 SendCheckboxNotification(view, type, profile); | 158 SendCheckboxNotification(view, type, profile); |
| 149 } else if (class_name == views::MenuButton::kViewClassName || | 159 } else if (class_name == views::MenuButton::kViewClassName || |
| 150 type == NotificationType::ACCESSIBILITY_MENU_OPENED || | 160 type == NotificationType::ACCESSIBILITY_MENU_OPENED || |
| 151 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) { | 161 type == NotificationType::ACCESSIBILITY_MENU_CLOSED) { |
| 152 SendMenuNotification(view, type, profile); | 162 SendMenuNotification(view, type, profile); |
| 153 } else if (IsMenuEvent(view, type)) { | 163 } else if (IsMenuEvent(view, type)) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 views::View* view, NotificationType type, Profile* profile) { | 298 views::View* view, NotificationType type, Profile* profile) { |
| 289 ui::AccessibleViewState state; | 299 ui::AccessibleViewState state; |
| 290 view->GetAccessibleState(&state); | 300 view->GetAccessibleState(&state); |
| 291 std::string name = UTF16ToUTF8(state.name); | 301 std::string name = UTF16ToUTF8(state.name); |
| 292 std::string value = UTF16ToUTF8(state.value); | 302 std::string value = UTF16ToUTF8(state.value); |
| 293 AccessibilityCheckboxInfo info( | 303 AccessibilityCheckboxInfo info( |
| 294 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); | 304 profile, name, state.state == ui::AccessibilityTypes::STATE_CHECKED); |
| 295 SendAccessibilityNotification(type, &info); | 305 SendAccessibilityNotification(type, &info); |
| 296 } | 306 } |
| 297 | 307 |
| 308 void AccessibilityEventRouterViews::SetAccessibilityEnabledForTesting( |
| 309 bool enabled) { |
| 310 accessibility_enabled_overridden_for_testing_ = true; |
| 311 accessibility_enabled_override_value_ = enabled; |
| 312 } |
| OLD | NEW |