accessibility_manager.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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
16class Profile;
17
18namespace chromeos {
19
20struct 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.
38class 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 the Sticky Keys is enabled, or false if not.
75  bool IsStickyKeysEnabled();
76
77  // Enables or disables spoken feedback. Enabling spoken feedback installs the
78  // ChromeVox component extension.
79  void EnableSpokenFeedback(bool enabled,
80                            ash::AccessibilityNotificationVisibility notify);
81
82  // Returns true if spoken feedback is enabled, or false if not.
83  bool IsSpokenFeedbackEnabled();
84
85  // Toggles whether Chrome OS spoken feedback is on or off.
86  void ToggleSpokenFeedback(ash::AccessibilityNotificationVisibility notify);
87
88  // Speaks the specified string.
89  void Speak(const std::string& text);
90
91  // Speaks the given text if the accessibility pref is already set.
92  void MaybeSpeak(const std::string& text);
93
94  // Enables or disables the high contrast mode for Chrome.
95  void EnableHighContrast(bool enabled);
96
97  // Returns true if High Contrast is enabled, or false if not.
98  bool IsHighContrastEnabled();
99
100  // Enables or disables autoclick.
101  void EnableAutoclick(bool enabled);
102
103  // Returns true if autoclick is enabled.
104  bool IsAutoclickEnabled();
105
106  // Set the delay for autoclicking after stopping the cursor in milliseconds.
107  void SetAutoclickDelay(int delay_ms);
108
109  // Returns the autoclick delay in milliseconds.
110  int GetAutoclickDelay() const;
111
112  void SetProfileForTest(Profile* profile);
113
114  static void SetBrailleControllerForTest(
115      extensions::api::braille_display_private::BrailleController* controller);
116
117 protected:
118  AccessibilityManager();
119  virtual ~AccessibilityManager();
120
121 private:
122  void LoadChromeVox();
123  void LoadChromeVoxToUserScreen();
124  void LoadChromeVoxToLockScreen();
125  void UnloadChromeVox();
126  void UnloadChromeVoxFromLockScreen();
127
128  void UpdateLargeCursorFromPref();
129  void UpdateStickyKeysFromPref();
130  void UpdateSpokenFeedbackFromPref();
131  void UpdateHighContrastFromPref();
132  void UpdateAutoclickFromPref();
133  void UpdateAutoclickDelayFromPref();
134  void LocalePrefChanged();
135
136  void CheckBrailleState();
137  void ReceiveBrailleDisplayState(
138      scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
139
140
141  void SetProfile(Profile* profile);
142
143  void UpdateChromeOSAccessibilityHistograms();
144
145  // content::NotificationObserver implementation:
146  virtual void Observe(int type,
147                       const content::NotificationSource& source,
148                       const content::NotificationDetails& details) OVERRIDE;
149
150  // extensions::api::braille_display_private::BrailleObserver implementation.
151  // Enables spoken feedback if a braille display becomes available.
152  virtual void OnDisplayStateChanged(
153      const extensions::api::braille_display_private::DisplayState&
154          display_state) OVERRIDE;
155
156  // Profile which has the current a11y context.
157  Profile* profile_;
158
159  // Profile which ChromeVox is currently loaded to. If NULL, ChromeVox is not
160  // loaded to any profile.
161  bool chrome_vox_loaded_on_lock_screen_;
162  bool chrome_vox_loaded_on_user_screen_;
163
164  content::NotificationRegistrar notification_registrar_;
165  scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
166  scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
167
168  PrefHandler large_cursor_pref_handler_;
169  PrefHandler spoken_feedback_pref_handler_;
170  PrefHandler high_contrast_pref_handler_;
171  PrefHandler autoclick_pref_handler_;
172  PrefHandler autoclick_delay_pref_handler_;
173
174  bool large_cursor_enabled_;
175  bool sticky_keys_enabled_;
176  bool spoken_feedback_enabled_;
177  bool high_contrast_enabled_;
178  bool autoclick_enabled_;
179  int autoclick_delay_ms_;
180
181  ash::AccessibilityNotificationVisibility spoken_feedback_notification_;
182
183  base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
184
185  DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
186};
187
188}  // namespace chromeos
189
190#endif  // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
191