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

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

Issue 11065008: Full Screen Magnifier: Add MagnificationManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase @169437 Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
6
7 #include "ash/magnifier/magnification_controller.h"
8 #include "ash/magnifier/partial_magnification_controller.h"
9 #include "ash/shell.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h"
12 #include "chrome/browser/api/prefs/pref_member.h"
13 #include "chrome/browser/chromeos/login/user_manager.h"
14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h"
23
24 namespace chromeos {
25
26 class MagnificationManagerImpl : public MagnificationManager,
27 public content::NotificationObserver {
28 public:
29 MagnificationManagerImpl() {
30 DCHECK(!instance_);
31 instance_ = this;
32
33 registrar_.Add(this,
34 chrome::NOTIFICATION_SESSION_STARTED,
35 content::NotificationService::AllSources());
36 registrar_.Add(this,
37 chrome::NOTIFICATION_PROFILE_CREATED,
38 content::NotificationService::AllSources());
39 registrar_.Add(this,
40 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
41 content::NotificationService::AllSources());
42
43 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
44 SetProfile(profile);
45 }
46 virtual ~MagnificationManagerImpl() {}
47
48 static MagnificationManagerImpl* GetInstance() {
49 return instance_;
50 }
51
52 // MagnificationManager implimentation:
53 accessibility::ScreenMagnifierType GetScreenMagnifierType() OVERRIDE {
54 if (!profile_)
55 return accessibility::MAGNIFIER_OFF;
56
57 PrefService* prefs = profile_->GetPrefs();
58 if (!prefs)
59 return accessibility::MAGNIFIER_OFF;
60
61 return accessibility::ScreenMagnifierTypeFromName(
62 prefs->GetString(prefs::kScreenMagnifierType).c_str());
63 }
64
65 void SetScreenMagnifier(accessibility::ScreenMagnifierType type) OVERRIDE {
66 PrefService* prefs = profile_->GetPrefs();
67 if (prefs) {
68 std::string typeString = ScreenMagnifierNameFromType(type);
69 if (typeString != prefs->GetString(prefs::kScreenMagnifierType)) {
70 prefs->SetString(prefs::kScreenMagnifierType, typeString);
71 prefs->CommitPendingWrite();
72 }
73 }
74
75 ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
76 type == accessibility::MAGNIFIER_FULL);
77 ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
78 type == accessibility::MAGNIFIER_PARTIAL);
79 }
80
81 private:
82 void SetProfile(Profile* profile) {
83 if (pref_change_registrar_) {
84 pref_change_registrar_.reset();
85 }
86
87 if (profile) {
88 pref_change_registrar_.reset(new PrefChangeRegistrar);
89 pref_change_registrar_->Init(profile->GetPrefs());
90 pref_change_registrar_->Add(
91 prefs::kScreenMagnifierType,
92 base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus,
93 base::Unretained(this)));
94 }
95
96 profile_ = profile;
97 UpdateMagnifierStatus();
98 }
99
100 void UpdateMagnifierStatus() {
101 UserManager* manager = UserManager::Get();
102 if (!profile_) {
103 SetScreenMagnifier(accessibility::MAGNIFIER_OFF);
104 } else if (manager && !manager->IsSessionStarted()) {
105 SetScreenMagnifier(accessibility::MAGNIFIER_FULL);
106 } else {
107 accessibility::ScreenMagnifierType type = GetScreenMagnifierType();
108 SetScreenMagnifier(type);
109 }
110 }
111
112 virtual void Observe(int type,
113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) OVERRIDE {
115 switch (type) {
116 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE:
117 case chrome::NOTIFICATION_SESSION_STARTED: {
118 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
119 SetProfile(profile);
120 break;
121 }
122 }
123 }
124
125 static MagnificationManagerImpl* instance_;
126
127 Profile* profile_;
128 content::NotificationRegistrar registrar_;
129 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
130
131 friend struct DefaultSingletonTraits<MagnificationManagerImpl>;
132 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl);
133 };
134
135 MagnificationManagerImpl* MagnificationManagerImpl::instance_ = NULL;
136
137 MagnificationManager* MagnificationManager::GetInstance() {
138 return MagnificationManagerImpl::GetInstance();
139 }
140
141 MagnificationManager* MagnificationManager::CreateInstance() {
142 // Makes sure that this is not called more than once.
143 CHECK(!GetInstance());
144
145 return new MagnificationManagerImpl();
146 }
147
148 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698