- add sources.
[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 "ash/accessibility_delegate.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/prefs/pref_change_registrar.h"
11 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
12 #include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15
16 class Profile;
17
18 namespace chromeos {
19
20 struct AccessibilityStatusEventDetails {
21   AccessibilityStatusEventDetails(
22       bool enabled,
23       ash::AccessibilityNotificationVisibility notify);
24
25   AccessibilityStatusEventDetails(
26       bool enabled,
27       ash::MagnifierType magnifier_type,
28       ash::AccessibilityNotificationVisibility notify);
29
30   bool enabled;
31   ash::MagnifierType magnifier_type;
32   ash::AccessibilityNotificationVisibility notify;
33 };
34
35 // AccessibilityManager changes the statuses of accessibility features
36 // watching profile notifications and pref-changes.
37 // TODO(yoshiki): merge MagnificationManager with AccessibilityManager.
38 class AccessibilityManager : public content::NotificationObserver,
39     extensions::api::braille_display_private::BrailleObserver {
40  public:
41   // Creates an instance of AccessibilityManager, this should be called once,
42   // because only one instance should exist at the same time.
43   static void Initialize();
44   // Deletes the existing instance of AccessibilityManager.
45   static void Shutdown();
46   // Returns the existing instance. If there is no instance, returns NULL.
47   static AccessibilityManager* Get();
48
49   // On a user's first login into a device, any a11y features enabled/disabled
50   // by the user on the login screen are enabled/disabled in the user's profile.
51   // This class watches for profile changes and copies settings into the user's
52   // profile when it detects a login with a newly created profile.
53   class PrefHandler {
54    public:
55     explicit PrefHandler(const char* pref_path);
56     virtual ~PrefHandler();
57
58     // Should be called from AccessibilityManager::SetProfile().
59     void HandleProfileChanged(Profile* previous_profile,
60                               Profile* current_profile);
61
62    private:
63     const char* pref_path_;
64   };
65
66   // Enables or disables the large cursor.
67   void EnableLargeCursor(bool enabled);
68   // Returns true if the large cursor is enabled, or false if not.
69   bool IsLargeCursorEnabled();
70
71   // Enables or disable Sticky Keys.
72   void EnableStickyKeys(bool enabled);
73
74   // Returns true if Incognito mode is allowed, or false if not.
75   bool IsIncognitoAllowed();
76
77   // Returns true if the Sticky Keys is enabled, or false if not.
78   bool IsStickyKeysEnabled();
79
80   // Enables or disables spoken feedback. Enabling spoken feedback installs the
81   // ChromeVox component extension.
82   void EnableSpokenFeedback(bool enabled,
83                             ash::AccessibilityNotificationVisibility notify);
84
85   // Returns true if spoken feedback is enabled, or false if not.
86   bool IsSpokenFeedbackEnabled();
87
88   // Toggles whether Chrome OS spoken feedback is on or off.
89   void ToggleSpokenFeedback(ash::AccessibilityNotificationVisibility notify);
90
91   // Speaks the specified string.
92   void Speak(const std::string& text);
93
94   // Speaks the given text if the accessibility pref is already set.
95   void MaybeSpeak(const std::string& text);
96
97   // Enables or disables the high contrast mode for Chrome.
98   void EnableHighContrast(bool enabled);
99
100   // Returns true if High Contrast is enabled, or false if not.
101   bool IsHighContrastEnabled();
102
103   // Enables or disables autoclick.
104   void EnableAutoclick(bool enabled);
105
106   // Returns true if autoclick is enabled.
107   bool IsAutoclickEnabled();
108
109   // Set the delay for autoclicking after stopping the cursor in milliseconds.
110   void SetAutoclickDelay(int delay_ms);
111
112   // Returns the autoclick delay in milliseconds.
113   int GetAutoclickDelay() const;
114
115   void SetProfileForTest(Profile* profile);
116
117   static void SetBrailleControllerForTest(
118       extensions::api::braille_display_private::BrailleController* controller);
119
120  protected:
121   AccessibilityManager();
122   virtual ~AccessibilityManager();
123
124  private:
125   void LoadChromeVox();
126   void LoadChromeVoxToUserScreen();
127   void LoadChromeVoxToLockScreen();
128   void UnloadChromeVox();
129   void UnloadChromeVoxFromLockScreen();
130
131   void UpdateLargeCursorFromPref();
132   void UpdateStickyKeysFromPref();
133   void UpdateSpokenFeedbackFromPref();
134   void UpdateHighContrastFromPref();
135   void UpdateAutoclickFromPref();
136   void UpdateAutoclickDelayFromPref();
137   void LocalePrefChanged();
138
139   void CheckBrailleState();
140   void ReceiveBrailleDisplayState(
141       scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
142
143
144   void SetProfile(Profile* profile);
145
146   void UpdateChromeOSAccessibilityHistograms();
147
148   // content::NotificationObserver implementation:
149   virtual void Observe(int type,
150                        const content::NotificationSource& source,
151                        const content::NotificationDetails& details) OVERRIDE;
152
153   // extensions::api::braille_display_private::BrailleObserver implementation.
154   // Enables spoken feedback if a braille display becomes available.
155   virtual void OnDisplayStateChanged(
156       const extensions::api::braille_display_private::DisplayState&
157           display_state) OVERRIDE;
158
159   // Profile which has the current a11y context.
160   Profile* profile_;
161
162   // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
163   // loaded to any profile.
164   bool chrome_vox_loaded_on_lock_screen_;
165   bool chrome_vox_loaded_on_user_screen_;
166
167   content::NotificationRegistrar notification_registrar_;
168   scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
169   scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
170
171   PrefHandler large_cursor_pref_handler_;
172   PrefHandler spoken_feedback_pref_handler_;
173   PrefHandler high_contrast_pref_handler_;
174   PrefHandler autoclick_pref_handler_;
175   PrefHandler autoclick_delay_pref_handler_;
176
177   bool large_cursor_enabled_;
178   bool sticky_keys_enabled_;
179   bool spoken_feedback_enabled_;
180   bool high_contrast_enabled_;
181   bool autoclick_enabled_;
182   int autoclick_delay_ms_;
183
184   ash::AccessibilityNotificationVisibility spoken_feedback_notification_;
185
186   base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
187
188   DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
189 };
190
191 }  // namespace chromeos
192
193 #endif  // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_