Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / accessibility / accessibility_manager.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
7
8 #include <set>
9
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"
24
25 #if !defined(USE_ATHENA)
26 #include "ash/session/session_state_observer.h"
27 #endif
28
29 namespace content {
30 class RenderViewHost;
31 }
32 class Profile;
33
34 namespace chromeos {
35
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
44 };
45
46 struct AccessibilityStatusEventDetails {
47   AccessibilityStatusEventDetails(
48       AccessibilityNotificationType notification_type,
49       bool enabled,
50       ui::AccessibilityNotificationVisibility notify);
51
52   AccessibilityStatusEventDetails(
53       AccessibilityNotificationType notification_type,
54       bool enabled,
55       ui::MagnifierType magnifier_type,
56       ui::AccessibilityNotificationVisibility notify);
57
58   AccessibilityNotificationType notification_type;
59   bool enabled;
60   ui::MagnifierType magnifier_type;
61   ui::AccessibilityNotificationVisibility notify;
62 };
63
64 typedef base::Callback<void(const AccessibilityStatusEventDetails&)>
65     AccessibilityStatusCallback;
66
67 typedef base::CallbackList<void(const AccessibilityStatusEventDetails&)>
68     AccessibilityStatusCallbackList;
69
70 typedef AccessibilityStatusCallbackList::Subscription
71     AccessibilityStatusSubscription;
72
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,
81 #endif
82       public input_method::InputMethodManager::Observer {
83  public:
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();
91
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.
96   class PrefHandler {
97    public:
98     explicit PrefHandler(const char* pref_path);
99     virtual ~PrefHandler();
100
101     // Should be called from AccessibilityManager::SetProfile().
102     void HandleProfileChanged(Profile* previous_profile,
103                               Profile* current_profile);
104
105    private:
106     const char* pref_path_;
107
108     DISALLOW_COPY_AND_ASSIGN(PrefHandler);
109   };
110
111   // Returns true when the accessibility menu should be shown.
112   bool ShouldShowAccessibilityMenu();
113
114   // Returns true when cursor compositing should be enabled.
115   bool ShouldEnableCursorCompositing();
116
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();
121
122   // Enables or disable Sticky Keys.
123   void EnableStickyKeys(bool enabled);
124
125   // Returns true if Incognito mode is allowed, or false if not.
126   bool IsIncognitoAllowed();
127
128   // Returns true if the Sticky Keys is enabled, or false if not.
129   bool IsStickyKeysEnabled();
130
131   // Enables or disables spoken feedback. Enabling spoken feedback installs the
132   // ChromeVox component extension.
133   void EnableSpokenFeedback(bool enabled,
134                             ui::AccessibilityNotificationVisibility notify);
135
136   // Returns true if spoken feedback is enabled, or false if not.
137   bool IsSpokenFeedbackEnabled();
138
139   // Toggles whether Chrome OS spoken feedback is on or off.
140   void ToggleSpokenFeedback(ui::AccessibilityNotificationVisibility notify);
141
142   // Enables or disables the high contrast mode for Chrome.
143   void EnableHighContrast(bool enabled);
144
145   // Returns true if High Contrast is enabled, or false if not.
146   bool IsHighContrastEnabled();
147
148   // Enables or disables autoclick.
149   void EnableAutoclick(bool enabled);
150
151   // Returns true if autoclick is enabled.
152   bool IsAutoclickEnabled();
153
154   // Set the delay for autoclicking after stopping the cursor in milliseconds.
155   void SetAutoclickDelay(int delay_ms);
156
157   // Returns the autoclick delay in milliseconds.
158   int GetAutoclickDelay() const;
159
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();
164
165   // Returns true if a braille display is connected to the system, otherwise
166   // false.
167   bool IsBrailleDisplayConnected() const;
168
169 #if !defined(USE_ATHENA)
170   // SessionStateObserver overrides:
171   virtual void ActiveUserChanged(const std::string& user_id) override;
172 #endif
173
174   void SetProfileForTest(Profile* profile);
175
176   static void SetBrailleControllerForTest(
177       extensions::api::braille_display_private::BrailleController* controller);
178
179   // Enables/disables system sounds.
180   void EnableSystemSounds(bool system_sounds_enabled);
181
182   // Initiates play of shutdown sound and returns it's duration.
183   base::TimeDelta PlayShutdownSound();
184
185   // Injects ChromeVox scripts into given |render_view_host|.
186   void InjectChromeVox(content::RenderViewHost* render_view_host);
187
188   // Register a callback to be notified when the status of an accessibility
189   // option changes.
190   scoped_ptr<AccessibilityStatusSubscription> RegisterCallback(
191       const AccessibilityStatusCallback& cb);
192
193   // Notify registered callbacks of a status change in an accessibility setting.
194   void NotifyAccessibilityStatusChanged(
195       AccessibilityStatusEventDetails& details);
196
197   // Notify accessibility when locale changes occur.
198   void OnLocaleChanged();
199
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);
204
205  protected:
206   AccessibilityManager();
207   virtual ~AccessibilityManager();
208
209  private:
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);
217
218   void UpdateLargeCursorFromPref();
219   void UpdateStickyKeysFromPref();
220   void UpdateSpokenFeedbackFromPref();
221   void UpdateHighContrastFromPref();
222   void UpdateAutoclickFromPref();
223   void UpdateAutoclickDelayFromPref();
224   void UpdateVirtualKeyboardFromPref();
225
226   void CheckBrailleState();
227   void ReceiveBrailleDisplayState(
228       scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
229   void UpdateBrailleImeState();
230
231   void SetProfile(Profile* profile);
232
233   void UpdateChromeOSAccessibilityHistograms();
234
235   // content::NotificationObserver
236   virtual void Observe(int type,
237                        const content::NotificationSource& source,
238                        const content::NotificationDetails& details) override;
239
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;
247
248   // InputMethodManager::Observer
249   virtual void InputMethodChanged(input_method::InputMethodManager* manager,
250                                   bool show_message) override;
251
252
253   // Profile which has the current a11y context.
254   Profile* profile_;
255
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_;
260
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_;
266 #endif
267
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_;
274
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_;
282
283   ui::AccessibilityNotificationVisibility spoken_feedback_notification_;
284
285   bool should_speak_chrome_vox_announcements_on_user_screen_;
286
287   bool system_sounds_enabled_;
288
289   AccessibilityStatusCallbackList callback_list_;
290
291   bool braille_display_connected_;
292   ScopedObserver<extensions::api::braille_display_private::BrailleController,
293                  AccessibilityManager> scoped_braille_observer_;
294
295   bool braille_ime_current_;
296
297   base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
298
299   DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
300 };
301
302 }  // namespace chromeos
303
304 #endif  // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_