OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ash/ash_touch_exploration_manager_chromeos.h" |
| 6 |
| 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" |
| 17 |
| 18 namespace ash { |
| 19 |
| 20 AshTouchExplorationManagerChromeOS::AshTouchExplorationManagerChromeOS( |
| 21 RootWindowController* root_window_controller) |
| 22 : root_window_controller_(root_window_controller), |
| 23 audio_handler_(chromeos::CrasAudioHandler::Get()) { |
| 24 Shell::GetInstance()->system_tray_notifier()-> |
| 25 AddAccessibilityObserver(this); |
| 26 UpdateTouchExplorationState(); |
| 27 } |
| 28 |
| 29 AshTouchExplorationManagerChromeOS::~AshTouchExplorationManagerChromeOS() { |
| 30 SystemTrayNotifier* system_tray_notifier = |
| 31 Shell::GetInstance()->system_tray_notifier(); |
| 32 if (system_tray_notifier) |
| 33 system_tray_notifier->RemoveAccessibilityObserver(this); |
| 34 } |
| 35 |
| 36 void AshTouchExplorationManagerChromeOS::OnAccessibilityModeChanged( |
| 37 AccessibilityNotificationVisibility notify) { |
| 38 UpdateTouchExplorationState(); |
| 39 } |
| 40 |
| 41 void AshTouchExplorationManagerChromeOS::PlayVolumeAdjustSound() { |
| 42 if (!VolumeAdjustSoundEnabled()) |
| 43 return; |
| 44 if ((!audio_handler_->IsOutputMuted()) || |
| 45 !(audio_handler_->GetOutputVolumePercent() == 100)) |
| 46 PlaySystemSoundIfSpokenFeedback(chromeos::SOUND_VOLUME_ADJUST); |
| 47 } |
| 48 |
| 49 void AshTouchExplorationManagerChromeOS::SetOutputLevel(float volume) { |
| 50 if (volume > 0) { |
| 51 if (audio_handler_->IsOutputMuted()) { |
| 52 audio_handler_->SetOutputMute(false); |
| 53 } |
| 54 } |
| 55 audio_handler_->SetOutputVolumePercent(volume); |
| 56 // Avoid negative volume. |
| 57 if (audio_handler_->IsOutputVolumeBelowDefaultMuteLevel()) |
| 58 audio_handler_->SetOutputMute(true); |
| 59 } |
| 60 |
| 61 void AshTouchExplorationManagerChromeOS::UpdateTouchExplorationState() { |
| 62 AccessibilityDelegate* delegate = |
| 63 Shell::GetInstance()->accessibility_delegate(); |
| 64 bool enabled = delegate->IsSpokenFeedbackEnabled(); |
| 65 |
| 66 if (enabled && !touch_exploration_controller_.get()) { |
| 67 touch_exploration_controller_.reset(new ui::TouchExplorationController( |
| 68 root_window_controller_->GetRootWindow(), this)); |
| 69 } else if (!enabled) { |
| 70 touch_exploration_controller_.reset(); |
| 71 } |
| 72 } |
| 73 |
| 74 bool AshTouchExplorationManagerChromeOS::VolumeAdjustSoundEnabled() { |
| 75 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 76 chromeos::switches::kDisableVolumeAdjustSound); |
| 77 } |
| 78 |
| 79 } // namespace ash |
OLD | NEW |