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

Unified Diff: chrome/browser/chromeos/accessibility/magnification_manager.cc

Issue 11821053: Revert 176087 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
===================================================================
--- chrome/browser/chromeos/accessibility/magnification_manager.cc (revision 176100)
+++ chrome/browser/chromeos/accessibility/magnification_manager.cc (working copy)
@@ -34,8 +34,7 @@
public:
MagnificationManagerImpl() : first_time_update_(true),
profile_(NULL),
- type_(ash::kDefaultMagnifierType),
- enabled_(false) {
+ type_(ash::MAGNIFIER_OFF) {
registrar_.Add(this,
chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
@@ -55,114 +54,64 @@
}
// MagnificationManager implimentation:
- bool IsMagnifierEnabled() const OVERRIDE {
- return enabled_;
- }
-
- ash::MagnifierType GetMagnifierType() const OVERRIDE {
+ ash::MagnifierType GetMagnifierType() OVERRIDE {
return type_;
}
- void SetMagnifierEnabled(bool enabled) OVERRIDE {
- // This method may be invoked even when the other magnifier settings (e.g.
- // type or scale) are changed, so we need to call magnification controller
- // even if |enabled| is unchanged. Only if |enabled| is false and the
- // magnifier is already disabled, we are sure that we don't need to reflect
- // the new settings right now because the magnifier keeps disabled.
- if (!enabled && !enabled_)
+ void SetMagnifier(ash::MagnifierType type) OVERRIDE {
+ if (type == type_ && type == ash::MAGNIFIER_OFF)
return;
- enabled_ = enabled;
+ type_ = type;
if (profile_) {
PrefService* prefs = profile_->GetPrefs();
- DCHECK(prefs);
- if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) {
- prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
- prefs->CommitPendingWrite();
+ if (prefs) {
+ bool enabled = (type != ash::MAGNIFIER_OFF);
+ if (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) {
+ prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
+ prefs->CommitPendingWrite();
+ }
}
}
- NotifyMagnifierChanged();
+ 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));
- if (type_ == ash::MAGNIFIER_FULL) {
- ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
- enabled_);
- } else {
- ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
- enabled_);
- }
+ ash::Shell::GetInstance()->magnification_controller()->SetEnabled(
+ type == ash::MAGNIFIER_FULL);
+ ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled(
+ type == ash::MAGNIFIER_PARTIAL);
}
- 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();
- DCHECK(prefs);
- prefs->SetInteger(prefs::kScreenMagnifierType, type);
- prefs->CommitPendingWrite();
- }
-
- 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() const OVERRIDE {
+ double GetSavedScreenMagnifierScale() 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::kDefaultMagnifierType;
+ return ash::MAGNIFIER_OFF;
- 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 ash::kDefaultMagnifierType;
+ return prefs->GetBoolean(prefs::kScreenMagnifierEnabled) ?
+ ash::MAGNIFIER_FULL : ash::MAGNIFIER_OFF;
}
void SetProfile(Profile* profile) {
@@ -175,27 +124,17 @@
pref_change_registrar_->Init(profile->GetPrefs());
pref_change_registrar_->Add(
prefs::kScreenMagnifierEnabled,
- base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref,
+ base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus,
base::Unretained(this)));
- pref_change_registrar_->Add(
- prefs::kScreenMagnifierType,
- base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref,
- base::Unretained(this)));
}
profile_ = profile;
- UpdateMagnifierStatusFromPref();
+ UpdateMagnifierStatus();
}
- void UpdateMagnifierStatusFromPref() {
- bool enabled = IsMagnifierEnabledFromPref();
- if (!enabled) {
- SetMagnifierEnabled(enabled);
- SetMagnifierType(GetMagnifierTypeFromPref());
- } else {
- SetMagnifierType(GetMagnifierTypeFromPref());
- SetMagnifierEnabled(enabled);
- }
+ void UpdateMagnifierStatus() {
+ ash::MagnifierType type = GetMagnifierTypeFromPref();
+ SetMagnifier(type);
}
// content::NotificationObserver implimentation:
@@ -229,7 +168,6 @@
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