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