OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" | 5 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/audio/sounds.h" |
| 9 #include "base/command_line.h" |
8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/extensions/api/system_private/system_private_api.h" | 11 #include "chrome/browser/extensions/api/system_private/system_private_api.h" |
| 12 #include "chromeos/audio/chromeos_sounds.h" |
| 13 #include "chromeos/chromeos_switches.h" |
10 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
| 15 #include "grit/browser_resources.h" |
| 16 #include "media/audio/sounds/sounds_manager.h" |
| 17 #include "ui/base/resource/resource_bundle.h" |
11 | 18 |
12 using chromeos::CrasAudioHandler; | 19 using chromeos::CrasAudioHandler; |
13 | 20 |
14 namespace { | 21 namespace { |
15 | 22 |
16 // Percent by which the volume should be changed when a volume key is pressed. | 23 // Percent by which the volume should be changed when a volume key is pressed. |
17 const double kStepPercentage = 4.0; | 24 const double kStepPercentage = 4.0; |
18 | 25 |
| 26 void PlayVolumeAdjustSound() { |
| 27 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 28 chromeos::switches::kEnableVolumeAdjustSound)) { |
| 29 ash::PlaySystemSound(chromeos::SOUND_VOLUME_ADJUST, |
| 30 true /* honor_spoken_feedback */); |
| 31 } |
| 32 } |
| 33 |
19 } // namespace | 34 } // namespace |
20 | 35 |
21 VolumeController::VolumeController() { | 36 VolumeController::VolumeController() { |
22 CrasAudioHandler::Get()->AddAudioObserver(this); | 37 CrasAudioHandler::Get()->AddAudioObserver(this); |
| 38 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 39 media::SoundsManager::Get()->Initialize( |
| 40 chromeos::SOUND_VOLUME_ADJUST, |
| 41 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); |
23 } | 42 } |
24 | 43 |
25 VolumeController::~VolumeController() { | 44 VolumeController::~VolumeController() { |
26 if (CrasAudioHandler::IsInitialized()) | 45 if (CrasAudioHandler::IsInitialized()) |
27 CrasAudioHandler::Get()->RemoveAudioObserver(this); | 46 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
28 } | 47 } |
29 | 48 |
30 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { | 49 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { |
31 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) | 50 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) |
32 content::RecordAction(base::UserMetricsAction("Accel_VolumeMute_F8")); | 51 content::RecordAction(base::UserMetricsAction("Accel_VolumeMute_F8")); |
33 | 52 |
34 CrasAudioHandler::Get()->SetOutputMute(true); | 53 CrasAudioHandler::Get()->SetOutputMute(true); |
35 return true; | 54 return true; |
36 } | 55 } |
37 | 56 |
38 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { | 57 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { |
39 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) | 58 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) |
40 content::RecordAction(base::UserMetricsAction("Accel_VolumeDown_F9")); | 59 content::RecordAction(base::UserMetricsAction("Accel_VolumeDown_F9")); |
41 | 60 |
42 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 61 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
43 if (audio_handler->IsOutputMuted()) { | 62 if (audio_handler->IsOutputMuted()) { |
44 audio_handler->SetOutputVolumePercent(0); | 63 audio_handler->SetOutputVolumePercent(0); |
45 } else { | 64 } else { |
46 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | 65 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); |
47 if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel()) | 66 if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel()) |
48 audio_handler->SetOutputMute(true); | 67 audio_handler->SetOutputMute(true); |
| 68 else |
| 69 PlayVolumeAdjustSound(); |
49 } | 70 } |
50 return true; | 71 return true; |
51 } | 72 } |
52 | 73 |
53 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { | 74 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { |
54 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) | 75 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) |
55 content::RecordAction(base::UserMetricsAction("Accel_VolumeUp_F10")); | 76 content::RecordAction(base::UserMetricsAction("Accel_VolumeUp_F10")); |
56 | 77 |
57 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 78 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| 79 bool play_sound = false; |
58 if (audio_handler->IsOutputMuted()) { | 80 if (audio_handler->IsOutputMuted()) { |
59 audio_handler->SetOutputMute(false); | 81 audio_handler->SetOutputMute(false); |
60 audio_handler->AdjustOutputVolumeToAudibleLevel(); | 82 audio_handler->AdjustOutputVolumeToAudibleLevel(); |
| 83 play_sound = true; |
61 } else { | 84 } else { |
| 85 play_sound = audio_handler->GetOutputVolumePercent() != 100; |
62 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | 86 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); |
63 } | 87 } |
64 | 88 |
| 89 if (play_sound) |
| 90 PlayVolumeAdjustSound(); |
65 return true; | 91 return true; |
66 } | 92 } |
67 | 93 |
68 void VolumeController::OnOutputVolumeChanged() { | 94 void VolumeController::OnOutputVolumeChanged() { |
69 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 95 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
70 extensions::DispatchVolumeChangedEvent( | 96 extensions::DispatchVolumeChangedEvent( |
71 audio_handler->GetOutputVolumePercent(), | 97 audio_handler->GetOutputVolumePercent(), |
72 audio_handler->IsOutputMuted()); | 98 audio_handler->IsOutputMuted()); |
73 } | 99 } |
74 | 100 |
75 void VolumeController::OnOutputMuteChanged() { | 101 void VolumeController::OnOutputMuteChanged() { |
76 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 102 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
77 extensions::DispatchVolumeChangedEvent( | 103 extensions::DispatchVolumeChangedEvent( |
78 audio_handler->GetOutputVolumePercent(), | 104 audio_handler->GetOutputVolumePercent(), |
79 audio_handler->IsOutputMuted()); | 105 audio_handler->IsOutputMuted()); |
80 } | 106 } |
OLD | NEW |