cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / chromeos / accessibility / accessibility_manager.h
blob9a06fa50e267805902c851a9c347896f685634a5
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/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"
26 namespace content {
27 class RenderViewHost;
29 class Profile;
31 namespace chromeos {
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,
46 bool enabled,
47 ui::AccessibilityNotificationVisibility notify);
49 AccessibilityStatusEventDetails(
50 AccessibilityNotificationType notification_type,
51 bool enabled,
52 ui::MagnifierType magnifier_type,
53 ui::AccessibilityNotificationVisibility notify);
55 AccessibilityNotificationType notification_type;
56 bool enabled;
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 {
78 public:
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.
91 class PrefHandler {
92 public:
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);
100 private:
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
161 // false.
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
182 // option changes.
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);
198 // Profile having the a11y context.
199 Profile* profile() { return profile_; }
201 protected:
202 AccessibilityManager();
203 ~AccessibilityManager() override;
205 private:
206 void LoadChromeVox();
207 void LoadChromeVoxToUserScreen(const base::Closure& done_cb);
208 void LoadChromeVoxToLockScreen(const base::Closure& done_cb);
209 void UnloadChromeVox();
210 void UnloadChromeVoxFromLockScreen();
211 void PostLoadChromeVox(Profile* profile);
212 void PostUnloadChromeVox(Profile* profile);
214 void UpdateLargeCursorFromPref();
215 void UpdateStickyKeysFromPref();
216 void UpdateSpokenFeedbackFromPref();
217 void UpdateHighContrastFromPref();
218 void UpdateAutoclickFromPref();
219 void UpdateAutoclickDelayFromPref();
220 void UpdateVirtualKeyboardFromPref();
222 void CheckBrailleState();
223 void ReceiveBrailleDisplayState(
224 scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
225 void UpdateBrailleImeState();
227 void SetProfile(Profile* profile);
229 void UpdateChromeOSAccessibilityHistograms();
231 // content::NotificationObserver
232 void Observe(int type,
233 const content::NotificationSource& source,
234 const content::NotificationDetails& details) override;
236 // extensions::api::braille_display_private::BrailleObserver implementation.
237 // Enables spoken feedback if a braille display becomes available.
238 void OnBrailleDisplayStateChanged(
239 const extensions::api::braille_display_private::DisplayState&
240 display_state) override;
241 void OnBrailleKeyEvent(
242 const extensions::api::braille_display_private::KeyEvent& event) override;
244 // InputMethodManager::Observer
245 void InputMethodChanged(input_method::InputMethodManager* manager,
246 Profile* profile,
247 bool show_message) override;
249 // Profile which has the current a11y context.
250 Profile* profile_;
252 // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
253 // loaded to any profile.
254 bool chrome_vox_loaded_on_lock_screen_;
255 bool chrome_vox_loaded_on_user_screen_;
257 content::NotificationRegistrar notification_registrar_;
258 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
259 scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
260 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_;
262 PrefHandler large_cursor_pref_handler_;
263 PrefHandler spoken_feedback_pref_handler_;
264 PrefHandler high_contrast_pref_handler_;
265 PrefHandler autoclick_pref_handler_;
266 PrefHandler autoclick_delay_pref_handler_;
267 PrefHandler virtual_keyboard_pref_handler_;
269 bool large_cursor_enabled_;
270 bool sticky_keys_enabled_;
271 bool spoken_feedback_enabled_;
272 bool high_contrast_enabled_;
273 bool autoclick_enabled_;
274 int autoclick_delay_ms_;
275 bool virtual_keyboard_enabled_;
277 ui::AccessibilityNotificationVisibility spoken_feedback_notification_;
279 bool should_speak_chrome_vox_announcements_on_user_screen_;
281 bool system_sounds_enabled_;
283 AccessibilityStatusCallbackList callback_list_;
285 bool braille_display_connected_;
286 ScopedObserver<extensions::api::braille_display_private::BrailleController,
287 AccessibilityManager> scoped_braille_observer_;
289 bool braille_ime_current_;
291 base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
293 DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
296 } // namespace chromeos
298 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_