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/chromeos/accessibility/magnification_manager.h" | 5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "ash/magnifier/magnification_controller.h" | 9 #include "ash/magnifier/magnification_controller.h" |
10 #include "ash/magnifier/partial_magnification_controller.h" | 10 #include "ash/magnifier/partial_magnification_controller.h" |
11 #include "ash/session/session_state_delegate.h" | 11 #include "ash/session/session_state_delegate.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
14 #include "ash/system/tray/system_tray_notifier.h" | 14 #include "ash/system/tray/system_tray_notifier.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/prefs/pref_member.h" | 17 #include "base/prefs/pref_member.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/focused_node_details.h" |
25 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
27 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
30 | 31 |
31 namespace chromeos { | 32 namespace chromeos { |
32 | 33 |
33 namespace { | 34 namespace { |
34 static MagnificationManager* g_magnification_manager = NULL; | 35 static MagnificationManager* g_magnification_manager = NULL; |
35 } | 36 } |
36 | 37 |
37 class MagnificationManagerImpl : public MagnificationManager, | 38 class MagnificationManagerImpl : public MagnificationManager, |
38 public content::NotificationObserver, | 39 public content::NotificationObserver, |
39 public ash::SessionStateObserver { | 40 public ash::SessionStateObserver { |
40 public: | 41 public: |
41 MagnificationManagerImpl() | 42 MagnificationManagerImpl() |
42 : first_time_update_(true), | 43 : first_time_update_(true), |
43 profile_(NULL), | 44 profile_(NULL), |
44 magnifier_enabled_pref_handler_( | 45 magnifier_enabled_pref_handler_( |
45 prefs::kAccessibilityScreenMagnifierEnabled), | 46 prefs::kAccessibilityScreenMagnifierEnabled), |
46 magnifier_type_pref_handler_(prefs::kAccessibilityScreenMagnifierType), | 47 magnifier_type_pref_handler_(prefs::kAccessibilityScreenMagnifierType), |
47 magnifier_scale_pref_handler_( | 48 magnifier_scale_pref_handler_( |
48 prefs::kAccessibilityScreenMagnifierScale), | 49 prefs::kAccessibilityScreenMagnifierScale), |
49 type_(ui::kDefaultMagnifierType), | 50 type_(ui::kDefaultMagnifierType), |
50 enabled_(false) { | 51 enabled_(false), |
| 52 observing_focus_change_in_page_(false) { |
51 registrar_.Add(this, | 53 registrar_.Add(this, |
52 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 54 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
53 content::NotificationService::AllSources()); | 55 content::NotificationService::AllSources()); |
54 registrar_.Add(this, | 56 registrar_.Add(this, |
55 chrome::NOTIFICATION_SESSION_STARTED, | 57 chrome::NOTIFICATION_SESSION_STARTED, |
56 content::NotificationService::AllSources()); | 58 content::NotificationService::AllSources()); |
57 registrar_.Add(this, | 59 registrar_.Add(this, |
58 chrome::NOTIFICATION_PROFILE_DESTROYED, | 60 chrome::NOTIFICATION_PROFILE_DESTROYED, |
59 content::NotificationService::AllSources()); | 61 content::NotificationService::AllSources()); |
60 } | 62 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // magnifier is already disabled, we are sure that we don't need to reflect | 150 // magnifier is already disabled, we are sure that we don't need to reflect |
149 // the new settings right now because the magnifier keeps disabled. | 151 // the new settings right now because the magnifier keeps disabled. |
150 if (!enabled && !enabled_) | 152 if (!enabled && !enabled_) |
151 return; | 153 return; |
152 | 154 |
153 enabled_ = enabled; | 155 enabled_ = enabled; |
154 | 156 |
155 if (type_ == ui::MAGNIFIER_FULL) { | 157 if (type_ == ui::MAGNIFIER_FULL) { |
156 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( | 158 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( |
157 enabled_); | 159 enabled_); |
| 160 MonitorFocusInPageChange(); |
158 } else { | 161 } else { |
159 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( | 162 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( |
160 enabled_); | 163 enabled_); |
161 } | 164 } |
162 } | 165 } |
163 | 166 |
164 virtual void SetMagnifierTypeInternal(ui::MagnifierType type) { | 167 virtual void SetMagnifierTypeInternal(ui::MagnifierType type) { |
165 if (type_ == type) | 168 if (type_ == type) |
166 return; | 169 return; |
167 | 170 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (AccessibilityManager::Get()) { | 209 if (AccessibilityManager::Get()) { |
207 AccessibilityManager::Get()->NotifyAccessibilityStatusChanged(details); | 210 AccessibilityManager::Get()->NotifyAccessibilityStatusChanged(details); |
208 if (ash::Shell::GetInstance()) { | 211 if (ash::Shell::GetInstance()) { |
209 ash::Shell::GetInstance()->SetCursorCompositingEnabled( | 212 ash::Shell::GetInstance()->SetCursorCompositingEnabled( |
210 AccessibilityManager::Get()->ShouldEnableCursorCompositing()); | 213 AccessibilityManager::Get()->ShouldEnableCursorCompositing()); |
211 } | 214 } |
212 } | 215 } |
213 #endif | 216 #endif |
214 } | 217 } |
215 | 218 |
| 219 void MonitorFocusInPageChange() { |
| 220 if (enabled_ && !observing_focus_change_in_page_) { |
| 221 registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 222 content::NotificationService::AllSources()); |
| 223 observing_focus_change_in_page_ = true; |
| 224 } else if (!enabled_ && observing_focus_change_in_page_) { |
| 225 registrar_.Remove(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 226 content::NotificationService::AllSources()); |
| 227 observing_focus_change_in_page_ = false; |
| 228 } |
| 229 } |
| 230 |
216 // content::NotificationObserver implementation: | 231 // content::NotificationObserver implementation: |
217 virtual void Observe(int type, | 232 virtual void Observe(int type, |
218 const content::NotificationSource& source, | 233 const content::NotificationSource& source, |
219 const content::NotificationDetails& details) override { | 234 const content::NotificationDetails& details) override { |
220 switch (type) { | 235 switch (type) { |
221 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 236 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
222 // Update |profile_| when entering the login screen. | 237 // Update |profile_| when entering the login screen. |
223 Profile* profile = ProfileManager::GetActiveUserProfile(); | 238 Profile* profile = ProfileManager::GetActiveUserProfile(); |
224 if (ProfileHelper::IsSigninProfile(profile)) | 239 if (ProfileHelper::IsSigninProfile(profile)) |
225 SetProfile(profile); | 240 SetProfile(profile); |
226 break; | 241 break; |
227 } | 242 } |
228 case chrome::NOTIFICATION_SESSION_STARTED: | 243 case chrome::NOTIFICATION_SESSION_STARTED: |
229 // Update |profile_| when entering a session. | 244 // Update |profile_| when entering a session. |
230 SetProfile(ProfileManager::GetActiveUserProfile()); | 245 SetProfile(ProfileManager::GetActiveUserProfile()); |
231 | 246 |
232 // Add a session state observer to be able to monitor session changes. | 247 // Add a session state observer to be able to monitor session changes. |
233 if (!session_state_observer_.get() && ash::Shell::HasInstance()) | 248 if (!session_state_observer_.get() && ash::Shell::HasInstance()) |
234 session_state_observer_.reset( | 249 session_state_observer_.reset( |
235 new ash::ScopedSessionStateObserver(this)); | 250 new ash::ScopedSessionStateObserver(this)); |
236 break; | 251 break; |
237 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 252 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
238 // Update |profile_| when exiting a session or shutting down. | 253 // Update |profile_| when exiting a session or shutting down. |
239 Profile* profile = content::Source<Profile>(source).ptr(); | 254 Profile* profile = content::Source<Profile>(source).ptr(); |
240 if (profile_ == profile) | 255 if (profile_ == profile) |
241 SetProfile(NULL); | 256 SetProfile(NULL); |
242 break; | 257 break; |
243 } | 258 } |
| 259 case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { |
| 260 content::FocusedNodeDetails* node_details = |
| 261 content::Details<content::FocusedNodeDetails>(details).ptr(); |
| 262 ash::Shell::GetInstance() |
| 263 ->magnification_controller() |
| 264 ->HandleFocusedNodeChanged(node_details->is_editable_node, |
| 265 node_details->node_bounds_in_screen); |
| 266 break; |
| 267 } |
244 } | 268 } |
245 } | 269 } |
246 | 270 |
247 bool first_time_update_; | 271 bool first_time_update_; |
248 Profile* profile_; | 272 Profile* profile_; |
249 | 273 |
250 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; | 274 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; |
251 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; | 275 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; |
252 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; | 276 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; |
253 | 277 |
254 ui::MagnifierType type_; | 278 ui::MagnifierType type_; |
255 bool enabled_; | 279 bool enabled_; |
| 280 bool observing_focus_change_in_page_; |
256 | 281 |
257 content::NotificationRegistrar registrar_; | 282 content::NotificationRegistrar registrar_; |
258 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 283 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
259 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; | 284 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; |
260 | 285 |
261 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 286 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
262 }; | 287 }; |
263 | 288 |
264 // static | 289 // static |
265 void MagnificationManager::Initialize() { | 290 void MagnificationManager::Initialize() { |
266 CHECK(g_magnification_manager == NULL); | 291 CHECK(g_magnification_manager == NULL); |
267 g_magnification_manager = new MagnificationManagerImpl(); | 292 g_magnification_manager = new MagnificationManagerImpl(); |
268 } | 293 } |
269 | 294 |
270 // static | 295 // static |
271 void MagnificationManager::Shutdown() { | 296 void MagnificationManager::Shutdown() { |
272 CHECK(g_magnification_manager); | 297 CHECK(g_magnification_manager); |
273 delete g_magnification_manager; | 298 delete g_magnification_manager; |
274 g_magnification_manager = NULL; | 299 g_magnification_manager = NULL; |
275 } | 300 } |
276 | 301 |
277 // static | 302 // static |
278 MagnificationManager* MagnificationManager::Get() { | 303 MagnificationManager* MagnificationManager::Get() { |
279 return g_magnification_manager; | 304 return g_magnification_manager; |
280 } | 305 } |
281 | 306 |
282 } // namespace chromeos | 307 } // namespace chromeos |
OLD | NEW |