blob: 8b3e0371d9f961ba2f60e32be133be89b9a48a03 [file] [log] [blame]
Qiang Xu0133ccb2017-11-13 23:32:061// 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 Ferreiro7b693762021-02-18 23:01:467#include "ash/components/audio/sounds.h"
Mike Wassermand13e95a2019-06-28 23:29:488#include "ash/public/cpp/accessibility_controller.h"
9#include "ash/public/cpp/accessibility_controller_enums.h"
Henrique Ferreirof352a75012021-01-16 00:37:1910#include "chrome/browser/ash/accessibility/accessibility_manager.h"
Qiang Xu0133ccb2017-11-13 23:32:0611#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 D840d9532018-11-27 06:20:4814#include "content/public/browser/tts_controller.h"
Qiang Xu0133ccb2017-11-13 23:32:0615#include "ui/base/l10n/l10n_util.h"
16
17namespace {
18
Qiang Xu0133ccb2017-11-13 23:32:0619void SetAutomationManagerEnabled(content::BrowserContext* context,
20 bool enabled) {
21 DCHECK(context);
22 AutomationManagerAura* manager = AutomationManagerAura::GetInstance();
23 if (enabled)
David Tsenge1cf45a62018-09-25 22:55:1824 manager->Enable();
Qiang Xu0133ccb2017-11-13 23:32:0625 else
26 manager->Disable();
27}
28
29} // namespace
30
Mike Wassermand13e95a2019-06-28 23:29:4831AccessibilityControllerClient::AccessibilityControllerClient() {
32 ash::AccessibilityController::Get()->SetClient(this);
33}
Qiang Xu0133ccb2017-11-13 23:32:0634
Mike Wassermand13e95a2019-06-28 23:29:4835AccessibilityControllerClient::~AccessibilityControllerClient() {
36 ash::AccessibilityController::Get()->SetClient(nullptr);
Qiang Xu0133ccb2017-11-13 23:32:0637}
38
Qiang Xu0133ccb2017-11-13 23:32:0639void AccessibilityControllerClient::TriggerAccessibilityAlert(
Mike Wassermand13e95a2019-06-28 23:29:4840 ash::AccessibilityAlert alert) {
Qiang Xu0133ccb2017-11-13 23:32:0641 Profile* profile = ProfileManager::GetActiveUserProfile();
42 if (!profile)
43 return;
44
45 int msg = 0;
46 switch (alert) {
Mike Wassermand13e95a2019-06-28 23:29:4847 case ash::AccessibilityAlert::CAPS_ON:
Qiang Xu0133ccb2017-11-13 23:32:0648 msg = IDS_A11Y_ALERT_CAPS_ON;
49 break;
Mike Wassermand13e95a2019-06-28 23:29:4850 case ash::AccessibilityAlert::CAPS_OFF:
Qiang Xu0133ccb2017-11-13 23:32:0651 msg = IDS_A11Y_ALERT_CAPS_OFF;
52 break;
Mike Wassermand13e95a2019-06-28 23:29:4853 case ash::AccessibilityAlert::SCREEN_ON:
Qiang Xu0133ccb2017-11-13 23:32:0654 // 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 Wassermand13e95a2019-06-28 23:29:4859 case ash::AccessibilityAlert::SCREEN_OFF:
Qiang Xu0133ccb2017-11-13 23:32:0660 msg = IDS_A11Y_ALERT_SCREEN_OFF;
61 break;
Mike Wassermand13e95a2019-06-28 23:29:4862 case ash::AccessibilityAlert::WINDOW_MOVED_TO_ANOTHER_DISPLAY:
Qiang Xu58049b22018-03-01 20:43:1963 msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_ANOTHER_DISPLAY;
Qiang Xu14011242017-11-14 19:41:5064 break;
Mike Wassermand13e95a2019-06-28 23:29:4865 case ash::AccessibilityAlert::WINDOW_NEEDED:
Qiang Xu0133ccb2017-11-13 23:32:0666 msg = IDS_A11Y_ALERT_WINDOW_NEEDED;
67 break;
Mike Wassermand13e95a2019-06-28 23:29:4868 case ash::AccessibilityAlert::WINDOW_OVERVIEW_MODE_ENTERED:
Qiang Xu0133ccb2017-11-13 23:32:0669 msg = IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED;
70 break;
Mike Wassermand13e95a2019-06-28 23:29:4871 case ash::AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED:
Min Chencd12cbbe62019-03-18 17:41:2772 msg = IDS_A11Y_ALERT_WORKSPACE_FULLSCREEN_STATE_ENTERED;
73 break;
Mike Wassermand13e95a2019-06-28 23:29:4874 case ash::AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_EXITED:
Min Chencd12cbbe62019-03-18 17:41:2775 msg = IDS_A11Y_ALERT_WORKSPACE_FULLSCREEN_STATE_EXITED;
76 break;
Mike Wassermand13e95a2019-06-28 23:29:4877 case ash::AccessibilityAlert::NONE:
Qiang Xu0133ccb2017-11-13 23:32:0678 msg = 0;
79 break;
80 }
81
82 if (msg) {
83 AutomationManagerAura::GetInstance()->HandleAlert(
David Tsenge1cf45a62018-09-25 22:55:1884 l10n_util::GetStringUTF8(msg));
Qiang Xu0133ccb2017-11-13 23:32:0685 // After handling the alert, if the alert is screen-off, we should
86 // disable automation manager to handle any following a11y events.
Mike Wassermand13e95a2019-06-28 23:29:4887 if (alert == ash::AccessibilityAlert::SCREEN_OFF)
Qiang Xu0133ccb2017-11-13 23:32:0688 SetAutomationManagerEnabled(profile, false);
89 }
90}
91
Min Chenedffb5272019-07-25 23:53:1892void 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 Ferreirobd3e9972021-01-14 18:48:48101void AccessibilityControllerClient::PlayEarcon(chromeos::Sound sound_key) {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31102 AccessibilityManager::Get()->PlayEarcon(
103 sound_key, PlaySoundOption::kOnlyIfSpokenFeedbackEnabled);
Qiang Xu89af823e2017-12-05 04:04:47104}
105
Mike Wassermand13e95a2019-06-28 23:29:48106base::TimeDelta AccessibilityControllerClient::PlayShutdownSound() {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31107 return AccessibilityManager::Get()->PlayShutdownSound();
Qiang Xu89af823e2017-12-05 04:04:47108}
109
Qiang Xu9e12fa762017-12-19 03:27:49110void AccessibilityControllerClient::HandleAccessibilityGesture(
David Tseng67c641552020-06-24 07:11:23111 ax::mojom::Gesture gesture,
112 gfx::PointF location) {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31113 AccessibilityManager::Get()->HandleAccessibilityGesture(gesture, location);
Qiang Xu9e12fa762017-12-19 03:27:49114}
115
Mike Wassermand13e95a2019-06-28 23:29:48116bool AccessibilityControllerClient::ToggleDictation() {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31117 return AccessibilityManager::Get()->ToggleDictation();
David Tseng8a5de492018-01-17 20:41:37118}
119
Qiang Xud9f289a2018-02-21 00:31:24120void AccessibilityControllerClient::SilenceSpokenFeedback() {
Katie D840d9532018-11-27 06:20:48121 content::TtsController::GetInstance()->Stop();
Qiang Xud9f289a2018-02-21 00:31:24122}
123
124void AccessibilityControllerClient::OnTwoFingerTouchStart() {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31125 AccessibilityManager::Get()->OnTwoFingerTouchStart();
Qiang Xud9f289a2018-02-21 00:31:24126}
127
128void AccessibilityControllerClient::OnTwoFingerTouchStop() {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31129 AccessibilityManager::Get()->OnTwoFingerTouchStop();
Qiang Xud9f289a2018-02-21 00:31:24130}
131
Mike Wassermand13e95a2019-06-28 23:29:48132bool AccessibilityControllerClient::ShouldToggleSpokenFeedbackViaTouch() const {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31133 return AccessibilityManager::Get()->ShouldToggleSpokenFeedbackViaTouch();
Qiang Xuc1b3e7ea2018-02-12 19:57:38134}
135
136void AccessibilityControllerClient::PlaySpokenFeedbackToggleCountdown(
137 int tick_count) {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31138 AccessibilityManager::Get()->PlaySpokenFeedbackToggleCountdown(tick_count);
Qiang Xuc1b3e7ea2018-02-12 19:57:38139}
140
Katie D30e08412018-05-02 17:24:22141void AccessibilityControllerClient::RequestSelectToSpeakStateChange() {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31142 AccessibilityManager::Get()->RequestSelectToSpeakStateChange();
Katie D30e08412018-05-02 17:24:22143}
Katie Db16cab02019-07-08 23:36:08144
145void AccessibilityControllerClient::RequestAutoclickScrollableBoundsForPoint(
146 gfx::Point& point_in_screen) {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31147 AccessibilityManager::Get()->RequestAutoclickScrollableBoundsForPoint(
148 point_in_screen);
Katie Db16cab02019-07-08 23:36:08149}
Katie D9adcfb12020-06-24 17:03:44150
Josiah Kb3474bd32020-10-23 21:44:58151void AccessibilityControllerClient::MagnifierBoundsChanged(
152 const gfx::Rect& bounds_in_screen) {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31153 AccessibilityManager::Get()->MagnifierBoundsChanged(bounds_in_screen);
Josiah Kb3474bd32020-10-23 21:44:58154}
155
Katie D9adcfb12020-06-24 17:03:44156void AccessibilityControllerClient::OnSwitchAccessDisabled() {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31157 AccessibilityManager::Get()->OnSwitchAccessDisabled();
Katie D9adcfb12020-06-24 17:03:44158}
Joel Riley5beea9f92020-11-20 22:27:15159
160void AccessibilityControllerClient::OnSelectToSpeakPanelAction(
Joel Rileyd1f17e942020-12-01 22:02:23161 ash::SelectToSpeakPanelAction action,
162 double value) {
Henrique Ferreiro47a76db3b2021-01-18 20:56:31163 AccessibilityManager::Get()->OnSelectToSpeakPanelAction(action, value);
Joel Riley5beea9f92020-11-20 22:27:15164}