Roll src/third_party/WebKit f103b33:23b201b (svn 202622:202623)
[chromium-blink-merge.git] / ash / ash_touch_exploration_manager_chromeos.cc
blobca5fa9480dadaf81c0ea3a68c607ec8bb0ef637a
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"
18 namespace ash {
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 ui::AccessibilityNotificationVisibility notify) {
37 UpdateTouchExplorationState();
40 void AshTouchExplorationManager::SetOutputLevel(int volume) {
41 if (volume > 0) {
42 if (audio_handler_->IsOutputMuted()) {
43 audio_handler_->SetOutputMute(false);
46 audio_handler_->SetOutputVolumePercent(volume);
47 // Avoid negative volume.
48 if (audio_handler_->IsOutputVolumeBelowDefaultMuteLevel())
49 audio_handler_->SetOutputMute(true);
52 void AshTouchExplorationManager::SilenceSpokenFeedback() {
53 AccessibilityDelegate* delegate =
54 Shell::GetInstance()->accessibility_delegate();
55 if (!delegate->IsSpokenFeedbackEnabled())
56 return;
57 delegate->SilenceSpokenFeedback();
60 void AshTouchExplorationManager::PlayVolumeAdjustEarcon() {
61 if (!VolumeAdjustSoundEnabled())
62 return;
63 if (!audio_handler_->IsOutputMuted() &&
64 audio_handler_->GetOutputVolumePercent() != 100)
65 PlaySystemSoundIfSpokenFeedback(chromeos::SOUND_VOLUME_ADJUST);
68 void AshTouchExplorationManager::PlayPassthroughEarcon() {
69 Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
70 chromeos::SOUND_PASSTHROUGH);
73 void AshTouchExplorationManager::PlayExitScreenEarcon() {
74 Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
75 chromeos::SOUND_EXIT_SCREEN);
78 void AshTouchExplorationManager::PlayEnterScreenEarcon() {
79 Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
80 chromeos::SOUND_ENTER_SCREEN);
83 void AshTouchExplorationManager::UpdateTouchExplorationState() {
84 AccessibilityDelegate* delegate =
85 Shell::GetInstance()->accessibility_delegate();
86 bool enabled = delegate->IsSpokenFeedbackEnabled();
88 if (enabled && !touch_exploration_controller_.get()) {
89 touch_exploration_controller_.reset(new ui::TouchExplorationController(
90 root_window_controller_->GetRootWindow(), this));
91 } else if (!enabled) {
92 touch_exploration_controller_.reset();
96 bool AshTouchExplorationManager::VolumeAdjustSoundEnabled() {
97 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
98 chromeos::switches::kDisableVolumeAdjustSound);
101 } // namespace ash