Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: chrome/browser/chromeos/accessibility/magnification_manager.cc

Issue 11642014: Re-introduce the partial magnifier (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the build failure on win_aura Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_PROFILE_CREATED, 40 chrome::NOTIFICATION_PROFILE_CREATED,
40 content::NotificationService::AllSources()); 41 content::NotificationService::AllSources());
41 registrar_.Add(this, 42 registrar_.Add(this,
42 chrome::NOTIFICATION_SESSION_STARTED, 43 chrome::NOTIFICATION_SESSION_STARTED,
43 content::NotificationService::AllSources()); 44 content::NotificationService::AllSources());
44 registrar_.Add(this, 45 registrar_.Add(this,
45 chrome::NOTIFICATION_PROFILE_DESTROYED, 46 chrome::NOTIFICATION_PROFILE_DESTROYED,
46 content::NotificationService::AllSources()); 47 content::NotificationService::AllSources());
47 registrar_.Add(this, 48 registrar_.Add(this,
48 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, 49 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
49 content::NotificationService::AllSources()); 50 content::NotificationService::AllSources());
50 } 51 }
51 52
52 virtual ~MagnificationManagerImpl() { 53 virtual ~MagnificationManagerImpl() {
53 CHECK(this == g_magnification_manager); 54 CHECK(this == g_magnification_manager);
54 } 55 }
55 56
56 // MagnificationManager implimentation: 57 // MagnificationManager implimentation:
57 ash::MagnifierType GetMagnifierType() OVERRIDE { 58 bool IsMagnifierEnabled() const OVERRIDE {
59 return enabled_;
60 }
61
62 ash::MagnifierType GetMagnifierType() const OVERRIDE {
58 return type_; 63 return type_;
59 } 64 }
60 65
61 void SetMagnifier(ash::MagnifierType type) OVERRIDE { 66 void SetMagnifierEnabled(bool enabled) OVERRIDE {
62 if (type == type_ && type == ash::MAGNIFIER_OFF) 67 // This method may be invoked even when the other magnifier settings (e.g.
68 // type or scale) are changed, so we need to call magnification controller
69 // even if |enabled| is unchanged. Only if |enabled| is false and the
70 // magnifier is already disabled, we are sure that we don't need to reflect
71 // the new settings right now because the magnifier keeps disabled.
72 if (!enabled && !enabled_)
63 return; 73 return;
64 74
75 enabled_ = enabled;
76
77 if (profile_) {
78 PrefService* prefs = profile_->GetPrefs();
79 DCHECK(prefs);
80 if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) {
81 prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
82 prefs->CommitPendingWrite();
83 }
84 }
85
86 NotifyMagnifierChanged();
87
88 if (type_ == ash::MAGNIFIER_FULL) {
89 ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
90 enabled_);
91 } else {
92 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
93 enabled_);
94 }
95 }
96
97 void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
98 if (type_ == type)
99 return;
100
101 DCHECK(type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL);
65 type_ = type; 102 type_ = type;
66 103
67 if (profile_) { 104 if (profile_) {
68 PrefService* prefs = profile_->GetPrefs(); 105 PrefService* prefs = profile_->GetPrefs();
69 if (prefs) { 106 DCHECK(prefs);
70 bool enabled = (type != ash::MAGNIFIER_OFF); 107 prefs->SetInteger(prefs::kScreenMagnifierType, type);
71 if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) { 108 prefs->CommitPendingWrite();
72 prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
73 prefs->CommitPendingWrite();
74 }
75 }
76 } 109 }
77 110
78 accessibility::AccessibilityStatusEventDetails details( 111 NotifyMagnifierChanged();
79 type != ash::MAGNIFIER_OFF, ash::A11Y_NOTIFICATION_NONE);
80 content::NotificationService::current()->Notify(
81 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
82 content::NotificationService::AllSources(),
83 content::Details<accessibility::AccessibilityStatusEventDetails>(
84 &details));
85 112
86 ash::Shell::GetInstance()->magnification_controller()->SetEnabled( 113 if (enabled_) {
87 type == ash::MAGNIFIER_FULL); 114 ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
88 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( 115 type_ == ash::MAGNIFIER_FULL);
89 type == ash::MAGNIFIER_PARTIAL); 116 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
117 type_ == ash::MAGNIFIER_PARTIAL);
118 }
90 } 119 }
91 120
92 void SaveScreenMagnifierScale(double scale) OVERRIDE { 121 void SaveScreenMagnifierScale(double scale) OVERRIDE {
93 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); 122 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
123 DCHECK(profile->GetPrefs());
94 profile->GetPrefs()->SetDouble(prefs::kScreenMagnifierScale, scale); 124 profile->GetPrefs()->SetDouble(prefs::kScreenMagnifierScale, scale);
95 } 125 }
96 126
97 double GetSavedScreenMagnifierScale() OVERRIDE { 127 double GetSavedScreenMagnifierScale() const OVERRIDE {
98 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); 128 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
129 DCHECK(profile->GetPrefs());
99 if (profile->GetPrefs()->HasPrefPath(prefs::kScreenMagnifierScale)) 130 if (profile->GetPrefs()->HasPrefPath(prefs::kScreenMagnifierScale))
100 return profile->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale); 131 return profile->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale);
101 return std::numeric_limits<double>::min(); 132 return std::numeric_limits<double>::min();
102 } 133 }
103 134
104 private: 135 private:
136 void NotifyMagnifierChanged() {
137 accessibility::AccessibilityStatusEventDetails details(
138 enabled_, type_, ash::A11Y_NOTIFICATION_NONE);
139 content::NotificationService::current()->Notify(
140 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
141 content::NotificationService::AllSources(),
142 content::Details<accessibility::AccessibilityStatusEventDetails>(
143 &details));
144 }
145
146 bool IsMagnifierEnabledFromPref() {
147 if (!profile_)
148 return false;
149
150 DCHECK(profile_->GetPrefs());
151 return profile_->GetPrefs()->GetBoolean(prefs::kScreenMagnifierEnabled);
152 }
153
105 ash::MagnifierType GetMagnifierTypeFromPref() { 154 ash::MagnifierType GetMagnifierTypeFromPref() {
106 if (!profile_) 155 if (!profile_)
107 return ash::MAGNIFIER_OFF; 156 return ash::kDefaultMagnifierType;
108 157
109 PrefService* prefs = profile_->GetPrefs(); 158 DCHECK(profile_->GetPrefs());
110 if (!prefs) 159 ash::MagnifierType type = static_cast<ash::MagnifierType>(
111 return ash::MAGNIFIER_OFF; 160 profile_->GetPrefs()->GetInteger(prefs::kScreenMagnifierType));
112 161
113 return prefs->GetBoolean(prefs::kScreenMagnifierEnabled) ? 162 if (type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL)
114 ash::MAGNIFIER_FULL : ash::MAGNIFIER_OFF; 163 return type;
164
165 return ash::kDefaultMagnifierType;
115 } 166 }
116 167
117 void SetProfile(Profile* profile) { 168 void SetProfile(Profile* profile) {
118 if (pref_change_registrar_) { 169 if (pref_change_registrar_) {
119 pref_change_registrar_.reset(); 170 pref_change_registrar_.reset();
120 } 171 }
121 172
122 if (profile) { 173 if (profile) {
123 pref_change_registrar_.reset(new PrefChangeRegistrar); 174 pref_change_registrar_.reset(new PrefChangeRegistrar);
124 pref_change_registrar_->Init(profile->GetPrefs()); 175 pref_change_registrar_->Init(profile->GetPrefs());
125 pref_change_registrar_->Add( 176 pref_change_registrar_->Add(
126 prefs::kScreenMagnifierEnabled, 177 prefs::kScreenMagnifierEnabled,
127 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, 178 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref,
179 base::Unretained(this)));
180 pref_change_registrar_->Add(
181 prefs::kScreenMagnifierType,
182 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref,
128 base::Unretained(this))); 183 base::Unretained(this)));
129 } 184 }
130 185
131 profile_ = profile; 186 profile_ = profile;
132 UpdateMagnifierStatus(); 187 UpdateMagnifierStatusFromPref();
133 } 188 }
134 189
135 void UpdateMagnifierStatus() { 190 void UpdateMagnifierStatusFromPref() {
136 ash::MagnifierType type = GetMagnifierTypeFromPref(); 191 bool enabled = IsMagnifierEnabledFromPref();
137 SetMagnifier(type); 192 if (!enabled) {
193 SetMagnifierEnabled(enabled);
194 SetMagnifierType(GetMagnifierTypeFromPref());
195 } else {
196 SetMagnifierType(GetMagnifierTypeFromPref());
197 SetMagnifierEnabled(enabled);
198 }
138 } 199 }
139 200
140 // content::NotificationObserver implimentation: 201 // content::NotificationObserver implimentation:
141 virtual void Observe(int type, 202 virtual void Observe(int type,
142 const content::NotificationSource& source, 203 const content::NotificationSource& source,
143 const content::NotificationDetails& details) OVERRIDE { 204 const content::NotificationDetails& details) OVERRIDE {
144 switch (type) { 205 switch (type) {
145 // When entering the login screen or non-guest desktop. 206 // When entering the login screen or non-guest desktop.
146 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: 207 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE:
147 case chrome::NOTIFICATION_SESSION_STARTED: { 208 case chrome::NOTIFICATION_SESSION_STARTED: {
(...skipping 13 matching lines...) Expand all
161 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 222 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
162 SetProfile(NULL); 223 SetProfile(NULL);
163 break; 224 break;
164 } 225 }
165 } 226 }
166 } 227 }
167 228
168 bool first_time_update_; 229 bool first_time_update_;
169 Profile* profile_; 230 Profile* profile_;
170 ash::MagnifierType type_; 231 ash::MagnifierType type_;
232 bool enabled_;
171 content::NotificationRegistrar registrar_; 233 content::NotificationRegistrar registrar_;
172 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; 234 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
173 235
174 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); 236 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl);
175 }; 237 };
176 238
177 // static 239 // static
178 void MagnificationManager::Initialize() { 240 void MagnificationManager::Initialize() {
179 CHECK(g_magnification_manager == NULL); 241 CHECK(g_magnification_manager == NULL);
180 g_magnification_manager = new MagnificationManagerImpl(); 242 g_magnification_manager = new MagnificationManagerImpl();
181 } 243 }
182 244
183 // static 245 // static
184 void MagnificationManager::Shutdown() { 246 void MagnificationManager::Shutdown() {
185 CHECK(g_magnification_manager); 247 CHECK(g_magnification_manager);
186 delete g_magnification_manager; 248 delete g_magnification_manager;
187 g_magnification_manager = NULL; 249 g_magnification_manager = NULL;
188 } 250 }
189 251
190 // static 252 // static
191 MagnificationManager* MagnificationManager::Get() { 253 MagnificationManager* MagnificationManager::Get() {
192 return g_magnification_manager; 254 return g_magnification_manager;
193 } 255 }
194 256
195 } // namespace chromeos 257 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698