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 "base/callback_forward.h"
11 #include "base/callback_list.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/scoped_observer.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
17 #include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
18 #include "chromeos/ime/input_method_manager.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "extensions/browser/event_router.h"
22 #include "extensions/browser/extension_system.h"
23 #include "ui/chromeos/accessibility_types.h"
25 #if !defined(USE_ATHENA)
26 #include "ash/session/session_state_observer.h"
36 enum AccessibilityNotificationType {
37 ACCESSIBILITY_MANAGER_SHUTDOWN,
38 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE,
39 ACCESSIBILITY_TOGGLE_LARGE_CURSOR,
40 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
41 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK,
42 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD,
43 ACCESSIBILITY_BRAILLE_DISPLAY_CONNECTION_STATE_CHANGED
46 struct AccessibilityStatusEventDetails {
47 AccessibilityStatusEventDetails(
48 AccessibilityNotificationType notification_type,
50 ui::AccessibilityNotificationVisibility notify);
52 AccessibilityStatusEventDetails(
53 AccessibilityNotificationType notification_type,
55 ui::MagnifierType magnifier_type,
56 ui::AccessibilityNotificationVisibility notify);
58 AccessibilityNotificationType notification_type;
60 ui::MagnifierType magnifier_type;
61 ui::AccessibilityNotificationVisibility notify;
64 typedef base::Callback<void(const AccessibilityStatusEventDetails&)>
65 AccessibilityStatusCallback;
67 typedef base::CallbackList<void(const AccessibilityStatusEventDetails&)>
68 AccessibilityStatusCallbackList;
70 typedef AccessibilityStatusCallbackList::Subscription
71 AccessibilityStatusSubscription;
73 // AccessibilityManager changes the statuses of accessibility features
74 // watching profile notifications and pref-changes.
75 // TODO(yoshiki): merge MagnificationManager with AccessibilityManager.
76 class AccessibilityManager
77 : public content::NotificationObserver,
78 public extensions::api::braille_display_private::BrailleObserver,
79 #if !defined(USE_ATHENA)
80 public ash::SessionStateObserver,
82 public input_method::InputMethodManager::Observer {
84 // Creates an instance of AccessibilityManager, this should be called once,
85 // because only one instance should exist at the same time.
86 static void Initialize();
87 // Deletes the existing instance of AccessibilityManager.
88 static void Shutdown();
89 // Returns the existing instance. If there is no instance, returns NULL.
90 static AccessibilityManager* Get();
92 // On a user's first login into a device, any a11y features enabled/disabled
93 // by the user on the login screen are enabled/disabled in the user's profile.
94 // This class watches for profile changes and copies settings into the user's
95 // profile when it detects a login with a newly created profile.
98 explicit PrefHandler(const char* pref_path);
99 virtual ~PrefHandler();
101 // Should be called from AccessibilityManager::SetProfile().
102 void HandleProfileChanged(Profile* previous_profile,
103 Profile* current_profile);
106 const char* pref_path_;
108 DISALLOW_COPY_AND_ASSIGN(PrefHandler);
111 // Returns true when the accessibility menu should be shown.
112 bool ShouldShowAccessibilityMenu();
114 // Returns true when cursor compositing should be enabled.
115 bool ShouldEnableCursorCompositing();
117 // Enables or disables the large cursor.
118 void EnableLargeCursor(bool enabled);
119 // Returns true if the large cursor is enabled, or false if not.
120 bool IsLargeCursorEnabled();
122 // Enables or disable Sticky Keys.
123 void EnableStickyKeys(bool enabled);
125 // Returns true if Incognito mode is allowed, or false if not.
126 bool IsIncognitoAllowed();
128 // Returns true if the Sticky Keys is enabled, or false if not.
129 bool IsStickyKeysEnabled();
131 // Enables or disables spoken feedback. Enabling spoken feedback installs the
132 // ChromeVox component extension.
133 void EnableSpokenFeedback(bool enabled,
134 ui::AccessibilityNotificationVisibility notify);
136 // Returns true if spoken feedback is enabled, or false if not.
137 bool IsSpokenFeedbackEnabled();
139 // Toggles whether Chrome OS spoken feedback is on or off.
140 void ToggleSpokenFeedback(ui::AccessibilityNotificationVisibility notify);
142 // Enables or disables the high contrast mode for Chrome.
143 void EnableHighContrast(bool enabled);
145 // Returns true if High Contrast is enabled, or false if not.
146 bool IsHighContrastEnabled();
148 // Enables or disables autoclick.
149 void EnableAutoclick(bool enabled);
151 // Returns true if autoclick is enabled.
152 bool IsAutoclickEnabled();
154 // Set the delay for autoclicking after stopping the cursor in milliseconds.
155 void SetAutoclickDelay(int delay_ms);
157 // Returns the autoclick delay in milliseconds.
158 int GetAutoclickDelay() const;
160 // Enables or disables the virtual keyboard.
161 void EnableVirtualKeyboard(bool enabled);
162 // Returns true if the virtual keyboard is enabled, otherwise false.
163 bool IsVirtualKeyboardEnabled();
165 // Returns true if a braille display is connected to the system, otherwise
167 bool IsBrailleDisplayConnected() const;
169 #if !defined(USE_ATHENA)
170 // SessionStateObserver overrides:
171 virtual void ActiveUserChanged(const std::string& user_id) override;
174 void SetProfileForTest(Profile* profile);
176 static void SetBrailleControllerForTest(
177 extensions::api::braille_display_private::BrailleController* controller);
179 // Enables/disables system sounds.
180 void EnableSystemSounds(bool system_sounds_enabled);
182 // Initiates play of shutdown sound and returns it's duration.
183 base::TimeDelta PlayShutdownSound();
185 // Injects ChromeVox scripts into given |render_view_host|.
186 void InjectChromeVox(content::RenderViewHost* render_view_host);
188 // Register a callback to be notified when the status of an accessibility
190 scoped_ptr<AccessibilityStatusSubscription> RegisterCallback(
191 const AccessibilityStatusCallback& cb);
193 // Notify registered callbacks of a status change in an accessibility setting.
194 void NotifyAccessibilityStatusChanged(
195 AccessibilityStatusEventDetails& details);
197 // Notify accessibility when locale changes occur.
198 void OnLocaleChanged();
200 // Plays an earcon. Earcons are brief and distinctive sounds that indicate
201 // when their mapped event has occurred. The sound key enums can be found in
202 // chromeos/audio/chromeos_sounds.h.
203 void PlayEarcon(int sound_key);
206 AccessibilityManager();
207 virtual ~AccessibilityManager();
210 void LoadChromeVox();
211 void LoadChromeVoxToUserScreen(const base::Closure& done_cb);
212 void LoadChromeVoxToLockScreen(const base::Closure& done_cb);
213 void UnloadChromeVox();
214 void UnloadChromeVoxFromLockScreen();
215 void PostLoadChromeVox(Profile* profile);
216 void PostUnloadChromeVox(Profile* profile);
218 void UpdateLargeCursorFromPref();
219 void UpdateStickyKeysFromPref();
220 void UpdateSpokenFeedbackFromPref();
221 void UpdateHighContrastFromPref();
222 void UpdateAutoclickFromPref();
223 void UpdateAutoclickDelayFromPref();
224 void UpdateVirtualKeyboardFromPref();
226 void CheckBrailleState();
227 void ReceiveBrailleDisplayState(
228 scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
229 void UpdateBrailleImeState();
231 void SetProfile(Profile* profile);
233 void UpdateChromeOSAccessibilityHistograms();
235 // content::NotificationObserver
236 virtual void Observe(int type,
237 const content::NotificationSource& source,
238 const content::NotificationDetails& details) override;
240 // extensions::api::braille_display_private::BrailleObserver implementation.
241 // Enables spoken feedback if a braille display becomes available.
242 virtual void OnBrailleDisplayStateChanged(
243 const extensions::api::braille_display_private::DisplayState&
244 display_state) override;
245 virtual void OnBrailleKeyEvent(
246 const extensions::api::braille_display_private::KeyEvent& event) override;
248 // InputMethodManager::Observer
249 virtual void InputMethodChanged(input_method::InputMethodManager* manager,
250 bool show_message) override;
253 // Profile which has the current a11y context.
256 // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
257 // loaded to any profile.
258 bool chrome_vox_loaded_on_lock_screen_;
259 bool chrome_vox_loaded_on_user_screen_;
261 content::NotificationRegistrar notification_registrar_;
262 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
263 scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
264 #if !defined(USE_ATHENA)
265 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_;
268 PrefHandler large_cursor_pref_handler_;
269 PrefHandler spoken_feedback_pref_handler_;
270 PrefHandler high_contrast_pref_handler_;
271 PrefHandler autoclick_pref_handler_;
272 PrefHandler autoclick_delay_pref_handler_;
273 PrefHandler virtual_keyboard_pref_handler_;
275 bool large_cursor_enabled_;
276 bool sticky_keys_enabled_;
277 bool spoken_feedback_enabled_;
278 bool high_contrast_enabled_;
279 bool autoclick_enabled_;
280 int autoclick_delay_ms_;
281 bool virtual_keyboard_enabled_;
283 ui::AccessibilityNotificationVisibility spoken_feedback_notification_;
285 bool should_speak_chrome_vox_announcements_on_user_screen_;
287 bool system_sounds_enabled_;
289 AccessibilityStatusCallbackList callback_list_;
291 bool braille_display_connected_;
292 ScopedObserver<extensions::api::braille_display_private::BrailleController,
293 AccessibilityManager> scoped_braille_observer_;
295 bool braille_ime_current_;
297 base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
299 DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
302 } // namespace chromeos
304 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_