[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 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 | #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 6 | |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 9 | |
| 10 | #include <memory> |
dcheng | 7c802f0 | 2015-12-31 16:09:55 | [diff] [blame] | 11 | #include <utility> |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 12 | #include <vector> |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 13 | |
James Cook | 08e91dc | 2018-03-08 18:53:19 | [diff] [blame] | 14 | #include "ash/accessibility/accessibility_controller.h" |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 15 | #include "ash/public/cpp/ash_pref_names.h" |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 16 | #include "ash/public/interfaces/accessibility_focus_ring_controller.mojom.h" |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 17 | #include "ash/public/interfaces/constants.mojom.h" |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 18 | #include "ash/root_window_controller.h" |
pkotwicz | 04d5c89 | 2015-01-15 00:05:36 | [diff] [blame] | 19 | #include "ash/shell.h" |
pkotwicz | 04d5c89 | 2015-01-15 00:05:36 | [diff] [blame] | 20 | #include "ash/sticky_keys/sticky_keys_controller.h" |
[email protected] | 44beb03 | 2014-06-11 06:24:37 | [diff] [blame] | 21 | #include "base/callback.h" |
| 22 | #include "base/callback_helpers.h" |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 23 | #include "base/command_line.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 24 | #include "base/memory/ptr_util.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 25 | #include "base/memory/singleton.h" |
asvitkine | b5663751 | 2016-09-01 19:41:40 | [diff] [blame] | 26 | #include "base/metrics/histogram_macros.h" |
[email protected] | ab38d19 | 2013-12-13 11:38:58 | [diff] [blame] | 27 | #include "base/path_service.h" |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 29 | #include "base/strings/string_split.h" |
| 30 | #include "base/strings/string_util.h" |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 31 | #include "base/values.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 32 | #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 33 | #include "chrome/browser/browser_process.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 34 | #include "chrome/browser/chrome_notification_types.h" |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 35 | #include "chrome/browser/chromeos/accessibility/accessibility_extension_loader.h" |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 36 | #include "chrome/browser/chromeos/accessibility/dictation_chromeos.h" |
pkotwicz | 04d5c89 | 2015-01-15 00:05:36 | [diff] [blame] | 37 | #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
Katie D | 4ea6944 | 2018-04-02 23:17:30 | [diff] [blame] | 38 | #include "chrome/browser/chromeos/accessibility/select_to_speak_event_handler.h" |
elichtenberg | c4b4bf46 | 2017-02-28 20:48:10 | [diff] [blame] | 39 | #include "chrome/browser/chromeos/accessibility/switch_access_event_handler.h" |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 40 | #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 41 | #include "chrome/browser/chromeos/ash_config.h" |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 42 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 43 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 44 | #include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 46 | #include "chrome/browser/profiles/profile.h" |
| 47 | #include "chrome/browser/profiles/profile_manager.h" |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 48 | #include "chrome/browser/speech/tts_controller.h" |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 49 | #include "chrome/browser/ui/singleton_tabs.h" |
[email protected] | ab38d19 | 2013-12-13 11:38:58 | [diff] [blame] | 50 | #include "chrome/common/chrome_paths.h" |
[email protected] | 9848bf6c | 2014-05-09 12:34:00 | [diff] [blame] | 51 | #include "chrome/common/extensions/api/accessibility_private.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 52 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 53 | #include "chrome/common/pref_names.h" |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 54 | #include "chrome/common/url_constants.h" |
[email protected] | b58d2f8 | 2014-08-09 05:36:14 | [diff] [blame] | 55 | #include "chrome/grit/browser_resources.h" |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 56 | #include "chromeos/audio/chromeos_sounds.h" |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 57 | #include "chromeos/chromeos_switches.h" |
dtseng | 3a17f21 | 2017-03-25 08:58:52 | [diff] [blame] | 58 | #include "chromeos/dbus/dbus_thread_manager.h" |
| 59 | #include "chromeos/dbus/power_manager_client.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 60 | #include "components/prefs/pref_member.h" |
| 61 | #include "components/prefs/pref_service.h" |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 62 | #include "components/session_manager/core/session_manager.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 63 | #include "content/public/browser/browser_accessibility_state.h" |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 64 | #include "content/public/browser/browser_thread.h" |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 65 | #include "content/public/browser/focused_node_details.h" |
[email protected] | 9cf54f36 | 2013-07-01 07:28:12 | [diff] [blame] | 66 | #include "content/public/browser/notification_details.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 67 | #include "content/public/browser/notification_service.h" |
[email protected] | 9cf54f36 | 2013-07-01 07:28:12 | [diff] [blame] | 68 | #include "content/public/browser/notification_source.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 69 | #include "content/public/browser/web_ui.h" |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 70 | #include "content/public/common/content_switches.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 71 | #include "content/public/common/service_manager_connection.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 72 | #include "extensions/browser/extension_registry.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 73 | #include "extensions/common/extension.h" |
[email protected] | fb820c0 | 2014-03-13 15:07:08 | [diff] [blame] | 74 | #include "extensions/common/extension_messages.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 75 | #include "extensions/common/extension_resource.h" |
hanxi | 79f7a57 | 2015-03-09 20:46:59 | [diff] [blame] | 76 | #include "extensions/common/host_id.h" |
Ken Rockot | 388ba4fc | 2018-02-10 17:23:41 | [diff] [blame] | 77 | #include "mash/public/mojom/launchable.mojom.h" |
[email protected] | 12b0a84 | 2013-12-04 20:48:13 | [diff] [blame] | 78 | #include "media/audio/sounds/sounds_manager.h" |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 79 | #include "media/base/media_switches.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 80 | #include "services/service_manager/public/cpp/connector.h" |
Qiang Xu | c4b0575 | 2018-02-13 20:10:28 | [diff] [blame] | 81 | #include "ui/accessibility/ax_enum_util.h" |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 82 | #include "ui/base/ime/chromeos/extension_ime_util.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 83 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 66193f7 | 2017-06-26 22:24:18 | [diff] [blame] | 84 | #include "ui/views/widget/widget.h" |
jamescook | 9eb0f91 | 2017-02-03 19:13:39 | [diff] [blame] | 85 | #include "ui/views/widget/widget_observer.h" |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 86 | #include "url/gurl.h" |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 87 | |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 88 | using content::BrowserThread; |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 89 | using extensions::api::braille_display_private::BrailleController; |
| 90 | using extensions::api::braille_display_private::DisplayState; |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 91 | using extensions::api::braille_display_private::KeyEvent; |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 92 | using extensions::api::braille_display_private::StubBrailleController; |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 93 | |
| 94 | namespace chromeos { |
| 95 | |
| 96 | namespace { |
| 97 | |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 98 | // When this flag is set, system sounds will not be played. |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 99 | constexpr char kAshDisableSystemSounds[] = "ash-disable-system-sounds"; |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 100 | |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 101 | static chromeos::AccessibilityManager* g_accessibility_manager = nullptr; |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 102 | |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 103 | static BrailleController* g_braille_controller_for_test = nullptr; |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 104 | |
| 105 | BrailleController* GetBrailleController() { |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 106 | if (g_braille_controller_for_test) |
| 107 | return g_braille_controller_for_test; |
| 108 | // Don't use the real braille controller for tests to avoid automatically |
| 109 | // starting ChromeVox which confuses some tests. |
| 110 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 111 | if (command_line->HasSwitch(::switches::kTestType)) |
plundblad | cf1d08f | 2015-09-28 09:18:58 | [diff] [blame] | 112 | return StubBrailleController::GetInstance(); |
| 113 | return BrailleController::GetInstance(); |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 116 | } // namespace |
| 117 | |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 118 | class ChromeVoxPanelWidgetObserver : public views::WidgetObserver { |
| 119 | public: |
| 120 | ChromeVoxPanelWidgetObserver(views::Widget* widget, |
| 121 | AccessibilityManager* manager) |
| 122 | : widget_(widget), manager_(manager) { |
| 123 | widget_->AddObserver(this); |
| 124 | } |
| 125 | |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 126 | ~ChromeVoxPanelWidgetObserver() override = default; |
| 127 | |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 128 | void OnWidgetClosing(views::Widget* widget) override { |
| 129 | CHECK_EQ(widget_, widget); |
| 130 | widget->RemoveObserver(this); |
| 131 | manager_->OnChromeVoxPanelClosing(); |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 132 | // |this| is deleted. |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void OnWidgetDestroying(views::Widget* widget) override { |
| 136 | CHECK_EQ(widget_, widget); |
| 137 | widget->RemoveObserver(this); |
| 138 | manager_->OnChromeVoxPanelDestroying(); |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 139 | // |this| is deleted. |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | private: |
| 143 | views::Widget* widget_; |
| 144 | AccessibilityManager* manager_; |
| 145 | |
| 146 | DISALLOW_COPY_AND_ASSIGN(ChromeVoxPanelWidgetObserver); |
| 147 | }; |
| 148 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 149 | /////////////////////////////////////////////////////////////////////////////// |
| 150 | // AccessibilityStatusEventDetails |
| 151 | |
| 152 | AccessibilityStatusEventDetails::AccessibilityStatusEventDetails( |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 153 | AccessibilityNotificationType notification_type, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 154 | bool enabled) |
| 155 | : notification_type(notification_type), enabled(enabled) {} |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 156 | |
| 157 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 158 | // |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 159 | // AccessibilityManager |
| 160 | |
| 161 | // static |
| 162 | void AccessibilityManager::Initialize() { |
| 163 | CHECK(g_accessibility_manager == NULL); |
| 164 | g_accessibility_manager = new AccessibilityManager(); |
| 165 | } |
| 166 | |
| 167 | // static |
| 168 | void AccessibilityManager::Shutdown() { |
| 169 | CHECK(g_accessibility_manager); |
| 170 | delete g_accessibility_manager; |
| 171 | g_accessibility_manager = NULL; |
| 172 | } |
| 173 | |
| 174 | // static |
| 175 | AccessibilityManager* AccessibilityManager::Get() { |
| 176 | return g_accessibility_manager; |
| 177 | } |
| 178 | |
Qiang Xu | dce8aeb | 2018-01-11 04:17:28 | [diff] [blame] | 179 | // static |
| 180 | void AccessibilityManager::ShowAccessibilityHelp(Browser* browser) { |
| 181 | ShowSingletonTab(browser, GURL(chrome::kChromeAccessibilityHelpURL)); |
| 182 | } |
| 183 | |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 184 | AccessibilityManager::AccessibilityManager() |
| 185 | : profile_(NULL), |
Qiang(Joe) Xu | a0f64459 | 2017-12-01 02:16:50 | [diff] [blame] | 186 | spoken_feedback_enabled_(false), |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 187 | select_to_speak_enabled_(false), |
| 188 | switch_access_enabled_(false), |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 189 | braille_display_connected_(false), |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 190 | scoped_braille_observer_(this), |
anand.ratn | 04aae9ef | 2014-09-16 04:16:51 | [diff] [blame] | 191 | braille_ime_current_(false), |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 192 | chromevox_panel_(nullptr), |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 193 | extension_registry_observer_(this), |
anand.ratn | 04aae9ef | 2014-09-16 04:16:51 | [diff] [blame] | 194 | weak_ptr_factory_(this) { |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 195 | notification_registrar_.Add(this, |
[email protected] | 093d9ba | 2013-07-23 19:26:21 | [diff] [blame] | 196 | chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 197 | content::NotificationService::AllSources()); |
| 198 | notification_registrar_.Add(this, |
Yuki Awano | d59b649 | 2017-07-28 00:52:11 | [diff] [blame] | 199 | chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 200 | content::NotificationService::AllSources()); |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 201 | notification_registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 202 | content::NotificationService::AllSources()); |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 203 | notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 204 | content::NotificationService::AllSources()); |
David Tseng | 768d798 | 2017-12-21 00:20:11 | [diff] [blame] | 205 | notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 206 | content::NotificationService::AllSources()); |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 207 | notification_registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 208 | content::NotificationService::AllSources()); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 209 | input_method::InputMethodManager::Get()->AddObserver(this); |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 210 | session_manager::SessionManager::Get()->AddObserver(this); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 211 | |
[email protected] | 12b0a84 | 2013-12-04 20:48:13 | [diff] [blame] | 212 | ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 213 | media::SoundsManager* manager = media::SoundsManager::Get(); |
| 214 | manager->Initialize(SOUND_SHUTDOWN, |
| 215 | bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); |
| 216 | manager->Initialize( |
| 217 | SOUND_SPOKEN_FEEDBACK_ENABLED, |
| 218 | bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); |
| 219 | manager->Initialize( |
| 220 | SOUND_SPOKEN_FEEDBACK_DISABLED, |
| 221 | bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); |
[email protected] | 07f3ea9 | 2014-08-14 05:23:38 | [diff] [blame] | 222 | manager->Initialize(SOUND_PASSTHROUGH, |
| 223 | bundle.GetRawDataResource(IDR_SOUND_PASSTHROUGH_WAV)); |
| 224 | manager->Initialize(SOUND_EXIT_SCREEN, |
| 225 | bundle.GetRawDataResource(IDR_SOUND_EXIT_SCREEN_WAV)); |
| 226 | manager->Initialize(SOUND_ENTER_SCREEN, |
| 227 | bundle.GetRawDataResource(IDR_SOUND_ENTER_SCREEN_WAV)); |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 228 | manager->Initialize(SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_HIGH, |
| 229 | bundle.GetRawDataResource( |
| 230 | IDR_SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_HIGH_WAV)); |
| 231 | manager->Initialize(SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_LOW, |
| 232 | bundle.GetRawDataResource( |
| 233 | IDR_SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_LOW_WAV)); |
David Tseng | 580f050e | 2017-09-05 21:18:41 | [diff] [blame] | 234 | manager->Initialize(SOUND_TOUCH_TYPE, |
| 235 | bundle.GetRawDataResource(IDR_SOUND_TOUCH_TYPE_WAV)); |
Zach Helfinstein | b89fef4 | 2018-04-12 21:38:54 | [diff] [blame] | 236 | manager->Initialize(SOUND_DICTATION_END, |
| 237 | bundle.GetRawDataResource(IDR_SOUND_DICTATION_END_WAV)); |
| 238 | manager->Initialize(SOUND_DICTATION_START, |
| 239 | bundle.GetRawDataResource(IDR_SOUND_DICTATION_START_WAV)); |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 240 | |
| 241 | base::FilePath resources_path; |
| 242 | if (!PathService::Get(chrome::DIR_RESOURCES, &resources_path)) |
| 243 | NOTREACHED(); |
| 244 | chromevox_loader_ = base::WrapUnique(new AccessibilityExtensionLoader( |
| 245 | extension_misc::kChromeVoxExtensionId, |
| 246 | resources_path.Append(extension_misc::kChromeVoxExtensionPath), |
| 247 | base::Bind(&AccessibilityManager::PostUnloadChromeVox, |
| 248 | weak_ptr_factory_.GetWeakPtr()))); |
dmazzoni | 5288b261 | 2016-09-16 23:05:39 | [diff] [blame] | 249 | select_to_speak_loader_ = base::WrapUnique(new AccessibilityExtensionLoader( |
| 250 | extension_misc::kSelectToSpeakExtensionId, |
| 251 | resources_path.Append(extension_misc::kSelectToSpeakExtensionPath), |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 252 | base::Bind(&AccessibilityManager::PostUnloadSelectToSpeak, |
| 253 | weak_ptr_factory_.GetWeakPtr()))); |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 254 | switch_access_loader_ = base::WrapUnique(new AccessibilityExtensionLoader( |
| 255 | extension_misc::kSwitchAccessExtensionId, |
| 256 | resources_path.Append(extension_misc::kSwitchAccessExtensionPath), |
| 257 | base::Closure())); |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 258 | |
| 259 | // Connect to ash's AccessibilityController interface. |
| 260 | content::ServiceManagerConnection::GetForProcess() |
| 261 | ->GetConnector() |
| 262 | ->BindInterface(ash::mojom::kServiceName, &accessibility_controller_); |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 263 | |
| 264 | // Connect to ash's AccessibilityFocusRingController interface. |
| 265 | content::ServiceManagerConnection::GetForProcess() |
| 266 | ->GetConnector() |
| 267 | ->BindInterface(ash::mojom::kServiceName, |
| 268 | &accessibility_focus_ring_controller_); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | AccessibilityManager::~AccessibilityManager() { |
| 272 | CHECK(this == g_accessibility_manager); |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 273 | AccessibilityStatusEventDetails details(ACCESSIBILITY_MANAGER_SHUTDOWN, |
| 274 | false); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 275 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 276 | input_method::InputMethodManager::Get()->RemoveObserver(this); |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 277 | session_manager::SessionManager::Get()->RemoveObserver(this); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 278 | |
| 279 | if (chromevox_panel_) { |
James Cook | 769799b | 2018-03-12 16:59:04 | [diff] [blame] | 280 | chromevox_panel_->CloseNow(); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 281 | chromevox_panel_ = nullptr; |
| 282 | } |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 285 | bool AccessibilityManager::ShouldShowAccessibilityMenu() { |
| 286 | // If any of the loaded profiles has an accessibility feature turned on - or |
| 287 | // enforced to always show the menu - we return true to show the menu. |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 288 | // NOTE: This includes the login screen profile, so if a feature is turned on |
| 289 | // at the login screen the menu will show even if the user has no features |
| 290 | // enabled inside the session. http://crbug.com/755631 |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 291 | std::vector<Profile*> profiles = |
| 292 | g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 293 | for (std::vector<Profile*>::iterator it = profiles.begin(); |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 294 | it != profiles.end(); ++it) { |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 295 | PrefService* prefs = (*it)->GetPrefs(); |
| 296 | if (prefs->GetBoolean(ash::prefs::kAccessibilityStickyKeysEnabled) || |
| 297 | prefs->GetBoolean(ash::prefs::kAccessibilityLargeCursorEnabled) || |
| 298 | prefs->GetBoolean(ash::prefs::kAccessibilitySpokenFeedbackEnabled) || |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 299 | prefs->GetBoolean(ash::prefs::kAccessibilitySelectToSpeakEnabled) || |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 300 | prefs->GetBoolean(ash::prefs::kAccessibilityHighContrastEnabled) || |
| 301 | prefs->GetBoolean(ash::prefs::kAccessibilityAutoclickEnabled) || |
| 302 | prefs->GetBoolean(ash::prefs::kShouldAlwaysShowAccessibilityMenu) || |
| 303 | prefs->GetBoolean(ash::prefs::kAccessibilityScreenMagnifierEnabled) || |
| 304 | prefs->GetBoolean(ash::prefs::kAccessibilityVirtualKeyboardEnabled) || |
| 305 | prefs->GetBoolean(ash::prefs::kAccessibilityMonoAudioEnabled) || |
| 306 | prefs->GetBoolean(ash::prefs::kAccessibilityCaretHighlightEnabled) || |
| 307 | prefs->GetBoolean(ash::prefs::kAccessibilityCursorHighlightEnabled) || |
Ahmed Fakhry | 07892721 | 2018-04-06 20:59:09 | [diff] [blame] | 308 | prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled) || |
| 309 | prefs->GetBoolean(ash::prefs::kDockedMagnifierEnabled)) { |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 310 | return true; |
Ahmed Fakhry | 07892721 | 2018-04-06 20:59:09 | [diff] [blame] | 311 | } |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 312 | } |
| 313 | return false; |
| 314 | } |
| 315 | |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 316 | void AccessibilityManager::UpdateAlwaysShowMenuFromPref() { |
| 317 | if (!profile_) |
| 318 | return; |
| 319 | |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 320 | // TODO(crbug.com/594887): Fix for mash by moving pref into ash. |
| 321 | if (GetAshConfig() == ash::Config::MASH) |
| 322 | return; |
| 323 | |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 324 | // Update system tray menu visibility. |
James Cook | 08e91dc | 2018-03-08 18:53:19 | [diff] [blame] | 325 | ash::Shell::Get() |
| 326 | ->accessibility_controller() |
Qiang Xu | 9c3bc70 | 2018-03-26 23:12:28 | [diff] [blame] | 327 | ->NotifyAccessibilityStatusChanged(); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 330 | void AccessibilityManager::EnableLargeCursor(bool enabled) { |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 331 | if (!profile_) |
| 332 | return; |
| 333 | |
| 334 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 335 | pref_service->SetBoolean(ash::prefs::kAccessibilityLargeCursorEnabled, |
| 336 | enabled); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 337 | pref_service->CommitPendingWrite(); |
| 338 | } |
| 339 | |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 340 | void AccessibilityManager::OnLargeCursorChanged() { |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 341 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_LARGE_CURSOR, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 342 | IsLargeCursorEnabled()); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 343 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 344 | } |
| 345 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 346 | bool AccessibilityManager::IsLargeCursorEnabled() const { |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 347 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 348 | ash::prefs::kAccessibilityLargeCursorEnabled); |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 349 | } |
| 350 | |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 351 | void AccessibilityManager::EnableStickyKeys(bool enabled) { |
| 352 | if (!profile_) |
| 353 | return; |
| 354 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 355 | pref_service->SetBoolean(ash::prefs::kAccessibilityStickyKeysEnabled, |
| 356 | enabled); |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 357 | pref_service->CommitPendingWrite(); |
| 358 | } |
| 359 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 360 | bool AccessibilityManager::IsStickyKeysEnabled() const { |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 361 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 362 | ash::prefs::kAccessibilityStickyKeysEnabled); |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 363 | } |
| 364 | |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 365 | void AccessibilityManager::OnStickyKeysChanged() { |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 366 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_STICKY_KEYS, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 367 | IsStickyKeysEnabled()); |
minch | d9d54248 | 2017-04-07 19:29:56 | [diff] [blame] | 368 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 369 | } |
| 370 | |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 371 | void AccessibilityManager::EnableSpokenFeedback(bool enabled) { |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 372 | if (!profile_) |
| 373 | return; |
[email protected] | 5d2ea36 | 2013-12-13 08:10:18 | [diff] [blame] | 374 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 375 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 376 | pref_service->SetBoolean(ash::prefs::kAccessibilitySpokenFeedbackEnabled, |
| 377 | enabled); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 378 | pref_service->CommitPendingWrite(); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 379 | } |
| 380 | |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 381 | void AccessibilityManager::OnSpokenFeedbackChanged() { |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 382 | if (!profile_) |
| 383 | return; |
| 384 | |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 385 | const bool enabled = profile_->GetPrefs()->GetBoolean( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 386 | ash::prefs::kAccessibilitySpokenFeedbackEnabled); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 387 | |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 388 | if (enabled) { |
| 389 | chromevox_loader_->SetProfile( |
| 390 | profile_, base::Bind(&AccessibilityManager::PostSwitchChromeVoxProfile, |
| 391 | weak_ptr_factory_.GetWeakPtr())); |
| 392 | } |
dmazzoni | 2c01320 | 2016-09-07 19:59:37 | [diff] [blame] | 393 | |
Qiang(Joe) Xu | a0f64459 | 2017-12-01 02:16:50 | [diff] [blame] | 394 | if (spoken_feedback_enabled_ == enabled) |
| 395 | return; |
| 396 | |
| 397 | spoken_feedback_enabled_ = enabled; |
| 398 | |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 399 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 400 | enabled); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 401 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 402 | |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 403 | if (enabled) { |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 404 | chromevox_loader_->Load(profile_, |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 405 | base::Bind(&AccessibilityManager::PostLoadChromeVox, |
| 406 | weak_ptr_factory_.GetWeakPtr())); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 407 | } else { |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 408 | chromevox_loader_->Unload(); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 409 | } |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 410 | UpdateBrailleImeState(); |
[email protected] | b0a2ce3 | 2013-07-23 15:24:53 | [diff] [blame] | 411 | } |
| 412 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 413 | bool AccessibilityManager::IsSpokenFeedbackEnabled() const { |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 414 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 415 | ash::prefs::kAccessibilitySpokenFeedbackEnabled); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 418 | void AccessibilityManager::EnableHighContrast(bool enabled) { |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 419 | if (!profile_) |
| 420 | return; |
| 421 | |
| 422 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 423 | pref_service->SetBoolean(ash::prefs::kAccessibilityHighContrastEnabled, |
| 424 | enabled); |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 425 | pref_service->CommitPendingWrite(); |
| 426 | } |
| 427 | |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 428 | bool AccessibilityManager::IsHighContrastEnabled() const { |
| 429 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 430 | ash::prefs::kAccessibilityHighContrastEnabled); |
| 431 | } |
[email protected] | d80f1930 | 2013-06-07 13:12:14 | [diff] [blame] | 432 | |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 433 | void AccessibilityManager::OnHighContrastChanged() { |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 434 | AccessibilityStatusEventDetails details( |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 435 | ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE, IsHighContrastEnabled()); |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 436 | NotifyAccessibilityStatusChanged(details); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 437 | } |
| 438 | |
[email protected] | 628b890 | 2014-03-12 05:26:41 | [diff] [blame] | 439 | void AccessibilityManager::OnLocaleChanged() { |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 440 | if (!profile_) |
| 441 | return; |
| 442 | |
| 443 | if (!IsSpokenFeedbackEnabled()) |
| 444 | return; |
| 445 | |
| 446 | // If the system locale changes and spoken feedback is enabled, |
| 447 | // reload ChromeVox so that it switches its internal translations |
| 448 | // to the new language. |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 449 | EnableSpokenFeedback(false); |
| 450 | EnableSpokenFeedback(true); |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 451 | } |
| 452 | |
yawano | ca05a1af | 2017-01-25 02:38:17 | [diff] [blame] | 453 | void AccessibilityManager::OnViewFocusedInArc( |
| 454 | const gfx::Rect& bounds_in_screen) { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 455 | accessibility_controller_->SetFocusHighlightRect(bounds_in_screen); |
yawano | ca05a1af | 2017-01-25 02:38:17 | [diff] [blame] | 456 | } |
| 457 | |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 458 | bool AccessibilityManager::PlayEarcon(int sound_key, PlaySoundOption option) { |
[email protected] | 07f3ea9 | 2014-08-14 05:23:38 | [diff] [blame] | 459 | DCHECK(sound_key < chromeos::SOUND_COUNT); |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 460 | base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 461 | if (cl->HasSwitch(kAshDisableSystemSounds)) |
| 462 | return false; |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 463 | if (option == PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED && |
David Tseng | 89850d1 | 2017-08-29 02:23:41 | [diff] [blame] | 464 | !IsSpokenFeedbackEnabled()) { |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 465 | return false; |
| 466 | } |
| 467 | return media::SoundsManager::Get()->Play(sound_key); |
[email protected] | 07f3ea9 | 2014-08-14 05:23:38 | [diff] [blame] | 468 | } |
| 469 | |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 470 | void AccessibilityManager::OnTwoFingerTouchStart() { |
dmazzoni | c613a56 | 2017-05-02 03:19:19 | [diff] [blame] | 471 | if (!profile()) |
| 472 | return; |
| 473 | |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 474 | extensions::EventRouter* event_router = |
| 475 | extensions::EventRouter::Get(profile()); |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 476 | |
Jinho Bang | 341ce5b0 | 2018-01-17 22:46:03 | [diff] [blame] | 477 | auto event_args = std::make_unique<base::ListValue>(); |
| 478 | auto event = std::make_unique<extensions::Event>( |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 479 | extensions::events::ACCESSIBILITY_PRIVATE_ON_TWO_FINGER_TOUCH_START, |
| 480 | extensions::api::accessibility_private::OnTwoFingerTouchStart::kEventName, |
| 481 | std::move(event_args)); |
| 482 | event_router->BroadcastEvent(std::move(event)); |
| 483 | } |
| 484 | |
| 485 | void AccessibilityManager::OnTwoFingerTouchStop() { |
dmazzoni | c613a56 | 2017-05-02 03:19:19 | [diff] [blame] | 486 | if (!profile()) |
| 487 | return; |
| 488 | |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 489 | extensions::EventRouter* event_router = |
| 490 | extensions::EventRouter::Get(profile()); |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 491 | |
Jinho Bang | 341ce5b0 | 2018-01-17 22:46:03 | [diff] [blame] | 492 | auto event_args = std::make_unique<base::ListValue>(); |
| 493 | auto event = std::make_unique<extensions::Event>( |
dmazzoni | df9a1e92 | 2017-04-13 05:10:44 | [diff] [blame] | 494 | extensions::events::ACCESSIBILITY_PRIVATE_ON_TWO_FINGER_TOUCH_STOP, |
| 495 | extensions::api::accessibility_private::OnTwoFingerTouchStop::kEventName, |
| 496 | std::move(event_args)); |
| 497 | event_router->BroadcastEvent(std::move(event)); |
| 498 | } |
| 499 | |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 500 | bool AccessibilityManager::ShouldToggleSpokenFeedbackViaTouch() { |
dmazzoni | 200099c | 2017-01-31 23:21:40 | [diff] [blame] | 501 | #if 1 |
| 502 | // Temporarily disabling this feature until UI feedback is fixed. |
| 503 | // http://crbug.com/662501 |
| 504 | return false; |
| 505 | #else |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 506 | policy::BrowserPolicyConnectorChromeOS* connector = |
| 507 | g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 508 | if (!connector) |
| 509 | return false; |
| 510 | |
| 511 | if (!connector->IsEnterpriseManaged()) |
| 512 | return false; |
| 513 | |
| 514 | const policy::DeviceCloudPolicyManagerChromeOS* const |
| 515 | device_cloud_policy_manager = connector->GetDeviceCloudPolicyManager(); |
| 516 | if (!device_cloud_policy_manager) |
| 517 | return false; |
| 518 | |
| 519 | if (!device_cloud_policy_manager->IsRemoraRequisition()) |
| 520 | return false; |
| 521 | |
| 522 | KioskAppManager* manager = KioskAppManager::Get(); |
| 523 | KioskAppManager::App app; |
| 524 | CHECK(manager->GetApp(manager->GetAutoLaunchApp(), &app)); |
| 525 | return app.was_auto_launched_with_zero_delay; |
dmazzoni | 200099c | 2017-01-31 23:21:40 | [diff] [blame] | 526 | #endif |
dmazzoni | 16d2dec | 2016-12-19 23:27:57 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | bool AccessibilityManager::PlaySpokenFeedbackToggleCountdown(int tick_count) { |
| 530 | return media::SoundsManager::Get()->Play( |
| 531 | tick_count % 2 ? SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_HIGH |
| 532 | : SOUND_SPOKEN_FEEDBACK_TOGGLE_COUNTDOWN_LOW); |
| 533 | } |
| 534 | |
Qiang Xu | 9e12fa76 | 2017-12-19 03:27:49 | [diff] [blame] | 535 | void AccessibilityManager::HandleAccessibilityGesture( |
Qiang Xu | c4b0575 | 2018-02-13 20:10:28 | [diff] [blame] | 536 | ax::mojom::Gesture gesture) { |
dmazzoni | 82ef29a | 2016-05-10 23:37:51 | [diff] [blame] | 537 | extensions::EventRouter* event_router = |
| 538 | extensions::EventRouter::Get(profile()); |
dmazzoni | 82ef29a | 2016-05-10 23:37:51 | [diff] [blame] | 539 | |
Katie D | 30e0841 | 2018-05-02 17:24:22 | [diff] [blame] | 540 | std::unique_ptr<base::ListValue> event_args = |
| 541 | std::make_unique<base::ListValue>(); |
Qiang Xu | c4b0575 | 2018-02-13 20:10:28 | [diff] [blame] | 542 | event_args->AppendString(ui::ToString(gesture)); |
dmazzoni | 82ef29a | 2016-05-10 23:37:51 | [diff] [blame] | 543 | std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 544 | extensions::events::ACCESSIBILITY_PRIVATE_ON_ACCESSIBILITY_GESTURE, |
| 545 | extensions::api::accessibility_private::OnAccessibilityGesture:: |
| 546 | kEventName, |
| 547 | std::move(event_args))); |
| 548 | event_router->DispatchEventWithLazyListener( |
| 549 | extension_misc::kChromeVoxExtensionId, std::move(event)); |
| 550 | } |
| 551 | |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 552 | void AccessibilityManager::SetTouchAccessibilityAnchorPoint( |
| 553 | const gfx::Point& anchor_point) { |
dmazzoni | 50f6580 | 2017-06-28 18:19:39 | [diff] [blame] | 554 | for (auto* rwc : ash::RootWindowController::root_window_controllers()) |
| 555 | rwc->SetTouchAccessibilityAnchorPoint(anchor_point); |
dmazzoni | ff86e347 | 2016-06-03 19:52:32 | [diff] [blame] | 556 | } |
| 557 | |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 558 | void AccessibilityManager::EnableAutoclick(bool enabled) { |
| 559 | if (!profile_) |
| 560 | return; |
| 561 | |
| 562 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 563 | pref_service->SetBoolean(ash::prefs::kAccessibilityAutoclickEnabled, enabled); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 564 | pref_service->CommitPendingWrite(); |
| 565 | } |
| 566 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 567 | bool AccessibilityManager::IsAutoclickEnabled() const { |
Qiang Xu | d0f3be2e | 2018-01-08 12:48:18 | [diff] [blame] | 568 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 569 | ash::prefs::kAccessibilityAutoclickEnabled); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 572 | void AccessibilityManager::EnableVirtualKeyboard(bool enabled) { |
| 573 | if (!profile_) |
| 574 | return; |
| 575 | |
| 576 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 577 | pref_service->SetBoolean(ash::prefs::kAccessibilityVirtualKeyboardEnabled, |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 578 | enabled); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 579 | pref_service->CommitPendingWrite(); |
| 580 | } |
| 581 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 582 | bool AccessibilityManager::IsVirtualKeyboardEnabled() const { |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 583 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 584 | ash::prefs::kAccessibilityVirtualKeyboardEnabled); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 585 | } |
| 586 | |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 587 | void AccessibilityManager::OnVirtualKeyboardChanged() { |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 588 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 589 | IsVirtualKeyboardEnabled()); |
rsadam | a1104b8 | 2014-11-03 20:50:52 | [diff] [blame] | 590 | NotifyAccessibilityStatusChanged(details); |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 591 | } |
| 592 | |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 593 | void AccessibilityManager::EnableMonoAudio(bool enabled) { |
| 594 | if (!profile_) |
| 595 | return; |
| 596 | |
| 597 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 598 | pref_service->SetBoolean(ash::prefs::kAccessibilityMonoAudioEnabled, enabled); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 599 | pref_service->CommitPendingWrite(); |
| 600 | } |
| 601 | |
minch | 0bfec0b | 2017-04-10 17:50:09 | [diff] [blame] | 602 | bool AccessibilityManager::IsMonoAudioEnabled() const { |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 603 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 604 | ash::prefs::kAccessibilityMonoAudioEnabled); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 605 | } |
| 606 | |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 607 | void AccessibilityManager::OnMonoAudioChanged() { |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 608 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_MONO_AUDIO, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 609 | IsMonoAudioEnabled()); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 610 | NotifyAccessibilityStatusChanged(details); |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 611 | } |
| 612 | |
Daniel Erat | 477c56d | 2017-12-13 21:42:54 | [diff] [blame] | 613 | void AccessibilityManager::SetDarkenScreen(bool darken) { |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 614 | accessibility_controller_->SetDarkenScreen(darken); |
Daniel Erat | 477c56d | 2017-12-13 21:42:54 | [diff] [blame] | 615 | } |
| 616 | |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 617 | void AccessibilityManager::SetCaretHighlightEnabled(bool enabled) { |
| 618 | if (!profile_) |
| 619 | return; |
| 620 | |
| 621 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 622 | pref_service->SetBoolean(ash::prefs::kAccessibilityCaretHighlightEnabled, |
| 623 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 624 | pref_service->CommitPendingWrite(); |
| 625 | } |
| 626 | |
| 627 | bool AccessibilityManager::IsCaretHighlightEnabled() const { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 628 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 629 | ash::prefs::kAccessibilityCaretHighlightEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 630 | } |
| 631 | |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 632 | void AccessibilityManager::OnCaretHighlightChanged() { |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 633 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_CARET_HIGHLIGHT, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 634 | IsCaretHighlightEnabled()); |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 635 | NotifyAccessibilityStatusChanged(details); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | void AccessibilityManager::SetCursorHighlightEnabled(bool enabled) { |
| 639 | if (!profile_) |
| 640 | return; |
| 641 | |
| 642 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 643 | pref_service->SetBoolean(ash::prefs::kAccessibilityCursorHighlightEnabled, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 644 | enabled); |
| 645 | pref_service->CommitPendingWrite(); |
| 646 | } |
| 647 | |
| 648 | bool AccessibilityManager::IsCursorHighlightEnabled() const { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 649 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 650 | ash::prefs::kAccessibilityCursorHighlightEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 651 | } |
| 652 | |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 653 | void AccessibilityManager::OnCursorHighlightChanged() { |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 654 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_CURSOR_HIGHLIGHT, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 655 | IsCursorHighlightEnabled()); |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 656 | NotifyAccessibilityStatusChanged(details); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | void AccessibilityManager::SetFocusHighlightEnabled(bool enabled) { |
| 660 | if (!profile_) |
| 661 | return; |
| 662 | |
| 663 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 664 | pref_service->SetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled, |
| 665 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 666 | pref_service->CommitPendingWrite(); |
| 667 | } |
| 668 | |
| 669 | bool AccessibilityManager::IsFocusHighlightEnabled() const { |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 670 | return profile_ && profile_->GetPrefs()->GetBoolean( |
| 671 | ash::prefs::kAccessibilityFocusHighlightEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 672 | } |
| 673 | |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 674 | void AccessibilityManager::OnFocusHighlightChanged() { |
| 675 | bool enabled = IsFocusHighlightEnabled(); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 676 | |
dmazzoni | 42e4b00 | 2016-06-08 20:58:42 | [diff] [blame] | 677 | // Focus highlighting can't be on when spoken feedback is on, because |
| 678 | // ChromeVox does its own focus highlighting. |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 679 | if (IsSpokenFeedbackEnabled()) |
dmazzoni | 42e4b00 | 2016-06-08 20:58:42 | [diff] [blame] | 680 | enabled = false; |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 681 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_FOCUS_HIGHLIGHT, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 682 | enabled); |
minch | a0b24ab | 2017-03-31 22:16:01 | [diff] [blame] | 683 | NotifyAccessibilityStatusChanged(details); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 684 | } |
| 685 | |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 686 | void AccessibilityManager::SetSelectToSpeakEnabled(bool enabled) { |
| 687 | if (!profile_) |
| 688 | return; |
| 689 | |
| 690 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 691 | pref_service->SetBoolean(ash::prefs::kAccessibilitySelectToSpeakEnabled, |
| 692 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 693 | pref_service->CommitPendingWrite(); |
| 694 | } |
| 695 | |
| 696 | bool AccessibilityManager::IsSelectToSpeakEnabled() const { |
| 697 | return select_to_speak_enabled_; |
| 698 | } |
| 699 | |
Katie D | 30e0841 | 2018-05-02 17:24:22 | [diff] [blame] | 700 | void AccessibilityManager::RequestSelectToSpeakStateChange() { |
| 701 | extensions::EventRouter* event_router = |
| 702 | extensions::EventRouter::Get(profile_); |
| 703 | |
| 704 | // Send an event to the Select-to-Speak extension requesting a state change. |
| 705 | std::unique_ptr<base::ListValue> event_args = |
| 706 | std::make_unique<base::ListValue>(); |
| 707 | std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 708 | extensions::events:: |
| 709 | ACCESSIBILITY_PRIVATE_ON_SELECT_TO_SPEAK_STATE_CHANGE_REQUESTED, |
| 710 | extensions::api::accessibility_private:: |
| 711 | OnSelectToSpeakStateChangeRequested::kEventName, |
| 712 | std::move(event_args))); |
| 713 | event_router->DispatchEventWithLazyListener( |
| 714 | extension_misc::kSelectToSpeakExtensionId, std::move(event)); |
| 715 | } |
| 716 | |
| 717 | void AccessibilityManager::OnSelectToSpeakStateChanged( |
| 718 | ash::mojom::SelectToSpeakState state) { |
Katie D | ae8cce5 | 2018-05-02 21:16:28 | [diff] [blame^] | 719 | // Forward the state change event to select_to_speak_event_handler_. |
| 720 | // The extension may have requested that the handler enter SELECTING state. |
| 721 | // Prepare to start capturing events from stylus, mouse or touch. |
| 722 | if (select_to_speak_event_handler_) { |
| 723 | select_to_speak_event_handler_->SetSelectToSpeakStateSelecting( |
| 724 | state == ash::mojom::SelectToSpeakState::kSelectToSpeakStateSelecting); |
| 725 | } |
Katie D | 30e0841 | 2018-05-02 17:24:22 | [diff] [blame] | 726 | |
| 727 | accessibility_controller_->SetSelectToSpeakState(state); |
| 728 | } |
| 729 | |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 730 | void AccessibilityManager::OnSelectToSpeakChanged() { |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 731 | if (!profile_) |
| 732 | return; |
| 733 | |
| 734 | const bool enabled = profile_->GetPrefs()->GetBoolean( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 735 | ash::prefs::kAccessibilitySelectToSpeakEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 736 | |
| 737 | if (select_to_speak_enabled_ == enabled) |
| 738 | return; |
| 739 | select_to_speak_enabled_ = enabled; |
| 740 | |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 741 | AccessibilityStatusEventDetails details(ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK, |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 742 | enabled); |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 743 | NotifyAccessibilityStatusChanged(details); |
| 744 | |
Katie D | 4ea6944 | 2018-04-02 23:17:30 | [diff] [blame] | 745 | if (enabled) { |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 746 | select_to_speak_loader_->Load(profile_, base::Closure() /* done_cb */); |
Katie D | 4ea6944 | 2018-04-02 23:17:30 | [diff] [blame] | 747 | select_to_speak_event_handler_.reset( |
| 748 | new chromeos::SelectToSpeakEventHandler()); |
| 749 | } else { |
dmazzoni | 5288b261 | 2016-09-16 23:05:39 | [diff] [blame] | 750 | select_to_speak_loader_->Unload(); |
Katie D | 4ea6944 | 2018-04-02 23:17:30 | [diff] [blame] | 751 | select_to_speak_event_handler_.reset(nullptr); |
| 752 | } |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | void AccessibilityManager::SetSwitchAccessEnabled(bool enabled) { |
| 756 | if (!profile_) |
| 757 | return; |
| 758 | |
| 759 | PrefService* pref_service = profile_->GetPrefs(); |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 760 | pref_service->SetBoolean(ash::prefs::kAccessibilitySwitchAccessEnabled, |
| 761 | enabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 762 | pref_service->CommitPendingWrite(); |
| 763 | } |
| 764 | |
| 765 | bool AccessibilityManager::IsSwitchAccessEnabled() const { |
| 766 | return switch_access_enabled_; |
| 767 | } |
| 768 | |
| 769 | void AccessibilityManager::UpdateSwitchAccessFromPref() { |
| 770 | if (!profile_) |
| 771 | return; |
| 772 | |
| 773 | const bool enabled = profile_->GetPrefs()->GetBoolean( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 774 | ash::prefs::kAccessibilitySwitchAccessEnabled); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 775 | |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 776 | // The Switch Access setting is behind a flag. Don't enable the feature |
| 777 | // even if the preference is enabled, if the flag isn't also set. |
| 778 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 779 | if (!command_line->HasSwitch( |
| 780 | chromeos::switches::kEnableExperimentalAccessibilityFeatures)) { |
| 781 | if (enabled) { |
| 782 | LOG(WARNING) << "Switch access enabled but experimental accessibility " |
| 783 | << "features flag is not set."; |
| 784 | } |
| 785 | return; |
| 786 | } |
| 787 | |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 788 | if (switch_access_enabled_ == enabled) |
| 789 | return; |
| 790 | switch_access_enabled_ = enabled; |
| 791 | |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 792 | if (enabled) { |
| 793 | switch_access_loader_->Load(profile_, base::Closure() /* done_cb */); |
elichtenberg | c4b4bf46 | 2017-02-28 20:48:10 | [diff] [blame] | 794 | switch_access_event_handler_.reset( |
| 795 | new chromeos::SwitchAccessEventHandler()); |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 796 | } else { |
| 797 | switch_access_loader_->Unload(); |
elichtenberg | c4b4bf46 | 2017-02-28 20:48:10 | [diff] [blame] | 798 | switch_access_event_handler_.reset(nullptr); |
elichtenberg | 0746c1bd | 2017-02-22 07:59:15 | [diff] [blame] | 799 | } |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 800 | } |
| 801 | |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 802 | bool AccessibilityManager::IsBrailleDisplayConnected() const { |
| 803 | return braille_display_connected_; |
| 804 | } |
| 805 | |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 806 | void AccessibilityManager::CheckBrailleState() { |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 807 | BrailleController* braille_controller = GetBrailleController(); |
| 808 | if (!scoped_braille_observer_.IsObserving(braille_controller)) |
| 809 | scoped_braille_observer_.Add(braille_controller); |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 810 | BrowserThread::PostTaskAndReplyWithResult( |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 811 | BrowserThread::IO, FROM_HERE, |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 812 | base::Bind(&BrailleController::GetDisplayState, |
| 813 | base::Unretained(braille_controller)), |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 814 | base::Bind(&AccessibilityManager::ReceiveBrailleDisplayState, |
| 815 | weak_ptr_factory_.GetWeakPtr())); |
| 816 | } |
| 817 | |
| 818 | void AccessibilityManager::ReceiveBrailleDisplayState( |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 819 | std::unique_ptr<extensions::api::braille_display_private::DisplayState> |
| 820 | state) { |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 821 | OnBrailleDisplayStateChanged(*state); |
| 822 | } |
| 823 | |
| 824 | void AccessibilityManager::UpdateBrailleImeState() { |
| 825 | if (!profile_) |
| 826 | return; |
| 827 | PrefService* pref_service = profile_->GetPrefs(); |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 828 | std::string preload_engines_str = |
| 829 | pref_service->GetString(prefs::kLanguagePreloadEngines); |
| 830 | std::vector<base::StringPiece> preload_engines = base::SplitStringPiece( |
| 831 | preload_engines_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 832 | std::vector<base::StringPiece>::iterator it = |
| 833 | std::find(preload_engines.begin(), preload_engines.end(), |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 834 | extension_ime_util::kBrailleImeEngineId); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 835 | bool is_enabled = (it != preload_engines.end()); |
| 836 | bool should_be_enabled = |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 837 | (IsSpokenFeedbackEnabled() && braille_display_connected_); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 838 | if (is_enabled == should_be_enabled) |
| 839 | return; |
| 840 | if (should_be_enabled) |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 841 | preload_engines.push_back(extension_ime_util::kBrailleImeEngineId); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 842 | else |
| 843 | preload_engines.erase(it); |
| 844 | pref_service->SetString(prefs::kLanguagePreloadEngines, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 845 | base::JoinString(preload_engines, ",")); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 846 | braille_ime_current_ = false; |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 847 | } |
| 848 | |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 849 | // Overridden from InputMethodManager::Observer. |
| 850 | void AccessibilityManager::InputMethodChanged( |
| 851 | input_method::InputMethodManager* manager, |
alemate | f0673029 | 2015-05-12 21:36:07 | [diff] [blame] | 852 | Profile* /* profile */, |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 853 | bool show_message) { |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 854 | // Sticky keys is implemented only in ash. |
dpolukhin | 04e5b809 | 2014-09-11 02:55:05 | [diff] [blame] | 855 | // TODO(dpolukhin): support Athena, crbug.com/408733. |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 856 | if (GetAshConfig() != ash::Config::MASH) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 857 | ash::Shell::Get()->sticky_keys_controller()->SetModifiersEnabled( |
riajiang | 4b626b97 | 2016-09-13 16:12:49 | [diff] [blame] | 858 | manager->IsISOLevel5ShiftUsedByCurrentInputMethod(), |
| 859 | manager->IsAltGrUsedByCurrentInputMethod()); |
| 860 | } |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 861 | const chromeos::input_method::InputMethodDescriptor descriptor = |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 862 | manager->GetActiveIMEState()->GetCurrentInputMethod(); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 863 | braille_ime_current_ = |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 864 | (descriptor.id() == extension_ime_util::kBrailleImeEngineId); |
[email protected] | 1488a035f | 2014-03-28 21:12:07 | [diff] [blame] | 865 | } |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 866 | |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 867 | void AccessibilityManager::OnSessionStateChanged() { |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 868 | // Don't reload ChromeVox during shutdown. http://crrev.com/c/838180 |
| 869 | if (app_terminating_) |
| 870 | return; |
| 871 | |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 872 | if (!chromevox_panel_) |
| 873 | return; |
| 874 | if (chromevox_panel_->for_blocked_user_session() == |
| 875 | session_manager::SessionManager::Get()->IsUserSessionBlocked()) { |
| 876 | return; |
| 877 | } |
| 878 | |
| 879 | // If user session got blocked or unblocked, reload ChromeVox panel, as |
| 880 | // functionality available to the panel differs based on whether the user |
| 881 | // session is active (and unlocked) or not. |
| 882 | ReloadChromeVoxPanel(); |
| 883 | } |
| 884 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 885 | void AccessibilityManager::SetProfile(Profile* profile) { |
Yuki Awano | d59b649 | 2017-07-28 00:52:11 | [diff] [blame] | 886 | // Do nothing if this is called for the current profile. This can happen. For |
| 887 | // example, ChromeSessionManager fires both |
| 888 | // NOTIFICATION_LOGIN_USER_PROFILE_PREPARED and NOTIFICATION_SESSION_STARTED, |
| 889 | // and we are observing both events. |
| 890 | if (profile_ == profile) |
| 891 | return; |
| 892 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 893 | pref_change_registrar_.reset(); |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 894 | local_state_pref_change_registrar_.reset(); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 895 | |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 896 | // Clear all dictation state on profile change. |
| 897 | dictation_.reset(); |
| 898 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 899 | if (profile) { |
[email protected] | 0aae2fe | 2013-07-05 07:04:42 | [diff] [blame] | 900 | // TODO(yoshiki): Move following code to PrefHandler. |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 901 | pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 902 | pref_change_registrar_->Init(profile->GetPrefs()); |
| 903 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 904 | ash::prefs::kShouldAlwaysShowAccessibilityMenu, |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 905 | base::Bind(&AccessibilityManager::UpdateAlwaysShowMenuFromPref, |
| 906 | base::Unretained(this))); |
| 907 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 908 | ash::prefs::kAccessibilityLargeCursorEnabled, |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 909 | base::Bind(&AccessibilityManager::OnLargeCursorChanged, |
[email protected] | 8126b81 | 2013-06-06 03:49:17 | [diff] [blame] | 910 | base::Unretained(this))); |
| 911 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 912 | ash::prefs::kAccessibilityLargeCursorDipSize, |
James Cook | 9f9ff79d3 | 2017-09-01 00:39:29 | [diff] [blame] | 913 | base::Bind(&AccessibilityManager::OnLargeCursorChanged, |
yawano | dc5533b3 | 2017-02-23 11:04:38 | [diff] [blame] | 914 | base::Unretained(this))); |
| 915 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 916 | ash::prefs::kAccessibilityStickyKeysEnabled, |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 917 | base::Bind(&AccessibilityManager::OnStickyKeysChanged, |
[email protected] | 93a534e | 2013-06-20 16:41:44 | [diff] [blame] | 918 | base::Unretained(this))); |
| 919 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 920 | ash::prefs::kAccessibilitySpokenFeedbackEnabled, |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 921 | base::Bind(&AccessibilityManager::OnSpokenFeedbackChanged, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 922 | base::Unretained(this))); |
| 923 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 924 | ash::prefs::kAccessibilityHighContrastEnabled, |
James Cook | 5fbdccb | 2017-09-01 21:17:55 | [diff] [blame] | 925 | base::Bind(&AccessibilityManager::OnHighContrastChanged, |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 926 | base::Unretained(this))); |
[email protected] | 1c88156 | 2013-10-12 07:52:58 | [diff] [blame] | 927 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 928 | ash::prefs::kAccessibilityVirtualKeyboardEnabled, |
Qiang Xu | 67fbc7a | 2018-02-16 02:52:41 | [diff] [blame] | 929 | base::Bind(&AccessibilityManager::OnVirtualKeyboardChanged, |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 930 | base::Unretained(this))); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 931 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 932 | ash::prefs::kAccessibilityMonoAudioEnabled, |
Qiang Xu | 1ee9802 | 2017-11-21 19:52:55 | [diff] [blame] | 933 | base::Bind(&AccessibilityManager::OnMonoAudioChanged, |
warx | 533c8f6 | 2016-04-12 01:19:43 | [diff] [blame] | 934 | base::Unretained(this))); |
| 935 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 936 | ash::prefs::kAccessibilityCaretHighlightEnabled, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 937 | base::Bind(&AccessibilityManager::OnCaretHighlightChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 938 | base::Unretained(this))); |
| 939 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 940 | ash::prefs::kAccessibilityCursorHighlightEnabled, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 941 | base::Bind(&AccessibilityManager::OnCursorHighlightChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 942 | base::Unretained(this))); |
| 943 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 944 | ash::prefs::kAccessibilityFocusHighlightEnabled, |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 945 | base::Bind(&AccessibilityManager::OnFocusHighlightChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 946 | base::Unretained(this))); |
| 947 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 948 | ash::prefs::kAccessibilitySelectToSpeakEnabled, |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 949 | base::Bind(&AccessibilityManager::OnSelectToSpeakChanged, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 950 | base::Unretained(this))); |
| 951 | pref_change_registrar_->Add( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 952 | ash::prefs::kAccessibilitySwitchAccessEnabled, |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 953 | base::Bind(&AccessibilityManager::UpdateSwitchAccessFromPref, |
| 954 | base::Unretained(this))); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 955 | |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 956 | local_state_pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 957 | local_state_pref_change_registrar_->Init(g_browser_process->local_state()); |
| 958 | local_state_pref_change_registrar_->Add( |
| 959 | prefs::kApplicationLocale, |
[email protected] | 628b890 | 2014-03-12 05:26:41 | [diff] [blame] | 960 | base::Bind(&AccessibilityManager::OnLocaleChanged, |
[email protected] | d1d5f4f | 2013-06-14 07:17:09 | [diff] [blame] | 961 | base::Unretained(this))); |
| 962 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 963 | content::BrowserAccessibilityState::GetInstance()->AddHistogramCallback( |
James Cook | 12ccadd | 2017-10-09 03:53:34 | [diff] [blame] | 964 | base::Bind(&AccessibilityManager::UpdateChromeOSAccessibilityHistograms, |
| 965 | base::Unretained(this))); |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 966 | |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 967 | extensions::ExtensionRegistry* registry = |
| 968 | extensions::ExtensionRegistry::Get(profile); |
| 969 | if (!extension_registry_observer_.IsObserving(registry)) |
| 970 | extension_registry_observer_.Add(registry); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 971 | } |
| 972 | |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 973 | bool had_profile = (profile_ != NULL); |
| 974 | profile_ = profile; |
| 975 | |
| 976 | if (!had_profile && profile) |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 977 | CheckBrailleState(); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 978 | else |
| 979 | UpdateBrailleImeState(); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 980 | UpdateAlwaysShowMenuFromPref(); |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 981 | UpdateSwitchAccessFromPref(); |
dmazzoni | 39d6d4b | 2016-03-29 22:18:00 | [diff] [blame] | 982 | |
Qiang Xu | 8889e37 | 2018-01-12 02:04:42 | [diff] [blame] | 983 | // TODO(warx): reconcile to ash once the prefs registration above is moved to |
| 984 | // ash. |
| 985 | OnSpokenFeedbackChanged(); |
Katie D | 6af68c5e | 2018-02-14 23:21:16 | [diff] [blame] | 986 | OnSelectToSpeakChanged(); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 987 | } |
| 988 | |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 989 | void AccessibilityManager::ActiveUserChanged( |
| 990 | const user_manager::User* active_user) { |
xiyuan | 8c6a411 | 2017-06-19 21:03:49 | [diff] [blame] | 991 | if (active_user && active_user->is_profile_created()) |
| 992 | SetProfile(ProfileManager::GetActiveUserProfile()); |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 993 | } |
| 994 | |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 995 | base::TimeDelta AccessibilityManager::PlayShutdownSound() { |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 996 | if (!PlayEarcon(SOUND_SHUTDOWN, |
| 997 | PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED)) { |
[email protected] | 4f011f1 | 2014-01-15 08:22:45 | [diff] [blame] | 998 | return base::TimeDelta(); |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 999 | } |
[email protected] | 4f011f1 | 2014-01-15 08:22:45 | [diff] [blame] | 1000 | return media::SoundsManager::Get()->GetDuration(SOUND_SHUTDOWN); |
[email protected] | ce89d939 | 2013-12-11 21:05:20 | [diff] [blame] | 1001 | } |
| 1002 | |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 1003 | std::unique_ptr<AccessibilityStatusSubscription> |
| 1004 | AccessibilityManager::RegisterCallback(const AccessibilityStatusCallback& cb) { |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 1005 | return callback_list_.Add(cb); |
| 1006 | } |
| 1007 | |
| 1008 | void AccessibilityManager::NotifyAccessibilityStatusChanged( |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 1009 | const AccessibilityStatusEventDetails& details) { |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 1010 | callback_list_.Notify(details); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 1011 | |
James Cook | 696fb106a | 2017-08-17 21:50:44 | [diff] [blame] | 1012 | // TODO(crbug.com/594887): Fix for mash by moving pref into ash. |
| 1013 | if (GetAshConfig() == ash::Config::MASH) |
| 1014 | return; |
| 1015 | |
Zach Helfinstein | bbb6bad | 2018-05-02 18:21:51 | [diff] [blame] | 1016 | if (details.notification_type == ACCESSIBILITY_TOGGLE_DICTATION) { |
| 1017 | ash::Shell::Get()->accessibility_controller()->SetDictationActive( |
| 1018 | details.enabled); |
| 1019 | ash::Shell::Get() |
| 1020 | ->accessibility_controller() |
| 1021 | ->NotifyAccessibilityStatusChanged(); |
| 1022 | return; |
| 1023 | } |
| 1024 | |
James Cook | ec14495 | 2017-09-01 00:05:16 | [diff] [blame] | 1025 | // Update system tray menu visibility. Prefs tracked inside ash handle their |
| 1026 | // own updates to avoid race conditions (pref updates are asynchronous between |
| 1027 | // chrome and ash). |
Zach Helfinstein | bbb6bad | 2018-05-02 18:21:51 | [diff] [blame] | 1028 | if (details.notification_type == ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER || |
| 1029 | details.notification_type == ACCESSIBILITY_TOGGLE_DICTATION) { |
James Cook | 08e91dc | 2018-03-08 18:53:19 | [diff] [blame] | 1030 | ash::Shell::Get() |
| 1031 | ->accessibility_controller() |
Qiang Xu | 9c3bc70 | 2018-03-26 23:12:28 | [diff] [blame] | 1032 | ->NotifyAccessibilityStatusChanged(); |
James Cook | fc97f0a | 2017-08-16 20:05:35 | [diff] [blame] | 1033 | } |
[email protected] | d8edc9c | 2014-02-25 00:06:03 | [diff] [blame] | 1034 | } |
| 1035 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1036 | void AccessibilityManager::UpdateChromeOSAccessibilityHistograms() { |
| 1037 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSpokenFeedback", |
| 1038 | IsSpokenFeedbackEnabled()); |
| 1039 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosHighContrast", |
| 1040 | IsHighContrastEnabled()); |
| 1041 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosVirtualKeyboard", |
[email protected] | e1b299b | 2014-01-29 23:53:41 | [diff] [blame] | 1042 | IsVirtualKeyboardEnabled()); |
[email protected] | 7fb7ea4 | 2014-02-12 21:19:31 | [diff] [blame] | 1043 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosStickyKeys", IsStickyKeysEnabled()); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1044 | if (MagnificationManager::Get()) { |
James Cook | db81c767 | 2017-08-30 15:18:24 | [diff] [blame] | 1045 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosScreenMagnifier", |
| 1046 | MagnificationManager::Get()->IsMagnifierEnabled()); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1047 | } |
[email protected] | ca3a0a8 | 2013-06-18 06:52:12 | [diff] [blame] | 1048 | if (profile_) { |
| 1049 | const PrefService* const prefs = profile_->GetPrefs(); |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1050 | |
| 1051 | bool large_cursor_enabled = |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1052 | prefs->GetBoolean(ash::prefs::kAccessibilityLargeCursorEnabled); |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1053 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosLargeCursor", |
| 1054 | large_cursor_enabled); |
yawano | 92daff5 | 2017-04-21 06:34:28 | [diff] [blame] | 1055 | if (large_cursor_enabled) { |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1056 | UMA_HISTOGRAM_COUNTS_100( |
| 1057 | "Accessibility.CrosLargeCursorSize", |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1058 | prefs->GetInteger(ash::prefs::kAccessibilityLargeCursorDipSize)); |
yawano | 0c3441c7 | 2017-04-11 01:09:16 | [diff] [blame] | 1059 | } |
| 1060 | |
[email protected] | ca3a0a8 | 2013-06-18 06:52:12 | [diff] [blame] | 1061 | UMA_HISTOGRAM_BOOLEAN( |
| 1062 | "Accessibility.CrosAlwaysShowA11yMenu", |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1063 | prefs->GetBoolean(ash::prefs::kShouldAlwaysShowAccessibilityMenu)); |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1064 | |
[email protected] | ced247a | 2014-06-13 19:14:19 | [diff] [blame] | 1065 | bool autoclick_enabled = |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1066 | prefs->GetBoolean(ash::prefs::kAccessibilityAutoclickEnabled); |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1067 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosAutoclick", autoclick_enabled); |
| 1068 | if (autoclick_enabled) { |
| 1069 | // We only want to log the autoclick delay if the user has actually |
| 1070 | // enabled autoclick. |
| 1071 | UMA_HISTOGRAM_CUSTOM_TIMES( |
| 1072 | "Accessibility.CrosAutoclickDelay", |
| 1073 | base::TimeDelta::FromMilliseconds( |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1074 | prefs->GetInteger(ash::prefs::kAccessibilityAutoclickDelayMs)), |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1075 | base::TimeDelta::FromMilliseconds(1), |
James Cook | c63b9fd | 2017-08-18 18:48:32 | [diff] [blame] | 1076 | base::TimeDelta::FromMilliseconds(3000), 50); |
[email protected] | 0b5a0d2b | 2013-10-30 03:43:40 | [diff] [blame] | 1077 | } |
[email protected] | ca3a0a8 | 2013-06-18 06:52:12 | [diff] [blame] | 1078 | } |
dmazzoni | 756089a2 | 2016-03-15 23:55:16 | [diff] [blame] | 1079 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosCaretHighlight", |
| 1080 | IsCaretHighlightEnabled()); |
| 1081 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosCursorHighlight", |
| 1082 | IsCursorHighlightEnabled()); |
| 1083 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosFocusHighlight", |
| 1084 | IsFocusHighlightEnabled()); |
| 1085 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSelectToSpeak", |
| 1086 | IsSelectToSpeakEnabled()); |
| 1087 | UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSwitchAccess", |
| 1088 | IsSwitchAccessEnabled()); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | void AccessibilityManager::Observe( |
| 1092 | int type, |
| 1093 | const content::NotificationSource& source, |
| 1094 | const content::NotificationDetails& details) { |
| 1095 | switch (type) { |
[email protected] | 093d9ba | 2013-07-23 19:26:21 | [diff] [blame] | 1096 | case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
[email protected] | 9cf54f36 | 2013-07-01 07:28:12 | [diff] [blame] | 1097 | // Update |profile_| when entering the login screen. |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1098 | Profile* profile = ProfileManager::GetActiveUserProfile(); |
[email protected] | d888cdc | 2013-06-24 17:06:20 | [diff] [blame] | 1099 | if (ProfileHelper::IsSigninProfile(profile)) |
| 1100 | SetProfile(profile); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1101 | break; |
[email protected] | d888cdc | 2013-06-24 17:06:20 | [diff] [blame] | 1102 | } |
Yuki Awano | d59b649 | 2017-07-28 00:52:11 | [diff] [blame] | 1103 | case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: |
| 1104 | // Update |profile_| when login user profile is prepared. |
| 1105 | // NOTIFICATION_SESSION_STARTED is not fired from UserSessionManager, but |
| 1106 | // profile may be changed by UserSessionManager in OOBE flow. |
| 1107 | SetProfile(ProfileManager::GetActiveUserProfile()); |
| 1108 | break; |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 1109 | case chrome::NOTIFICATION_SESSION_STARTED: |
| 1110 | // Update |profile_| when entering a session. |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1111 | SetProfile(ProfileManager::GetActiveUserProfile()); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1112 | |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1113 | // Add a session state observer to be able to monitor session changes. |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 1114 | if (!session_state_observer_.get()) |
[email protected] | c2012257 | 2013-12-16 20:35:58 | [diff] [blame] | 1115 | session_state_observer_.reset( |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 1116 | new user_manager::ScopedUserSessionStateObserver(this)); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1117 | break; |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1118 | case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
[email protected] | e6f2064 | 2013-06-11 17:05:46 | [diff] [blame] | 1119 | // Update |profile_| when exiting a session or shutting down. |
| 1120 | Profile* profile = content::Source<Profile>(source).ptr(); |
| 1121 | if (profile_ == profile) |
| 1122 | SetProfile(NULL); |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1123 | break; |
| 1124 | } |
David Tseng | 768d798 | 2017-12-21 00:20:11 | [diff] [blame] | 1125 | case chrome::NOTIFICATION_APP_TERMINATING: { |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 1126 | app_terminating_ = true; |
David Tseng | 768d798 | 2017-12-21 00:20:11 | [diff] [blame] | 1127 | break; |
| 1128 | } |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 1129 | case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { |
Qiang Xu | 0f12228 | 2018-04-19 16:55:40 | [diff] [blame] | 1130 | // Avoid unnecessary mojo IPC to ash when focus highlight feature is not |
| 1131 | // enabled. |
| 1132 | if (!IsFocusHighlightEnabled()) |
| 1133 | return; |
Qiang Xu | 95eea57 | 2018-02-17 08:10:31 | [diff] [blame] | 1134 | content::FocusedNodeDetails* node_details = |
| 1135 | content::Details<content::FocusedNodeDetails>(details).ptr(); |
| 1136 | accessibility_controller_->SetFocusHighlightRect( |
| 1137 | node_details->node_bounds_in_screen); |
| 1138 | break; |
| 1139 | } |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1143 | void AccessibilityManager::OnBrailleDisplayStateChanged( |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 1144 | const DisplayState& display_state) { |
[email protected] | a81b2c3 | 2014-03-28 06:35:01 | [diff] [blame] | 1145 | braille_display_connected_ = display_state.available; |
Qiang Xu | 797a8e7 | 2018-01-21 11:19:08 | [diff] [blame] | 1146 | accessibility_controller_->BrailleDisplayStateChanged( |
| 1147 | braille_display_connected_); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1148 | UpdateBrailleImeState(); |
[email protected] | 8c79e3f | 2013-10-30 01:05:14 | [diff] [blame] | 1149 | } |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1150 | |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1151 | void AccessibilityManager::OnBrailleKeyEvent(const KeyEvent& event) { |
| 1152 | // Ensure the braille IME is active on braille keyboard (dots) input. |
| 1153 | if ((event.command == |
| 1154 | extensions::api::braille_display_private::KEY_COMMAND_DOTS) && |
| 1155 | !braille_ime_current_) { |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 1156 | input_method::InputMethodManager::Get() |
| 1157 | ->GetActiveIMEState() |
jamescook | 2d60f03 | 2017-06-01 00:55:21 | [diff] [blame] | 1158 | ->ChangeInputMethod(extension_ime_util::kBrailleImeEngineId, |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 1159 | false /* show_message */); |
[email protected] | 2e5e0b1 | 2014-05-07 13:30:20 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1163 | void AccessibilityManager::OnExtensionUnloaded( |
| 1164 | content::BrowserContext* browser_context, |
| 1165 | const extensions::Extension* extension, |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 1166 | extensions::UnloadedExtensionReason reason) { |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1167 | if (extension->id() == keyboard_listener_extension_id_) { |
| 1168 | keyboard_listener_extension_id_ = std::string(); |
| 1169 | keyboard_listener_capture_ = false; |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | void AccessibilityManager::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 1174 | extension_registry_observer_.Remove(registry); |
| 1175 | } |
| 1176 | |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1177 | void AccessibilityManager::PostLoadChromeVox() { |
James Cook | 0c4f37ac0 | 2018-01-17 02:17:09 | [diff] [blame] | 1178 | // In browser_tests loading the ChromeVox extension can race with shutdown. |
| 1179 | // http://crbug.com/801700 |
| 1180 | if (app_terminating_) |
| 1181 | return; |
| 1182 | |
[email protected] | ee8bbd97 | 2014-02-03 06:52:47 | [diff] [blame] | 1183 | // Do any setup work needed immediately after ChromeVox actually loads. |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 1184 | PlayEarcon(SOUND_SPOKEN_FEEDBACK_ENABLED, PlaySoundOption::ALWAYS); |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1185 | |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 1186 | extensions::EventRouter* event_router = |
| 1187 | extensions::EventRouter::Get(profile_); |
dtseng | 703a204 | 2015-01-22 17:46:51 | [diff] [blame] | 1188 | |
Katie D | 30e0841 | 2018-05-02 17:24:22 | [diff] [blame] | 1189 | std::unique_ptr<base::ListValue> event_args = |
| 1190 | std::make_unique<base::ListValue>(); |
dtseng | 4702f8e | 2017-01-11 18:54:12 | [diff] [blame] | 1191 | std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 1192 | extensions::events::ACCESSIBILITY_PRIVATE_ON_INTRODUCE_CHROME_VOX, |
| 1193 | extensions::api::accessibility_private::OnIntroduceChromeVox::kEventName, |
| 1194 | std::move(event_args))); |
| 1195 | event_router->DispatchEventWithLazyListener( |
| 1196 | extension_misc::kChromeVoxExtensionId, std::move(event)); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1197 | |
James Cook | 769799b | 2018-03-12 16:59:04 | [diff] [blame] | 1198 | if (!chromevox_panel_) { |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 1199 | chromevox_panel_ = new ChromeVoxPanel( |
| 1200 | profile_, |
| 1201 | session_manager::SessionManager::Get()->IsUserSessionBlocked()); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1202 | chromevox_panel_widget_observer_.reset( |
| 1203 | new ChromeVoxPanelWidgetObserver(chromevox_panel_->GetWidget(), this)); |
| 1204 | } |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 1205 | |
| 1206 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 1207 | ::switches::kEnableAudioFocus)) { |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 1208 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
Dominic Mazzoni | c85a5c9 | 2017-08-31 18:53:30 | [diff] [blame] | 1209 | ::switches::kEnableAudioFocus); |
dtseng | d50debe3 | 2016-12-29 06:23:37 | [diff] [blame] | 1210 | } |
[email protected] | 0e9504d | 2013-11-05 02:33:29 | [diff] [blame] | 1211 | } |
| 1212 | |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1213 | void AccessibilityManager::PostUnloadChromeVox() { |
[email protected] | 9d6c9136 | 2013-12-07 21:56:27 | [diff] [blame] | 1214 | // Do any teardown work needed immediately after ChromeVox actually unloads. |
sadrul | cdc2bb4 | 2016-07-13 19:44:51 | [diff] [blame] | 1215 | PlayEarcon(SOUND_SPOKEN_FEEDBACK_DISABLED, PlaySoundOption::ALWAYS); |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 1216 | |
dmazzoni | fb33d59 | 2014-10-30 19:26:54 | [diff] [blame] | 1217 | // Clear the accessibility focus ring. |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 1218 | SetFocusRing(std::vector<gfx::Rect>(), |
| 1219 | ash::mojom::FocusRingBehavior::PERSIST_FOCUS_RING); |
dmazzoni | 337c5af | 2016-09-13 23:08:57 | [diff] [blame] | 1220 | |
| 1221 | if (chromevox_panel_) { |
| 1222 | chromevox_panel_->Close(); |
| 1223 | chromevox_panel_ = nullptr; |
| 1224 | } |
dtseng | 3a17f21 | 2017-03-25 08:58:52 | [diff] [blame] | 1225 | |
| 1226 | // In case the user darkened the screen, undarken it now. |
Qiang Xu | 4e5853d38 | 2018-01-09 07:21:07 | [diff] [blame] | 1227 | SetDarkenScreen(false); |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 1228 | |
| 1229 | // Stop speech. |
| 1230 | TtsController::GetInstance()->Stop(); |
[email protected] | 9d6c9136 | 2013-12-07 21:56:27 | [diff] [blame] | 1231 | } |
| 1232 | |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1233 | void AccessibilityManager::PostSwitchChromeVoxProfile() { |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 1234 | ReloadChromeVoxPanel(); |
| 1235 | } |
| 1236 | |
| 1237 | void AccessibilityManager::ReloadChromeVoxPanel() { |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1238 | if (chromevox_panel_) { |
James Cook | 769799b | 2018-03-12 16:59:04 | [diff] [blame] | 1239 | chromevox_panel_->CloseNow(); |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1240 | chromevox_panel_ = nullptr; |
| 1241 | } |
tbarzic | cd5ad22 | 2017-03-24 04:46:31 | [diff] [blame] | 1242 | chromevox_panel_ = new ChromeVoxPanel( |
| 1243 | profile_, session_manager::SessionManager::Get()->IsUserSessionBlocked()); |
dmazzoni | 63199b1 | 2016-10-19 15:44:36 | [diff] [blame] | 1244 | chromevox_panel_widget_observer_.reset( |
| 1245 | new ChromeVoxPanelWidgetObserver(chromevox_panel_->GetWidget(), this)); |
| 1246 | } |
| 1247 | |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1248 | void AccessibilityManager::OnChromeVoxPanelClosing() { |
jamescook | 788b4fc | 2017-05-18 16:16:06 | [diff] [blame] | 1249 | chromevox_panel_widget_observer_.reset(); |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1250 | chromevox_panel_ = nullptr; |
dmazzoni | 94a4f88 | 2015-11-13 05:46:52 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | void AccessibilityManager::OnChromeVoxPanelDestroying() { |
| 1254 | chromevox_panel_widget_observer_.reset(nullptr); |
| 1255 | chromevox_panel_ = nullptr; |
| 1256 | } |
| 1257 | |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 1258 | void AccessibilityManager::PostUnloadSelectToSpeak() { |
| 1259 | // Do any teardown work needed immediately after Select-to-Speak actually |
| 1260 | // unloads. |
| 1261 | |
| 1262 | // Clear the accessibility focus ring and highlight. |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 1263 | HideFocusRing(); |
| 1264 | HideHighlights(); |
Katie D | 6264a8e | 2018-02-07 02:32:20 | [diff] [blame] | 1265 | |
| 1266 | // Stop speech. |
| 1267 | TtsController::GetInstance()->Stop(); |
| 1268 | } |
| 1269 | |
dtseng | fb6d7cd | 2016-01-20 23:00:13 | [diff] [blame] | 1270 | void AccessibilityManager::SetKeyboardListenerExtensionId( |
| 1271 | const std::string& id, |
| 1272 | content::BrowserContext* context) { |
| 1273 | keyboard_listener_extension_id_ = id; |
| 1274 | |
| 1275 | extensions::ExtensionRegistry* registry = |
| 1276 | extensions::ExtensionRegistry::Get(context); |
| 1277 | if (!extension_registry_observer_.IsObserving(registry) && !id.empty()) |
| 1278 | extension_registry_observer_.Add(registry); |
| 1279 | } |
| 1280 | |
elichtenberg | a108c8a | 2017-06-02 21:13:19 | [diff] [blame] | 1281 | void AccessibilityManager::SetSwitchAccessKeys(const std::set<int>& key_codes) { |
| 1282 | if (switch_access_enabled_) |
| 1283 | switch_access_event_handler_->SetKeysToCapture(key_codes); |
| 1284 | } |
| 1285 | |
Zach Helfinstein | bbb6bad | 2018-05-02 18:21:51 | [diff] [blame] | 1286 | bool AccessibilityManager::ToggleDictation() { |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 1287 | if (!profile_) |
Zach Helfinstein | bbb6bad | 2018-05-02 18:21:51 | [diff] [blame] | 1288 | return false; |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 1289 | |
| 1290 | if (!dictation_.get()) |
| 1291 | dictation_ = std::make_unique<DictationChromeos>(profile_); |
| 1292 | |
Zach Helfinstein | bbb6bad | 2018-05-02 18:21:51 | [diff] [blame] | 1293 | return dictation_->OnToggleDictation(); |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 1294 | } |
| 1295 | |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 1296 | void AccessibilityManager::SetFocusRingColor(SkColor color) { |
| 1297 | accessibility_focus_ring_controller_->SetFocusRingColor(color); |
| 1298 | } |
| 1299 | |
| 1300 | void AccessibilityManager::ResetFocusRingColor() { |
| 1301 | accessibility_focus_ring_controller_->ResetFocusRingColor(); |
| 1302 | } |
| 1303 | |
| 1304 | void AccessibilityManager::SetFocusRing( |
| 1305 | const std::vector<gfx::Rect>& rects_in_screen, |
| 1306 | ash::mojom::FocusRingBehavior focus_ring_behavior) { |
| 1307 | accessibility_focus_ring_controller_->SetFocusRing(rects_in_screen, |
| 1308 | focus_ring_behavior); |
| 1309 | if (focus_ring_observer_for_test_) |
| 1310 | focus_ring_observer_for_test_.Run(); |
| 1311 | } |
| 1312 | |
| 1313 | void AccessibilityManager::HideFocusRing() { |
| 1314 | accessibility_focus_ring_controller_->HideFocusRing(); |
| 1315 | if (focus_ring_observer_for_test_) |
| 1316 | focus_ring_observer_for_test_.Run(); |
| 1317 | } |
| 1318 | |
| 1319 | void AccessibilityManager::SetHighlights( |
| 1320 | const std::vector<gfx::Rect>& rects_in_screen, |
| 1321 | SkColor color) { |
| 1322 | accessibility_focus_ring_controller_->SetHighlights(rects_in_screen, color); |
| 1323 | } |
| 1324 | |
| 1325 | void AccessibilityManager::HideHighlights() { |
| 1326 | accessibility_focus_ring_controller_->HideHighlights(); |
| 1327 | } |
| 1328 | |
Qiang Xu | 797a8e7 | 2018-01-21 11:19:08 | [diff] [blame] | 1329 | void AccessibilityManager::SetProfileForTest(Profile* profile) { |
| 1330 | SetProfile(profile); |
| 1331 | } |
| 1332 | |
| 1333 | // static |
| 1334 | void AccessibilityManager::SetBrailleControllerForTest( |
| 1335 | BrailleController* controller) { |
| 1336 | g_braille_controller_for_test = controller; |
| 1337 | } |
| 1338 | |
| 1339 | void AccessibilityManager::FlushForTesting() { |
| 1340 | accessibility_controller_.FlushForTesting(); |
| 1341 | } |
| 1342 | |
Qiang Xu | 56a7581 | 2018-03-15 00:28:34 | [diff] [blame] | 1343 | void AccessibilityManager::SetFocusRingObserverForTest( |
| 1344 | base::RepeatingCallback<void()> observer) { |
| 1345 | focus_ring_observer_for_test_ = observer; |
| 1346 | } |
| 1347 | |
[email protected] | 1dfebfc | 2013-06-04 03:14:32 | [diff] [blame] | 1348 | } // namespace chromeos |