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
3 // found in the LICENSE file.
5 #include "ash/system/audio/tray_audio.h"
9 #include "ash/ash_constants.h"
10 #include "ash/metrics/user_metrics_recorder.h"
11 #include "ash/shell.h"
12 #include "ash/system/audio/tray_audio_delegate.h"
13 #include "ash/system/audio/volume_view.h"
14 #include "ash/system/tray/actionable_view.h"
15 #include "ash/system/tray/fixed_sized_scroll_view.h"
16 #include "ash/system/tray/hover_highlight_view.h"
17 #include "ash/system/tray/system_tray.h"
18 #include "ash/system/tray/system_tray_delegate.h"
19 #include "ash/system/tray/system_tray_notifier.h"
20 #include "ash/system/tray/tray_constants.h"
21 #include "ash/volume_control_delegate.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h"
25 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkPaint.h"
27 #include "third_party/skia/include/core/SkRect.h"
28 #include "third_party/skia/include/effects/SkGradientShader.h"
29 #include "ui/gfx/canvas.h"
30 #include "ui/gfx/font_list.h"
31 #include "ui/gfx/image/image.h"
32 #include "ui/gfx/image/image_skia_operations.h"
33 #include "ui/views/controls/button/image_button.h"
34 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/slider.h"
37 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/view.h"
42 TrayAudio::TrayAudio(SystemTray
* system_tray
,
43 scoped_ptr
<system::TrayAudioDelegate
> audio_delegate
)
44 : TrayImageItem(system_tray
, IDR_AURA_UBER_TRAY_VOLUME_MUTE
),
45 audio_delegate_(audio_delegate
.Pass()),
47 pop_up_volume_view_(false) {
48 Shell::GetInstance()->system_tray_notifier()->AddAudioObserver(this);
51 TrayAudio::~TrayAudio() {
52 Shell::GetInstance()->system_tray_notifier()->RemoveAudioObserver(this);
56 bool TrayAudio::ShowAudioDeviceMenu() {
57 #if defined(OS_CHROMEOS)
64 bool TrayAudio::GetInitialVisibility() {
65 return audio_delegate_
->IsOutputAudioMuted();
68 views::View
* TrayAudio::CreateDefaultView(user::LoginStatus status
) {
69 volume_view_
= new tray::VolumeView(this, audio_delegate_
.get(), true);
73 views::View
* TrayAudio::CreateDetailedView(user::LoginStatus status
) {
74 volume_view_
= new tray::VolumeView(this, audio_delegate_
.get(), false);
78 void TrayAudio::DestroyDefaultView() {
82 void TrayAudio::DestroyDetailedView() {
85 pop_up_volume_view_
= false;
89 bool TrayAudio::ShouldHideArrow() const {
93 bool TrayAudio::ShouldShowShelf() const {
94 return TrayAudio::ShowAudioDeviceMenu() && !pop_up_volume_view_
;
97 void TrayAudio::OnOutputVolumeChanged() {
99 static_cast<float>(audio_delegate_
->GetOutputVolumeLevel()) / 100.0f
;
101 tray_view()->SetVisible(GetInitialVisibility());
104 volume_view_
->SetVolumeLevel(percent
);
105 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds
);
108 pop_up_volume_view_
= true;
109 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds
, false);
112 void TrayAudio::OnOutputMuteChanged() {
114 tray_view()->SetVisible(GetInitialVisibility());
117 volume_view_
->Update();
118 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds
);
120 pop_up_volume_view_
= true;
121 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds
, false);
125 void TrayAudio::OnAudioNodesChanged() {
129 void TrayAudio::OnActiveOutputNodeChanged() {
133 void TrayAudio::OnActiveInputNodeChanged() {
137 void TrayAudio::Update() {
139 tray_view()->SetVisible(GetInitialVisibility());
141 volume_view_
->SetVolumeLevel(
142 static_cast<float>(audio_delegate_
->GetOutputVolumeLevel()) / 100.0f
);
143 volume_view_
->Update();