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

Side by Side Diff: ash/system/audio/tray_audio.cc

Issue 163953007: Refactor the TrayAudio code so that it can be used by other platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove missing else condition Created 6 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
James Cook 2014/02/18 19:34:48 ditto
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/audio/tray_audio.h"
6
7 #include <cmath>
8
9 #include "ash/ash_constants.h"
10 #include "ash/ash_switches.h"
11 #include "ash/metrics/user_metrics_recorder.h"
12 #include "ash/shell.h"
13 #include "ash/system/audio/tray_audio_delegate.h"
14 #include "ash/system/audio/volume_view.h"
15 #include "ash/system/tray/actionable_view.h"
16 #include "ash/system/tray/fixed_sized_scroll_view.h"
17 #include "ash/system/tray/hover_highlight_view.h"
18 #include "ash/system/tray/system_tray.h"
19 #include "ash/system/tray/system_tray_delegate.h"
20 #include "ash/system/tray/system_tray_notifier.h"
21 #include "ash/system/tray/tray_constants.h"
22 #include "ash/volume_control_delegate.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "grit/ash_resources.h"
25 #include "grit/ash_strings.h"
26 #include "third_party/skia/include/core/SkCanvas.h"
27 #include "third_party/skia/include/core/SkPaint.h"
28 #include "third_party/skia/include/core/SkRect.h"
29 #include "third_party/skia/include/effects/SkGradientShader.h"
30 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/font_list.h"
34 #include "ui/gfx/image/image.h"
35 #include "ui/gfx/image/image_skia_operations.h"
36 #include "ui/views/controls/button/image_button.h"
37 #include "ui/views/controls/image_view.h"
38 #include "ui/views/controls/label.h"
39 #include "ui/views/controls/slider.h"
40 #include "ui/views/layout/box_layout.h"
41 #include "ui/views/view.h"
42
43 namespace ash {
44 namespace internal {
45
46 TrayAudio::TrayAudio(SystemTray* system_tray,
47 system::TrayAudioDelegate* audio_delegate)
48 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE),
49 audio_delegate_(audio_delegate),
50 volume_view_(NULL),
51 pop_up_volume_view_(false) {
52 Shell::GetInstance()->system_tray_notifier()->AddAudioObserver(this);
53 }
54
55 TrayAudio::~TrayAudio() {
56 Shell::GetInstance()->system_tray_notifier()->RemoveAudioObserver(this);
57 }
58
59 bool TrayAudio::GetInitialVisibility() {
60 return audio_delegate_->IsOutputAudioMuted();
61 }
62
63 views::View* TrayAudio::CreateDefaultView(user::LoginStatus status) {
64 volume_view_ = new tray::VolumeView(this, audio_delegate_, true);
65 return volume_view_;
66 }
67
68 views::View* TrayAudio::CreateDetailedView(user::LoginStatus status) {
69 volume_view_ = new tray::VolumeView(this, audio_delegate_, false);
70 return volume_view_;
71 }
72
73 void TrayAudio::DestroyDefaultView() {
74 volume_view_ = NULL;
75 }
76
77 void TrayAudio::DestroyDetailedView() {
78 if (volume_view_) {
79 volume_view_ = NULL;
80 pop_up_volume_view_ = false;
81 }
82 }
83
84 bool TrayAudio::ShouldHideArrow() const {
85 return true;
86 }
87
88 bool TrayAudio::ShouldShowShelf() const {
89 return ash::switches::ShowAudioDeviceMenu() && !pop_up_volume_view_;
90 }
91
92 void TrayAudio::OnOutputVolumeChanged() {
93 float percent =
94 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f;
95 if (tray_view())
96 tray_view()->SetVisible(GetInitialVisibility());
97
98 if (volume_view_) {
99 volume_view_->SetVolumeLevel(percent);
100 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
101 return;
102 }
103 pop_up_volume_view_ = true;
104 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
105 }
106
107 void TrayAudio::OnOutputMuteChanged() {
108 if (tray_view())
109 tray_view()->SetVisible(GetInitialVisibility());
110
111 if (volume_view_) {
112 volume_view_->Update();
113 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
114 } else {
115 pop_up_volume_view_ = true;
116 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
117 }
118 }
119
120 void TrayAudio::OnAudioNodesChanged() {
121 Update();
122 }
123
124 void TrayAudio::OnActiveOutputNodeChanged() {
125 Update();
126 }
127
128 void TrayAudio::OnActiveInputNodeChanged() {
129 Update();
130 }
131
132 void TrayAudio::Update() {
133 if (tray_view())
134 tray_view()->SetVisible(GetInitialVisibility());
135 if (volume_view_) {
136 volume_view_->SetVolumeLevel(
137 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f);
138 volume_view_->Update();
139 }
140 }
141
142 } // namespace internal
143 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698