Home | History | Annotate | Download | only in ash
      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 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();
     26 }
     27 
     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);
     33 }
     34 
     35 void AshTouchExplorationManager::OnAccessibilityModeChanged(
     36     AccessibilityNotificationVisibility notify) {
     37   UpdateTouchExplorationState();
     38 }
     39 
     40 void AshTouchExplorationManager::SetOutputLevel(int volume) {
     41   if (volume > 0) {
     42     if (audio_handler_->IsOutputMuted()) {
     43       audio_handler_->SetOutputMute(false);
     44     }
     45   }
     46   audio_handler_->SetOutputVolumePercent(volume);
     47   // Avoid negative volume.
     48   if (audio_handler_->IsOutputVolumeBelowDefaultMuteLevel())
     49     audio_handler_->SetOutputMute(true);
     50 }
     51 
     52 void AshTouchExplorationManager::SilenceSpokenFeedback() {
     53   AccessibilityDelegate* delegate =
     54     Shell::GetInstance()->accessibility_delegate();
     55   if (!delegate->IsSpokenFeedbackEnabled())
     56     return;
     57   delegate->SilenceSpokenFeedback();
     58 }
     59 
     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);
     66 }
     67 
     68 void AshTouchExplorationManager::PlayPassthroughEarcon() {
     69   Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
     70       chromeos::SOUND_PASSTHROUGH);
     71 }
     72 
     73 void AshTouchExplorationManager::PlayExitScreenEarcon() {
     74   Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
     75       chromeos::SOUND_EXIT_SCREEN);
     76 }
     77 
     78 void AshTouchExplorationManager::PlayEnterScreenEarcon() {
     79   Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
     80       chromeos::SOUND_ENTER_SCREEN);
     81 }
     82 
     83 void AshTouchExplorationManager::UpdateTouchExplorationState() {
     84   AccessibilityDelegate* delegate =
     85       Shell::GetInstance()->accessibility_delegate();
     86   bool enabled = delegate->IsSpokenFeedbackEnabled();
     87 
     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();
     93   }
     94 }
     95 
     96 bool AshTouchExplorationManager::VolumeAdjustSoundEnabled() {
     97   return !CommandLine::ForCurrentProcess()->HasSwitch(
     98       chromeos::switches::kDisableVolumeAdjustSound);
     99 }
    100 
    101 }  // namespace ash
    102