1 // Copyright 2014 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.
5 #include "ash/ash_touch_exploration_manager_chromeos.h"
7 #include "ash/accessibility_delegate.h"
8 #include "ash/audio/sounds.h"
9 #include "ash/root_window_controller.h"
10 #include "ash/shell.h"
11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/command_line.h"
13 #include "chromeos/audio/chromeos_sounds.h"
14 #include "chromeos/audio/cras_audio_handler.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "ui/chromeos/touch_exploration_controller.h"
20 AshTouchExplorationManager::AshTouchExplorationManager(
21 RootWindowController
* root_window_controller
)
22 : root_window_controller_(root_window_controller
),
23 audio_handler_(chromeos::CrasAudioHandler::Get()) {
24 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this);
25 UpdateTouchExplorationState();
28 AshTouchExplorationManager::~AshTouchExplorationManager() {
29 SystemTrayNotifier
* system_tray_notifier
=
30 Shell::GetInstance()->system_tray_notifier();
31 if (system_tray_notifier
)
32 system_tray_notifier
->RemoveAccessibilityObserver(this);
35 void AshTouchExplorationManager::OnAccessibilityModeChanged(
36 AccessibilityNotificationVisibility notify
) {
37 UpdateTouchExplorationState();
40 void AshTouchExplorationManager::PlayVolumeAdjustSound() {
41 if (!VolumeAdjustSoundEnabled())
43 if ((!audio_handler_
->IsOutputMuted()) ||
44 !(audio_handler_
->GetOutputVolumePercent() == 100))
45 PlaySystemSoundIfSpokenFeedback(chromeos::SOUND_VOLUME_ADJUST
);
48 void AshTouchExplorationManager::SetOutputLevel(int volume
) {
50 if (audio_handler_
->IsOutputMuted()) {
51 audio_handler_
->SetOutputMute(false);
54 audio_handler_
->SetOutputVolumePercent(volume
);
55 // Avoid negative volume.
56 if (audio_handler_
->IsOutputVolumeBelowDefaultMuteLevel())
57 audio_handler_
->SetOutputMute(true);
60 void AshTouchExplorationManager::UpdateTouchExplorationState() {
61 AccessibilityDelegate
* delegate
=
62 Shell::GetInstance()->accessibility_delegate();
63 bool enabled
= delegate
->IsSpokenFeedbackEnabled();
65 if (enabled
&& !touch_exploration_controller_
.get()) {
66 touch_exploration_controller_
.reset(new ui::TouchExplorationController(
67 root_window_controller_
->GetRootWindow(), this));
68 } else if (!enabled
) {
69 touch_exploration_controller_
.reset();
73 bool AshTouchExplorationManager::VolumeAdjustSoundEnabled() {
74 return !CommandLine::ForCurrentProcess()->HasSwitch(
75 chromeos::switches::kDisableVolumeAdjustSound
);