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