| 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.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/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/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_source.h" |
| 17 #include "ui/base/accessibility/accessible_view_state.h" | 19 #include "ui/base/accessibility/accessible_view_state.h" |
| 18 #include "ui/views/controls/button/text_button.h" | 20 #include "ui/views/controls/button/text_button.h" |
| 19 #include "ui/views/controls/menu/menu_item_view.h" | 21 #include "ui/views/controls/menu/menu_item_view.h" |
| 20 #include "ui/views/controls/menu/submenu_view.h" | 22 #include "ui/views/controls/menu/submenu_view.h" |
| 21 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
| 22 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 23 | 25 |
| 24 using views::FocusManager; | 26 using views::FocusManager; |
| 25 | 27 |
| 26 AccessibilityEventRouterViews::AccessibilityEventRouterViews() | 28 AccessibilityEventRouterViews::AccessibilityEventRouterViews() |
| 27 : most_recent_profile_(NULL) { | 29 : most_recent_profile_(NULL) { |
| 30 // Register for notification when profile is destroyed to ensure that all |
| 31 // observers are detatched at that time. |
| 32 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 33 content::NotificationService::AllSources()); |
| 28 } | 34 } |
| 29 | 35 |
| 30 AccessibilityEventRouterViews::~AccessibilityEventRouterViews() { | 36 AccessibilityEventRouterViews::~AccessibilityEventRouterViews() { |
| 31 } | 37 } |
| 32 | 38 |
| 33 // static | 39 // static |
| 34 AccessibilityEventRouterViews* AccessibilityEventRouterViews::GetInstance() { | 40 AccessibilityEventRouterViews* AccessibilityEventRouterViews::GetInstance() { |
| 35 return Singleton<AccessibilityEventRouterViews>::get(); | 41 return Singleton<AccessibilityEventRouterViews>::get(); |
| 36 } | 42 } |
| 37 | 43 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 AccessibilityMenuItemInfo info(most_recent_profile_, | 99 AccessibilityMenuItemInfo info(most_recent_profile_, |
| 94 UTF16ToUTF8(menu_item_name), | 100 UTF16ToUTF8(menu_item_name), |
| 95 UTF16ToUTF8(menu_name), | 101 UTF16ToUTF8(menu_name), |
| 96 has_submenu, | 102 has_submenu, |
| 97 item_index, | 103 item_index, |
| 98 item_count); | 104 item_count); |
| 99 SendAccessibilityNotification( | 105 SendAccessibilityNotification( |
| 100 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, &info); | 106 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, &info); |
| 101 } | 107 } |
| 102 | 108 |
| 109 void AccessibilityEventRouterViews::Observe( |
| 110 int type, |
| 111 const content::NotificationSource& source, |
| 112 const content::NotificationDetails& details) { |
| 113 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); |
| 114 Profile* profile = content::Source<Profile>(source).ptr(); |
| 115 if (profile == most_recent_profile_) |
| 116 most_recent_profile_ = NULL; |
| 117 } |
| 118 |
| 103 // | 119 // |
| 104 // Private methods | 120 // Private methods |
| 105 // | 121 // |
| 106 | 122 |
| 107 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( | 123 void AccessibilityEventRouterViews::DispatchAccessibilityNotification( |
| 108 views::View* view, int type) { | 124 views::View* view, int type) { |
| 109 // Get the profile associated with this view. If it's not found, use | 125 // Get the profile associated with this view. If it's not found, use |
| 110 // the most recent profile where accessibility events were sent, or | 126 // the most recent profile where accessibility events were sent, or |
| 111 // the default profile. | 127 // the default profile. |
| 112 Profile* profile = NULL; | 128 Profile* profile = NULL; |
| 113 views::Widget* widget = view->GetWidget(); | 129 views::Widget* widget = view->GetWidget(); |
| 114 if (widget) { | 130 if (widget) { |
| 115 profile = reinterpret_cast<Profile*>( | 131 profile = reinterpret_cast<Profile*>( |
| 116 widget->GetNativeWindowProperty(Profile::kProfileKey)); | 132 widget->GetNativeWindowProperty(Profile::kProfileKey)); |
| 117 } | 133 } |
| 118 if (!profile) | 134 if (!profile) |
| 119 profile = most_recent_profile_; | 135 profile = most_recent_profile_; |
| 120 if (!profile) | |
| 121 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | |
| 122 if (!profile) { | 136 if (!profile) { |
| 123 NOTREACHED(); | 137 if (g_browser_process->profile_manager()) |
| 138 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 139 } |
| 140 if (!profile) { |
| 141 LOG(WARNING) << "Accessibility notification but no profile"; |
| 124 return; | 142 return; |
| 125 } | 143 } |
| 126 | 144 |
| 127 most_recent_profile_ = profile; | 145 most_recent_profile_ = profile; |
| 128 | 146 |
| 129 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || | 147 if (type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED || |
| 130 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) { | 148 type == chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED) { |
| 131 SendMenuNotification(view, type, profile); | 149 SendMenuNotification(view, type, profile); |
| 132 return; | 150 return; |
| 133 } | 151 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 return UTF16ToUTF8(state.name); | 460 return UTF16ToUTF8(state.name); |
| 443 | 461 |
| 444 for (int i = 0; i < view->child_count(); ++i) { | 462 for (int i = 0; i < view->child_count(); ++i) { |
| 445 views::View* child = view->child_at(i); | 463 views::View* child = view->child_at(i); |
| 446 std::string result = RecursiveGetStaticText(child); | 464 std::string result = RecursiveGetStaticText(child); |
| 447 if (!result.empty()) | 465 if (!result.empty()) |
| 448 return result; | 466 return result; |
| 449 } | 467 } |
| 450 return std::string(); | 468 return std::string(); |
| 451 } | 469 } |
| OLD | NEW |