Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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:30:26
an explicit static_cast<int>(value * 100) would in
| |
| 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 if (new_volume == current_volume) |
| 312 // 1%, which is beyond cras audio api's granularity for output volume. | |
| 313 if (std::abs(new_volume - current_volume) < 1.0f) | |
| 314 return; | 315 return; |
| 315 WmShell::Get()->RecordUserMetricsAction( | 316 WmShell::Get()->RecordUserMetricsAction( |
| 316 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU | 317 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU |
| 317 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); | 318 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); |
| 318 if (new_volume > current_volume) | 319 if (new_volume > current_volume) |
| 319 HandleVolumeUp(new_volume); | 320 HandleVolumeUp(new_volume); |
| 320 else | 321 else |
| 321 HandleVolumeDown(new_volume); | 322 HandleVolumeDown(new_volume); |
| 322 } | 323 } |
| 323 icon_->Update(); | 324 icon_->Update(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 336 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 337 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 337 // Separator's prefered size is based on set bounds. When an empty bounds is | 338 // 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 | 339 // 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. | 340 // its height on each bounds change so that it is laid out properly. |
| 340 if (separator_) | 341 if (separator_) |
| 341 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); | 342 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); |
| 342 } | 343 } |
| 343 | 344 |
| 344 } // namespace tray | 345 } // namespace tray |
| 345 } // namespace ash | 346 } // namespace ash |
| OLD | NEW |