BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / accessibility / accessibility_manager.h
blobc961b205611a6156155f7457dcdc20efd3e7426a
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 "ash/shell_observer.h"
12 #include "base/callback_forward.h"
13 #include "base/callback_list.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/prefs/pref_change_registrar.h"
16 #include "base/scoped_observer.h"
17 #include "base/time/time.h"
18 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
19 #include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "extensions/browser/event_router.h"
23 #include "extensions/browser/extension_system.h"
24 #include "ui/base/ime/chromeos/input_method_manager.h"
25 #include "ui/chromeos/accessibility_types.h"
27 namespace content {
28 class RenderViewHost;
30 class Profile;
32 namespace chromeos {
34 enum AccessibilityNotificationType {
35 ACCESSIBILITY_MANAGER_SHUTDOWN,
36 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE,
37 ACCESSIBILITY_TOGGLE_LARGE_CURSOR,
38 ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER,
39 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK,
40 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD,
41 ACCESSIBILITY_BRAILLE_DISPLAY_CONNECTION_STATE_CHANGED
44 struct AccessibilityStatusEventDetails {
45 AccessibilityStatusEventDetails(
46 AccessibilityNotificationType notification_type,
47 bool enabled,
48 ui::AccessibilityNotificationVisibility notify);
50 AccessibilityStatusEventDetails(
51 AccessibilityNotificationType notification_type,
52 bool enabled,
53 ui::MagnifierType magnifier_type,
54 ui::AccessibilityNotificationVisibility notify);
56 AccessibilityNotificationType notification_type;
57 bool enabled;
58 ui::MagnifierType magnifier_type;
59 ui::AccessibilityNotificationVisibility notify;
62 typedef base::Callback<void(const AccessibilityStatusEventDetails&)>
63 AccessibilityStatusCallback;
65 typedef base::CallbackList<void(const AccessibilityStatusEventDetails&)>
66 AccessibilityStatusCallbackList;
68 typedef AccessibilityStatusCallbackList::Subscription
69 AccessibilityStatusSubscription;
71 // AccessibilityManager changes the statuses of accessibility features
72 // watching profile notifications and pref-changes.
73 // TODO(yoshiki): merge MagnificationManager with AccessibilityManager.
74 class AccessibilityManager
75 : public content::NotificationObserver,
76 public extensions::api::braille_display_private::BrailleObserver,
77 public ash::SessionStateObserver,
78 public ash::ShellObserver,
79 public input_method::InputMethodManager::Observer {
80 public:
81 // Creates an instance of AccessibilityManager, this should be called once,
82 // because only one instance should exist at the same time.
83 static void Initialize();
84 // Deletes the existing instance of AccessibilityManager.
85 static void Shutdown();
86 // Returns the existing instance. If there is no instance, returns NULL.
87 static AccessibilityManager* Get();
89 // On a user's first login into a device, any a11y features enabled/disabled
90 // by the user on the login screen are enabled/disabled in the user's profile.
91 // This class watches for profile changes and copies settings into the user's
92 // profile when it detects a login with a newly created profile.
93 class PrefHandler {
94 public:
95 explicit PrefHandler(const char* pref_path);
96 virtual ~PrefHandler();
98 // Should be called from AccessibilityManager::SetProfile().
99 void HandleProfileChanged(Profile* previous_profile,
100 Profile* current_profile);
102 private:
103 const char* pref_path_;
105 DISALLOW_COPY_AND_ASSIGN(PrefHandler);
108 // Returns true when the accessibility menu should be shown.
109 bool ShouldShowAccessibilityMenu();
111 // Returns true when cursor compositing should be enabled.
112 bool ShouldEnableCursorCompositing();
114 // Enables or disables the large cursor.
115 void EnableLargeCursor(bool enabled);
116 // Returns true if the large cursor is enabled, or false if not.
117 bool IsLargeCursorEnabled();
119 // Enables or disable Sticky Keys.
120 void EnableStickyKeys(bool enabled);
122 // Returns true if Incognito mode is allowed, or false if not.
123 bool IsIncognitoAllowed();
125 // Returns true if the Sticky Keys is enabled, or false if not.
126 bool IsStickyKeysEnabled();
128 // Enables or disables spoken feedback. Enabling spoken feedback installs the
129 // ChromeVox component extension.
130 void EnableSpokenFeedback(bool enabled,
131 ui::AccessibilityNotificationVisibility notify);
133 // Returns true if spoken feedback is enabled, or false if not.
134 bool IsSpokenFeedbackEnabled();
136 // Toggles whether Chrome OS spoken feedback is on or off.
137 void ToggleSpokenFeedback(ui::AccessibilityNotificationVisibility notify);
139 // Enables or disables the high contrast mode for Chrome.
140 void EnableHighContrast(bool enabled);
142 // Returns true if High Contrast is enabled, or false if not.
143 bool IsHighContrastEnabled();
145 // Enables or disables autoclick.
146 void EnableAutoclick(bool enabled);
148 // Returns true if autoclick is enabled.
149 bool IsAutoclickEnabled();
151 // Set the delay for autoclicking after stopping the cursor in milliseconds.
152 void SetAutoclickDelay(int delay_ms);
154 // Returns the autoclick delay in milliseconds.
155 int GetAutoclickDelay() const;
157 // Enables or disables the virtual keyboard.
158 void EnableVirtualKeyboard(bool enabled);
159 // Returns true if the virtual keyboard is enabled, otherwise false.
160 bool IsVirtualKeyboardEnabled();
162 // Returns true if a braille display is connected to the system, otherwise
163 // false.
164 bool IsBrailleDisplayConnected() const;
166 // SessionStateObserver overrides:
167 void ActiveUserChanged(const std::string& user_id) override;
169 // ShellObserver overrides:
170 void OnAppTerminating() override;
172 void SetProfileForTest(Profile* profile);
174 static void SetBrailleControllerForTest(
175 extensions::api::braille_display_private::BrailleController* controller);
177 // Enables/disables system sounds.
178 void EnableSystemSounds(bool system_sounds_enabled);
180 // Initiates play of shutdown sound and returns it's duration.
181 base::TimeDelta PlayShutdownSound();
183 // Injects ChromeVox scripts into given |render_view_host|.
184 void InjectChromeVox(content::RenderViewHost* render_view_host);
186 // Register a callback to be notified when the status of an accessibility
187 // option changes.
188 scoped_ptr<AccessibilityStatusSubscription> RegisterCallback(
189 const AccessibilityStatusCallback& cb);
191 // Notify registered callbacks of a status change in an accessibility setting.
192 void NotifyAccessibilityStatusChanged(
193 AccessibilityStatusEventDetails& details);
195 // Notify accessibility when locale changes occur.
196 void OnLocaleChanged();
198 // Plays an earcon. Earcons are brief and distinctive sounds that indicate
199 // when their mapped event has occurred. The sound key enums can be found in
200 // chromeos/audio/chromeos_sounds.h.
201 void PlayEarcon(int sound_key);
203 // Profile having the a11y context.
204 Profile* profile() { return profile_; }
206 protected:
207 AccessibilityManager();
208 ~AccessibilityManager() override;
210 private:
211 void LoadChromeVox();
212 void LoadChromeVoxToUserScreen(const base::Closure& done_cb);
213 void LoadChromeVoxToLockScreen(const base::Closure& done_cb);
214 void UnloadChromeVox();
215 void UnloadChromeVoxFromLockScreen();
216 void PostLoadChromeVox(Profile* profile);
217 void PostUnloadChromeVox(Profile* profile);
219 void UpdateLargeCursorFromPref();
220 void UpdateStickyKeysFromPref();
221 void UpdateSpokenFeedbackFromPref();
222 void UpdateHighContrastFromPref();
223 void UpdateAutoclickFromPref();
224 void UpdateAutoclickDelayFromPref();
225 void UpdateVirtualKeyboardFromPref();
227 void CheckBrailleState();
228 void ReceiveBrailleDisplayState(
229 scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
230 void UpdateBrailleImeState();
232 void SetProfile(Profile* profile);
234 void UpdateChromeOSAccessibilityHistograms();
236 // content::NotificationObserver
237 void Observe(int type,
238 const content::NotificationSource& source,
239 const content::NotificationDetails& details) override;
241 // extensions::api::braille_display_private::BrailleObserver implementation.
242 // Enables spoken feedback if a braille display becomes available.
243 void OnBrailleDisplayStateChanged(
244 const extensions::api::braille_display_private::DisplayState&
245 display_state) override;
246 void OnBrailleKeyEvent(
247 const extensions::api::braille_display_private::KeyEvent& event) override;
249 // InputMethodManager::Observer
250 void InputMethodChanged(input_method::InputMethodManager* manager,
251 Profile* profile,
252 bool show_message) override;
254 // Profile which has the current a11y context.
255 Profile* profile_;
257 // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
258 // loaded to any profile.
259 bool chrome_vox_loaded_on_lock_screen_;
260 bool chrome_vox_loaded_on_user_screen_;
262 content::NotificationRegistrar notification_registrar_;
263 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
264 scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
265 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_;
267 PrefHandler large_cursor_pref_handler_;
268 PrefHandler spoken_feedback_pref_handler_;
269 PrefHandler high_contrast_pref_handler_;
270 PrefHandler autoclick_pref_handler_;
271 PrefHandler autoclick_delay_pref_handler_;
272 PrefHandler virtual_keyboard_pref_handler_;
274 bool large_cursor_enabled_;
275 bool sticky_keys_enabled_;
276 bool spoken_feedback_enabled_;
277 bool high_contrast_enabled_;
278 bool autoclick_enabled_;
279 int autoclick_delay_ms_;
280 bool virtual_keyboard_enabled_;
282 ui::AccessibilityNotificationVisibility spoken_feedback_notification_;
284 bool should_speak_chrome_vox_announcements_on_user_screen_;
286 bool system_sounds_enabled_;
288 AccessibilityStatusCallbackList callback_list_;
290 bool braille_display_connected_;
291 ScopedObserver<extensions::api::braille_display_private::BrailleController,
292 AccessibilityManager> scoped_braille_observer_;
294 bool braille_ime_current_;
296 base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
298 DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
301 } // namespace chromeos
303 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_