| 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 "ash/magnifier/magnification_controller.h" | 7 #include "ash/magnifier/magnification_controller.h" |
| 8 #include "ash/magnifier/partial_magnification_controller.h" | 8 #include "ash/magnifier/partial_magnification_controller.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/tray/system_tray_notifier.h" | 10 #include "ash/system/tray/system_tray_notifier.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "chrome/browser/api/prefs/pref_member.h" | 13 #include "chrome/browser/api/prefs/pref_member.h" |
| 14 #include "chrome/browser/chromeos/login/user_manager.h" | 14 #include "chrome/browser/chromeos/login/user_manager.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 const double kInitialMagnifiedScale = 2.0; |
| 28 static MagnificationManager* g_magnification_manager = NULL; | 29 static MagnificationManager* g_magnification_manager = NULL; |
| 29 } | 30 } |
| 30 | 31 |
| 31 class MagnificationManagerImpl : public MagnificationManager, | 32 class MagnificationManagerImpl : public MagnificationManager, |
| 32 public content::NotificationObserver { | 33 public content::NotificationObserver { |
| 33 public: | 34 public: |
| 34 MagnificationManagerImpl() : profile_(NULL), | 35 MagnificationManagerImpl() : first_time_update_(true), |
| 36 profile_(NULL), |
| 35 type_(ash::MAGNIFIER_OFF) { | 37 type_(ash::MAGNIFIER_OFF) { |
| 36 registrar_.Add(this, | 38 registrar_.Add(this, |
| 37 chrome::NOTIFICATION_SESSION_STARTED, | 39 chrome::NOTIFICATION_SESSION_STARTED, |
| 38 content::NotificationService::AllSources()); | 40 content::NotificationService::AllSources()); |
| 39 registrar_.Add(this, | 41 registrar_.Add(this, |
| 40 chrome::NOTIFICATION_PROFILE_DESTROYED, | 42 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 41 content::NotificationService::AllSources()); | 43 content::NotificationService::AllSources()); |
| 42 registrar_.Add(this, | 44 registrar_.Add(this, |
| 43 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, | 45 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, |
| 44 content::NotificationService::AllSources()); | 46 content::NotificationService::AllSources()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 prefs::kMagnifierType, | 131 prefs::kMagnifierType, |
| 130 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, | 132 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, |
| 131 base::Unretained(this))); | 133 base::Unretained(this))); |
| 132 } | 134 } |
| 133 | 135 |
| 134 profile_ = profile; | 136 profile_ = profile; |
| 135 UpdateMagnifierStatus(); | 137 UpdateMagnifierStatus(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void UpdateMagnifierStatus() { | 140 void UpdateMagnifierStatus() { |
| 141 // Historycally, from r162080 to r170956, screen magnifier had been enabled |
| 142 // with 1.0x scale on login screen by default, hence some users |
| 143 // unintentionally have the pref to enable magnifier. Now, the default scale |
| 144 // is 2.0x on login screen (same as other screens), so despite them, with |
| 145 // the old pref, their screen might be magnified with 2.0x scale. |
| 146 // The following code prevents it. If the user on login screen has full |
| 147 // screen magnifier pref but no scale pref, doesn't make magnifier enabled. |
| 148 // TODO(yoshiki): remove this in the near future: crbug.com/164627 |
| 149 if (first_time_update_) { |
| 150 first_time_update_ = false; |
| 151 UserManager* manager = UserManager::Get(); |
| 152 if (profile_ && |
| 153 !profile_->GetPrefs()->HasPrefPath(prefs::kScreenMagnifierScale) && |
| 154 accessibility::MagnifierTypeFromName(profile_->GetPrefs()->GetString( |
| 155 prefs::kMagnifierType).c_str()) == ash::MAGNIFIER_FULL && |
| 156 manager && |
| 157 !manager->IsSessionStarted()) { |
| 158 SetMagnifier(ash::MAGNIFIER_OFF); |
| 159 profile_->GetPrefs()->SetDouble(prefs::kScreenMagnifierScale, |
| 160 kInitialMagnifiedScale); |
| 161 return; |
| 162 } |
| 163 } |
| 164 |
| 139 ash::MagnifierType type = GetMagnifierTypeFromPref(); | 165 ash::MagnifierType type = GetMagnifierTypeFromPref(); |
| 140 SetMagnifier(type); | 166 SetMagnifier(type); |
| 141 } | 167 } |
| 142 | 168 |
| 143 // content::NotificationObserver implimentation: | 169 // content::NotificationObserver implimentation: |
| 144 virtual void Observe(int type, | 170 virtual void Observe(int type, |
| 145 const content::NotificationSource& source, | 171 const content::NotificationSource& source, |
| 146 const content::NotificationDetails& details) OVERRIDE { | 172 const content::NotificationDetails& details) OVERRIDE { |
| 147 switch (type) { | 173 switch (type) { |
| 148 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: | 174 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: |
| 149 case chrome::NOTIFICATION_SESSION_STARTED: { | 175 case chrome::NOTIFICATION_SESSION_STARTED: { |
| 150 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 176 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 151 SetProfile(profile); | 177 SetProfile(profile); |
| 152 break; | 178 break; |
| 153 } | 179 } |
| 154 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 180 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 155 SetProfile(NULL); | 181 SetProfile(NULL); |
| 156 break; | 182 break; |
| 157 } | 183 } |
| 158 } | 184 } |
| 159 } | 185 } |
| 160 | 186 |
| 187 bool first_time_update_; |
| 161 Profile* profile_; | 188 Profile* profile_; |
| 162 ash::MagnifierType type_; | 189 ash::MagnifierType type_; |
| 163 content::NotificationRegistrar registrar_; | 190 content::NotificationRegistrar registrar_; |
| 164 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 191 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 165 | 192 |
| 166 ObserverList<MagnificationObserver> observers_; | 193 ObserverList<MagnificationObserver> observers_; |
| 167 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 194 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
| 168 }; | 195 }; |
| 169 | 196 |
| 170 // static | 197 // static |
| 171 void MagnificationManager::Initialize() { | 198 void MagnificationManager::Initialize() { |
| 172 CHECK(g_magnification_manager == NULL); | 199 CHECK(g_magnification_manager == NULL); |
| 173 g_magnification_manager = new MagnificationManagerImpl(); | 200 g_magnification_manager = new MagnificationManagerImpl(); |
| 174 } | 201 } |
| 175 | 202 |
| 176 // static | 203 // static |
| 177 void MagnificationManager::Shutdown() { | 204 void MagnificationManager::Shutdown() { |
| 178 CHECK(g_magnification_manager); | 205 CHECK(g_magnification_manager); |
| 179 delete g_magnification_manager; | 206 delete g_magnification_manager; |
| 180 g_magnification_manager = NULL; | 207 g_magnification_manager = NULL; |
| 181 } | 208 } |
| 182 | 209 |
| 183 // static | 210 // static |
| 184 MagnificationManager* MagnificationManager::Get() { | 211 MagnificationManager* MagnificationManager::Get() { |
| 185 return g_magnification_manager; | 212 return g_magnification_manager; |
| 186 } | 213 } |
| 187 | 214 |
| 188 } // namespace chromeos | 215 } // namespace chromeos |
| OLD | NEW |