diff options
author | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 15:08:11 +0000 |
---|---|---|
committer | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 15:08:11 +0000 |
commit | 5c6c6f55b07c37377e43b01d2a9dbb25756cdc1b (patch) | |
tree | 724882355eaa2e33711d69ef3418346429c4e55e | |
parent | 151ab510191868fecd29300ade986d5c4ffcc3bd (diff) | |
download | chromium_src-5c6c6f55b07c37377e43b01d2a9dbb25756cdc1b.zip chromium_src-5c6c6f55b07c37377e43b01d2a9dbb25756cdc1b.tar.gz chromium_src-5c6c6f55b07c37377e43b01d2a9dbb25756cdc1b.tar.bz2 |
Re-introduce the partial magnifier
Major Changes:
- Adding a selectbox at the right of screen magnifier setting on the setting page.
- Adding 'screen_magnifier_type2' pref.
- Separating the enable/disable state of magnifier from MagnifierType. MagnifierType does no longer indicate the current enable/disable status.
- Add IsMagnifierEnabled() to shell delegate.
BUG=166832
TEST=confirm that magnifier can be enabled/disabled via the tray and the settings page. browser_test passes.
R=zork@chromium.org, derat@chromium.org, nkostylev@chromium.org
TBR=jhawkins@chromium.org
# TBRing for small changed in C/B/ui/webui/options/ and C/B/resources/options/
Review URL: https://chromiumcodereview.appspot.com/11642014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176087 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 536 insertions, 257 deletions
diff --git a/ash/magnifier/magnifier_constants.h b/ash/magnifier/magnifier_constants.h index 4ca4c89..aa7cac7 100644 --- a/ash/magnifier/magnifier_constants.h +++ b/ash/magnifier/magnifier_constants.h @@ -7,12 +7,16 @@ namespace ash { +// Note: Do not change these values; UMA and prefs depend on them. enum MagnifierType { - MAGNIFIER_OFF, - MAGNIFIER_FULL, - MAGNIFIER_PARTIAL, + MAGNIFIER_FULL = 1, + MAGNIFIER_PARTIAL = 2, }; +const int kMaxMagnifierType = 2; + +const MagnifierType kDefaultMagnifierType = MAGNIFIER_FULL; + } // namespace ash #endif // ASH_MAGNIFIER_MAGNIFIER_CONSTANTS_H_ diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc index fde2bd1..681dfb5 100644 --- a/ash/shell/shell_delegate_impl.cc +++ b/ash/shell/shell_delegate_impl.cc @@ -25,7 +25,8 @@ ShellDelegateImpl::ShellDelegateImpl() locked_(false), spoken_feedback_enabled_(false), high_contrast_enabled_(false), - screen_magnifier_type_(MAGNIFIER_OFF) { + screen_magnifier_enabled_(false), + screen_magnifier_type_(kDefaultMagnifierType) { } ShellDelegateImpl::~ShellDelegateImpl() { @@ -134,10 +135,18 @@ bool ShellDelegateImpl::IsHighContrastEnabled() const { return high_contrast_enabled_; } -void ShellDelegateImpl::SetMagnifier(MagnifierType type) { +void ShellDelegateImpl::SetMagnifierEnabled(bool enabled) { + screen_magnifier_enabled_ = enabled; +} + +void ShellDelegateImpl::SetMagnifierType(MagnifierType type) { screen_magnifier_type_ = type; } +bool ShellDelegateImpl::IsMagnifierEnabled() const { + return screen_magnifier_enabled_; +} + MagnifierType ShellDelegateImpl::GetMagnifierType() const { return screen_magnifier_type_; } diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h index 3a987e2..e94d08a 100644 --- a/ash/shell/shell_delegate_impl.h +++ b/ash/shell/shell_delegate_impl.h @@ -46,7 +46,9 @@ class ShellDelegateImpl : public ash::ShellDelegate { virtual bool IsSpokenFeedbackEnabled() const OVERRIDE; virtual void ToggleHighContrast() OVERRIDE; virtual bool IsHighContrastEnabled() const OVERRIDE; - virtual void SetMagnifier(MagnifierType type) OVERRIDE; + virtual void SetMagnifierEnabled(bool enabled) OVERRIDE; + virtual void SetMagnifierType(MagnifierType type) OVERRIDE; + virtual bool IsMagnifierEnabled() const OVERRIDE; virtual MagnifierType GetMagnifierType() const OVERRIDE; virtual bool ShouldAlwaysShowAccessibilityMenu() const OVERRIDE; virtual app_list::AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE; @@ -79,6 +81,7 @@ class ShellDelegateImpl : public ash::ShellDelegate { bool locked_; bool spoken_feedback_enabled_; bool high_contrast_enabled_; + bool screen_magnifier_enabled_; MagnifierType screen_magnifier_type_; DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl); diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index bdd3958..6a9dd08 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -149,8 +149,14 @@ class ASH_EXPORT ShellDelegate { // Returns true if high contrast mode is enabled. virtual bool IsHighContrastEnabled() const = 0; - // Invoked to change the mode of the screen magnifier. - virtual void SetMagnifier(MagnifierType type) = 0; + // Invoked to enable the screen magnifier. + virtual void SetMagnifierEnabled(bool enabled) = 0; + + // Invoked to change the type of the screen magnifier. + virtual void SetMagnifierType(MagnifierType type) = 0; + + // Returns if the screen magnifier is enabled or not. + virtual bool IsMagnifierEnabled() const = 0; // Returns the current screen magnifier mode. virtual MagnifierType GetMagnifierType() const = 0; diff --git a/ash/system/tray_accessibility.cc b/ash/system/tray_accessibility.cc index 9b1d261..b64671a 100644 --- a/ash/system/tray_accessibility.cc +++ b/ash/system/tray_accessibility.cc @@ -44,7 +44,7 @@ uint32 GetAccessibilityState() { state |= A11Y_SPOKEN_FEEDBACK; if (shell_delegate->IsHighContrastEnabled()) state |= A11Y_HIGH_CONTRAST; - if (shell_delegate->GetMagnifierType() != ash::MAGNIFIER_OFF) + if (shell_delegate->IsMagnifierEnabled()) state |= A11Y_SCREEN_MAGNIFIER; return state; } @@ -138,8 +138,7 @@ void AccessibilityDetailedView::AppendAccessibilityList() { IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE), high_contrast_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL, high_contrast_enabled_); - screen_magnifier_enabled_ = - shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL; + screen_magnifier_enabled_ = shell_delegate->IsMagnifierEnabled(); screen_magnifier_view_ = AddScrollListItem( bundle.GetLocalizedString( IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER), @@ -198,10 +197,7 @@ void AccessibilityDetailedView::ClickedOn(views::View* sender) { } else if (sender == high_contrast_view_) { shell_delegate->ToggleHighContrast(); } else if (sender == screen_magnifier_view_) { - bool screen_magnifier_enabled = - shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL; - shell_delegate->SetMagnifier( - screen_magnifier_enabled ? ash::MAGNIFIER_OFF : ash::MAGNIFIER_FULL); + shell_delegate->SetMagnifierEnabled(!shell_delegate->IsMagnifierEnabled()); } } diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index f782c86..c2fdc60 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -24,7 +24,8 @@ TestShellDelegate::TestShellDelegate() session_started_(true), spoken_feedback_enabled_(false), high_contrast_enabled_(false), - screen_magnifier_type_(MAGNIFIER_OFF), + screen_magnifier_enabled_(false), + screen_magnifier_type_(kDefaultMagnifierType), user_logged_in_(true), can_lock_screen_(true), num_exit_requests_(0) { @@ -124,10 +125,18 @@ bool TestShellDelegate::IsHighContrastEnabled() const { return high_contrast_enabled_; } -void TestShellDelegate::SetMagnifier(const MagnifierType type) { +void TestShellDelegate::SetMagnifierEnabled(bool enabled) { + screen_magnifier_enabled_ = enabled; +} + +void TestShellDelegate::SetMagnifierType(MagnifierType type) { screen_magnifier_type_ = type; } +bool TestShellDelegate::IsMagnifierEnabled() const { + return screen_magnifier_enabled_; +} + MagnifierType TestShellDelegate::GetMagnifierType() const { return screen_magnifier_type_; } diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index f7bb171..76add5d 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -45,7 +45,9 @@ class TestShellDelegate : public ShellDelegate { virtual bool IsSpokenFeedbackEnabled() const OVERRIDE; virtual void ToggleHighContrast() OVERRIDE; virtual bool IsHighContrastEnabled() const OVERRIDE; - virtual void SetMagnifier(MagnifierType type) OVERRIDE; + virtual void SetMagnifierEnabled(bool enabled) OVERRIDE; + virtual void SetMagnifierType(MagnifierType type) OVERRIDE; + virtual bool IsMagnifierEnabled() const OVERRIDE; virtual MagnifierType GetMagnifierType() const OVERRIDE; virtual bool ShouldAlwaysShowAccessibilityMenu() const OVERRIDE; virtual app_list::AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE; @@ -94,6 +96,7 @@ class TestShellDelegate : public ShellDelegate { bool session_started_; bool spoken_feedback_enabled_; bool high_contrast_enabled_; + bool screen_magnifier_enabled_; MagnifierType screen_magnifier_type_; bool user_logged_in_; bool can_lock_screen_; diff --git a/chrome/browser/chromeos/accessibility/accessibility_util.cc b/chrome/browser/chromeos/accessibility/accessibility_util.cc index faa58f9..86778d6 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_util.cc +++ b/chrome/browser/chromeos/accessibility/accessibility_util.cc @@ -50,10 +50,6 @@ using content::RenderViewHost; namespace chromeos { namespace accessibility { -const char kScreenMagnifierOff[] = ""; -const char kScreenMagnifierFull[] = "full"; -const char kScreenMagnifierPartial[] = "partial"; - // Helper class that directly loads an extension's content scripts into // all of the frames corresponding to a given RenderViewHost. class ContentScriptLoader { @@ -123,10 +119,14 @@ void UpdateChromeOSAccessibilityHistograms() { IsHighContrastEnabled()); UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosVirtualKeyboard", IsVirtualKeyboardEnabled()); - if (MagnificationManager::Get()) + if (MagnificationManager::Get()) { + uint32 type = MagnificationManager::Get()->IsMagnifierEnabled() ? + MagnificationManager::Get()->GetMagnifierType() : 0; + // '0' means magnifier is disabled. UMA_HISTOGRAM_ENUMERATION("Accessibility.CrosScreenMagnifier", - MagnificationManager::Get()->GetMagnifierType(), - 3); + type, + ash::kMaxMagnifierType + 1); + } } void Initialize() { @@ -290,27 +290,6 @@ bool IsVirtualKeyboardEnabled() { return virtual_keyboard_enabled; } -ash::MagnifierType MagnifierTypeFromName(const char type_name[]) { - if (0 == strcmp(type_name, kScreenMagnifierFull)) - return ash::MAGNIFIER_FULL; - else if (0 == strcmp(type_name, kScreenMagnifierPartial)) - return ash::MAGNIFIER_PARTIAL; - else - return ash::MAGNIFIER_OFF; -} - -const char* ScreenMagnifierNameFromType(ash::MagnifierType type) { - switch (type) { - case ash::MAGNIFIER_OFF: - return kScreenMagnifierOff; - case ash::MAGNIFIER_FULL: - return kScreenMagnifierFull; - case ash::MAGNIFIER_PARTIAL: - return kScreenMagnifierPartial; - } - return kScreenMagnifierOff; -} - void MaybeSpeak(const std::string& utterance) { if (IsSpokenFeedbackEnabled()) Speak(utterance); diff --git a/chrome/browser/chromeos/accessibility/accessibility_util.h b/chrome/browser/chromeos/accessibility/accessibility_util.h index e672b5d..e70d60d 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_util.h +++ b/chrome/browser/chromeos/accessibility/accessibility_util.h @@ -24,9 +24,19 @@ struct AccessibilityStatusEventDetails { AccessibilityStatusEventDetails( bool enabled, ash::AccessibilityNotificationVisibility notify) : enabled(enabled), + magnifier_type(ash::kDefaultMagnifierType), + notify(notify) {} + + AccessibilityStatusEventDetails( + bool enabled, + ash::MagnifierType magnifier_type, + ash::AccessibilityNotificationVisibility notify) + : enabled(enabled), + magnifier_type(magnifier_type), notify(notify) {} bool enabled; + ash::MagnifierType magnifier_type; ash::AccessibilityNotificationVisibility notify; }; @@ -64,12 +74,6 @@ bool IsHighContrastEnabled(); // Returns true if the Virtual Keyboard is enabled, or false if not. bool IsVirtualKeyboardEnabled(); -// Translates from a string to MagnifierType. -ash::MagnifierType MagnifierTypeFromName(const char type_name[]); - -// Translates from a MagnifierType to type string. -const char* ScreenMagnifierNameFromType(ash::MagnifierType type); - // Speaks the given text if the accessibility pref is already set. void MaybeSpeak(const std::string& utterance); diff --git a/chrome/browser/chromeos/accessibility/magnification_manager.cc b/chrome/browser/chromeos/accessibility/magnification_manager.cc index 25d4879..38d4f9e 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::kDefaultMagnifierType), + enabled_(false) { registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, content::NotificationService::AllSources()); @@ -54,64 +55,114 @@ 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 { + // 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_) return; - type_ = type; + enabled_ = enabled; 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 (enabled != prefs->GetBoolean(prefs::kScreenMagnifierEnabled)) { + prefs->SetBoolean(prefs::kScreenMagnifierEnabled, enabled); + 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 (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(); + 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() 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::kDefaultMagnifierType; + + 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::kDefaultMagnifierType; } void SetProfile(Profile* profile) { @@ -124,17 +175,27 @@ class MagnificationManagerImpl : public MagnificationManager, pref_change_registrar_->Init(profile->GetPrefs()); pref_change_registrar_->Add( prefs::kScreenMagnifierEnabled, - base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatus, + base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref, + base::Unretained(this))); + pref_change_registrar_->Add( + prefs::kScreenMagnifierType, + base::Bind(&MagnificationManagerImpl::UpdateMagnifierStatusFromPref, base::Unretained(this))); } profile_ = profile; - UpdateMagnifierStatus(); + UpdateMagnifierStatusFromPref(); } - void UpdateMagnifierStatus() { - ash::MagnifierType type = GetMagnifierTypeFromPref(); - SetMagnifier(type); + void UpdateMagnifierStatusFromPref() { + bool enabled = IsMagnifierEnabledFromPref(); + if (!enabled) { + SetMagnifierEnabled(enabled); + SetMagnifierType(GetMagnifierTypeFromPref()); + } else { + SetMagnifierType(GetMagnifierTypeFromPref()); + SetMagnifierEnabled(enabled); + } } // content::NotificationObserver implimentation: @@ -168,6 +229,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_; diff --git a/chrome/browser/chromeos/accessibility/magnification_manager.h b/chrome/browser/chromeos/accessibility/magnification_manager.h index 680b7fc..f323e0a 100644 --- a/chrome/browser/chromeos/accessibility/magnification_manager.h +++ b/chrome/browser/chromeos/accessibility/magnification_manager.h @@ -24,20 +24,30 @@ class MagnificationManager { // Returns the existing instance. If there is no instance, creates one. // because only one instance should exist at the same time. static void Initialize(); + // Deletes the existing instance of MagnificationManager. static void Shutdown(); + // Returns the existing instance. If there is no instance, returns NULL. static MagnificationManager* Get(); + // Returns if the screen magnifier is enabled. + virtual bool IsMagnifierEnabled() const = 0; + // Returns the current type of the screen magnifier. - virtual ash::MagnifierType GetMagnifierType() = 0; + virtual ash::MagnifierType GetMagnifierType() const = 0; + + // Enables the screen magnifier. + virtual void SetMagnifierEnabled(bool enabled) = 0; + // Changes the type of the screen magnifier. - virtual void SetMagnifier(ash::MagnifierType type) = 0; + virtual void SetMagnifierType(ash::MagnifierType type) = 0; // Saves the magnifier scale to the pref. virtual void SaveScreenMagnifierScale(double scale) = 0; + // Loads the magnifier scale from the pref. - virtual double GetSavedScreenMagnifierScale() = 0; + virtual double GetSavedScreenMagnifierScale() const = 0; protected: virtual ~MagnificationManager() {} diff --git a/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc b/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc index 6a1a89a..c99202a 100644 --- a/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc +++ b/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc @@ -24,11 +24,67 @@ namespace chromeos { +namespace { + +void SetMagnifierEnabled(bool enabled) { + MagnificationManager::Get()->SetMagnifierEnabled(enabled); +} + +void SetMagnifierType(ash::MagnifierType type) { + MagnificationManager::Get()->SetMagnifierType(type); +} + +void SetFullScreenMagnifierScale(double scale) { + ash::Shell::GetInstance()-> + magnification_controller()->SetScale(scale, false); +} + +double GetFullScreenMagnifierScale() { + return ash::Shell::GetInstance()->magnification_controller()->GetScale(); +} + +void SetSavedFullScreenMagnifierScale(double scale) { + MagnificationManager::Get()->SaveScreenMagnifierScale(scale); +} + +double GetSavedFullScreenMagnifierScale() { + return MagnificationManager::Get()->GetSavedScreenMagnifierScale(); +} + +ash::MagnifierType GetMagnifierType() { + return MagnificationManager::Get()->GetMagnifierType(); +} + +bool IsMagnifierEnabled() { + return MagnificationManager::Get()->IsMagnifierEnabled(); +} + +Profile* profile() { + Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); + DCHECK(profile); + return profile; +} + +PrefServiceBase* prefs() { + return PrefServiceBase::FromBrowserContext(profile()); +} + +void EnableScreenManagnifierToPref(bool enabled) { + prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, enabled); +} + +void SetScreenManagnifierTypeToPref(ash::MagnifierType type) { + prefs()->SetInteger(prefs::kScreenMagnifierType, type); +} + +} // anonymouse namespace + class MagnificationManagerTest : public CrosInProcessBrowserTest, public content::NotificationObserver { protected: MagnificationManagerTest() : observed_(false), - observed_type_(ash::MAGNIFIER_OFF) {} + observed_enabled_(false), + observed_type_(ash::kDefaultMagnifierType) {} virtual ~MagnificationManagerTest() {} virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { @@ -37,16 +93,6 @@ class MagnificationManagerTest : public CrosInProcessBrowserTest, TestingProfile::kTestUserProfileDir); } - Profile* profile() { - Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); - DCHECK(profile); - return profile; - } - - PrefServiceBase* prefs() { - return PrefServiceBase::FromBrowserContext(profile()); - } - virtual void SetUpOnMainThread() OVERRIDE { registrar_.Add( this, @@ -54,37 +100,6 @@ class MagnificationManagerTest : public CrosInProcessBrowserTest, content::NotificationService::AllSources()); } - void SetScreenManagnifierType(ash::MagnifierType type) { - MagnificationManager::Get()->SetMagnifier(type); - } - - void SetScreenManagnifierTypeToPref(ash::MagnifierType type) { - prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, - (type != ash::MAGNIFIER_OFF) ? true : false); - } - - void SetFullScreenMagnifierScale(double scale) { - ash::Shell::GetInstance()-> - magnification_controller()->SetScale(scale, false); - } - - double GetFullScreenMagnifierScale() { - return ash::Shell::GetInstance()->magnification_controller()->GetScale(); - } - - void SetSavedFullScreenMagnifierScale(double scale) { - MagnificationManager::Get()->SaveScreenMagnifierScale(scale); - } - - double GetSavedFullScreenMagnifierScale() { - return MagnificationManager::Get()->GetSavedScreenMagnifierScale(); - } - - void CheckCurrentMagnifierType( - ash::MagnifierType type) { - EXPECT_EQ(MagnificationManager::Get()->GetMagnifierType(), type); - } - // content::NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, @@ -96,14 +111,15 @@ class MagnificationManagerTest : public CrosInProcessBrowserTest, details).ptr(); observed_ = true; - observed_type_ = accessibility_status->enabled ? ash::MAGNIFIER_FULL : - ash::MAGNIFIER_OFF; + observed_enabled_ = accessibility_status->enabled; + observed_type_ = accessibility_status->magnifier_type; break; } } } bool observed_; + bool observed_enabled_; ash::MagnifierType observed_type_; content::NotificationRegistrar registrar_; DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); @@ -111,121 +127,200 @@ class MagnificationManagerTest : public CrosInProcessBrowserTest, IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginOffToOff) { // Confirms that magnifier is disabled on the login screen. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); // Logs in. UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); // Confirms that magnifier is still disabled just after login. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); UserManager::Get()->SessionStarted(); // Confirms that magnifier is still disabled just after login. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); // Enables magnifier. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); // Confirms that magnifier is enabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); } IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginFullToOff) { // Confirms that magnifier is disabled on the login screen. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); // Enables magnifier on login scren. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); // Logs in (but the session is not started yet). UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); // Confirms that magnifier is keeping enabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); UserManager::Get()->SessionStarted(); // Confirms that magnifier is disabled just after login. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); } IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginOffToFull) { // Changes to full screen magnifier again and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); // Logs in (but the session is not started yet). UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); // Confirms that magnifier is keeping disabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); // Enable magnifier on the pref. + EnableScreenManagnifierToPref(true); SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); SetSavedFullScreenMagnifierScale(2.5); UserManager::Get()->SessionStarted(); // Confirms that the prefs are successfully loaded. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); EXPECT_EQ(2.5, GetFullScreenMagnifierScale()); } +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginOffToPartial) { + // Changes to full screen magnifier again and confirms that. + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); + + // Logs in (but the session is not started yet). + UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); + + // Confirms that magnifier is keeping disabled. + EXPECT_FALSE(IsMagnifierEnabled()); + // Enable magnifier on the pref. + EnableScreenManagnifierToPref(true); + SetScreenManagnifierTypeToPref(ash::MAGNIFIER_PARTIAL); + + UserManager::Get()->SessionStarted(); + + // Confirms that the prefs are successfully loaded. + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); + + // Full screen magnifier scale is 1.0x since it's 'partial' magnifier. + EXPECT_EQ(1.0, GetFullScreenMagnifierScale()); +} + IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginFullToFull) { // Changes to full screen magnifier again and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); // Logs in (but the session is not started yet). UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); // Confirms that magnifier is keeping enabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); // Enable magnifier on the pref. + EnableScreenManagnifierToPref(true); SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); SetSavedFullScreenMagnifierScale(2.5); UserManager::Get()->SessionStarted(); // Confirms that the prefs are successfully loaded. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); EXPECT_EQ(2.5, GetFullScreenMagnifierScale()); } -IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ChangeMagnifierType) { - // Changes to full screen magnifier and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); - - // Changes to partial screen magnifier and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_PARTIAL); - CheckCurrentMagnifierType(ash::MAGNIFIER_PARTIAL); - - // Disable magnifier and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); - +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginFullToPartial) { // Changes to full screen magnifier again and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); - // Logs in + // Logs in (but the session is not started yet). UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); - UserManager::Get()->SessionStarted(); - // Changes to full screen magnifier and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + // Confirms that magnifier is keeping enabled. + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + // Enable magnifier on the pref. + EnableScreenManagnifierToPref(true); + SetScreenManagnifierTypeToPref(ash::MAGNIFIER_PARTIAL); - // Changes to partial screen magnifier and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_PARTIAL); - CheckCurrentMagnifierType(ash::MAGNIFIER_PARTIAL); + UserManager::Get()->SessionStarted(); - // Disable magnifier and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + // Confirms that the prefs are successfully loaded. + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); - // Changes to full screen magnifier again and confirms that. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + // Full screen magnifier scale is 1.0x since it's 'partial' magnifier. + EXPECT_EQ(1.0, GetFullScreenMagnifierScale()); +} + +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ChangeMagnifierType) { + // Enables/disables full screen magnifier. + SetMagnifierEnabled(false); + SetMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + // Enables/disables partial screen magnifier. + SetMagnifierType(ash::MAGNIFIER_PARTIAL); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); + + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); + + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); + + // Changes the magnifier type when the magnifier is enabled. + SetMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + SetMagnifierType(ash::MAGNIFIER_PARTIAL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); + + SetMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + // Changes the magnifier type when the magnifier is disabled. + SetMagnifierEnabled(false); + SetMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + SetMagnifierType(ash::MAGNIFIER_PARTIAL); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); + + SetMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_FALSE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); } IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, TypePref) { @@ -234,48 +329,75 @@ IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, TypePref) { UserManager::Get()->SessionStarted(); // Confirms that magnifier is disabled just after login. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); // Sets the pref as true to enable magnifier. SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); + EnableScreenManagnifierToPref(true); // Confirms that magnifier is enabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); + + SetScreenManagnifierTypeToPref(ash::MAGNIFIER_PARTIAL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); // Sets the pref as false to disabled magnifier. - SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF); + EnableScreenManagnifierToPref(false); // Confirms that magnifier is disabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(IsMagnifierEnabled()); // Sets the pref as true to enable magnifier again. - SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); + EnableScreenManagnifierToPref(true); // Confirms that magnifier is enabled. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); } -IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ResumeSavedTypePref) { +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ResumeSavedTypeFullPref) { // Loads the profile of the user. UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); // Sets the pref as true to enable magnifier before login. + EnableScreenManagnifierToPref(true); SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); // Logs in. UserManager::Get()->SessionStarted(); // Confirms that magnifier is enabled just after login. - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); +} + +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ResumeSavedTypePartialPref) { + // Loads the profile of the user. + UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); + + // Sets the pref as true to enable magnifier before login. + EnableScreenManagnifierToPref(true); + SetScreenManagnifierTypeToPref(ash::MAGNIFIER_PARTIAL); + + // Logs in. + UserManager::Get()->SessionStarted(); + + // Confirms that magnifier is enabled just after login. + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, GetMagnifierType()); } IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ScalePref) { - SetScreenManagnifierType(ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); // Sets 2.5x to the pref. SetSavedFullScreenMagnifierScale(2.5); // Enables full screen magnifier. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); // Confirms that 2.5x is restored. EXPECT_EQ(2.5, GetFullScreenMagnifierScale()); @@ -286,30 +408,33 @@ IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ScalePref) { } IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, InvalidScalePref) { - // TEST 1: too small scale - SetScreenManagnifierType(ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + // TEST 1: Sets too small scale + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); // Sets too small value to the pref. SetSavedFullScreenMagnifierScale(0.5); // Enables full screen magnifier. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); // Confirms that the actual scale is set to the minimum scale. EXPECT_EQ(1.0, GetFullScreenMagnifierScale()); - // TEST 2: too large scale - SetScreenManagnifierType(ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + // TEST 2: Sets too large scale + SetMagnifierEnabled(false); + EXPECT_FALSE(IsMagnifierEnabled()); // Sets too large value to the pref. SetSavedFullScreenMagnifierScale(50.0); // Enables full screen magnifier. - SetScreenManagnifierType(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(IsMagnifierEnabled()); + EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); // Confirms that the actual scale is set to the maximum scale. EXPECT_EQ(4.0, GetFullScreenMagnifierScale()); @@ -321,30 +446,53 @@ IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); UserManager::Get()->SessionStarted(); - // Before the test, sets to full magnifier. - SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + // Enable magnifier (without type) + EnableScreenManagnifierToPref(true); + EXPECT_TRUE(observed_); // Disables magnifier and confirms observer is invoked. observed_ = false; - SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(observed_); - EXPECT_EQ(observed_type_, ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + + // Disables magnifier again and confirms observer is not invoked. + observed_ = false; + SetMagnifierEnabled(false); + EXPECT_FALSE(observed_); // Enables full screen magnifier and confirms observer is invoked. observed_ = false; - SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); + SetMagnifierType(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); + EXPECT_TRUE(observed_); + + // Enables full screen magnifier again and confirms observer is invoked. + observed_ = false; + SetMagnifierEnabled(true); + EXPECT_TRUE(observed_); + EXPECT_TRUE(observed_enabled_); + EXPECT_EQ(ash::MAGNIFIER_FULL, observed_type_); + + // Switches to partial screen magnifier and confirms observer is invoked. + observed_ = false; + SetMagnifierType(ash::MAGNIFIER_PARTIAL); + EXPECT_TRUE(observed_); + EXPECT_TRUE(observed_enabled_); + EXPECT_EQ(ash::MAGNIFIER_PARTIAL, observed_type_); + + // Switches to partial screen magnifier and confirms observer is invoked. + observed_ = false; + SetMagnifierType(ash::MAGNIFIER_FULL); EXPECT_TRUE(observed_); - EXPECT_EQ(observed_type_, ash::MAGNIFIER_FULL); - CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); + EXPECT_TRUE(observed_enabled_); + EXPECT_EQ(ash::MAGNIFIER_FULL, observed_type_); // Disables magnifier again and confirms observer is invoked. observed_ = false; - SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(observed_); - EXPECT_EQ(observed_type_, ash::MAGNIFIER_OFF); - CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); + EXPECT_FALSE(observed_enabled_); + EXPECT_FALSE(IsMagnifierEnabled()); } } // namespace chromeos diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 8ee9f98..5aa9e7f 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/preferences.h" +#include "ash/magnifier/magnifier_constants.h" #include "base/chromeos/chromeos_version.h" #include "base/command_line.h" #include "base/i18n/time_formatting.h" @@ -13,6 +14,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/drive/drive_file_system_util.h" #include "chrome/browser/chromeos/input_method/input_method_configuration.h" #include "chrome/browser/chromeos/input_method/input_method_manager.h" @@ -114,6 +116,9 @@ void Preferences::RegisterUserPrefs(PrefServiceSyncable* prefs) { prefs->RegisterBooleanPref(prefs::kScreenMagnifierEnabled, false, PrefServiceSyncable::SYNCABLE_PREF); + prefs->RegisterIntegerPref(prefs::kScreenMagnifierType, + ash::kDefaultMagnifierType, + PrefServiceSyncable::SYNCABLE_PREF); prefs->RegisterDoublePref(prefs::kScreenMagnifierScale, std::numeric_limits<double>::min(), PrefServiceSyncable::UNSYNCABLE_PREF); @@ -304,13 +309,14 @@ void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) { accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, prefs, callback); screen_magnifier_enabled_.Init(prefs::kScreenMagnifierEnabled, prefs, callback); + screen_magnifier_type_.Init(prefs::kScreenMagnifierType, prefs, callback); screen_magnifier_scale_.Init(prefs::kScreenMagnifierScale, prefs, callback); mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback); touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback); use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, callback); disable_drive_.Init(prefs::kDisableDrive, prefs, callback); disable_drive_over_cellular_.Init(prefs::kDisableDriveOverCellular, - prefs, callback); + prefs, callback); disable_drive_hosted_files_.Init(prefs::kDisableDriveHostedFiles, prefs, callback); download_default_directory_.Init(prefs::kDownloadDefaultDirectory, diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index d00b66e..cb18e44 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -111,6 +111,7 @@ class Preferences : public PrefServiceObserver { BooleanPrefMember vert_edge_scroll_enabled_; BooleanPrefMember accessibility_enabled_; BooleanPrefMember screen_magnifier_enabled_; + IntegerPrefMember screen_magnifier_type_; DoublePrefMember screen_magnifier_scale_; IntegerPrefMember speed_factor_; IntegerPrefMember mouse_sensitivity_; diff --git a/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc b/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc index 220d928..23adfd6 100644 --- a/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc +++ b/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc @@ -30,8 +30,8 @@ namespace chromeos { -namespace { - ui::MouseEvent& dummyEvent = *((ui::MouseEvent*)0); +void SetMagnifierEnabled(bool enabled) { + MagnificationManager::Get()->SetMagnifierEnabled(enabled); } class TrayAccessibilityTest : public CrosInProcessBrowserTest { @@ -150,13 +150,13 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowTrayIcon) { EXPECT_FALSE(IsTrayIconVisible()); // Toggling magnifier the visibillity of the icon. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(IsTrayIconVisible()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_FALSE(IsTrayIconVisible()); // Enabling all accessibility features. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(IsTrayIconVisible()); accessibility::EnableHighContrast(true); EXPECT_TRUE(IsTrayIconVisible()); @@ -166,7 +166,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowTrayIcon) { EXPECT_TRUE(IsTrayIconVisible()); accessibility::EnableHighContrast(false); EXPECT_TRUE(IsTrayIconVisible()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_FALSE(IsTrayIconVisible()); // Confirms that prefs::kShouldAlwaysShowAccessibilityMenu doesn't affect @@ -208,13 +208,13 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenu) { EXPECT_FALSE(CanCreateMenuItem()); // Toggling screen magnifier changes the visibillity of the menu. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CanCreateMenuItem()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_FALSE(CanCreateMenuItem()); // Enabling all accessibility features. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CanCreateMenuItem()); accessibility::EnableHighContrast(true); EXPECT_TRUE(CanCreateMenuItem()); @@ -224,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenu) { EXPECT_TRUE(CanCreateMenuItem()); accessibility::EnableHighContrast(false); EXPECT_TRUE(CanCreateMenuItem()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_FALSE(CanCreateMenuItem()); } @@ -255,13 +255,13 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowMenuOption) { EXPECT_TRUE(CanCreateMenuItem()); // The menu is keeping visible regardless of toggling screen magnifier. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CanCreateMenuItem()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(CanCreateMenuItem()); // Enabling all accessibility features. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CanCreateMenuItem()); accessibility::EnableHighContrast(true); EXPECT_TRUE(CanCreateMenuItem()); @@ -271,7 +271,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowMenuOption) { EXPECT_TRUE(CanCreateMenuItem()); accessibility::EnableHighContrast(false); EXPECT_TRUE(CanCreateMenuItem()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(CanCreateMenuItem()); // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true. @@ -300,13 +300,13 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) { EXPECT_TRUE(CanCreateMenuItem()); // The menu is keeping visible regardless of toggling screen magnifier. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CanCreateMenuItem()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(CanCreateMenuItem()); // Enabling all accessibility features. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CanCreateMenuItem()); accessibility::EnableHighContrast(true); EXPECT_TRUE(CanCreateMenuItem()); @@ -316,7 +316,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) { EXPECT_TRUE(CanCreateMenuItem()); accessibility::EnableHighContrast(false); EXPECT_TRUE(CanCreateMenuItem()); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(CanCreateMenuItem()); // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true. @@ -362,17 +362,14 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ClickDetailMenu) { // Confirms that the check item toggles the magnifier. EXPECT_FALSE(accessibility::IsHighContrastEnabled()); - EXPECT_EQ(ash::MAGNIFIER_OFF, - MagnificationManager::Get()->GetMagnifierType()); + EXPECT_FALSE(MagnificationManager::Get()->IsMagnifierEnabled()); EXPECT_TRUE(CreateDetailedMenu()); ClickScreenMagnifierOnDetailMenu(); - EXPECT_EQ(ash::MAGNIFIER_FULL, - MagnificationManager::Get()->GetMagnifierType()); + EXPECT_TRUE(MagnificationManager::Get()->IsMagnifierEnabled()); EXPECT_TRUE(CreateDetailedMenu()); ClickScreenMagnifierOnDetailMenu(); - EXPECT_EQ(ash::MAGNIFIER_OFF, - MagnificationManager::Get()->GetMagnifierType()); + EXPECT_FALSE(MagnificationManager::Get()->IsMagnifierEnabled()); } IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { @@ -416,7 +413,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { CloseDetailMenu(); // Enabling full screen magnifier. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CreateDetailedMenu()); EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu()); EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu()); @@ -424,7 +421,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { CloseDetailMenu(); // Disabling screen magnifier. - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(CreateDetailedMenu()); EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu()); EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu()); @@ -434,7 +431,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { // Enabling all of the a11y features. accessibility::EnableSpokenFeedback(true, NULL, ash::A11Y_NOTIFICATION_NONE); accessibility::EnableHighContrast(true); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_FULL); + SetMagnifierEnabled(true); EXPECT_TRUE(CreateDetailedMenu()); EXPECT_TRUE(IsSpokenFeedbackEnabledOnDetailMenu()); EXPECT_TRUE(IsHighContrastEnabledOnDetailMenu()); @@ -444,7 +441,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { // Disabling all of the a11y features. accessibility::EnableSpokenFeedback(false, NULL, ash::A11Y_NOTIFICATION_NONE); accessibility::EnableHighContrast(false); - MagnificationManager::Get()->SetMagnifier(ash::MAGNIFIER_OFF); + SetMagnifierEnabled(false); EXPECT_TRUE(CreateDetailedMenu()); EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu()); EXPECT_FALSE(IsHighContrastEnabledOnDetailMenu()); diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html index 9a1bf83..7c26ef9 100644 --- a/chrome/browser/resources/options/browser_options.html +++ b/chrome/browser/resources/options/browser_options.html @@ -637,6 +637,10 @@ pref="settings.a11y.screen_magnifier" type="checkbox"> <span i18n-content="accessibilityScreenMagnifier"></span> </label> + <select id="accessibility-screen-magnifier-type-select" + class="control" i18n-options="magnifierList" data-type="number" + pref="settings.a11y.screen_magnifier_type2"> + </select> </div> </div> <div class="option-name" id="accessibility-tap-dragging"> diff --git a/chrome/browser/ui/ash/ash_init.cc b/chrome/browser/ui/ash/ash_init.cc index 0f50c6b..ef9d18a 100644 --- a/chrome/browser/ui/ash/ash_init.cc +++ b/chrome/browser/ui/ash/ash_init.cc @@ -96,12 +96,14 @@ void OpenAsh() { chromeos::accessibility::IsHighContrastEnabled()); DCHECK(chromeos::MagnificationManager::Get()); + bool magnifier_enabled = + chromeos::MagnificationManager::Get()->IsMagnifierEnabled(); ash::MagnifierType magnifier_type = chromeos::MagnificationManager::Get()->GetMagnifierType(); - ash::Shell::GetInstance()->magnification_controller()->SetEnabled( - magnifier_type == ash::MAGNIFIER_FULL); - ash::Shell::GetInstance()->partial_magnification_controller()->SetEnabled( - magnifier_type == ash::MAGNIFIER_PARTIAL); + ash::Shell::GetInstance()->magnification_controller()-> + SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_FULL); + ash::Shell::GetInstance()->partial_magnification_controller()-> + SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_PARTIAL); if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableZeroBrowsersOpenForTests)) { diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc index 5354516..b784036 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc @@ -355,19 +355,35 @@ void ChromeShellDelegate::ToggleHighContrast() { #endif } +bool ChromeShellDelegate::IsMagnifierEnabled() const { +#if defined(OS_CHROMEOS) + DCHECK(chromeos::MagnificationManager::Get()); + return chromeos::MagnificationManager::Get()->IsMagnifierEnabled(); +#else + return false; +#endif +} + ash::MagnifierType ChromeShellDelegate::GetMagnifierType() const { #if defined(OS_CHROMEOS) DCHECK(chromeos::MagnificationManager::Get()); return chromeos::MagnificationManager::Get()->GetMagnifierType(); #else - return ash::MAGNIFIER_OFF; + return ash::kDefaultMagnifierType; +#endif +} + +void ChromeShellDelegate::SetMagnifierEnabled(bool enabled) { +#if defined(OS_CHROMEOS) + DCHECK(chromeos::MagnificationManager::Get()); + return chromeos::MagnificationManager::Get()->SetMagnifierEnabled(enabled); #endif } -void ChromeShellDelegate::SetMagnifier(ash::MagnifierType type) { +void ChromeShellDelegate::SetMagnifierType(ash::MagnifierType type) { #if defined(OS_CHROMEOS) DCHECK(chromeos::MagnificationManager::Get()); - return chromeos::MagnificationManager::Get()->SetMagnifier(type); + return chromeos::MagnificationManager::Get()->SetMagnifierType(type); #endif } diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.h b/chrome/browser/ui/ash/chrome_shell_delegate.h index 401bcb53..7270a37 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.h +++ b/chrome/browser/ui/ash/chrome_shell_delegate.h @@ -61,7 +61,9 @@ class ChromeShellDelegate : public ash::ShellDelegate, virtual void ToggleSpokenFeedback( ash::AccessibilityNotificationVisibility notify) OVERRIDE; virtual bool IsHighContrastEnabled() const OVERRIDE; - virtual void SetMagnifier(ash::MagnifierType type) OVERRIDE; + virtual void SetMagnifierEnabled(bool enabled) OVERRIDE; + virtual void SetMagnifierType(ash::MagnifierType type) OVERRIDE; + virtual bool IsMagnifierEnabled() const OVERRIDE; virtual ash::MagnifierType GetMagnifierType() const OVERRIDE; virtual bool ShouldAlwaysShowAccessibilityMenu() const OVERRIDE; virtual app_list::AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE; diff --git a/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc b/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc index 82784e49..34dc189 100644 --- a/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc +++ b/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc @@ -149,10 +149,8 @@ void CoreOobeHandler::HandleEnableScreenMagnifier(const base::ListValue* args) { return; } // TODO(nkostylev): Add support for partial screen magnifier. - ash::MagnifierType type = enabled ? ash::MAGNIFIER_FULL : - ash::MAGNIFIER_OFF; DCHECK(MagnificationManager::Get()); - MagnificationManager::Get()->SetMagnifier(type); + MagnificationManager::Get()->SetMagnifierEnabled(enabled); } void CoreOobeHandler::HandleEnableSpokenFeedback(const base::ListValue* args) { @@ -173,15 +171,13 @@ void CoreOobeHandler::ShowOobeUI(bool show) { void CoreOobeHandler::UpdateA11yState() { DCHECK(MagnificationManager::Get()); - ash::MagnifierType type = MagnificationManager::Get()->GetMagnifierType(); - base::DictionaryValue a11y_info; a11y_info.SetBoolean("highContrastEnabled", accessibility::IsHighContrastEnabled()); a11y_info.SetBoolean("spokenFeedbackEnabled", accessibility::IsSpokenFeedbackEnabled()); a11y_info.SetBoolean("screenMagnifierEnabled", - type != ash::MAGNIFIER_OFF); + MagnificationManager::Get()->IsMagnifierEnabled()); web_ui()->CallJavascriptFunction("cr.ui.Oobe.refreshA11yInfo", a11y_info); } diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index c4a25d7..7b00522 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -85,6 +85,7 @@ #endif #if defined(OS_CHROMEOS) +#include "ash/magnifier/magnifier_constants.h" #include "chrome/browser/chromeos/accessibility/accessibility_util.h" #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" #include "chrome/browser/chromeos/login/user_manager.h" @@ -423,6 +424,22 @@ void BrowserOptionsHandler::GetLocalizedValues(DictionaryValue* values) { values->SetString("accessibilityLearnMoreURL", chrome::kChromeAccessibilityHelpURL); + + // Creates magnifierList. + base::ListValue* magnifierList = new base::ListValue(); + base::ListValue* option_full = new base::ListValue(); + option_full->Append(base::Value::CreateIntegerValue(ash::MAGNIFIER_FULL)); + option_full->Append(new base::StringValue(l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL))); + base::ListValue* option_partial = new base::ListValue(); + option_partial->Append(base::Value::CreateIntegerValue( + ash::MAGNIFIER_PARTIAL)); + option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL))); + magnifierList->Append(option_full); + magnifierList->Append(option_partial); + values->Set("magnifierList", magnifierList); + #endif #if defined(OS_MACOSX) values->SetString("macPasswordsWarning", diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 174bb08..eaa2156 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -743,6 +743,10 @@ const char kSpokenFeedbackEnabled[] = "settings.accessibility"; const char kHighContrastEnabled[] = "settings.a11y.high_contrast_enabled"; // A boolean pref which determines whether screen magnifier is enabled. const char kScreenMagnifierEnabled[] = "settings.a11y.screen_magnifier"; +// A integer pref which determines what type of screen magnifier is enabled. +// Note that: 'screen_magnifier_type' had been used as string pref. Hence, +// we are using another name pref here. +const char kScreenMagnifierType[] = "settings.a11y.screen_magnifier_type2"; // A double pref which determines a zooming scale of the screen magnifier. const char kScreenMagnifierScale[] = "settings.a11y.screen_magnifier_scale"; // A boolean pref which determines whether virtual keyboard is enabled. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 77fab57..fb59a0d 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -271,6 +271,7 @@ extern const char kLanguageXkbAutoRepeatInterval[]; extern const char kSpokenFeedbackEnabled[]; extern const char kHighContrastEnabled[]; extern const char kScreenMagnifierEnabled[]; +extern const char kScreenMagnifierType[]; extern const char kScreenMagnifierScale[]; extern const char kVirtualKeyboardEnabled[]; extern const char kShouldAlwaysShowAccessibilityMenu[]; |