Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/browser/ui/views/ash/volume_controller_chromeos.cc

Issue 10411028: Fix the volume controlling behaviors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
22 } // namespace 17 } // namespace
23 18
24 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { 19 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) {
25 if (accelerator.key_code() == ui::VKEY_F8) 20 if (accelerator.key_code() == ui::VKEY_F8)
26 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); 21 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8"));
27 22
28 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 23 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
29 24
30 // Always muting (and not toggling) as per final decision on 25 // Always muting (and not toggling) as per final decision on
31 // http://crosbug.com/3751 26 // http://crosbug.com/3751
(...skipping 19 matching lines...) Expand all
51 return true; 46 return true;
52 } 47 }
53 48
54 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { 49 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) {
55 if (accelerator.key_code() == ui::VKEY_F10) 50 if (accelerator.key_code() == ui::VKEY_F10)
56 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); 51 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10"));
57 52
58 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 53 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
59 if (audio_handler->IsMuted()) { 54 if (audio_handler->IsMuted()) {
60 audio_handler->SetMuted(false); 55 audio_handler->SetMuted(false);
61 if (audio_handler->GetVolumePercent() <= 0.1) // float comparison 56 // If volume percent is still 0.0 after reset the mute status, it means that
62 audio_handler->SetVolumePercent(kVolumePercentOnVolumeUpWhileMuted); 57 // the mute status was done by VolumeDown, so we need to increase
58 // the volume as usual.
59 if (audio_handler->GetVolumePercent() == 0.0)
60 audio_handler->AdjustVolumeByPercent(kStepPercentage);
63 } else { 61 } else {
64 audio_handler->AdjustVolumeByPercent(kStepPercentage); 62 audio_handler->AdjustVolumeByPercent(kStepPercentage);
65 } 63 }
66 64
67 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), 65 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(),
68 audio_handler->IsMuted()); 66 audio_handler->IsMuted());
69 return true; 67 return true;
70 } 68 }
71 69
72 void VolumeController::SetVolumePercent(double percent) { 70 void VolumeController::SetVolumePercent(double percent) {
73 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 71 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
74 if (audio_handler->IsMuted()) { 72 if (audio_handler->IsMuted()) {
75 audio_handler->SetMuted(false); 73 audio_handler->SetMuted(false);
76 } 74 }
77 audio_handler->SetVolumePercent(percent); 75 audio_handler->SetVolumePercent(percent);
78 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), 76 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(),
79 audio_handler->IsMuted()); 77 audio_handler->IsMuted());
80 } 78 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/audio/audio_handler.cc ('k') | chrome/browser/ui/views/ash/volume_controller_chromeos_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698