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

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

Issue 2483393002: chromeos: Combine TrayAudio and TrayAudioChromeOs classes (Closed)
Patch Set: rebase 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/audio/tray_audio.h ('k') | ash/common/system/audio/tray_audio_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ash/common/system/audio/tray_audio.h"
6
7 #include <cmath>
8 #include <utility>
9
10 #include "ash/common/ash_constants.h"
11 #include "ash/common/system/audio/tray_audio_delegate.h"
12 #include "ash/common/system/audio/volume_view.h"
13 #include "ash/common/system/tray/actionable_view.h"
14 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
15 #include "ash/common/system/tray/hover_highlight_view.h"
16 #include "ash/common/system/tray/system_tray_delegate.h"
17 #include "ash/common/system/tray/system_tray_notifier.h"
18 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/wm_shell.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "grit/ash_resources.h"
22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkPaint.h"
24 #include "third_party/skia/include/core/SkRect.h"
25 #include "third_party/skia/include/effects/SkGradientShader.h"
26 #include "ui/display/display.h"
27 #include "ui/display/manager/managed_display_info.h"
28 #include "ui/display/screen.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/layout/box_layout.h"
37 #include "ui/views/view.h"
38
39 namespace ash {
40
41 TrayAudio::TrayAudio(SystemTray* system_tray,
42 std::unique_ptr<system::TrayAudioDelegate> audio_delegate)
43 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO),
44 audio_delegate_(std::move(audio_delegate)),
45 volume_view_(NULL),
46 pop_up_volume_view_(false) {
47 WmShell::Get()->system_tray_notifier()->AddAudioObserver(this);
48 display::Screen::GetScreen()->AddObserver(this);
49 }
50
51 TrayAudio::~TrayAudio() {
52 display::Screen::GetScreen()->RemoveObserver(this);
53 WmShell::Get()->system_tray_notifier()->RemoveAudioObserver(this);
54 }
55
56 // static
57 bool TrayAudio::ShowAudioDeviceMenu() {
58 #if defined(OS_CHROMEOS)
59 return true;
60 #else
61 return false;
62 #endif
63 }
64
65 bool TrayAudio::GetInitialVisibility() {
66 return audio_delegate_->IsOutputAudioMuted();
67 }
68
69 views::View* TrayAudio::CreateDefaultView(LoginStatus status) {
70 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true);
71 return volume_view_;
72 }
73
74 views::View* TrayAudio::CreateDetailedView(LoginStatus status) {
75 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), false);
76 return volume_view_;
77 }
78
79 void TrayAudio::DestroyDefaultView() {
80 volume_view_ = NULL;
81 }
82
83 void TrayAudio::DestroyDetailedView() {
84 if (volume_view_) {
85 volume_view_ = NULL;
86 pop_up_volume_view_ = false;
87 }
88 }
89
90 bool TrayAudio::ShouldHideArrow() const {
91 return true;
92 }
93
94 bool TrayAudio::ShouldShowShelf() const {
95 return TrayAudio::ShowAudioDeviceMenu() && !pop_up_volume_view_;
96 }
97
98 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */,
99 double /* volume */) {
100 float percent =
101 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f;
102 if (tray_view())
103 tray_view()->SetVisible(GetInitialVisibility());
104
105 if (volume_view_) {
106 volume_view_->SetVolumeLevel(percent);
107 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
108 return;
109 }
110 pop_up_volume_view_ = true;
111 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
112 }
113
114 void TrayAudio::OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) {
115 if (tray_view())
116 tray_view()->SetVisible(GetInitialVisibility());
117
118 if (volume_view_) {
119 volume_view_->Update();
120 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
121 } else if (!system_adjust) {
122 pop_up_volume_view_ = true;
123 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
124 }
125 }
126
127 void TrayAudio::OnAudioNodesChanged() {
128 Update();
129 }
130
131 void TrayAudio::OnActiveOutputNodeChanged() {
132 Update();
133 }
134
135 void TrayAudio::OnActiveInputNodeChanged() {
136 Update();
137 }
138
139 void TrayAudio::ChangeInternalSpeakerChannelMode() {
140 // Swap left/right channel only if it is in Yoga mode.
141 system::TrayAudioDelegate::AudioChannelMode channel_mode =
142 system::TrayAudioDelegate::NORMAL;
143 if (display::Display::HasInternalDisplay()) {
144 const display::ManagedDisplayInfo& display_info =
145 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId());
146 if (display_info.GetActiveRotation() == display::Display::ROTATE_180)
147 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED;
148 }
149
150 audio_delegate_->SetInternalSpeakerChannelMode(channel_mode);
151 }
152
153 void TrayAudio::OnDisplayAdded(const display::Display& new_display) {
154 if (!new_display.IsInternal())
155 return;
156 ChangeInternalSpeakerChannelMode();
157 }
158
159 void TrayAudio::OnDisplayRemoved(const display::Display& old_display) {
160 if (!old_display.IsInternal())
161 return;
162 ChangeInternalSpeakerChannelMode();
163 }
164
165 void TrayAudio::OnDisplayMetricsChanged(const display::Display& display,
166 uint32_t changed_metrics) {
167 if (!display.IsInternal())
168 return;
169
170 if (changed_metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION)
171 ChangeInternalSpeakerChannelMode();
172 }
173
174 void TrayAudio::Update() {
175 if (tray_view())
176 tray_view()->SetVisible(GetInitialVisibility());
177 if (volume_view_) {
178 volume_view_->SetVolumeLevel(
179 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f);
180 volume_view_->Update();
181 }
182 }
183
184 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/audio/tray_audio.h ('k') | ash/common/system/audio/tray_audio_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698