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.
5 #ifndef CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_
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"
20 struct AccessibilityStatusEventDetails {
21 AccessibilityStatusEventDetails(
23 ash::AccessibilityNotificationVisibility notify);
25 AccessibilityStatusEventDetails(
27 ash::MagnifierType magnifier_type,
28 ash::AccessibilityNotificationVisibility notify);
31 ash::MagnifierType magnifier_type;
32 ash::AccessibilityNotificationVisibility notify;
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 {
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();
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.
55 explicit PrefHandler(const char* pref_path);
56 virtual ~PrefHandler();
58 // Should be called from AccessibilityManager::SetProfile().
59 void HandleProfileChanged(Profile* previous_profile,
60 Profile* current_profile);
63 const char* pref_path_;
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();
71 // Enables or disable Sticky Keys.
72 void EnableStickyKeys(bool enabled);
74 // Returns true if Incognito mode is allowed, or false if not.
75 bool IsIncognitoAllowed();
77 // Returns true if the Sticky Keys is enabled, or false if not.
78 bool IsStickyKeysEnabled();
80 // Enables or disables spoken feedback. Enabling spoken feedback installs the
81 // ChromeVox component extension.
82 void EnableSpokenFeedback(bool enabled,
83 ash::AccessibilityNotificationVisibility notify);
85 // Returns true if spoken feedback is enabled, or false if not.
86 bool IsSpokenFeedbackEnabled();
88 // Toggles whether Chrome OS spoken feedback is on or off.
89 void ToggleSpokenFeedback(ash::AccessibilityNotificationVisibility notify);
91 // Speaks the specified string.
92 void Speak(const std::string& text);
94 // Speaks the given text if the accessibility pref is already set.
95 void MaybeSpeak(const std::string& text);
97 // Enables or disables the high contrast mode for Chrome.
98 void EnableHighContrast(bool enabled);
100 // Returns true if High Contrast is enabled, or false if not.
101 bool IsHighContrastEnabled();
103 // Enables or disables autoclick.
104 void EnableAutoclick(bool enabled);
106 // Returns true if autoclick is enabled.
107 bool IsAutoclickEnabled();
109 // Set the delay for autoclicking after stopping the cursor in milliseconds.
110 void SetAutoclickDelay(int delay_ms);
112 // Returns the autoclick delay in milliseconds.
113 int GetAutoclickDelay() const;
115 void SetProfileForTest(Profile* profile);
117 static void SetBrailleControllerForTest(
118 extensions::api::braille_display_private::BrailleController* controller);
121 AccessibilityManager();
122 virtual ~AccessibilityManager();
125 void LoadChromeVox();
126 void LoadChromeVoxToUserScreen();
127 void LoadChromeVoxToLockScreen();
128 void UnloadChromeVox();
129 void UnloadChromeVoxFromLockScreen();
131 void UpdateLargeCursorFromPref();
132 void UpdateStickyKeysFromPref();
133 void UpdateSpokenFeedbackFromPref();
134 void UpdateHighContrastFromPref();
135 void UpdateAutoclickFromPref();
136 void UpdateAutoclickDelayFromPref();
137 void LocalePrefChanged();
139 void CheckBrailleState();
140 void ReceiveBrailleDisplayState(
141 scoped_ptr<extensions::api::braille_display_private::DisplayState> state);
144 void SetProfile(Profile* profile);
146 void UpdateChromeOSAccessibilityHistograms();
148 // content::NotificationObserver implementation:
149 virtual void Observe(int type,
150 const content::NotificationSource& source,
151 const content::NotificationDetails& details) OVERRIDE;
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;
159 // Profile which has the current a11y context.
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_;
167 content::NotificationRegistrar notification_registrar_;
168 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
169 scoped_ptr<PrefChangeRegistrar> local_state_pref_change_registrar_;
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_;
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_;
184 ash::AccessibilityNotificationVisibility spoken_feedback_notification_;
186 base::WeakPtrFactory<AccessibilityManager> weak_ptr_factory_;
188 DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
191 } // namespace chromeos
193 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_ACCESSIBILITY_MANAGER_H_