Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 1 | // Copyright 2017 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/ui/ash/accessibility/accessibility_controller_client.h" |
| 6 | |
Henrique Ferreiro | 7b69376 | 2021-02-18 23:01:46 | [diff] [blame^] | 7 | #include "ash/components/audio/sounds.h" |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 8 | #include "ash/public/cpp/accessibility_controller.h" |
| 9 | #include "ash/public/cpp/accessibility_controller_enums.h" |
Henrique Ferreiro | f352a7501 | 2021-01-16 00:37:19 | [diff] [blame] | 10 | #include "chrome/browser/ash/accessibility/accessibility_manager.h" |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile_manager.h" |
| 12 | #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" |
| 13 | #include "chrome/grit/generated_resources.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 14 | #include "content/public/browser/tts_controller.h" |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 15 | #include "ui/base/l10n/l10n_util.h" |
| 16 | |
| 17 | namespace { |
| 18 | |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 19 | void SetAutomationManagerEnabled(content::BrowserContext* context, |
| 20 | bool enabled) { |
| 21 | DCHECK(context); |
| 22 | AutomationManagerAura* manager = AutomationManagerAura::GetInstance(); |
| 23 | if (enabled) |
David Tseng | e1cf45a6 | 2018-09-25 22:55:18 | [diff] [blame] | 24 | manager->Enable(); |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 25 | else |
| 26 | manager->Disable(); |
| 27 | } |
| 28 | |
| 29 | } // namespace |
| 30 | |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 31 | AccessibilityControllerClient::AccessibilityControllerClient() { |
| 32 | ash::AccessibilityController::Get()->SetClient(this); |
| 33 | } |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 34 | |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 35 | AccessibilityControllerClient::~AccessibilityControllerClient() { |
| 36 | ash::AccessibilityController::Get()->SetClient(nullptr); |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 37 | } |
| 38 | |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 39 | void AccessibilityControllerClient::TriggerAccessibilityAlert( |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 40 | ash::AccessibilityAlert alert) { |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 41 | Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 42 | if (!profile) |
| 43 | return; |
| 44 | |
| 45 | int msg = 0; |
| 46 | switch (alert) { |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 47 | case ash::AccessibilityAlert::CAPS_ON: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 48 | msg = IDS_A11Y_ALERT_CAPS_ON; |
| 49 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 50 | case ash::AccessibilityAlert::CAPS_OFF: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 51 | msg = IDS_A11Y_ALERT_CAPS_OFF; |
| 52 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 53 | case ash::AccessibilityAlert::SCREEN_ON: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 54 | // Enable automation manager when alert is screen-on, as it is |
| 55 | // previously disabled by alert screen-off. |
| 56 | SetAutomationManagerEnabled(profile, true); |
| 57 | msg = IDS_A11Y_ALERT_SCREEN_ON; |
| 58 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 59 | case ash::AccessibilityAlert::SCREEN_OFF: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 60 | msg = IDS_A11Y_ALERT_SCREEN_OFF; |
| 61 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 62 | case ash::AccessibilityAlert::WINDOW_MOVED_TO_ANOTHER_DISPLAY: |
Qiang Xu | 58049b2 | 2018-03-01 20:43:19 | [diff] [blame] | 63 | msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_ANOTHER_DISPLAY; |
Qiang Xu | 1401124 | 2017-11-14 19:41:50 | [diff] [blame] | 64 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 65 | case ash::AccessibilityAlert::WINDOW_NEEDED: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 66 | msg = IDS_A11Y_ALERT_WINDOW_NEEDED; |
| 67 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 68 | case ash::AccessibilityAlert::WINDOW_OVERVIEW_MODE_ENTERED: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 69 | msg = IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED; |
| 70 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 71 | case ash::AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED: |
Min Chen | cd12cbbe6 | 2019-03-18 17:41:27 | [diff] [blame] | 72 | msg = IDS_A11Y_ALERT_WORKSPACE_FULLSCREEN_STATE_ENTERED; |
| 73 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 74 | case ash::AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_EXITED: |
Min Chen | cd12cbbe6 | 2019-03-18 17:41:27 | [diff] [blame] | 75 | msg = IDS_A11Y_ALERT_WORKSPACE_FULLSCREEN_STATE_EXITED; |
| 76 | break; |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 77 | case ash::AccessibilityAlert::NONE: |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 78 | msg = 0; |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | if (msg) { |
| 83 | AutomationManagerAura::GetInstance()->HandleAlert( |
David Tseng | e1cf45a6 | 2018-09-25 22:55:18 | [diff] [blame] | 84 | l10n_util::GetStringUTF8(msg)); |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 85 | // After handling the alert, if the alert is screen-off, we should |
| 86 | // disable automation manager to handle any following a11y events. |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 87 | if (alert == ash::AccessibilityAlert::SCREEN_OFF) |
Qiang Xu | 0133ccb | 2017-11-13 23:32:06 | [diff] [blame] | 88 | SetAutomationManagerEnabled(profile, false); |
| 89 | } |
| 90 | } |
| 91 | |
Min Chen | edffb527 | 2019-07-25 23:53:18 | [diff] [blame] | 92 | void AccessibilityControllerClient::TriggerAccessibilityAlertWithMessage( |
| 93 | const std::string& message) { |
| 94 | Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 95 | if (!profile) |
| 96 | return; |
| 97 | |
| 98 | AutomationManagerAura::GetInstance()->HandleAlert(message); |
| 99 | } |
| 100 | |
Henrique Ferreiro | bd3e997 | 2021-01-14 18:48:48 | [diff] [blame] | 101 | void AccessibilityControllerClient::PlayEarcon(chromeos::Sound sound_key) { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 102 | AccessibilityManager::Get()->PlayEarcon( |
| 103 | sound_key, PlaySoundOption::kOnlyIfSpokenFeedbackEnabled); |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 104 | } |
| 105 | |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 106 | base::TimeDelta AccessibilityControllerClient::PlayShutdownSound() { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 107 | return AccessibilityManager::Get()->PlayShutdownSound(); |
Qiang Xu | 89af823e | 2017-12-05 04:04:47 | [diff] [blame] | 108 | } |
| 109 | |
Qiang Xu | 9e12fa76 | 2017-12-19 03:27:49 | [diff] [blame] | 110 | void AccessibilityControllerClient::HandleAccessibilityGesture( |
David Tseng | 67c64155 | 2020-06-24 07:11:23 | [diff] [blame] | 111 | ax::mojom::Gesture gesture, |
| 112 | gfx::PointF location) { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 113 | AccessibilityManager::Get()->HandleAccessibilityGesture(gesture, location); |
Qiang Xu | 9e12fa76 | 2017-12-19 03:27:49 | [diff] [blame] | 114 | } |
| 115 | |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 116 | bool AccessibilityControllerClient::ToggleDictation() { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 117 | return AccessibilityManager::Get()->ToggleDictation(); |
David Tseng | 8a5de49 | 2018-01-17 20:41:37 | [diff] [blame] | 118 | } |
| 119 | |
Qiang Xu | d9f289a | 2018-02-21 00:31:24 | [diff] [blame] | 120 | void AccessibilityControllerClient::SilenceSpokenFeedback() { |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 121 | content::TtsController::GetInstance()->Stop(); |
Qiang Xu | d9f289a | 2018-02-21 00:31:24 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void AccessibilityControllerClient::OnTwoFingerTouchStart() { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 125 | AccessibilityManager::Get()->OnTwoFingerTouchStart(); |
Qiang Xu | d9f289a | 2018-02-21 00:31:24 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void AccessibilityControllerClient::OnTwoFingerTouchStop() { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 129 | AccessibilityManager::Get()->OnTwoFingerTouchStop(); |
Qiang Xu | d9f289a | 2018-02-21 00:31:24 | [diff] [blame] | 130 | } |
| 131 | |
Mike Wasserman | d13e95a | 2019-06-28 23:29:48 | [diff] [blame] | 132 | bool AccessibilityControllerClient::ShouldToggleSpokenFeedbackViaTouch() const { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 133 | return AccessibilityManager::Get()->ShouldToggleSpokenFeedbackViaTouch(); |
Qiang Xu | c1b3e7ea | 2018-02-12 19:57:38 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void AccessibilityControllerClient::PlaySpokenFeedbackToggleCountdown( |
| 137 | int tick_count) { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 138 | AccessibilityManager::Get()->PlaySpokenFeedbackToggleCountdown(tick_count); |
Qiang Xu | c1b3e7ea | 2018-02-12 19:57:38 | [diff] [blame] | 139 | } |
| 140 | |
Katie D | 30e0841 | 2018-05-02 17:24:22 | [diff] [blame] | 141 | void AccessibilityControllerClient::RequestSelectToSpeakStateChange() { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 142 | AccessibilityManager::Get()->RequestSelectToSpeakStateChange(); |
Katie D | 30e0841 | 2018-05-02 17:24:22 | [diff] [blame] | 143 | } |
Katie D | b16cab0 | 2019-07-08 23:36:08 | [diff] [blame] | 144 | |
| 145 | void AccessibilityControllerClient::RequestAutoclickScrollableBoundsForPoint( |
| 146 | gfx::Point& point_in_screen) { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 147 | AccessibilityManager::Get()->RequestAutoclickScrollableBoundsForPoint( |
| 148 | point_in_screen); |
Katie D | b16cab0 | 2019-07-08 23:36:08 | [diff] [blame] | 149 | } |
Katie D | 9adcfb1 | 2020-06-24 17:03:44 | [diff] [blame] | 150 | |
Josiah K | b3474bd3 | 2020-10-23 21:44:58 | [diff] [blame] | 151 | void AccessibilityControllerClient::MagnifierBoundsChanged( |
| 152 | const gfx::Rect& bounds_in_screen) { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 153 | AccessibilityManager::Get()->MagnifierBoundsChanged(bounds_in_screen); |
Josiah K | b3474bd3 | 2020-10-23 21:44:58 | [diff] [blame] | 154 | } |
| 155 | |
Katie D | 9adcfb1 | 2020-06-24 17:03:44 | [diff] [blame] | 156 | void AccessibilityControllerClient::OnSwitchAccessDisabled() { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 157 | AccessibilityManager::Get()->OnSwitchAccessDisabled(); |
Katie D | 9adcfb1 | 2020-06-24 17:03:44 | [diff] [blame] | 158 | } |
Joel Riley | 5beea9f9 | 2020-11-20 22:27:15 | [diff] [blame] | 159 | |
| 160 | void AccessibilityControllerClient::OnSelectToSpeakPanelAction( |
Joel Riley | d1f17e94 | 2020-12-01 22:02:23 | [diff] [blame] | 161 | ash::SelectToSpeakPanelAction action, |
| 162 | double value) { |
Henrique Ferreiro | 47a76db3b | 2021-01-18 20:56:31 | [diff] [blame] | 163 | AccessibilityManager::Get()->OnSelectToSpeakPanelAction(action, value); |
Joel Riley | 5beea9f9 | 2020-11-20 22:27:15 | [diff] [blame] | 164 | } |