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

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: review fix (comment #4) 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 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..727526e0912f446396b880e3b971d3f4d6499405 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::DEFAULT_MAGNIFIER_TYPE),
+ enabled_(false) {
registrar_.Add(this,
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
@@ -51,64 +52,111 @@ 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 SetMagnifierEnabled(bool enabled) OVERRIDE {
+ if (enabled_ == enabled && !enabled)
Daniel Erat 2013/01/08 00:28:49 i'm a bit surprised by this -- you need to do the
yoshiki 2013/01/09 03:03:15 We need the rest of the work. Added a comment. On
+ return;
+
+ enabled_ = enabled;
+
+ if (profile_) {
+ PrefService* prefs = profile_->GetPrefs();
+ DCHECK(prefs);
+ if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) {
Daniel Erat 2013/01/08 00:28:49 shouldn't we already match the pref? why is this
yoshiki 2013/01/09 03:03:15 We need to keep it for the reason in the above com
+ prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
+ prefs->CommitPendingWrite();
+ }
+ }
+
+ NotifyMagnifierChanged();
+
+ if (type_ == ash::MAGNIFIER_FULL) {
+ ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
+ enabled_);
+ } else {
+ ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
+ enabled_);
+ }
+ }
+
+ void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
+ if (type_ == type)
return;
+ DCHECK(type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL);
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);
+ if (type != prefs->GetInteger(prefs::kScreenMagnifierType)) {
Daniel Erat 2013/01/08 00:28:49 ditto here
yoshiki 2013/01/09 03:03:15 Done. This can be removed.
+ prefs->SetInteger(prefs::kScreenMagnifierType, type);
+ prefs->CommitPendingWrite();
}
}
- accessibility::AccessibilityStatusEventDetails details(
- type != ash::MAGNIFIER_OFF, ash::A11Y_NOTIFICATION_NONE);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
- content::NotificationService::AllSources(),
- content::Details<accessibility::AccessibilityStatusEventDetails>(
- &details));
-
- ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
- type == ash::MAGNIFIER_FULL);
- ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
- type == ash::MAGNIFIER_PARTIAL);
+ NotifyMagnifierChanged();
+
+ if (enabled_) {
+ ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
+ type_ == ash::MAGNIFIER_FULL);
+ ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
+ 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:
+ void NotifyMagnifierChanged() {
+ accessibility::AccessibilityStatusEventDetails details(
+ enabled_, type_, ash::A11Y_NOTIFICATION_NONE);
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
+ content::NotificationService::AllSources(),
+ content::Details<accessibility::AccessibilityStatusEventDetails>(
+ &details));
+ }
+
+ 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::DEFAULT_MAGNIFIER_TYPE;
+
+ DCHECK(profile_->GetPrefs());
+ ash::MagnifierType type = static_cast<ash::MagnifierType>(
+ profile_->GetPrefs()->GetInteger(prefs::kScreenMagnifierType));
- PrefService* prefs = profile_->GetPrefs();
- if (!prefs)
- return ash::MAGNIFIER_OFF;
+ if (type == ash::MAGNIFIER_FULL || type == ash::MAGNIFIER_PARTIAL)
+ return type;
- return prefs->GetBoolean(prefs::kScreenMagnifierEnabled) ?
- ash::MAGNIFIER_FULL : ash::MAGNIFIER_OFF;
+ return ash::DEFAULT_MAGNIFIER_TYPE;
}
void SetProfile(Profile* profile) {
@@ -123,6 +171,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 +182,14 @@ class MagnificationManagerImpl : public MagnificationManager,
}
void UpdateMagnifierStatus() {
Daniel Erat 2013/01/08 00:28:49 nit: maybe rename this to something like UpdateMag
yoshiki 2013/01/09 03:03:15 Done.
- ash::MagnifierType type = GetMagnifierTypeFromPref();
- SetMagnifier(type);
+ bool enabled = IsMagnifierEnabledFromPref();
+ if (!enabled) {
+ SetMagnifierEnabled(enabled);
+ SetMagnifierType(GetMagnifierTypeFromPref());
+ } else {
+ SetMagnifierType(GetMagnifierTypeFromPref());
+ SetMagnifierEnabled(enabled);
+ }
}
// content::NotificationObserver implimentation:
@@ -155,6 +213,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