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; | |
29 static MagnificationManager* g_magnification_manager = NULL; | 28 static MagnificationManager* g_magnification_manager = NULL; |
30 } | 29 } |
31 | 30 |
32 class MagnificationManagerImpl : public MagnificationManager, | 31 class MagnificationManagerImpl : public MagnificationManager, |
33 public content::NotificationObserver { | 32 public content::NotificationObserver { |
34 public: | 33 public: |
35 MagnificationManagerImpl() : first_time_update_(true), | 34 MagnificationManagerImpl() : profile_(NULL), |
36 profile_(NULL), | |
37 type_(ash::MAGNIFIER_OFF) { | 35 type_(ash::MAGNIFIER_OFF) { |
38 registrar_.Add(this, | 36 registrar_.Add(this, |
39 chrome::NOTIFICATION_SESSION_STARTED, | 37 chrome::NOTIFICATION_SESSION_STARTED, |
40 content::NotificationService::AllSources()); | 38 content::NotificationService::AllSources()); |
41 registrar_.Add(this, | 39 registrar_.Add(this, |
42 chrome::NOTIFICATION_PROFILE_DESTROYED, | 40 chrome::NOTIFICATION_PROFILE_DESTROYED, |
43 content::NotificationService::AllSources()); | 41 content::NotificationService::AllSources()); |
44 registrar_.Add(this, | 42 registrar_.Add(this, |
45 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, | 43 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, |
46 content::NotificationService::AllSources()); | 44 content::NotificationService::AllSources()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 prefs::kMagnifierType, | 129 prefs::kMagnifierType, |
132 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, | 130 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, |
133 base::Unretained(this))); | 131 base::Unretained(this))); |
134 } | 132 } |
135 | 133 |
136 profile_ = profile; | 134 profile_ = profile; |
137 UpdateMagnifierStatus(); | 135 UpdateMagnifierStatus(); |
138 } | 136 } |
139 | 137 |
140 void UpdateMagnifierStatus() { | 138 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 | |
165 ash::MagnifierType type = GetMagnifierTypeFromPref(); | 139 ash::MagnifierType type = GetMagnifierTypeFromPref(); |
166 SetMagnifier(type); | 140 SetMagnifier(type); |
167 } | 141 } |
168 | 142 |
169 // content::NotificationObserver implimentation: | 143 // content::NotificationObserver implimentation: |
170 virtual void Observe(int type, | 144 virtual void Observe(int type, |
171 const content::NotificationSource& source, | 145 const content::NotificationSource& source, |
172 const content::NotificationDetails& details) OVERRIDE { | 146 const content::NotificationDetails& details) OVERRIDE { |
173 switch (type) { | 147 switch (type) { |
174 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: | 148 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: |
175 case chrome::NOTIFICATION_SESSION_STARTED: { | 149 case chrome::NOTIFICATION_SESSION_STARTED: { |
176 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 150 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
177 SetProfile(profile); | 151 SetProfile(profile); |
178 break; | 152 break; |
179 } | 153 } |
180 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 154 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
181 SetProfile(NULL); | 155 SetProfile(NULL); |
182 break; | 156 break; |
183 } | 157 } |
184 } | 158 } |
185 } | 159 } |
186 | 160 |
187 bool first_time_update_; | |
188 Profile* profile_; | 161 Profile* profile_; |
189 ash::MagnifierType type_; | 162 ash::MagnifierType type_; |
190 content::NotificationRegistrar registrar_; | 163 content::NotificationRegistrar registrar_; |
191 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 164 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
192 | 165 |
193 ObserverList<MagnificationObserver> observers_; | 166 ObserverList<MagnificationObserver> observers_; |
194 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 167 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
195 }; | 168 }; |
196 | 169 |
197 // static | 170 // static |
198 void MagnificationManager::Initialize() { | 171 void MagnificationManager::Initialize() { |
199 CHECK(g_magnification_manager == NULL); | 172 CHECK(g_magnification_manager == NULL); |
200 g_magnification_manager = new MagnificationManagerImpl(); | 173 g_magnification_manager = new MagnificationManagerImpl(); |
201 } | 174 } |
202 | 175 |
203 // static | 176 // static |
204 void MagnificationManager::Shutdown() { | 177 void MagnificationManager::Shutdown() { |
205 CHECK(g_magnification_manager); | 178 CHECK(g_magnification_manager); |
206 delete g_magnification_manager; | 179 delete g_magnification_manager; |
207 g_magnification_manager = NULL; | 180 g_magnification_manager = NULL; |
208 } | 181 } |
209 | 182 |
210 // static | 183 // static |
211 MagnificationManager* MagnificationManager::Get() { | 184 MagnificationManager* MagnificationManager::Get() { |
212 return g_magnification_manager; | 185 return g_magnification_manager; |
213 } | 186 } |
214 | 187 |
215 } // namespace chromeos | 188 } // namespace chromeos |
OLD | NEW |