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 30 matching lines...) Expand all Loading... | |
41 public: | 41 public: |
42 MagnificationManagerImpl() | 42 MagnificationManagerImpl() |
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_(ui::kDefaultMagnifierType), | 49 type_(ui::kDefaultMagnifierType), |
50 enabled_(false), | 50 enabled_(false), |
51 keep_focus_centered_(false), | |
51 observing_focus_change_in_page_(false) { | 52 observing_focus_change_in_page_(false) { |
52 registrar_.Add(this, | 53 registrar_.Add(this, |
53 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 54 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
54 content::NotificationService::AllSources()); | 55 content::NotificationService::AllSources()); |
55 registrar_.Add(this, | 56 registrar_.Add(this, |
56 chrome::NOTIFICATION_SESSION_STARTED, | 57 chrome::NOTIFICATION_SESSION_STARTED, |
57 content::NotificationService::AllSources()); | 58 content::NotificationService::AllSources()); |
58 registrar_.Add(this, | 59 registrar_.Add(this, |
59 chrome::NOTIFICATION_PROFILE_DESTROYED, | 60 chrome::NOTIFICATION_PROFILE_DESTROYED, |
60 content::NotificationService::AllSources()); | 61 content::NotificationService::AllSources()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 pref_change_registrar_.reset(new PrefChangeRegistrar); | 120 pref_change_registrar_.reset(new PrefChangeRegistrar); |
120 pref_change_registrar_->Init(profile->GetPrefs()); | 121 pref_change_registrar_->Init(profile->GetPrefs()); |
121 pref_change_registrar_->Add( | 122 pref_change_registrar_->Add( |
122 prefs::kAccessibilityScreenMagnifierEnabled, | 123 prefs::kAccessibilityScreenMagnifierEnabled, |
123 base::Bind(&MagnificationManagerImpl::UpdateMagnifierFromPrefs, | 124 base::Bind(&MagnificationManagerImpl::UpdateMagnifierFromPrefs, |
124 base::Unretained(this))); | 125 base::Unretained(this))); |
125 pref_change_registrar_->Add( | 126 pref_change_registrar_->Add( |
126 prefs::kAccessibilityScreenMagnifierType, | 127 prefs::kAccessibilityScreenMagnifierType, |
127 base::Bind(&MagnificationManagerImpl::UpdateMagnifierFromPrefs, | 128 base::Bind(&MagnificationManagerImpl::UpdateMagnifierFromPrefs, |
128 base::Unretained(this))); | 129 base::Unretained(this))); |
130 pref_change_registrar_->Add( | |
131 prefs::kAccessibilityScreenMagnifierCenterFocus, | |
132 base::Bind(&MagnificationManagerImpl::UpdateMagnifierFromPrefs, | |
133 base::Unretained(this))); | |
129 } | 134 } |
130 | 135 |
131 magnifier_enabled_pref_handler_.HandleProfileChanged(profile_, profile); | 136 magnifier_enabled_pref_handler_.HandleProfileChanged(profile_, profile); |
132 magnifier_type_pref_handler_.HandleProfileChanged(profile_, profile); | 137 magnifier_type_pref_handler_.HandleProfileChanged(profile_, profile); |
133 magnifier_scale_pref_handler_.HandleProfileChanged(profile_, profile); | 138 magnifier_scale_pref_handler_.HandleProfileChanged(profile_, profile); |
134 | 139 |
135 profile_ = profile; | 140 profile_ = profile; |
136 UpdateMagnifierFromPrefs(); | 141 UpdateMagnifierFromPrefs(); |
137 } | 142 } |
138 | 143 |
(...skipping 18 matching lines...) Expand all Loading... | |
157 } | 162 } |
158 } | 163 } |
159 | 164 |
160 virtual void SetMagnifierTypeInternal(ui::MagnifierType type) { | 165 virtual void SetMagnifierTypeInternal(ui::MagnifierType type) { |
161 if (type_ == type) | 166 if (type_ == type) |
162 return; | 167 return; |
163 | 168 |
164 type_ = ui::MAGNIFIER_FULL; // (leave out for full magnifier) | 169 type_ = ui::MAGNIFIER_FULL; // (leave out for full magnifier) |
165 } | 170 } |
166 | 171 |
172 virtual void SetMagniferKeepFocusCenteredInternal(bool keep_focus_centered) { | |
173 if (keep_focus_centered_ == keep_focus_centered) | |
174 return; | |
175 | |
176 keep_focus_centered_ = keep_focus_centered; | |
177 | |
178 if (type_ == ui::MAGNIFIER_FULL) { | |
179 ash::Shell::GetInstance() | |
180 ->magnification_controller() | |
181 ->SetKeepFocusCentered(keep_focus_centered_); | |
182 } | |
183 } | |
184 | |
167 void UpdateMagnifierFromPrefs() { | 185 void UpdateMagnifierFromPrefs() { |
168 if (!profile_) | 186 if (!profile_) |
169 return; | 187 return; |
170 | 188 |
171 const bool enabled = profile_->GetPrefs()->GetBoolean( | 189 const bool enabled = profile_->GetPrefs()->GetBoolean( |
172 prefs::kAccessibilityScreenMagnifierEnabled); | 190 prefs::kAccessibilityScreenMagnifierEnabled); |
173 const int type_integer = profile_->GetPrefs()->GetInteger( | 191 const int type_integer = profile_->GetPrefs()->GetInteger( |
174 prefs::kAccessibilityScreenMagnifierType); | 192 prefs::kAccessibilityScreenMagnifierType); |
193 const bool keep_focus_centered = profile_->GetPrefs()->GetBoolean( | |
194 prefs::kAccessibilityScreenMagnifierCenterFocus); | |
175 | 195 |
176 ui::MagnifierType type = ui::kDefaultMagnifierType; | 196 ui::MagnifierType type = ui::kDefaultMagnifierType; |
177 if (type_integer > 0 && type_integer <= ui::kMaxMagnifierType) { | 197 if (type_integer > 0 && type_integer <= ui::kMaxMagnifierType) { |
178 type = static_cast<ui::MagnifierType>(type_integer); | 198 type = static_cast<ui::MagnifierType>(type_integer); |
179 } else if (type_integer == 0) { | 199 } else if (type_integer == 0) { |
180 // Type 0 is used to disable the screen magnifier through policy. As the | 200 // Type 0 is used to disable the screen magnifier through policy. As the |
181 // magnifier type is irrelevant in this case, it is OK to just fall back | 201 // magnifier type is irrelevant in this case, it is OK to just fall back |
182 // to the default. | 202 // to the default. |
183 } else { | 203 } else { |
184 NOTREACHED(); | 204 NOTREACHED(); |
185 } | 205 } |
186 | 206 |
187 if (!enabled) { | 207 if (!enabled) { |
188 SetMagnifierEnabledInternal(enabled); | 208 SetMagnifierEnabledInternal(enabled); |
189 SetMagnifierTypeInternal(type); | 209 SetMagnifierTypeInternal(type); |
210 SetMagniferKeepFocusCenteredInternal(keep_focus_centered); | |
190 } else { | 211 } else { |
191 SetMagnifierTypeInternal(type); | 212 SetMagnifierTypeInternal(type); |
213 SetMagniferKeepFocusCenteredInternal(keep_focus_centered); | |
oshima
2015/05/28 22:41:35
can you keep the (reverse) order?
jennyz
2015/05/29 21:41:24
Done.
| |
192 SetMagnifierEnabledInternal(enabled); | 214 SetMagnifierEnabledInternal(enabled); |
193 } | 215 } |
194 | 216 |
195 AccessibilityStatusEventDetails details( | 217 AccessibilityStatusEventDetails details( |
196 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, | 218 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, |
197 enabled_, | 219 enabled_, |
198 type_, | 220 type_, |
199 ui::A11Y_NOTIFICATION_NONE); | 221 ui::A11Y_NOTIFICATION_NONE); |
200 | 222 |
201 if (AccessibilityManager::Get()) { | 223 if (AccessibilityManager::Get()) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 } | 282 } |
261 | 283 |
262 Profile* profile_; | 284 Profile* profile_; |
263 | 285 |
264 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; | 286 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; |
265 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; | 287 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; |
266 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; | 288 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; |
267 | 289 |
268 ui::MagnifierType type_; | 290 ui::MagnifierType type_; |
269 bool enabled_; | 291 bool enabled_; |
292 bool keep_focus_centered_; | |
270 bool observing_focus_change_in_page_; | 293 bool observing_focus_change_in_page_; |
271 | 294 |
272 content::NotificationRegistrar registrar_; | 295 content::NotificationRegistrar registrar_; |
273 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 296 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
274 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; | 297 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_; |
275 | 298 |
276 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 299 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
277 }; | 300 }; |
278 | 301 |
279 // static | 302 // static |
280 void MagnificationManager::Initialize() { | 303 void MagnificationManager::Initialize() { |
281 CHECK(g_magnification_manager == NULL); | 304 CHECK(g_magnification_manager == NULL); |
282 g_magnification_manager = new MagnificationManagerImpl(); | 305 g_magnification_manager = new MagnificationManagerImpl(); |
283 } | 306 } |
284 | 307 |
285 // static | 308 // static |
286 void MagnificationManager::Shutdown() { | 309 void MagnificationManager::Shutdown() { |
287 CHECK(g_magnification_manager); | 310 CHECK(g_magnification_manager); |
288 delete g_magnification_manager; | 311 delete g_magnification_manager; |
289 g_magnification_manager = NULL; | 312 g_magnification_manager = NULL; |
290 } | 313 } |
291 | 314 |
292 // static | 315 // static |
293 MagnificationManager* MagnificationManager::Get() { | 316 MagnificationManager* MagnificationManager::Get() { |
294 return g_magnification_manager; | 317 return g_magnification_manager; |
295 } | 318 } |
296 | 319 |
297 } // namespace chromeos | 320 } // namespace chromeos |
OLD | NEW |