1 // Copyright (c) 2013 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
10 #include "ash/accessibility_delegate.h"
11 #include "ash/session_state_observer.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
16 #include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
17 #include "chrome/browser/extensions/extension_system.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "extensions/browser/event_router.h"
26 struct AccessibilityStatusEventDetails
{
27 AccessibilityStatusEventDetails(
29 ash::AccessibilityNotificationVisibility notify
);
31 AccessibilityStatusEventDetails(
33 ash::MagnifierType magnifier_type
,
34 ash::AccessibilityNotificationVisibility notify
);
37 ash::MagnifierType magnifier_type
;
38 ash::AccessibilityNotificationVisibility notify
;
41 // AccessibilityManager changes the statuses of accessibility features
42 // watching profile notifications and pref-changes.
43 // TODO(yoshiki): merge MagnificationManager with AccessibilityManager.
44 class AccessibilityManager
: public content::NotificationObserver
,
45 public extensions::EventRouter::Observer
,
46 extensions::api::braille_display_private::BrailleObserver
,
47 public ash::SessionStateObserver
{
49 // Creates an instance of AccessibilityManager, this should be called once,
50 // because only one instance should exist at the same time.
51 static void Initialize();
52 // Deletes the existing instance of AccessibilityManager.
53 static void Shutdown();
54 // Returns the existing instance. If there is no instance, returns NULL.
55 static AccessibilityManager
* Get();
57 // On a user's first login into a device, any a11y features enabled/disabled
58 // by the user on the login screen are enabled/disabled in the user's profile.
59 // This class watches for profile changes and copies settings into the user's
60 // profile when it detects a login with a newly created profile.
63 explicit PrefHandler(const char* pref_path
);
64 virtual ~PrefHandler();
66 // Should be called from AccessibilityManager::SetProfile().
67 void HandleProfileChanged(Profile
* previous_profile
,
68 Profile
* current_profile
);
71 const char* pref_path_
;
74 // Returns true when the accessibility menu should be shown.
75 bool ShouldShowAccessibilityMenu();
77 // Enables or disables the large cursor.
78 void EnableLargeCursor(bool enabled
);
79 // Returns true if the large cursor is enabled, or false if not.
80 bool IsLargeCursorEnabled();
82 // Enables or disable Sticky Keys.
83 void EnableStickyKeys(bool enabled
);
85 // Returns true if Incognito mode is allowed, or false if not.
86 bool IsIncognitoAllowed();
88 // Returns true if the Sticky Keys is enabled, or false if not.
89 bool IsStickyKeysEnabled();
91 // Enables or disables spoken feedback. Enabling spoken feedback installs the
92 // ChromeVox component extension.
93 void EnableSpokenFeedback(bool enabled
,
94 ash::AccessibilityNotificationVisibility notify
);
96 // Returns true if spoken feedback is enabled, or false if not.
97 bool IsSpokenFeedbackEnabled();
99 // Toggles whether Chrome OS spoken feedback is on or off.
100 void ToggleSpokenFeedback(ash::AccessibilityNotificationVisibility notify
);
102 // Enables or disables the high contrast mode for Chrome.
103 void EnableHighContrast(bool enabled
);
105 // Returns true if High Contrast is enabled, or false if not.
106 bool IsHighContrastEnabled();
108 // Enables or disables autoclick.
109 void EnableAutoclick(bool enabled
);
111 // Returns true if autoclick is enabled.
112 bool IsAutoclickEnabled();
114 // Set the delay for autoclicking after stopping the cursor in milliseconds.
115 void SetAutoclickDelay(int delay_ms
);
117 // Returns the autoclick delay in milliseconds.
118 int GetAutoclickDelay() const;
120 // SessionStateObserver overrides:
121 virtual void ActiveUserChanged(const std::string
& user_id
) OVERRIDE
;
123 void SetProfileForTest(Profile
* profile
);
125 static void SetBrailleControllerForTest(
126 extensions::api::braille_display_private::BrailleController
* controller
);
128 // Enables/disables system sounds.
129 void EnableSystemSounds(bool system_sounds_enabled
);
131 // Initiates play of shutdown sound and returns it's duration.
132 base::TimeDelta
PlayShutdownSound();
135 AccessibilityManager();
136 virtual ~AccessibilityManager();
139 void LoadChromeVox();
140 void LoadChromeVoxToUserScreen();
141 void LoadChromeVoxToLockScreen();
142 void UnloadChromeVox();
143 void UnloadChromeVoxFromLockScreen();
144 void SetUpPreLoadChromeVox(Profile
* profile
);
145 void TearDownPostUnloadChromeVox(Profile
* profile
);
147 void UpdateLargeCursorFromPref();
148 void UpdateStickyKeysFromPref();
149 void UpdateSpokenFeedbackFromPref();
150 void UpdateHighContrastFromPref();
151 void UpdateAutoclickFromPref();
152 void UpdateAutoclickDelayFromPref();
153 void LocalePrefChanged();
155 void CheckBrailleState();
156 void ReceiveBrailleDisplayState(
157 scoped_ptr
<extensions::api::braille_display_private::DisplayState
> state
);
160 void SetProfile(Profile
* profile
);
162 void UpdateChromeOSAccessibilityHistograms();
164 // content::NotificationObserver implementation:
165 virtual void Observe(int type
,
166 const content::NotificationSource
& source
,
167 const content::NotificationDetails
& details
) OVERRIDE
;
169 // extensions::api::braille_display_private::BrailleObserver implementation.
170 // Enables spoken feedback if a braille display becomes available.
171 virtual void OnDisplayStateChanged(
172 const extensions::api::braille_display_private::DisplayState
&
173 display_state
) OVERRIDE
;
175 // EventRouter::Observer implementation.
176 virtual void OnListenerAdded(
177 const extensions::EventListenerInfo
& details
) OVERRIDE
;
178 virtual void OnListenerRemoved(
179 const extensions::EventListenerInfo
& details
) OVERRIDE
;
181 // Profile which has the current a11y context.
184 // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
185 // loaded to any profile.
186 bool chrome_vox_loaded_on_lock_screen_
;
187 bool chrome_vox_loaded_on_user_screen_
;
189 // Set of profiles ChromeVox is loaded to.
190 std::set
<Profile
*> chromevox_profiles_
;
192 content::NotificationRegistrar notification_registrar_
;
193 scoped_ptr
<PrefChangeRegistrar
> pref_change_registrar_
;
194 scoped_ptr
<PrefChangeRegistrar
> local_state_pref_change_registrar_
;
195 scoped_ptr
<ash::ScopedSessionStateObserver
> session_state_observer_
;
197 PrefHandler large_cursor_pref_handler_
;
198 PrefHandler spoken_feedback_pref_handler_
;
199 PrefHandler high_contrast_pref_handler_
;
200 PrefHandler autoclick_pref_handler_
;
201 PrefHandler autoclick_delay_pref_handler_
;
203 bool large_cursor_enabled_
;
204 bool sticky_keys_enabled_
;
205 bool spoken_feedback_enabled_
;
206 bool high_contrast_enabled_
;
207 bool autoclick_enabled_
;
208 int autoclick_delay_ms_
;
210 ash::AccessibilityNotificationVisibility spoken_feedback_notification_
;
212 base::WeakPtrFactory
<AccessibilityManager
> weak_ptr_factory_
;
214 bool should_speak_chrome_vox_announcements_on_user_screen_
;
216 bool system_sounds_enabled_
;
218 DISALLOW_COPY_AND_ASSIGN(AccessibilityManager
);
221 } // namespace chromeos
223 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_