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

Side by Side 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, 4 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
« no previous file with comments | « ash/system/audio/tray_volume.h ('k') | ash/system/tray/tray_views.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/system/audio/tray_volume.h" 5 #include "ash/system/audio/tray_volume.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 virtual ~VolumeButton() {} 58 virtual ~VolumeButton() {}
59 59
60 void Update() { 60 void Update() {
61 ash::SystemTrayDelegate* delegate = 61 ash::SystemTrayDelegate* delegate =
62 ash::Shell::GetInstance()->tray_delegate(); 62 ash::Shell::GetInstance()->tray_delegate();
63 float level = delegate->GetVolumeLevel(); 63 float level = delegate->GetVolumeLevel();
64 int image_index = delegate->IsAudioMuted() ? 64 int image_index = delegate->IsAudioMuted() ?
65 0 : (level == 1.0 ? 65 0 : (level == 1.0 ?
66 kVolumeLevels : std::ceil(level * (kVolumeLevels - 1))); 66 kVolumeLevels :
67 67 std::max(1, int(std::ceil(level * (kVolumeLevels - 1)))));
68 if (image_index != image_index_) { 68 if (image_index != image_index_) {
69 gfx::Rect region(0, image_index * kVolumeImageHeight, 69 gfx::Rect region(0, image_index * kVolumeImageHeight,
70 kVolumeImageWidth, kVolumeImageHeight); 70 kVolumeImageWidth, kVolumeImageHeight);
71 gfx::ImageSkia image_skia = gfx::ImageSkiaOperations::ExtractSubset( 71 gfx::ImageSkia image_skia = gfx::ImageSkiaOperations::ExtractSubset(
72 *(image_.ToImageSkia()), region); 72 *(image_.ToImageSkia()), region);
73 SetImage(views::CustomButton::BS_NORMAL, &image_skia); 73 SetImage(views::CustomButton::BS_NORMAL, &image_skia);
74 image_index_ = image_index; 74 image_index_ = image_index;
75 } 75 }
76 SchedulePaint(); 76 SchedulePaint();
77 } 77 }
(...skipping 25 matching lines...) Expand all
103 void Update() { 103 void Update() {
104 ash::SystemTrayDelegate* delegate = 104 ash::SystemTrayDelegate* delegate =
105 ash::Shell::GetInstance()->tray_delegate(); 105 ash::Shell::GetInstance()->tray_delegate();
106 UpdateButton(delegate->IsAudioMuted()); 106 UpdateButton(delegate->IsAudioMuted());
107 SchedulePaint(); 107 SchedulePaint();
108 } 108 }
109 109
110 DISALLOW_COPY_AND_ASSIGN(MuteButton); 110 DISALLOW_COPY_AND_ASSIGN(MuteButton);
111 }; 111 };
112 112
113 class VolumeSlider : public views::Slider {
114 public:
115 explicit VolumeSlider(views::SliderListener* listener)
116 : views::Slider(listener, views::Slider::HORIZONTAL) {
117 set_focus_border_color(kFocusBorderColor);
118 SetValue(ash::Shell::GetInstance()->tray_delegate()->GetVolumeLevel());
119 SetAccessibleName(
120 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
121 IDS_ASH_STATUS_TRAY_VOLUME));
122 Update();
123 }
124 virtual ~VolumeSlider() {}
125
126 void Update() {
127 UpdateState(!ash::Shell::GetInstance()->tray_delegate()->IsAudioMuted());
128 }
129
130 DISALLOW_COPY_AND_ASSIGN(VolumeSlider);
131 };
132
113 class VolumeView : public views::View, 133 class VolumeView : public views::View,
114 public views::ButtonListener, 134 public views::ButtonListener,
115 public views::SliderListener { 135 public views::SliderListener {
116 public: 136 public:
117 VolumeView() { 137 VolumeView() {
118 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 138 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
119 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); 139 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems));
120 140
121 icon_ = new VolumeButton(this); 141 icon_ = new VolumeButton(this);
122 AddChildView(icon_); 142 AddChildView(icon_);
123 143
124 mute_ = new MuteButton(this); 144 mute_ = new MuteButton(this);
125 AddChildView(mute_); 145 AddChildView(mute_);
126 146
127 ash::SystemTrayDelegate* delegate = 147 slider_ = new VolumeSlider(this);
128 ash::Shell::GetInstance()->tray_delegate();
129 slider_ = new views::Slider(this, views::Slider::HORIZONTAL);
130 slider_->set_focus_border_color(kFocusBorderColor);
131 slider_->SetValue(
132 delegate->IsAudioMuted() ? 0.0 : delegate->GetVolumeLevel());
133 slider_->SetAccessibleName(
134 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
135 IDS_ASH_STATUS_TRAY_VOLUME));
136 AddChildView(slider_); 148 AddChildView(slider_);
137 } 149 }
138 150
139 virtual ~VolumeView() {} 151 virtual ~VolumeView() {}
140 152
153 void Update() {
154 icon_->Update();
155 mute_->Update();
156 slider_->Update();
157 }
158
141 void SetVolumeLevel(float percent) { 159 void SetVolumeLevel(float percent) {
142 // The change in volume will be reflected via accessibility system events, 160 // The change in volume will be reflected via accessibility system events,
143 // so we prevent the UI event from being sent here. 161 // so we prevent the UI event from being sent here.
144 slider_->set_enable_accessibility_events(false); 162 slider_->set_enable_accessibility_events(false);
145 slider_->SetValue(percent); 163 slider_->SetValue(percent);
146 // It is possible that the volume was (un)muted, but the actual volume level 164 // It is possible that the volume was (un)muted, but the actual volume level
147 // did not change. In that case, setting the value of the slider won't 165 // did not change. In that case, setting the value of the slider won't
148 // trigger an update. So explicitly trigger an update. 166 // trigger an update. So explicitly trigger an update.
149 icon_->Update(); 167 Update();
150 mute_->Update();
151 slider_->set_enable_accessibility_events(true); 168 slider_->set_enable_accessibility_events(true);
152 } 169 }
153 170
154 private: 171 private:
155 // Overridden from views::View. 172 // Overridden from views::View.
156 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE { 173 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE {
157 int w = width() - slider_->x(); 174 int w = width() - slider_->x();
158 slider_->SetSize(gfx::Size(w, slider_->height())); 175 slider_->SetSize(gfx::Size(w, slider_->height()));
159 } 176 }
160 177
(...skipping 14 matching lines...) Expand all
175 if (reason == views::VALUE_CHANGED_BY_USER) { 192 if (reason == views::VALUE_CHANGED_BY_USER) {
176 ash::SystemTrayDelegate* delegate = 193 ash::SystemTrayDelegate* delegate =
177 ash::Shell::GetInstance()->tray_delegate(); 194 ash::Shell::GetInstance()->tray_delegate();
178 delegate->SetVolumeLevel(value); 195 delegate->SetVolumeLevel(value);
179 } 196 }
180 icon_->Update(); 197 icon_->Update();
181 } 198 }
182 199
183 VolumeButton* icon_; 200 VolumeButton* icon_;
184 MuteButton* mute_; 201 MuteButton* mute_;
185 views::Slider* slider_; 202 VolumeSlider* slider_;
186 203
187 DISALLOW_COPY_AND_ASSIGN(VolumeView); 204 DISALLOW_COPY_AND_ASSIGN(VolumeView);
188 }; 205 };
189 206
190 } // namespace tray 207 } // namespace tray
191 208
192 TrayVolume::TrayVolume() 209 TrayVolume::TrayVolume()
193 : TrayImageItem(IDR_AURA_UBER_TRAY_VOLUME_MUTE), 210 : TrayImageItem(IDR_AURA_UBER_TRAY_VOLUME_MUTE),
194 volume_view_(NULL), 211 volume_view_(NULL),
195 is_default_view_(false) { 212 is_default_view_(false) {
196 } 213 }
197 214
198 TrayVolume::~TrayVolume() { 215 TrayVolume::~TrayVolume() {
199 } 216 }
200 217
201 bool TrayVolume::GetInitialVisibility() { 218 bool TrayVolume::GetInitialVisibility() {
202 ash::SystemTrayDelegate* delegate = 219 ash::SystemTrayDelegate* delegate =
203 ash::Shell::GetInstance()->tray_delegate(); 220 ash::Shell::GetInstance()->tray_delegate();
204 return delegate->GetVolumeLevel() == 0.0 || delegate->IsAudioMuted(); 221 return delegate->IsAudioMuted();
205 } 222 }
206 223
207 views::View* TrayVolume::CreateDefaultView(user::LoginStatus status) { 224 views::View* TrayVolume::CreateDefaultView(user::LoginStatus status) {
208 volume_view_ = new tray::VolumeView; 225 volume_view_ = new tray::VolumeView;
209 is_default_view_ = true; 226 is_default_view_ = true;
210 return volume_view_; 227 return volume_view_;
211 } 228 }
212 229
213 views::View* TrayVolume::CreateDetailedView(user::LoginStatus status) { 230 views::View* TrayVolume::CreateDetailedView(user::LoginStatus status) {
214 volume_view_ = new tray::VolumeView; 231 volume_view_ = new tray::VolumeView;
(...skipping 18 matching lines...) Expand all
233 if (volume_view_) { 250 if (volume_view_) {
234 if (ash::Shell::GetInstance()->tray_delegate()->IsAudioMuted()) 251 if (ash::Shell::GetInstance()->tray_delegate()->IsAudioMuted())
235 percent = 0.0; 252 percent = 0.0;
236 volume_view_->SetVolumeLevel(percent); 253 volume_view_->SetVolumeLevel(percent);
237 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); 254 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
238 return; 255 return;
239 } 256 }
240 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); 257 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
241 } 258 }
242 259
260 void TrayVolume::OnMuteToggled() {
261 if (tray_view())
262 tray_view()->SetVisible(GetInitialVisibility());
263
264 if (volume_view_)
265 volume_view_->Update();
266 }
267
243 } // namespace internal 268 } // namespace internal
244 } // namespace ash 269 } // namespace ash
OLDNEW
« 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