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

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

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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
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/chromeos/audio/tray_audio.h"
6
7 #include "ash/common/system/chromeos/audio/audio_detailed_view.h"
8 #include "ash/common/system/chromeos/audio/tray_audio_delegate_chromeos.h"
9 #include "ash/common/system/chromeos/audio/volume_view.h"
10 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/wm_shell.h"
13 #include "ash/common/wm_window.h"
14 #include "ash/root_window_controller.h"
15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "ui/display/display.h"
17 #include "ui/display/manager/managed_display_info.h"
18 #include "ui/display/screen.h"
19 #include "ui/views/view.h"
20
21 namespace ash {
22
23 using chromeos::CrasAudioHandler;
24 using chromeos::DBusThreadManager;
25 using system::TrayAudioDelegate;
26 using system::TrayAudioDelegateChromeOs;
27
28 TrayAudio::TrayAudio(SystemTray* system_tray)
29 : TrayImageItem(system_tray, kSystemTrayVolumeMuteIcon, UMA_AUDIO),
30 audio_delegate_(new TrayAudioDelegateChromeOs()),
31 volume_view_(nullptr),
32 pop_up_volume_view_(false),
33 audio_detail_view_(nullptr) {
34 if (CrasAudioHandler::IsInitialized())
35 CrasAudioHandler::Get()->AddAudioObserver(this);
36 display::Screen::GetScreen()->AddObserver(this);
37 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
38 }
39
40 TrayAudio::~TrayAudio() {
41 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
42 display::Screen::GetScreen()->RemoveObserver(this);
43 if (CrasAudioHandler::IsInitialized())
44 CrasAudioHandler::Get()->RemoveAudioObserver(this);
45 }
46
47 // static
48 void TrayAudio::ShowPopUpVolumeView() {
49 // Show the popup on all monitors with a system tray.
50 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
51 SystemTray* system_tray = root->GetRootWindowController()->GetSystemTray();
52 if (!system_tray)
53 continue;
54 // Show the popup by simulating a volume change. The provided node id and
55 // volume value are ignored.
56 system_tray->GetTrayAudio()->OnOutputNodeVolumeChanged(0, 0);
57 }
58 }
59
60 bool TrayAudio::GetInitialVisibility() {
61 return audio_delegate_->IsOutputAudioMuted();
62 }
63
64 views::View* TrayAudio::CreateDefaultView(LoginStatus status) {
65 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true);
66 return volume_view_;
67 }
68
69 views::View* TrayAudio::CreateDetailedView(LoginStatus status) {
70 if (pop_up_volume_view_) {
71 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), false);
72 return volume_view_;
73 } else {
74 WmShell::Get()->RecordUserMetricsAction(
75 UMA_STATUS_AREA_DETAILED_AUDIO_VIEW);
76 audio_detail_view_ = new tray::AudioDetailedView(this);
77 return audio_detail_view_;
78 }
79 }
80
81 void TrayAudio::DestroyDefaultView() {
82 volume_view_ = NULL;
83 }
84
85 void TrayAudio::DestroyDetailedView() {
86 if (audio_detail_view_) {
87 audio_detail_view_ = nullptr;
88 } else if (volume_view_) {
89 volume_view_ = nullptr;
90 pop_up_volume_view_ = false;
91 }
92 }
93
94 bool TrayAudio::ShouldShowShelf() const {
95 return !pop_up_volume_view_;
96 }
97
98 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */,
99 int /* 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 // This event will be triggered when the lid of the device is opened to exit
159 // the docked mode, we should always start or re-start HDMI re-discovering
160 // grace period right after this event.
161 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true);
162 }
163
164 void TrayAudio::OnDisplayRemoved(const display::Display& old_display) {
165 if (!old_display.IsInternal())
166 return;
167 ChangeInternalSpeakerChannelMode();
168
169 // This event will be triggered when the lid of the device is closed to enter
170 // the docked mode, we should always start or re-start HDMI re-discovering
171 // grace period right after this event.
172 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true);
173 }
174
175 void TrayAudio::OnDisplayMetricsChanged(const display::Display& display,
176 uint32_t changed_metrics) {
177 if (!display.IsInternal())
178 return;
179
180 if (changed_metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION)
181 ChangeInternalSpeakerChannelMode();
182
183 // The event could be triggered multiple times during the HDMI display
184 // transition, we don't need to restart HDMI re-discovering grace period
185 // it is already started earlier.
186 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(false);
187 }
188
189 void TrayAudio::SuspendDone(const base::TimeDelta& sleep_duration) {
190 // This event is triggered when the device resumes after earlier suspension,
191 // we should always start or re-start HDMI re-discovering
192 // grace period right after this event.
193 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true);
194 }
195
196 void TrayAudio::Update() {
197 if (tray_view())
198 tray_view()->SetVisible(GetInitialVisibility());
199 if (volume_view_) {
200 volume_view_->SetVolumeLevel(
201 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f);
202 volume_view_->Update();
203 }
204
205 if (audio_detail_view_)
206 audio_detail_view_->Update();
207 }
208
209 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/audio/tray_audio.h ('k') | ash/common/system/chromeos/audio/tray_audio_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698