diff options
author | jennyz@google.com <jennyz@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 18:31:50 +0000 |
---|---|---|
committer | jennyz@google.com <jennyz@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 18:31:50 +0000 |
commit | 80fae6304b5a162e09fee1333adefd894ebb287f (patch) | |
tree | 961825421f986ea2c92331fd3b264a7d8d226770 /ash/system/audio | |
parent | 9840d2cf96a2d9873365f4a89b3fd3542730a1d4 (diff) | |
download | chromium_src-80fae6304b5a162e09fee1333adefd894ebb287f.zip chromium_src-80fae6304b5a162e09fee1333adefd894ebb287f.tar.gz chromium_src-80fae6304b5a162e09fee1333adefd894ebb287f.tar.bz2 |
Implement new slider control and disable the volume control when audio is muted.
Horizontal slider is implemented with image resources, and it changes UI based the on/off state.
Vertical slider is kept in the old way, since I don't have the UI resources for drawing the vertical slider. I wonder if I should remove the vertical slider bar supporting code, or leave it as it which is what I choose to do currently.
BUG=124097
TEST=Audio and brightness slider control should be in new UI, and audio slider bar should dim when muted.
TBR=oshima@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10830027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148778 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system/audio')
-rw-r--r-- | ash/system/audio/audio_observer.h | 1 | ||||
-rw-r--r-- | ash/system/audio/tray_volume.cc | 55 | ||||
-rw-r--r-- | ash/system/audio/tray_volume.h | 1 |
3 files changed, 42 insertions, 15 deletions
diff --git a/ash/system/audio/audio_observer.h b/ash/system/audio/audio_observer.h index ebf5adb..d0ff405 100644 --- a/ash/system/audio/audio_observer.h +++ b/ash/system/audio/audio_observer.h @@ -14,6 +14,7 @@ class ASH_EXPORT AudioObserver { virtual ~AudioObserver() {} virtual void OnVolumeChanged(float percent) = 0; + virtual void OnMuteToggled() = 0; }; } // namespace ash diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc index f395be6..0d63a8e 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 diff --git a/ash/system/audio/tray_volume.h b/ash/system/audio/tray_volume.h index 8dd71dc..2a0d06b 100644 --- a/ash/system/audio/tray_volume.h +++ b/ash/system/audio/tray_volume.h @@ -33,6 +33,7 @@ class TrayVolume : public TrayImageItem, // Overridden from AudioObserver. virtual void OnVolumeChanged(float percent) OVERRIDE; + virtual void OnMuteToggled() OVERRIDE; tray::VolumeView* volume_view_; |