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

Side by Side Diff: ash/common/system/chromeos/audio/volume_view.cc

Issue 2485353002: Fix the volume strength icon to reflect the volume control clicks (Closed)
Patch Set: fix variable type Created 4 years, 1 month 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
« no previous file with comments | « ash/common/system/chromeos/audio/volume_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/common/system/chromeos/audio/volume_view.h" 5 #include "ash/common/system/chromeos/audio/volume_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/material_design/material_design_controller.h" 9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/metrics/user_metrics_action.h" 10 #include "ash/common/metrics/user_metrics_action.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 VolumeView::~VolumeView() {} 220 VolumeView::~VolumeView() {}
221 221
222 void VolumeView::Update() { 222 void VolumeView::Update() {
223 icon_->Update(); 223 icon_->Update();
224 slider_->UpdateState(!audio_delegate_->IsOutputAudioMuted()); 224 slider_->UpdateState(!audio_delegate_->IsOutputAudioMuted());
225 UpdateDeviceTypeAndMore(); 225 UpdateDeviceTypeAndMore();
226 Layout(); 226 Layout();
227 } 227 }
228 228
229 void VolumeView::SetVolumeLevel(float percent) { 229 void VolumeView::SetVolumeLevel(float percent) {
230 // Update volume level to the current audio level.
231 Update();
232
230 // Slider's value is in finer granularity than audio volume level(0.01), 233 // Slider's value is in finer granularity than audio volume level(0.01),
231 // there will be a small discrepancy between slider's value and volume level 234 // there will be a small discrepancy between slider's value and volume level
232 // on audio side. To avoid the jittering in slider UI, do not set change 235 // on audio side. To avoid the jittering in slider UI, do not set change
233 // slider value if the change is less than 1%. 236 // slider value if the change is less than 1%.
234 if (std::abs(percent - slider_->value()) < 0.01) 237 if (std::abs(percent - slider_->value()) < 0.01)
235 return; 238 return;
236 slider_->SetValue(percent); 239 slider_->SetValue(percent);
237 // It is possible that the volume was (un)muted, but the actual volume level 240 // It is possible that the volume was (un)muted, but the actual volume level
238 // did not change. In that case, setting the value of the slider won't 241 // did not change. In that case, setting the value of the slider won't
239 // trigger an update. So explicitly trigger an update. 242 // trigger an update. So explicitly trigger an update.
(...skipping 21 matching lines...) Expand all
261 int device_icon = audio_delegate_->GetActiveOutputDeviceIconId(); 264 int device_icon = audio_delegate_->GetActiveOutputDeviceIconId();
262 if (device_icon != system::TrayAudioDelegate::kNoAudioDeviceIcon) { 265 if (device_icon != system::TrayAudioDelegate::kNoAudioDeviceIcon) {
263 device_type_->SetImage(ui::ResourceBundle::GetSharedInstance() 266 device_type_->SetImage(ui::ResourceBundle::GetSharedInstance()
264 .GetImageNamed(device_icon) 267 .GetImageNamed(device_icon)
265 .ToImageSkia()); 268 .ToImageSkia());
266 device_type_->SetVisible(true); 269 device_type_->SetVisible(true);
267 } 270 }
268 } 271 }
269 } 272 }
270 273
271 void VolumeView::HandleVolumeUp(float level) { 274 void VolumeView::HandleVolumeUp(int level) {
272 audio_delegate_->SetOutputVolumeLevel(level); 275 audio_delegate_->SetOutputVolumeLevel(level);
273 if (audio_delegate_->IsOutputAudioMuted() && 276 if (audio_delegate_->IsOutputAudioMuted() &&
274 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { 277 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) {
275 audio_delegate_->SetOutputAudioIsMuted(false); 278 audio_delegate_->SetOutputAudioIsMuted(false);
276 } 279 }
277 } 280 }
278 281
279 void VolumeView::HandleVolumeDown(float level) { 282 void VolumeView::HandleVolumeDown(int level) {
280 audio_delegate_->SetOutputVolumeLevel(level); 283 audio_delegate_->SetOutputVolumeLevel(level);
281 if (!audio_delegate_->IsOutputAudioMuted() && 284 if (!audio_delegate_->IsOutputAudioMuted() &&
282 level <= audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { 285 level <= audio_delegate_->GetOutputDefaultVolumeMuteLevel()) {
283 audio_delegate_->SetOutputAudioIsMuted(true); 286 audio_delegate_->SetOutputAudioIsMuted(true);
284 } else if (audio_delegate_->IsOutputAudioMuted() && 287 } else if (audio_delegate_->IsOutputAudioMuted() &&
285 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { 288 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) {
286 audio_delegate_->SetOutputAudioIsMuted(false); 289 audio_delegate_->SetOutputAudioIsMuted(false);
287 } 290 }
288 } 291 }
289 292
290 void VolumeView::ButtonPressed(views::Button* sender, const ui::Event& event) { 293 void VolumeView::ButtonPressed(views::Button* sender, const ui::Event& event) {
291 if (sender == icon_) { 294 if (sender == icon_) {
292 bool mute_on = !audio_delegate_->IsOutputAudioMuted(); 295 bool mute_on = !audio_delegate_->IsOutputAudioMuted();
293 audio_delegate_->SetOutputAudioIsMuted(mute_on); 296 audio_delegate_->SetOutputAudioIsMuted(mute_on);
294 if (!mute_on) 297 if (!mute_on)
295 audio_delegate_->AdjustOutputVolumeToAudibleLevel(); 298 audio_delegate_->AdjustOutputVolumeToAudibleLevel();
296 icon_->Update(); 299 icon_->Update();
297 } else if (sender == more_button_) { 300 } else if (sender == more_button_) {
298 owner_->TransitionDetailedView(); 301 owner_->TransitionDetailedView();
299 } else { 302 } else {
300 NOTREACHED() << "Unexpected sender=" << sender->GetClassName() << "."; 303 NOTREACHED() << "Unexpected sender=" << sender->GetClassName() << ".";
301 } 304 }
302 } 305 }
303 306
304 void VolumeView::SliderValueChanged(views::Slider* sender, 307 void VolumeView::SliderValueChanged(views::Slider* sender,
305 float value, 308 float value,
306 float old_value, 309 float old_value,
307 views::SliderChangeReason reason) { 310 views::SliderChangeReason reason) {
308 if (reason == views::VALUE_CHANGED_BY_USER) { 311 if (reason == views::VALUE_CHANGED_BY_USER) {
309 float new_volume = value * 100.0f; 312 int new_volume = value * 100;
James Cook 2016/11/11 22:21:15 Aside: I'm a little surprised that this doesn't ge
yiyix 2016/11/11 22:27:54 Do you think adding a comment here would help the
310 float current_volume = audio_delegate_->GetOutputVolumeLevel(); 313 int current_volume = audio_delegate_->GetOutputVolumeLevel();
311 // Do not call change audio volume if the difference is less than 314 // Do not call change audio volume if the difference is less than
312 // 1%, which is beyond cras audio api's granularity for output volume. 315 // 1%, which is beyond cras audio api's granularity for output volume.
313 if (std::abs(new_volume - current_volume) < 1.0f) 316 if (std::abs(new_volume - current_volume) < 1)
tdanderson 2016/11/11 19:48:35 if both values are now ints, the only way this can
yiyix 2016/11/11 22:27:54 You are right. Done
314 return; 317 return;
315 WmShell::Get()->RecordUserMetricsAction( 318 WmShell::Get()->RecordUserMetricsAction(
316 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU 319 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU
317 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); 320 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP);
318 if (new_volume > current_volume) 321 if (new_volume > current_volume)
319 HandleVolumeUp(new_volume); 322 HandleVolumeUp(new_volume);
320 else 323 else
321 HandleVolumeDown(new_volume); 324 HandleVolumeDown(new_volume);
322 } 325 }
323 icon_->Update(); 326 icon_->Update();
(...skipping 12 matching lines...) Expand all
336 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 339 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
337 // Separator's prefered size is based on set bounds. When an empty bounds is 340 // Separator's prefered size is based on set bounds. When an empty bounds is
338 // set on first layout this causes BoxLayout to ignore the separator. Reset 341 // set on first layout this causes BoxLayout to ignore the separator. Reset
339 // its height on each bounds change so that it is laid out properly. 342 // its height on each bounds change so that it is laid out properly.
340 if (separator_) 343 if (separator_)
341 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); 344 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height()));
342 } 345 }
343 346
344 } // namespace tray 347 } // namespace tray
345 } // namespace ash 348 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/audio/volume_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698