1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/accessibility/accessibility_controller_client.h"
#include "ash/accessibility/accessibility_controller.h"
#include "ash/public/cpp/accessibility_controller_enums.h"
#include "ash/wm/desks/templates/saved_desk_util.h"
#include "chrome/browser/ash/accessibility/accessibility_manager.h"
#include "chrome/browser/ash/accessibility/dictation.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/ash/components/audio/sounds.h"
#include "content/public/browser/tts_controller.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
using ::ash::AccessibilityManager;
void SetAutomationManagerEnabled(content::BrowserContext* context,
bool enabled) {
DCHECK(context);
AutomationManagerAura* manager = AutomationManagerAura::GetInstance();
if (enabled) {
manager->Enable();
} else {
manager->Disable();
}
}
} // namespace
AccessibilityControllerClient::AccessibilityControllerClient() {
ash::AccessibilityController::Get()->SetClient(this);
}
AccessibilityControllerClient::~AccessibilityControllerClient() {
ash::AccessibilityController::Get()->SetClient(nullptr);
}
void AccessibilityControllerClient::TriggerAccessibilityAlert(
ash::AccessibilityAlert alert) {
Profile* profile = ProfileManager::GetActiveUserProfile();
if (!profile) {
return;
}
int msg = 0;
switch (alert) {
case ash::AccessibilityAlert::CAPS_ON:
msg = IDS_A11Y_ALERT_CAPS_ON;
break;
case ash::AccessibilityAlert::CAPS_OFF:
msg = IDS_A11Y_ALERT_CAPS_OFF;
break;
case ash::AccessibilityAlert::SCREEN_ON:
// Enable automation manager when alert is screen-on, as it is
// previously disabled by alert screen-off.
SetAutomationManagerEnabled(profile, true);
msg = IDS_A11Y_ALERT_SCREEN_ON;
break;
case ash::AccessibilityAlert::SCREEN_OFF:
msg = IDS_A11Y_ALERT_SCREEN_OFF;
break;
case ash::AccessibilityAlert::WINDOW_MOVED_TO_ANOTHER_DISPLAY:
msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_ANOTHER_DISPLAY;
break;
case ash::AccessibilityAlert::WINDOW_NEEDED:
msg = IDS_A11Y_ALERT_WINDOW_NEEDED;
break;
case ash::AccessibilityAlert::WINDOW_OVERVIEW_MODE_ENTERED:
msg = IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED;
break;
case ash::AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED:
msg = IDS_A11Y_ALERT_WORKSPACE_FULLSCREEN_STATE_ENTERED;
break;
case ash::AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_EXITED:
msg = IDS_A11Y_ALERT_WORKSPACE_FULLSCREEN_STATE_EXITED;
break;
case ash::AccessibilityAlert::SAVED_DESKS_MODE_ENTERED:
msg = ash::saved_desk_util::AreDesksTemplatesEnabled()
? IDS_A11Y_ALERT_SAVED_DESKS_LIBRARY_MODE_ENTERED
: IDS_A11Y_ALERT_SAVED_DESKS_SAVED_FOR_LATER_MODE_ENTERED;
break;
case ash::AccessibilityAlert::FASTER_SPLIT_SCREEN_SETUP:
msg = IDS_A11Y_ALERT_FASTER_SPLITSCREEN_TOAST;
break;
case ash::AccessibilityAlert::SNAP_GROUP_RESIZE_LEFT:
msg = IDS_A11Y_ALERT_SNAP_GROUP_RESIZE_LEFT;
break;
case ash::AccessibilityAlert::SNAP_GROUP_RESIZE_RIGHT:
msg = IDS_A11Y_ALERT_SNAP_GROUP_RESIZE_RIGHT;
break;
case ash::AccessibilityAlert::SNAP_GROUP_RESIZE_UP:
msg = IDS_A11Y_ALERT_SNAP_GROUP_RESIZE_UP;
break;
case ash::AccessibilityAlert::SNAP_GROUP_RESIZE_DOWN:
msg = IDS_A11Y_ALERT_SNAP_GROUP_RESIZE_DOWN;
break;
case ash::AccessibilityAlert::SNAP_GROUP_CREATION:
msg = IDS_A11Y_ALERT_SNAP_GROUP_CREATION;
break;
case ash::AccessibilityAlert::NONE:
msg = 0;
break;
}
if (msg) {
AutomationManagerAura::GetInstance()->HandleAlert(
l10n_util::GetStringUTF8(msg));
// After handling the alert, if the alert is screen-off, we should
// disable automation manager to handle any following a11y events.
if (alert == ash::AccessibilityAlert::SCREEN_OFF) {
SetAutomationManagerEnabled(profile, false);
}
}
}
void AccessibilityControllerClient::TriggerAccessibilityAlertWithMessage(
const std::string& message) {
Profile* profile = ProfileManager::GetActiveUserProfile();
if (!profile) {
return;
}
AutomationManagerAura::GetInstance()->HandleAlert(message);
}
void AccessibilityControllerClient::PlayEarcon(ash::Sound sound_key) {
AccessibilityManager::Get()->PlayEarcon(
sound_key, ash::PlaySoundOption::kOnlyIfSpokenFeedbackEnabled);
}
base::TimeDelta AccessibilityControllerClient::PlayShutdownSound() {
return AccessibilityManager::Get()->PlayShutdownSound();
}
void AccessibilityControllerClient::HandleAccessibilityGesture(
ax::mojom::Gesture gesture,
gfx::PointF location) {
AccessibilityManager::Get()->HandleAccessibilityGesture(gesture, location);
}
bool AccessibilityControllerClient::ToggleDictation() {
return AccessibilityManager::Get()->ToggleDictation();
}
void AccessibilityControllerClient::SilenceSpokenFeedback() {
content::TtsController::GetInstance()->Stop();
}
bool AccessibilityControllerClient::ShouldToggleSpokenFeedbackViaTouch() const {
return AccessibilityManager::Get()->ShouldToggleSpokenFeedbackViaTouch();
}
void AccessibilityControllerClient::PlaySpokenFeedbackToggleCountdown(
int tick_count) {
AccessibilityManager::Get()->PlaySpokenFeedbackToggleCountdown(tick_count);
}
void AccessibilityControllerClient::RequestSelectToSpeakStateChange() {
AccessibilityManager::Get()->RequestSelectToSpeakStateChange();
}
void AccessibilityControllerClient::RequestAutoclickScrollableBoundsForPoint(
const gfx::Point& point_in_screen) {
AccessibilityManager::Get()->RequestAutoclickScrollableBoundsForPoint(
point_in_screen);
}
void AccessibilityControllerClient::MagnifierBoundsChanged(
const gfx::Rect& bounds_in_screen) {
AccessibilityManager::Get()->MagnifierBoundsChanged(bounds_in_screen);
}
void AccessibilityControllerClient::OnSwitchAccessDisabled() {
AccessibilityManager::Get()->OnSwitchAccessDisabled();
}
void AccessibilityControllerClient::OnSelectToSpeakPanelAction(
ash::SelectToSpeakPanelAction action,
double value) {
AccessibilityManager::Get()->OnSelectToSpeakPanelAction(action, value);
}
void AccessibilityControllerClient::SetA11yOverrideWindow(
aura::Window* a11y_override_window) {
AutomationManagerAura::GetInstance()->SetA11yOverrideWindow(
a11y_override_window);
}
std::string AccessibilityControllerClient::GetDictationDefaultLocale(
bool new_user) {
return ash::Dictation::DetermineDefaultSupportedLocale(
ProfileManager::GetActiveUserProfile(), new_user);
}
void AccessibilityControllerClient::SendFaceGazeDisableDialogResultToSettings(
bool accepted) {
AccessibilityManager::Get()->SendFaceGazeDisableDialogResultToSettings(
accepted);
}
|