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