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

Unified Diff: ash/system/audio/tray_volume.cc

Issue 10830027: Implement new slider control and disable the volume control when audio is muted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move enum from .h to .cc. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/audio/tray_volume.h ('k') | ash/system/tray/tray_views.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/audio/tray_volume.cc
diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc
index f395be6d67e46a6f932f76363ffcdfac71e25b9b..0d63a8e50d8ca0508ccc51608040b0058ae08dab 100644
--- a/ash/system/audio/tray_volume.cc
+++ b/ash/system/audio/tray_volume.cc
@@ -63,8 +63,8 @@ class VolumeButton : public views::ToggleImageButton {
float level = delegate->GetVolumeLevel();
int image_index = delegate->IsAudioMuted() ?
0 : (level == 1.0 ?
- kVolumeLevels : std::ceil(level * (kVolumeLevels - 1)));
-
+ kVolumeLevels :
+ std::max(1, int(std::ceil(level * (kVolumeLevels - 1)))));
if (image_index != image_index_) {
gfx::Rect region(0, image_index * kVolumeImageHeight,
kVolumeImageWidth, kVolumeImageHeight);
@@ -110,6 +110,26 @@ class MuteButton : public ash::internal::TrayBarButtonWithTitle {
DISALLOW_COPY_AND_ASSIGN(MuteButton);
};
+class VolumeSlider : public views::Slider {
+ public:
+ explicit VolumeSlider(views::SliderListener* listener)
+ : views::Slider(listener, views::Slider::HORIZONTAL) {
+ set_focus_border_color(kFocusBorderColor);
+ SetValue(ash::Shell::GetInstance()->tray_delegate()->GetVolumeLevel());
+ SetAccessibleName(
+ ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
+ IDS_ASH_STATUS_TRAY_VOLUME));
+ Update();
+ }
+ virtual ~VolumeSlider() {}
+
+ void Update() {
+ UpdateState(!ash::Shell::GetInstance()->tray_delegate()->IsAudioMuted());
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(VolumeSlider);
+};
+
class VolumeView : public views::View,
public views::ButtonListener,
public views::SliderListener {
@@ -124,20 +144,18 @@ class VolumeView : public views::View,
mute_ = new MuteButton(this);
AddChildView(mute_);
- ash::SystemTrayDelegate* delegate =
- ash::Shell::GetInstance()->tray_delegate();
- slider_ = new views::Slider(this, views::Slider::HORIZONTAL);
- slider_->set_focus_border_color(kFocusBorderColor);
- slider_->SetValue(
- delegate->IsAudioMuted() ? 0.0 : delegate->GetVolumeLevel());
- slider_->SetAccessibleName(
- ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
- IDS_ASH_STATUS_TRAY_VOLUME));
+ slider_ = new VolumeSlider(this);
AddChildView(slider_);
}
virtual ~VolumeView() {}
+ void Update() {
+ icon_->Update();
+ mute_->Update();
+ slider_->Update();
+ }
+
void SetVolumeLevel(float percent) {
// The change in volume will be reflected via accessibility system events,
// so we prevent the UI event from being sent here.
@@ -146,8 +164,7 @@ class VolumeView : public views::View,
// It is possible that the volume was (un)muted, but the actual volume level
// did not change. In that case, setting the value of the slider won't
// trigger an update. So explicitly trigger an update.
- icon_->Update();
- mute_->Update();
+ Update();
slider_->set_enable_accessibility_events(true);
}
@@ -182,7 +199,7 @@ class VolumeView : public views::View,
VolumeButton* icon_;
MuteButton* mute_;
- views::Slider* slider_;
+ VolumeSlider* slider_;
DISALLOW_COPY_AND_ASSIGN(VolumeView);
};
@@ -201,7 +218,7 @@ TrayVolume::~TrayVolume() {
bool TrayVolume::GetInitialVisibility() {
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate();
- return delegate->GetVolumeLevel() == 0.0 || delegate->IsAudioMuted();
+ return delegate->IsAudioMuted();
}
views::View* TrayVolume::CreateDefaultView(user::LoginStatus status) {
@@ -240,5 +257,13 @@ void TrayVolume::OnVolumeChanged(float percent) {
PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
}
+void TrayVolume::OnMuteToggled() {
+ if (tray_view())
+ tray_view()->SetVisible(GetInitialVisibility());
+
+ if (volume_view_)
+ volume_view_->Update();
+}
+
} // namespace internal
} // namespace ash
« no previous file with comments | « ash/system/audio/tray_volume.h ('k') | ash/system/tray/tray_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698