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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 public ash::SessionStateObserver { | 39 public ash::SessionStateObserver { |
40 public: | 40 public: |
41 MagnificationManagerImpl() | 41 MagnificationManagerImpl() |
42 : first_time_update_(true), | 42 : first_time_update_(true), |
43 profile_(NULL), | 43 profile_(NULL), |
44 magnifier_enabled_pref_handler_( | 44 magnifier_enabled_pref_handler_( |
45 prefs::kAccessibilityScreenMagnifierEnabled), | 45 prefs::kAccessibilityScreenMagnifierEnabled), |
46 magnifier_type_pref_handler_(prefs::kAccessibilityScreenMagnifierType), | 46 magnifier_type_pref_handler_(prefs::kAccessibilityScreenMagnifierType), |
47 magnifier_scale_pref_handler_( | 47 magnifier_scale_pref_handler_( |
48 prefs::kAccessibilityScreenMagnifierScale), | 48 prefs::kAccessibilityScreenMagnifierScale), |
49 type_(ash::kDefaultMagnifierType), | 49 type_(ui::kDefaultMagnifierType), |
50 enabled_(false) { | 50 enabled_(false) { |
51 registrar_.Add(this, | 51 registrar_.Add(this, |
52 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 52 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
53 content::NotificationService::AllSources()); | 53 content::NotificationService::AllSources()); |
54 registrar_.Add(this, | 54 registrar_.Add(this, |
55 chrome::NOTIFICATION_SESSION_STARTED, | 55 chrome::NOTIFICATION_SESSION_STARTED, |
56 content::NotificationService::AllSources()); | 56 content::NotificationService::AllSources()); |
57 registrar_.Add(this, | 57 registrar_.Add(this, |
58 chrome::NOTIFICATION_PROFILE_DESTROYED, | 58 chrome::NOTIFICATION_PROFILE_DESTROYED, |
59 content::NotificationService::AllSources()); | 59 content::NotificationService::AllSources()); |
60 } | 60 } |
61 | 61 |
62 virtual ~MagnificationManagerImpl() { | 62 virtual ~MagnificationManagerImpl() { |
63 CHECK(this == g_magnification_manager); | 63 CHECK(this == g_magnification_manager); |
64 } | 64 } |
65 | 65 |
66 // MagnificationManager implimentation: | 66 // MagnificationManager implimentation: |
67 virtual bool IsMagnifierEnabled() const override { | 67 virtual bool IsMagnifierEnabled() const override { |
68 return enabled_; | 68 return enabled_; |
69 } | 69 } |
70 | 70 |
71 virtual ash::MagnifierType GetMagnifierType() const override { | 71 virtual ui::MagnifierType GetMagnifierType() const override { |
72 return type_; | 72 return type_; |
73 } | 73 } |
74 | 74 |
75 virtual void SetMagnifierEnabled(bool enabled) override { | 75 virtual void SetMagnifierEnabled(bool enabled) override { |
76 if (!profile_) | 76 if (!profile_) |
77 return; | 77 return; |
78 | 78 |
79 PrefService* prefs = profile_->GetPrefs(); | 79 PrefService* prefs = profile_->GetPrefs(); |
80 prefs->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, enabled); | 80 prefs->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, enabled); |
81 prefs->CommitPendingWrite(); | 81 prefs->CommitPendingWrite(); |
82 } | 82 } |
83 | 83 |
84 virtual void SetMagnifierType(ash::MagnifierType type) override { | 84 virtual void SetMagnifierType(ui::MagnifierType type) override { |
85 if (!profile_) | 85 if (!profile_) |
86 return; | 86 return; |
87 | 87 |
88 PrefService* prefs = profile_->GetPrefs(); | 88 PrefService* prefs = profile_->GetPrefs(); |
89 prefs->SetInteger(prefs::kAccessibilityScreenMagnifierType, type); | 89 prefs->SetInteger(prefs::kAccessibilityScreenMagnifierType, type); |
90 prefs->CommitPendingWrite(); | 90 prefs->CommitPendingWrite(); |
91 } | 91 } |
92 | 92 |
93 virtual void SaveScreenMagnifierScale(double scale) override { | 93 virtual void SaveScreenMagnifierScale(double scale) override { |
94 if (!profile_) | 94 if (!profile_) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // This method may be invoked even when the other magnifier settings (e.g. | 145 // This method may be invoked even when the other magnifier settings (e.g. |
146 // type or scale) are changed, so we need to call magnification controller | 146 // type or scale) are changed, so we need to call magnification controller |
147 // even if |enabled| is unchanged. Only if |enabled| is false and the | 147 // even if |enabled| is unchanged. Only if |enabled| is false and the |
148 // magnifier is already disabled, we are sure that we don't need to reflect | 148 // 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. | 149 // the new settings right now because the magnifier keeps disabled. |
150 if (!enabled && !enabled_) | 150 if (!enabled && !enabled_) |
151 return; | 151 return; |
152 | 152 |
153 enabled_ = enabled; | 153 enabled_ = enabled; |
154 | 154 |
155 if (type_ == ash::MAGNIFIER_FULL) { | 155 if (type_ == ui::MAGNIFIER_FULL) { |
156 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( | 156 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( |
157 enabled_); | 157 enabled_); |
158 } else { | 158 } else { |
159 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( | 159 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( |
160 enabled_); | 160 enabled_); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 virtual void SetMagnifierTypeInternal(ash::MagnifierType type) { | 164 virtual void SetMagnifierTypeInternal(ui::MagnifierType type) { |
165 if (type_ == type) | 165 if (type_ == type) |
166 return; | 166 return; |
167 | 167 |
168 type_ = ash::MAGNIFIER_FULL; // (leave out for full magnifier) | 168 type_ = ui::MAGNIFIER_FULL; // (leave out for full magnifier) |
169 } | 169 } |
170 | 170 |
171 void UpdateMagnifierFromPrefs() { | 171 void UpdateMagnifierFromPrefs() { |
172 if (!profile_) | 172 if (!profile_) |
173 return; | 173 return; |
174 | 174 |
175 const bool enabled = profile_->GetPrefs()->GetBoolean( | 175 const bool enabled = profile_->GetPrefs()->GetBoolean( |
176 prefs::kAccessibilityScreenMagnifierEnabled); | 176 prefs::kAccessibilityScreenMagnifierEnabled); |
177 const int type_integer = profile_->GetPrefs()->GetInteger( | 177 const int type_integer = profile_->GetPrefs()->GetInteger( |
178 prefs::kAccessibilityScreenMagnifierType); | 178 prefs::kAccessibilityScreenMagnifierType); |
179 | 179 |
180 ash::MagnifierType type = ash::kDefaultMagnifierType; | 180 ui::MagnifierType type = ui::kDefaultMagnifierType; |
181 if (type_integer > 0 && type_integer <= ash::kMaxMagnifierType) { | 181 if (type_integer > 0 && type_integer <= ui::kMaxMagnifierType) { |
182 type = static_cast<ash::MagnifierType>(type_integer); | 182 type = static_cast<ui::MagnifierType>(type_integer); |
183 } else if (type_integer == 0) { | 183 } else if (type_integer == 0) { |
184 // Type 0 is used to disable the screen magnifier through policy. As the | 184 // Type 0 is used to disable the screen magnifier through policy. As the |
185 // magnifier type is irrelevant in this case, it is OK to just fall back | 185 // magnifier type is irrelevant in this case, it is OK to just fall back |
186 // to the default. | 186 // to the default. |
187 } else { | 187 } else { |
188 NOTREACHED(); | 188 NOTREACHED(); |
189 } | 189 } |
190 | 190 |
191 if (!enabled) { | 191 if (!enabled) { |
192 SetMagnifierEnabledInternal(enabled); | 192 SetMagnifierEnabledInternal(enabled); |
193 SetMagnifierTypeInternal(type); | 193 SetMagnifierTypeInternal(type); |
194 } else { | 194 } else { |
195 SetMagnifierTypeInternal(type); | 195 SetMagnifierTypeInternal(type); |
196 SetMagnifierEnabledInternal(enabled); | 196 SetMagnifierEnabledInternal(enabled); |
197 } | 197 } |
198 | 198 |
199 AccessibilityStatusEventDetails details( | 199 AccessibilityStatusEventDetails details( |
200 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, | 200 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, |
201 enabled_, | 201 enabled_, |
202 type_, | 202 type_, |
203 ash::A11Y_NOTIFICATION_NONE); | 203 ui::A11Y_NOTIFICATION_NONE); |
204 | 204 |
205 #if defined(OS_CHROMEOS) | 205 #if defined(OS_CHROMEOS) |
206 if (AccessibilityManager::Get()) { | 206 if (AccessibilityManager::Get()) { |
207 AccessibilityManager::Get()->NotifyAccessibilityStatusChanged(details); | 207 AccessibilityManager::Get()->NotifyAccessibilityStatusChanged(details); |
208 if (ash::Shell::GetInstance()) { | 208 if (ash::Shell::GetInstance()) { |
209 ash::Shell::GetInstance()->SetCursorCompositingEnabled( | 209 ash::Shell::GetInstance()->SetCursorCompositingEnabled( |
210 AccessibilityManager::Get()->ShouldEnableCursorCompositing()); | 210 AccessibilityManager::Get()->ShouldEnableCursorCompositing()); |
211 } | 211 } |
212 } | 212 } |
213 #endif | 213 #endif |
(...skipping 30 matching lines...) Expand all Loading... |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 bool first_time_update_; | 247 bool first_time_update_; |
248 Profile* profile_; | 248 Profile* profile_; |
249 | 249 |
250 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; | 250 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; |
251 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; | 251 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; |
252 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; | 252 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; |
253 | 253 |
254 ash::MagnifierType type_; | 254 ui::MagnifierType type_; |
255 bool enabled_; | 255 bool enabled_; |
256 | 256 |
257 content::NotificationRegistrar registrar_; | 257 content::NotificationRegistrar registrar_; |
258 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 258 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
259 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; | 259 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; |
260 | 260 |
261 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 261 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
262 }; | 262 }; |
263 | 263 |
264 // static | 264 // static |
265 void MagnificationManager::Initialize() { | 265 void MagnificationManager::Initialize() { |
266 CHECK(g_magnification_manager == NULL); | 266 CHECK(g_magnification_manager == NULL); |
267 g_magnification_manager = new MagnificationManagerImpl(); | 267 g_magnification_manager = new MagnificationManagerImpl(); |
268 } | 268 } |
269 | 269 |
270 // static | 270 // static |
271 void MagnificationManager::Shutdown() { | 271 void MagnificationManager::Shutdown() { |
272 CHECK(g_magnification_manager); | 272 CHECK(g_magnification_manager); |
273 delete g_magnification_manager; | 273 delete g_magnification_manager; |
274 g_magnification_manager = NULL; | 274 g_magnification_manager = NULL; |
275 } | 275 } |
276 | 276 |
277 // static | 277 // static |
278 MagnificationManager* MagnificationManager::Get() { | 278 MagnificationManager* MagnificationManager::Get() { |
279 return g_magnification_manager; | 279 return g_magnification_manager; |
280 } | 280 } |
281 | 281 |
282 } // namespace chromeos | 282 } // namespace chromeos |
OLD | NEW |