Chromium Code Reviews| 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" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 namespace { | 27 namespace { |
| 28 const double kInitialMagnifiedScale = 2.0; | 28 const double kInitialMagnifiedScale = 2.0; |
| 29 static MagnificationManager* g_magnification_manager = NULL; | 29 static MagnificationManager* g_magnification_manager = NULL; |
| 30 } | 30 } |
| 31 | 31 |
| 32 class MagnificationManagerImpl : public MagnificationManager, | 32 class MagnificationManagerImpl : public MagnificationManager, |
| 33 public content::NotificationObserver { | 33 public content::NotificationObserver { |
| 34 public: | 34 public: |
| 35 MagnificationManagerImpl() : first_time_update_(true), | 35 MagnificationManagerImpl() : first_time_update_(true), |
| 36 profile_(NULL), | 36 profile_(NULL), |
| 37 type_(ash::MAGNIFIER_OFF) { | 37 type_(ash::kDefaultMagnifierType), |
| 38 enabled_(false) { | |
| 38 registrar_.Add(this, | 39 registrar_.Add(this, |
| 39 chrome::NOTIFICATION_SESSION_STARTED, | 40 chrome::NOTIFICATION_SESSION_STARTED, |
| 40 content::NotificationService::AllSources()); | 41 content::NotificationService::AllSources()); |
| 41 registrar_.Add(this, | 42 registrar_.Add(this, |
| 42 chrome::NOTIFICATION_PROFILE_DESTROYED, | 43 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 43 content::NotificationService::AllSources()); | 44 content::NotificationService::AllSources()); |
| 44 registrar_.Add(this, | 45 registrar_.Add(this, |
| 45 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, | 46 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, |
| 46 content::NotificationService::AllSources()); | 47 content::NotificationService::AllSources()); |
| 47 } | 48 } |
| 48 | 49 |
| 49 virtual ~MagnificationManagerImpl() { | 50 virtual ~MagnificationManagerImpl() { |
| 50 CHECK(this == g_magnification_manager); | 51 CHECK(this == g_magnification_manager); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // MagnificationManager implimentation: | 54 // MagnificationManager implimentation: |
| 54 ash::MagnifierType GetMagnifierType() OVERRIDE { | 55 bool IsMagnifierEnabled() const OVERRIDE { |
| 56 return enabled_; | |
| 57 } | |
| 58 | |
| 59 ash::MagnifierType GetMagnifierType() const OVERRIDE { | |
| 55 return type_; | 60 return type_; |
| 56 } | 61 } |
| 57 | 62 |
| 58 void SetMagnifier(ash::MagnifierType type) OVERRIDE { | 63 void SetMagnifierEnabled(bool enabled) OVERRIDE { |
| 59 if (type == type_ && type == ash::MAGNIFIER_OFF) | 64 // This method may be invoked even when the other magnifier setting (e.g. |
|
Daniel Erat
2013/01/09 15:43:56
nit: s/setting/settings/
yoshiki
2013/01/10 06:25:39
Done.
| |
| 65 // type or scale) is changed, so we need to call magnification controller | |
|
Daniel Erat
2013/01/09 15:43:56
nit: s/is/are/
yoshiki
2013/01/10 06:25:39
Done.
| |
| 66 // even |enabled| is unchanged. Only if |enabled| is false and the magnifier | |
|
Daniel Erat
2013/01/09 15:43:56
nit: s/even/even if/
i'd also delete the last sen
yoshiki
2013/01/10 06:25:39
Done.
| |
| 67 // is already disabled, we are sure that we don't need to reflect the new | |
| 68 // settings right now because the magnifier keeps disabled, so returns here. | |
| 69 if (!enabled && !enabled_) | |
| 60 return; | 70 return; |
| 61 | 71 |
| 72 enabled_ = enabled; | |
| 73 | |
| 74 if (profile_) { | |
| 75 PrefService* prefs = profile_->GetPrefs(); | |
| 76 DCHECK(prefs); | |
| 77 if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) { | |
| 78 prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled); | |
| 79 prefs->CommitPendingWrite(); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 NotifyMagnifierChanged(); | |
| 84 | |
| 85 if (type_ == ash::MAGNIFIER_FULL) { | |
| 86 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( | |
| 87 enabled_); | |
| 88 } else { | |
| 89 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( | |
| 90 enabled_); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 void SetMagnifierType(ash::MagnifierType type) OVERRIDE { | |
| 95 if (type_ == type) | |
| 96 return; | |
| 97 | |
| 98 DCHECK(type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL); | |
| 62 type_ = type; | 99 type_ = type; |
| 63 | 100 |
| 64 if (profile_) { | 101 if (profile_) { |
| 65 PrefService* prefs = profile_->GetPrefs(); | 102 PrefService* prefs = profile_->GetPrefs(); |
| 66 if (prefs) { | 103 DCHECK(prefs); |
| 67 bool enabled = (type != ash::MAGNIFIER_OFF); | 104 prefs->SetInteger(prefs::kScreenMagnifierType, type); |
| 68 if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) { | 105 prefs->CommitPendingWrite(); |
| 69 prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled); | |
| 70 prefs->CommitPendingWrite(); | |
| 71 } | |
| 72 } | |
| 73 } | 106 } |
| 74 | 107 |
| 75 accessibility::AccessibilityStatusEventDetails details( | 108 NotifyMagnifierChanged(); |
| 76 type != ash::MAGNIFIER_OFF, ash::A11Y_NOTIFICATION_NONE); | |
| 77 content::NotificationService::current()->Notify( | |
| 78 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, | |
| 79 content::NotificationService::AllSources(), | |
| 80 content::Details<accessibility::AccessibilityStatusEventDetails>( | |
| 81 &details)); | |
| 82 | 109 |
| 83 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( | 110 if (enabled_) { |
| 84 type == ash::MAGNIFIER_FULL); | 111 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( |
| 85 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( | 112 type_ == ash::MAGNIFIER_FULL); |
| 86 type == ash::MAGNIFIER_PARTIAL); | 113 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( |
| 114 type_ == ash::MAGNIFIER_PARTIAL); | |
| 115 } | |
| 87 } | 116 } |
| 88 | 117 |
| 89 void SaveScreenMagnifierScale(double scale) OVERRIDE { | 118 void SaveScreenMagnifierScale(double scale) OVERRIDE { |
| 90 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 119 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 120 DCHECK(profile->GetPrefs()); | |
| 91 profile->GetPrefs()->SetDouble(prefs::kScreenMagnifierScale, scale); | 121 profile->GetPrefs()->SetDouble(prefs::kScreenMagnifierScale, scale); |
| 92 } | 122 } |
| 93 | 123 |
| 94 double GetSavedScreenMagnifierScale() OVERRIDE { | 124 double GetSavedScreenMagnifierScale() const OVERRIDE { |
| 95 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 125 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 126 DCHECK(profile->GetPrefs()); | |
| 96 if (profile->GetPrefs()->HasPrefPath(prefs::kScreenMagnifierScale)) | 127 if (profile->GetPrefs()->HasPrefPath(prefs::kScreenMagnifierScale)) |
| 97 return profile->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale); | 128 return profile->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale); |
| 98 return std::numeric_limits<double>::min(); | 129 return std::numeric_limits<double>::min(); |
| 99 } | 130 } |
| 100 | 131 |
| 101 private: | 132 private: |
| 133 void NotifyMagnifierChanged() { | |
| 134 accessibility::AccessibilityStatusEventDetails details( | |
| 135 enabled_, type_, ash::A11Y_NOTIFICATION_NONE); | |
| 136 content::NotificationService::current()->Notify( | |
| 137 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, | |
| 138 content::NotificationService::AllSources(), | |
| 139 content::Details<accessibility::AccessibilityStatusEventDetails>( | |
| 140 &details)); | |
| 141 } | |
| 142 | |
| 143 bool IsMagnifierEnabledFromPref() { | |
| 144 if (!profile_) | |
| 145 return false; | |
| 146 | |
| 147 DCHECK(profile_->GetPrefs()); | |
| 148 return profile_->GetPrefs()->GetBoolean(prefs::kScreenMagnifierEnabled); | |
| 149 } | |
| 150 | |
| 102 ash::MagnifierType GetMagnifierTypeFromPref() { | 151 ash::MagnifierType GetMagnifierTypeFromPref() { |
| 103 if (!profile_) | 152 if (!profile_) |
| 104 return ash::MAGNIFIER_OFF; | 153 return ash::kDefaultMagnifierType; |
| 105 | 154 |
| 106 PrefService* prefs = profile_->GetPrefs(); | 155 DCHECK(profile_->GetPrefs()); |
| 107 if (!prefs) | 156 ash::MagnifierType type = static_cast<ash::MagnifierType>( |
| 108 return ash::MAGNIFIER_OFF; | 157 profile_->GetPrefs()->GetInteger(prefs::kScreenMagnifierType)); |
| 109 | 158 |
| 110 return prefs->GetBoolean(prefs::kScreenMagnifierEnabled) ? | 159 if (type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL) |
| 111 ash::MAGNIFIER_FULL : ash::MAGNIFIER_OFF; | 160 return type; |
| 161 | |
| 162 return ash::kDefaultMagnifierType; | |
| 112 } | 163 } |
| 113 | 164 |
| 114 void SetProfile(Profile* profile) { | 165 void SetProfile(Profile* profile) { |
| 115 if (pref_change_registrar_) { | 166 if (pref_change_registrar_) { |
| 116 pref_change_registrar_.reset(); | 167 pref_change_registrar_.reset(); |
| 117 } | 168 } |
| 118 | 169 |
| 119 if (profile) { | 170 if (profile) { |
| 120 pref_change_registrar_.reset(new PrefChangeRegistrar); | 171 pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 121 pref_change_registrar_->Init(profile->GetPrefs()); | 172 pref_change_registrar_->Init(profile->GetPrefs()); |
| 122 pref_change_registrar_->Add( | 173 pref_change_registrar_->Add( |
| 123 prefs::kScreenMagnifierEnabled, | 174 prefs::kScreenMagnifierEnabled, |
| 124 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, | 175 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref, |
| 176 base::Unretained(this))); | |
| 177 pref_change_registrar_->Add( | |
| 178 prefs::kScreenMagnifierType, | |
| 179 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref, | |
| 125 base::Unretained(this))); | 180 base::Unretained(this))); |
| 126 } | 181 } |
| 127 | 182 |
| 128 profile_ = profile; | 183 profile_ = profile; |
| 129 UpdateMagnifierStatus(); | 184 UpdateMagnifierStatusFromPref(); |
| 130 } | 185 } |
| 131 | 186 |
| 132 void UpdateMagnifierStatus() { | 187 void UpdateMagnifierStatusFromPref() { |
| 133 ash::MagnifierType type = GetMagnifierTypeFromPref(); | 188 bool enabled = IsMagnifierEnabledFromPref(); |
| 134 SetMagnifier(type); | 189 if (!enabled) { |
| 190 SetMagnifierEnabled(enabled); | |
| 191 SetMagnifierType(GetMagnifierTypeFromPref()); | |
| 192 } else { | |
| 193 SetMagnifierType(GetMagnifierTypeFromPref()); | |
| 194 SetMagnifierEnabled(enabled); | |
| 195 } | |
| 135 } | 196 } |
| 136 | 197 |
| 137 // content::NotificationObserver implimentation: | 198 // content::NotificationObserver implimentation: |
| 138 virtual void Observe(int type, | 199 virtual void Observe(int type, |
| 139 const content::NotificationSource& source, | 200 const content::NotificationSource& source, |
| 140 const content::NotificationDetails& details) OVERRIDE { | 201 const content::NotificationDetails& details) OVERRIDE { |
| 141 switch (type) { | 202 switch (type) { |
| 142 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: | 203 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: |
| 143 case chrome::NOTIFICATION_SESSION_STARTED: { | 204 case chrome::NOTIFICATION_SESSION_STARTED: { |
| 144 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 205 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 145 SetProfile(profile); | 206 SetProfile(profile); |
| 146 break; | 207 break; |
| 147 } | 208 } |
| 148 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 209 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 149 SetProfile(NULL); | 210 SetProfile(NULL); |
| 150 break; | 211 break; |
| 151 } | 212 } |
| 152 } | 213 } |
| 153 } | 214 } |
| 154 | 215 |
| 155 bool first_time_update_; | 216 bool first_time_update_; |
| 156 Profile* profile_; | 217 Profile* profile_; |
| 157 ash::MagnifierType type_; | 218 ash::MagnifierType type_; |
| 219 bool enabled_; | |
| 158 content::NotificationRegistrar registrar_; | 220 content::NotificationRegistrar registrar_; |
| 159 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 221 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 160 | 222 |
| 161 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 223 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
| 162 }; | 224 }; |
| 163 | 225 |
| 164 // static | 226 // static |
| 165 void MagnificationManager::Initialize() { | 227 void MagnificationManager::Initialize() { |
| 166 CHECK(g_magnification_manager == NULL); | 228 CHECK(g_magnification_manager == NULL); |
| 167 g_magnification_manager = new MagnificationManagerImpl(); | 229 g_magnification_manager = new MagnificationManagerImpl(); |
| 168 } | 230 } |
| 169 | 231 |
| 170 // static | 232 // static |
| 171 void MagnificationManager::Shutdown() { | 233 void MagnificationManager::Shutdown() { |
| 172 CHECK(g_magnification_manager); | 234 CHECK(g_magnification_manager); |
| 173 delete g_magnification_manager; | 235 delete g_magnification_manager; |
| 174 g_magnification_manager = NULL; | 236 g_magnification_manager = NULL; |
| 175 } | 237 } |
| 176 | 238 |
| 177 // static | 239 // static |
| 178 MagnificationManager* MagnificationManager::Get() { | 240 MagnificationManager* MagnificationManager::Get() { |
| 179 return g_magnification_manager; | 241 return g_magnification_manager; |
| 180 } | 242 } |
| 181 | 243 |
| 182 } // namespace chromeos | 244 } // namespace chromeos |
| OLD | NEW |