Fix ChromeVox language switching on OOBE.
[chromium-blink-merge.git] / chrome / browser / chromeos / accessibility / accessibility_manager.h
blob5c7b0e7972c7dba12d4a9f3c182ad1a848020f9d
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_
8 #include <set>
10 #include "ash/accessibility_delegate.h"
11 #include "ash/session_state_observer.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/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 "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "extensions/browser/event_router.h"
21 #include "extensions/browser/extension_system.h"
23 namespace content {
24 class RenderViewHost;
26 class Profile;
28 namespace chromeos {
30 enum AccessibilityNotificationType {
31 ACCESSIBILITY_MANAGER_SHUTDOWN,
32 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE,
33 ACCESSIBILITY_TOGGLE_LARGE_CURSOR,
34 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
35 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK,
36 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD
39 struct AccessibilityStatusEventDetails {
40 AccessibilityStatusEventDetails(
41 AccessibilityNotificationType notification_type,
42 bool enabled,
43 ash::AccessibilityNotificationVisibility notify);
45 AccessibilityStatusEventDetails(
46 AccessibilityNotificationType notification_type,
47 bool enabled,
48 ash::MagnifierType magnifier_type,
49 ash::AccessibilityNotificationVisibility notify);
51 AccessibilityNotificationType notification_type;
52 bool enabled;
53 ash::MagnifierType magnifier_type;
54 ash::AccessibilityNotificationVisibility notify;
57 typedef base::Callback<void(const AccessibilityStatusEventDetails&)>
58 AccessibilityStatusCallback;
60 typedef base::CallbackList<void(const AccessibilityStatusEventDetails&)>
61 AccessibilityStatusCallbackList;
63 typedef AccessibilityStatusCallbackList::Subscription
64 AccessibilityStatusSubscription;
66 // AccessibilityManager changes the statuses of accessibility features
67 // watching profile notifications and pref-changes.
68 // TODO(yoshiki): merge MagnificationManager with AccessibilityManager.
69 class AccessibilityManager : public content::NotificationObserver,
70 extensions::api::braille_display_private::BrailleObserver,
71 public ash::SessionStateObserver {
72 public:
73 // Creates an instance of AccessibilityManager, this should be called once,
74 // because only one instance should exist at the same time.
75 static void Initialize();
76 // Deletes the existing instance of AccessibilityManager.
77 static void Shutdown();
78 // Returns the existing instance. If there is no instance, returns NULL.
79 static AccessibilityManager* Get();
81 // On a user's first login into a device, any a11y features enabled/disabled
82 // by the user on the login screen are enabled/disabled in the user's profile.
83 // This class watches for profile changes and copies settings into the user's
84 // profile when it detects a login with a newly created profile.
85 class PrefHandler {
86 public:
87 explicit PrefHandler(const char* pref_path);
88 virtual ~PrefHandler();
90 // Should be called from AccessibilityManager::SetProfile().
91 void HandleProfileChanged(Profile* previous_profile,
92 Profile* current_profile);
94 private:
95 const char* pref_path_;
98 // Returns true when the accessibility menu should be shown.
99 bool ShouldShowAccessibilityMenu();
101 // Returns true when cursor compositing should be enabled.
102 bool ShouldEnableCursorCompositing();
104 // Enables or disables the large cursor.
105 void EnableLargeCursor(bool enabled);
106 // Returns true if the large cursor is enabled, or false if not.
107 bool IsLargeCursorEnabled();
109 // Enables or disable Sticky Keys.
110 void EnableStickyKeys(bool enabled);
112 // Returns true if Incognito mode is allowed, or false if not.
113 bool IsIncognitoAllowed();
115 // Returns true if the Sticky Keys is enabled, or false if not.
116 bool IsStickyKeysEnabled();
118 // Enables or disables spoken feedback. Enabling spoken feedback installs the
119 // ChromeVox component extension.
120 void EnableSpokenFeedback(bool enabled,
121 ash::AccessibilityNotificationVisibility notify);
123 // Returns true if spoken feedback is enabled, or false if not.
124 bool IsSpokenFeedbackEnabled();
126 // Toggles whether Chrome OS spoken feedback is on or off.
127 void ToggleSpokenFeedback(ash::AccessibilityNotificationVisibility notify);
129 // Enables or disables the high contrast mode for Chrome.
130 void EnableHighContrast(bool enabled);
132 // Returns true if High Contrast is enabled, or false if not.
133 bool IsHighContrastEnabled();
135 // Enables or disables autoclick.
136 void EnableAutoclick(bool enabled);
138 // Returns true if autoclick is enabled.
139 bool IsAutoclickEnabled();
141 // Set the delay for autoclicking after stopping the cursor in milliseconds.
142 void SetAutoclickDelay(int delay_ms);
144 // Returns the autoclick delay in milliseconds.
145 int GetAutoclickDelay() const;
147 // Enables or disables the virtual keyboard.
148 void EnableVirtualKeyboard(bool enabled);
149 // Returns true if the virtual keyboard is enabled, otherwise false.
150 bool IsVirtualKeyboardEnabled();
152 // SessionStateObserver overrides:
153 virtual void ActiveUserChanged(const std::string& user_id) OVERRIDE;
155 void SetProfileForTest(Profile* profile);
157 static void SetBrailleControllerForTest(
158 extensions::api::braille_display_private::BrailleController* controller);
160 // Enables/disables system sounds.
161 void EnableSystemSounds(bool system_sounds_enabled);
163 // Initiates play of shutdown sound and returns it's duration.
164 base::TimeDelta PlayShutdownSound();
166 // Injects ChromeVox scripts into given |render_view_host|.
167 void InjectChromeVox(content::RenderViewHost* render_view_host);
169 // Register a callback to be notified when the status of an accessibility
170 // option changes.
171 scoped_ptr<AccessibilityStatusSubscription> RegisterCallback(
172 const AccessibilityStatusCallback& cb);
174 // Notify registered callbacks of a status change in an accessibility setting.
175 void NotifyAccessibilityStatusChanged(
176 AccessibilityStatusEventDetails& details);
178 // Notify accessibility when locale changes occur.
179 void OnLocaleChanged();
181 protected:
182 AccessibilityManager();
183 virtual ~AccessibilityManager();
185 private:
186 void LoadChromeVox();
187 void LoadChromeVoxToUserScreen();
188 void LoadChromeVoxToLockScreen();
189 void UnloadChromeVox();
190 void UnloadChromeVoxFromLockScreen();
191 void PostLoadChromeVox(Profile* profile);
192 void PostUnloadChromeVox(Profile* profile);
194 void UpdateLargeCursorFromPref();
195 void UpdateStickyKeysFromPref();
196 void UpdateSpokenFeedbackFromPref();
197 void UpdateHighContrastFromPref();
198 void UpdateAutoclickFromPref();
199 void UpdateAutoclickDelayFromPref();
200 void UpdateVirtualKeyboardFromPref();
202 void CheckBrailleState();
203 void ReceiveBrailleDisplayState(
204 scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
206 void SetProfile(Profile* profile);
208 void UpdateChromeOSAccessibilityHistograms();
210 // content::NotificationObserver implementation:
211 virtual void Observe(int type,
212 const content::NotificationSource& source,
213 const content::NotificationDetails& details) OVERRIDE;
215 // extensions::api::braille_display_private::BrailleObserver implementation.
216 // Enables spoken feedback if a braille display becomes available.
217 virtual void OnDisplayStateChanged(
218 const extensions::api::braille_display_private::DisplayState&
219 display_state) OVERRIDE;
221 // Profile which has the current a11y context.
222 Profile* profile_;
224 // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
225 // loaded to any profile.
226 bool chrome_vox_loaded_on_lock_screen_;
227 bool chrome_vox_loaded_on_user_screen_;
229 content::NotificationRegistrar notification_registrar_;
230 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
231 scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
232 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_;
234 PrefHandler large_cursor_pref_handler_;
235 PrefHandler spoken_feedback_pref_handler_;
236 PrefHandler high_contrast_pref_handler_;
237 PrefHandler autoclick_pref_handler_;
238 PrefHandler autoclick_delay_pref_handler_;
239 PrefHandler virtual_keyboard_pref_handler_;
241 bool large_cursor_enabled_;
242 bool sticky_keys_enabled_;
243 bool spoken_feedback_enabled_;
244 bool high_contrast_enabled_;
245 bool autoclick_enabled_;
246 int autoclick_delay_ms_;
247 bool virtual_keyboard_enabled_;
249 ash::AccessibilityNotificationVisibility spoken_feedback_notification_;
251 base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
253 bool should_speak_chrome_vox_announcements_on_user_screen_;
255 bool system_sounds_enabled_;
257 AccessibilityStatusCallbackList callback_list_;
259 DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
262 } // namespace chromeos
264 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_