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