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/views/ash/volume_controller_chromeos.h" | 5 #include "chrome/browser/ui/views/ash/volume_controller_chromeos.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/chromeos/audio/audio_handler.h" | 8 #include "chrome/browser/chromeos/audio/audio_handler.h" |
9 #include "chrome/browser/extensions/system/system_api.h" | 9 #include "chrome/browser/extensions/system/system_api.h" |
10 #include "content/public/browser/user_metrics.h" | 10 #include "content/public/browser/user_metrics.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Percent by which the volume should be changed when a volume key is pressed. | 14 // Percent by which the volume should be changed when a volume key is pressed. |
15 const double kStepPercentage = 4.0; | 15 const double kStepPercentage = 4.0; |
16 | 16 |
| 17 // Percent to which the volume should be set when the "volume up" key is pressed |
| 18 // while we're muted and have the volume set to 0. See |
| 19 // http://crosbug.com/13618. |
| 20 const double kVolumePercentOnVolumeUpWhileMuted = 25.0; |
| 21 |
17 } // namespace | 22 } // namespace |
18 | 23 |
19 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { | 24 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { |
20 if (accelerator.key_code() == ui::VKEY_F8) | 25 if (accelerator.key_code() == ui::VKEY_F8) |
21 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); | 26 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); |
22 | 27 |
23 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 28 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
24 | 29 |
25 // Always muting (and not toggling) as per final decision on | 30 // Always muting (and not toggling) as per final decision on |
26 // http://crosbug.com/3751 | 31 // http://crosbug.com/3751 |
(...skipping 19 matching lines...) Expand all Loading... |
46 return true; | 51 return true; |
47 } | 52 } |
48 | 53 |
49 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { | 54 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { |
50 if (accelerator.key_code() == ui::VKEY_F10) | 55 if (accelerator.key_code() == ui::VKEY_F10) |
51 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); | 56 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); |
52 | 57 |
53 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 58 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
54 if (audio_handler->IsMuted()) { | 59 if (audio_handler->IsMuted()) { |
55 audio_handler->SetMuted(false); | 60 audio_handler->SetMuted(false); |
56 // If volume percent is still 0.0 after reset the mute status, it means that | 61 if (audio_handler->GetVolumePercent() <= 0.1) // float comparison |
57 // the mute status was done by VolumeDown, so we need to increase | 62 audio_handler->SetVolumePercent(kVolumePercentOnVolumeUpWhileMuted); |
58 // the volume as usual. | |
59 if (audio_handler->GetVolumePercent() == 0.0) | |
60 audio_handler->AdjustVolumeByPercent(kStepPercentage); | |
61 } else { | 63 } else { |
62 audio_handler->AdjustVolumeByPercent(kStepPercentage); | 64 audio_handler->AdjustVolumeByPercent(kStepPercentage); |
63 } | 65 } |
64 | 66 |
65 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), | 67 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), |
66 audio_handler->IsMuted()); | 68 audio_handler->IsMuted()); |
67 return true; | 69 return true; |
68 } | 70 } |
69 | 71 |
70 void VolumeController::SetVolumePercent(double percent) { | 72 void VolumeController::SetVolumePercent(double percent) { |
71 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 73 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
72 audio_handler->SetVolumePercent(percent); | 74 audio_handler->SetVolumePercent(percent); |
73 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), | 75 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), |
74 audio_handler->IsMuted()); | 76 audio_handler->IsMuted()); |
75 } | 77 } |
OLD | NEW |