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 "base/command_line.h" | |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/extensions/api/system_private/system_private_api.h" | 10 #include "chrome/browser/extensions/api/system_private/system_private_api.h" |
11 #include "chromeos/audio/chromeos_sounds.h" | |
12 #include "chromeos/chromeos_switches.h" | |
10 #include "content/public/browser/user_metrics.h" | 13 #include "content/public/browser/user_metrics.h" |
14 #include "grit/browser_resources.h" | |
15 #include "media/audio/sounds/sounds_manager.h" | |
16 #include "ui/base/resource/resource_bundle.h" | |
11 | 17 |
12 using chromeos::CrasAudioHandler; | 18 using chromeos::CrasAudioHandler; |
13 | 19 |
14 namespace { | 20 namespace { |
15 | 21 |
16 // Percent by which the volume should be changed when a volume key is pressed. | 22 // Percent by which the volume should be changed when a volume key is pressed. |
17 const double kStepPercentage = 4.0; | 23 const double kStepPercentage = 4.0; |
18 | 24 |
25 void PlayVolumeAdjustSound() { | |
26 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
27 chromeos::switches::kEnableVolumeAdjustSound)) { | |
28 media::SoundsManager::Get()->Play(chromeos::SOUND_VOLUME_ADJUST); | |
29 } | |
30 } | |
31 | |
19 } // namespace | 32 } // namespace |
20 | 33 |
21 VolumeController::VolumeController() { | 34 VolumeController::VolumeController() { |
22 CrasAudioHandler::Get()->AddAudioObserver(this); | 35 CrasAudioHandler::Get()->AddAudioObserver(this); |
36 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
37 media::SoundsManager::Get()->Initialize( | |
38 chromeos::SOUND_VOLUME_ADJUST, | |
39 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); | |
23 } | 40 } |
24 | 41 |
25 VolumeController::~VolumeController() { | 42 VolumeController::~VolumeController() { |
26 if (CrasAudioHandler::IsInitialized()) | 43 if (CrasAudioHandler::IsInitialized()) |
27 CrasAudioHandler::Get()->RemoveAudioObserver(this); | 44 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
28 } | 45 } |
29 | 46 |
30 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { | 47 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { |
31 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) | 48 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) |
32 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); | 49 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); |
33 | 50 |
34 CrasAudioHandler::Get()->SetOutputMute(true); | 51 CrasAudioHandler::Get()->SetOutputMute(true); |
35 return true; | 52 return true; |
36 } | 53 } |
37 | 54 |
38 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { | 55 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { |
39 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) | 56 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) |
40 content::RecordAction(content::UserMetricsAction("Accel_VolumeDown_F9")); | 57 content::RecordAction(content::UserMetricsAction("Accel_VolumeDown_F9")); |
41 | 58 |
42 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 59 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
43 if (audio_handler->IsOutputMuted()) { | 60 if (audio_handler->IsOutputMuted()) { |
44 audio_handler->SetOutputVolumePercent(0); | 61 audio_handler->SetOutputVolumePercent(0); |
45 } else { | 62 } else { |
46 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | 63 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); |
47 if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel()) | 64 if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel()) |
48 audio_handler->SetOutputMute(true); | 65 audio_handler->SetOutputMute(true); |
49 } | 66 } |
67 | |
68 PlayVolumeAdjustSound(); | |
DaleCurtis
2014/01/02 20:11:17
Generally these stop playing when volume reaches t
ygorshenin1
2014/01/09 19:26:57
Done.
| |
50 return true; | 69 return true; |
51 } | 70 } |
52 | 71 |
53 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { | 72 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { |
54 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) | 73 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) |
55 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); | 74 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); |
56 | 75 |
57 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 76 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
58 if (audio_handler->IsOutputMuted()) { | 77 if (audio_handler->IsOutputMuted()) { |
59 audio_handler->SetOutputMute(false); | 78 audio_handler->SetOutputMute(false); |
60 audio_handler->AdjustOutputVolumeToAudibleLevel(); | 79 audio_handler->AdjustOutputVolumeToAudibleLevel(); |
61 } else { | 80 } else { |
62 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | 81 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); |
63 } | 82 } |
64 | 83 |
84 PlayVolumeAdjustSound(); | |
DaleCurtis
2014/01/02 20:11:17
Ditto, stop at 100% ?
ygorshenin1
2014/01/09 19:26:57
Done.
| |
65 return true; | 85 return true; |
66 } | 86 } |
67 | 87 |
68 void VolumeController::OnOutputVolumeChanged() { | 88 void VolumeController::OnOutputVolumeChanged() { |
69 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 89 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
70 extensions::DispatchVolumeChangedEvent( | 90 extensions::DispatchVolumeChangedEvent( |
71 audio_handler->GetOutputVolumePercent(), | 91 audio_handler->GetOutputVolumePercent(), |
72 audio_handler->IsOutputMuted()); | 92 audio_handler->IsOutputMuted()); |
73 } | 93 } |
74 | 94 |
75 void VolumeController::OnOutputMuteChanged() { | 95 void VolumeController::OnOutputMuteChanged() { |
76 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 96 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
77 extensions::DispatchVolumeChangedEvent( | 97 extensions::DispatchVolumeChangedEvent( |
78 audio_handler->GetOutputVolumePercent(), | 98 audio_handler->GetOutputVolumePercent(), |
79 audio_handler->IsOutputMuted()); | 99 audio_handler->IsOutputMuted()); |
80 } | 100 } |
OLD | NEW |