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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/accessibility/magnification_manager.cc
diff --git a/chrome/browser/chromeos/accessibility/magnification_manager.cc b/chrome/browser/chromeos/accessibility/magnification_manager.cc
index c4a7f686513bc1b2609b7514ad726af560f4b2d1..dc09e8245db27a2c292f3cac7d7b022ac098a88f 100644
--- a/chrome/browser/chromeos/accessibility/magnification_manager.cc
+++ b/chrome/browser/chromeos/accessibility/magnification_manager.cc
@@ -34,7 +34,8 @@ class MagnificationManagerImpl : public MagnificationManager,
public:
MagnificationManagerImpl() : first_time_update_(true),
profile_(NULL),
- type_(ash::MAGNIFIER_OFF) {
+ type_(ash::MAGNIFIER_DEFAULT),
+ enabled_(false) {
registrar_.Add(this,
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
@@ -51,29 +52,47 @@ class MagnificationManagerImpl : public MagnificationManager,
}
// MagnificationManager implimentation:
- ash::MagnifierType GetMagnifierType() OVERRIDE {
+ bool IsMagnifierEnabled() const OVERRIDE {
+ return enabled_;
+ }
+
+ ash::MagnifierType GetMagnifierType() const OVERRIDE {
return type_;
}
- void SetMagnifier(ash::MagnifierType type) OVERRIDE {
- if (type == type_ && type == ash::MAGNIFIER_OFF)
+ void SetMagnifier(bool enabled, ash::MagnifierType type) OVERRIDE {
+ if (type == ash::MAGNIFIER_TYPE_UNCHANGE)
+ type = type_;
+
+ if (enabled_ == enabled && type_ == type && !enabled)
return;
+ DCHECK(type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL);
+
+ enabled_ = enabled;
type_ = type;
if (profile_) {
PrefService* prefs = profile_->GetPrefs();
- if (prefs) {
- bool enabled = (type != ash::MAGNIFIER_OFF);
- if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) {
- prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
- prefs->CommitPendingWrite();
- }
+ DCHECK(prefs);
+ bool changed = false;
+
+ if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) {
+ prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
+ changed = true;
+ }
+
+ if (type != prefs->GetInteger(prefs::kScreenMagnifierType)) {
+ prefs->SetInteger(prefs::kScreenMagnifierType, type);
+ changed = true;
}
+
+ if (changed)
+ prefs->CommitPendingWrite();
}
accessibility::AccessibilityStatusEventDetails details(
- type != ash::MAGNIFIER_OFF, ash::A11Y_NOTIFICATION_NONE);
+ enabled, type, ash::A11Y_NOTIFICATION_NONE);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
content::NotificationService::AllSources(),
@@ -81,34 +100,46 @@ class MagnificationManagerImpl : public MagnificationManager,
&details));
ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
- type == ash::MAGNIFIER_FULL);
+ enabled && type == ash::MAGNIFIER_FULL);
ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
- type == ash::MAGNIFIER_PARTIAL);
+ enabled && type == ash::MAGNIFIER_PARTIAL);
}
void SaveScreenMagnifierScale(double scale) OVERRIDE {
Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+ DCHECK(profile->GetPrefs());
profile->GetPrefs()->SetDouble(prefs::kScreenMagnifierScale, scale);
}
- double GetSavedScreenMagnifierScale() OVERRIDE {
+ double GetSavedScreenMagnifierScale() const OVERRIDE {
Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+ DCHECK(profile->GetPrefs());
if (profile->GetPrefs()->HasPrefPath(prefs::kScreenMagnifierScale))
return profile->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale);
return std::numeric_limits<double>::min();
}
private:
+ bool IsMagnifierEnabledFromPref() {
+ if (!profile_)
+ return false;
+
+ DCHECK(profile_->GetPrefs());
+ return profile_->GetPrefs()->GetBoolean(prefs::kScreenMagnifierEnabled);
+ }
+
ash::MagnifierType GetMagnifierTypeFromPref() {
if (!profile_)
- return ash::MAGNIFIER_OFF;
+ return ash::MAGNIFIER_DEFAULT;
- PrefService* prefs = profile_->GetPrefs();
- if (!prefs)
- return ash::MAGNIFIER_OFF;
+ DCHECK(profile_->GetPrefs());
+ ash::MagnifierType type = static_cast<ash::MagnifierType>(
+ profile_->GetPrefs()->GetInteger(prefs::kScreenMagnifierType));
- return prefs->GetBoolean(prefs::kScreenMagnifierEnabled) ?
- ash::MAGNIFIER_FULL : ash::MAGNIFIER_OFF;
+ if (type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL)
+ return type;
+
+ return ash::MAGNIFIER_DEFAULT;
}
void SetProfile(Profile* profile) {
@@ -123,6 +154,10 @@ class MagnificationManagerImpl : public MagnificationManager,
prefs::kScreenMagnifierEnabled,
base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus,
base::Unretained(this)));
+ pref_change_registrar_->Add(
+ prefs::kScreenMagnifierType,
+ base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus,
+ base::Unretained(this)));
}
profile_ = profile;
@@ -130,8 +165,7 @@ class MagnificationManagerImpl : public MagnificationManager,
}
void UpdateMagnifierStatus() {
- ash::MagnifierType type = GetMagnifierTypeFromPref();
- SetMagnifier(type);
+ SetMagnifier(IsMagnifierEnabledFromPref(), GetMagnifierTypeFromPref());
}
// content::NotificationObserver implimentation:
@@ -155,6 +189,7 @@ class MagnificationManagerImpl : public MagnificationManager,
bool first_time_update_;
Profile* profile_;
ash::MagnifierType type_;
+ bool enabled_;
content::NotificationRegistrar registrar_;
scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;

Powered by Google App Engine
This is Rietveld 408576698