accessibility_manager.h revision 868fa2fe829687343ffae624259930155e16dbd8
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 content {
17class WebUI;
18}
19
20namespace chromeos {
21
22struct AccessibilityStatusEventDetails {
23  AccessibilityStatusEventDetails(
24      bool enabled,
25      ash::AccessibilityNotificationVisibility notify);
26
27  AccessibilityStatusEventDetails(
28      bool enabled,
29      ash::MagnifierType magnifier_type,
30      ash::AccessibilityNotificationVisibility notify);
31
32  bool enabled;
33  ash::MagnifierType magnifier_type;
34  ash::AccessibilityNotificationVisibility notify;
35};
36
37// AccessibilityManager changes the statuses of accessibility features
38// watching profile notifications and pref-changes.
39// TODO(yoshiki): merge MagnificationManager with AccessibilityManager.
40class AccessibilityManager : public content::NotificationObserver {
41 public:
42  // Creates an instance of AccessibilityManager, this should be called once,
43  // because only one instance should exist at the same time.
44  static void Initialize();
45  // Deletes the existing instance of AccessibilityManager.
46  static void Shutdown();
47  // Returns the existing instance. If there is no instance, returns NULL.
48  static AccessibilityManager* Get();
49
50  // Enables or disables the large cursor.
51  void EnableLargeCursor(bool enabled);
52  // Returns true if the large cursor is enabled, or false if not.
53  bool IsLargeCursorEnabled();
54
55  // Enables or disables spoken feedback. Enabling spoken feedback installs the
56  // ChromeVox component extension.  If this is being called in a login/oobe
57  // login screen, pass the WebUI object in login_web_ui so that ChromeVox
58  // can be injected directly into that screen, otherwise it should be NULL.
59  void EnableSpokenFeedback(bool enabled,
60                            content::WebUI* login_web_ui,
61                            ash::AccessibilityNotificationVisibility notify);
62
63  // Returns true if spoken feedback is enabled, or false if not.
64  bool IsSpokenFeedbackEnabled();
65
66  // Toggles whether Chrome OS spoken feedback is on or off. See docs for
67  // EnableSpokenFeedback, above.
68  void ToggleSpokenFeedback(content::WebUI* login_web_ui,
69                            ash::AccessibilityNotificationVisibility notify);
70
71  // Speaks the specified string.
72  void Speak(const std::string& text);
73
74  // Speaks the given text if the accessibility pref is already set.
75  void MaybeSpeak(const std::string& text);
76
77  // Enables or disables the high contrast mode for Chrome.
78  void EnableHighContrast(bool enabled);
79
80  // Returns true if High Contrast is enabled, or false if not.
81  bool IsHighContrastEnabled();
82
83  void SetProfileForTest(Profile* profile);
84
85 protected:
86  AccessibilityManager();
87  virtual ~AccessibilityManager();
88
89 private:
90  void UpdateLargeCursorFromPref();
91  void UpdateSpokenFeedbackFromPref();
92  void UpdateHighContrastFromPref();
93
94  void SetProfile(Profile* profile);
95
96  void UpdateChromeOSAccessibilityHistograms();
97
98  // content::NotificationObserver implementation:
99  virtual void Observe(int type,
100                       const content::NotificationSource& source,
101                       const content::NotificationDetails& details) OVERRIDE;
102
103  Profile* profile_;
104  content::NotificationRegistrar notification_registrar_;
105  scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
106
107  bool large_cursor_enabled_;
108  bool spoken_feedback_enabled_;
109  bool high_contrast_enabled_;
110
111  content::WebUI* spoken_feedback_login_web_ui_;
112  ash::AccessibilityNotificationVisibility spoken_feedback_notification_;
113
114  DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
115};
116
117}  // namespace chromeos
118
119#endif  // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
120