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/tray_audio.h" | 5 #include "ash/common/system/chromeos/audio/tray_audio.h" |
6 | 6 |
7 #include "ash/common/system/chromeos/audio/audio_detailed_view.h" | 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" | 8 #include "ash/common/system/chromeos/audio/volume_view.h" |
10 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
11 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
12 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
13 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
14 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
17 #include "ui/display/manager/managed_display_info.h" | 16 #include "ui/display/manager/managed_display_info.h" |
18 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
19 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
20 | 19 |
21 namespace ash { | 20 namespace ash { |
22 | 21 |
23 using chromeos::CrasAudioHandler; | 22 using chromeos::CrasAudioHandler; |
24 using chromeos::DBusThreadManager; | 23 using chromeos::DBusThreadManager; |
25 using system::TrayAudioDelegate; | |
26 using system::TrayAudioDelegateChromeOs; | |
27 | 24 |
28 TrayAudio::TrayAudio(SystemTray* system_tray) | 25 TrayAudio::TrayAudio(SystemTray* system_tray) |
29 : TrayImageItem(system_tray, kSystemTrayVolumeMuteIcon, UMA_AUDIO), | 26 : TrayImageItem(system_tray, kSystemTrayVolumeMuteIcon, UMA_AUDIO), |
30 audio_delegate_(new TrayAudioDelegateChromeOs()), | |
31 volume_view_(nullptr), | 27 volume_view_(nullptr), |
32 pop_up_volume_view_(false), | 28 pop_up_volume_view_(false), |
33 audio_detail_view_(nullptr) { | 29 audio_detail_view_(nullptr) { |
34 if (CrasAudioHandler::IsInitialized()) | 30 if (CrasAudioHandler::IsInitialized()) |
35 CrasAudioHandler::Get()->AddAudioObserver(this); | 31 CrasAudioHandler::Get()->AddAudioObserver(this); |
36 display::Screen::GetScreen()->AddObserver(this); | 32 display::Screen::GetScreen()->AddObserver(this); |
37 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 33 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
38 } | 34 } |
39 | 35 |
40 TrayAudio::~TrayAudio() { | 36 TrayAudio::~TrayAudio() { |
(...skipping 10 matching lines...) Expand all Loading... |
51 SystemTray* system_tray = root->GetRootWindowController()->GetSystemTray(); | 47 SystemTray* system_tray = root->GetRootWindowController()->GetSystemTray(); |
52 if (!system_tray) | 48 if (!system_tray) |
53 continue; | 49 continue; |
54 // Show the popup by simulating a volume change. The provided node id and | 50 // Show the popup by simulating a volume change. The provided node id and |
55 // volume value are ignored. | 51 // volume value are ignored. |
56 system_tray->GetTrayAudio()->OnOutputNodeVolumeChanged(0, 0); | 52 system_tray->GetTrayAudio()->OnOutputNodeVolumeChanged(0, 0); |
57 } | 53 } |
58 } | 54 } |
59 | 55 |
60 bool TrayAudio::GetInitialVisibility() { | 56 bool TrayAudio::GetInitialVisibility() { |
61 return audio_delegate_->IsOutputAudioMuted(); | 57 return CrasAudioHandler::Get()->IsOutputMuted(); |
62 } | 58 } |
63 | 59 |
64 views::View* TrayAudio::CreateDefaultView(LoginStatus status) { | 60 views::View* TrayAudio::CreateDefaultView(LoginStatus status) { |
65 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true); | 61 volume_view_ = new tray::VolumeView(this, true); |
66 return volume_view_; | 62 return volume_view_; |
67 } | 63 } |
68 | 64 |
69 views::View* TrayAudio::CreateDetailedView(LoginStatus status) { | 65 views::View* TrayAudio::CreateDetailedView(LoginStatus status) { |
70 if (pop_up_volume_view_) { | 66 if (pop_up_volume_view_) { |
71 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), false); | 67 volume_view_ = new tray::VolumeView(this, false); |
72 return volume_view_; | 68 return volume_view_; |
73 } else { | 69 } else { |
74 WmShell::Get()->RecordUserMetricsAction( | 70 WmShell::Get()->RecordUserMetricsAction( |
75 UMA_STATUS_AREA_DETAILED_AUDIO_VIEW); | 71 UMA_STATUS_AREA_DETAILED_AUDIO_VIEW); |
76 audio_detail_view_ = new tray::AudioDetailedView(this); | 72 audio_detail_view_ = new tray::AudioDetailedView(this); |
77 return audio_detail_view_; | 73 return audio_detail_view_; |
78 } | 74 } |
79 } | 75 } |
80 | 76 |
81 void TrayAudio::DestroyDefaultView() { | 77 void TrayAudio::DestroyDefaultView() { |
82 volume_view_ = NULL; | 78 volume_view_ = NULL; |
83 } | 79 } |
84 | 80 |
85 void TrayAudio::DestroyDetailedView() { | 81 void TrayAudio::DestroyDetailedView() { |
86 if (audio_detail_view_) { | 82 if (audio_detail_view_) { |
87 audio_detail_view_ = nullptr; | 83 audio_detail_view_ = nullptr; |
88 } else if (volume_view_) { | 84 } else if (volume_view_) { |
89 volume_view_ = nullptr; | 85 volume_view_ = nullptr; |
90 pop_up_volume_view_ = false; | 86 pop_up_volume_view_ = false; |
91 } | 87 } |
92 } | 88 } |
93 | 89 |
94 bool TrayAudio::ShouldShowShelf() const { | 90 bool TrayAudio::ShouldShowShelf() const { |
95 return !pop_up_volume_view_; | 91 return !pop_up_volume_view_; |
96 } | 92 } |
97 | 93 |
98 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, | 94 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, |
99 int /* volume */) { | 95 int /* volume */) { |
100 float percent = | 96 float percent = CrasAudioHandler::Get()->GetOutputVolumePercent() / 100.0f; |
101 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | |
102 if (tray_view()) | 97 if (tray_view()) |
103 tray_view()->SetVisible(GetInitialVisibility()); | 98 tray_view()->SetVisible(GetInitialVisibility()); |
104 | 99 |
105 if (volume_view_) { | 100 if (volume_view_) { |
106 volume_view_->SetVolumeLevel(percent); | 101 volume_view_->SetVolumeLevel(percent); |
107 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 102 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
108 return; | 103 return; |
109 } | 104 } |
110 pop_up_volume_view_ = true; | 105 pop_up_volume_view_ = true; |
111 ShowDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 106 ShowDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
(...skipping 19 matching lines...) Expand all Loading... |
131 void TrayAudio::OnActiveOutputNodeChanged() { | 126 void TrayAudio::OnActiveOutputNodeChanged() { |
132 Update(); | 127 Update(); |
133 } | 128 } |
134 | 129 |
135 void TrayAudio::OnActiveInputNodeChanged() { | 130 void TrayAudio::OnActiveInputNodeChanged() { |
136 Update(); | 131 Update(); |
137 } | 132 } |
138 | 133 |
139 void TrayAudio::ChangeInternalSpeakerChannelMode() { | 134 void TrayAudio::ChangeInternalSpeakerChannelMode() { |
140 // Swap left/right channel only if it is in Yoga mode. | 135 // Swap left/right channel only if it is in Yoga mode. |
141 system::TrayAudioDelegate::AudioChannelMode channel_mode = | 136 bool swap = false; |
142 system::TrayAudioDelegate::NORMAL; | |
143 if (display::Display::HasInternalDisplay()) { | 137 if (display::Display::HasInternalDisplay()) { |
144 const display::ManagedDisplayInfo& display_info = | 138 const display::ManagedDisplayInfo& display_info = |
145 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); | 139 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); |
146 if (display_info.GetActiveRotation() == display::Display::ROTATE_180) | 140 if (display_info.GetActiveRotation() == display::Display::ROTATE_180) |
147 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; | 141 swap = true; |
148 } | 142 } |
149 | 143 CrasAudioHandler::Get()->SwapInternalSpeakerLeftRightChannel(swap); |
150 audio_delegate_->SetInternalSpeakerChannelMode(channel_mode); | |
151 } | 144 } |
152 | 145 |
153 void TrayAudio::OnDisplayAdded(const display::Display& new_display) { | 146 void TrayAudio::OnDisplayAdded(const display::Display& new_display) { |
154 if (!new_display.IsInternal()) | 147 if (!new_display.IsInternal()) |
155 return; | 148 return; |
156 ChangeInternalSpeakerChannelMode(); | 149 ChangeInternalSpeakerChannelMode(); |
157 | 150 |
158 // This event will be triggered when the lid of the device is opened to exit | 151 // 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 | 152 // the docked mode, we should always start or re-start HDMI re-discovering |
160 // grace period right after this event. | 153 // grace period right after this event. |
161 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true); | 154 CrasAudioHandler::Get()->SetActiveHDMIOutoutRediscoveringIfNecessary(true); |
162 } | 155 } |
163 | 156 |
164 void TrayAudio::OnDisplayRemoved(const display::Display& old_display) { | 157 void TrayAudio::OnDisplayRemoved(const display::Display& old_display) { |
165 if (!old_display.IsInternal()) | 158 if (!old_display.IsInternal()) |
166 return; | 159 return; |
167 ChangeInternalSpeakerChannelMode(); | 160 ChangeInternalSpeakerChannelMode(); |
168 | 161 |
169 // This event will be triggered when the lid of the device is closed to enter | 162 // 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 | 163 // the docked mode, we should always start or re-start HDMI re-discovering |
171 // grace period right after this event. | 164 // grace period right after this event. |
172 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true); | 165 CrasAudioHandler::Get()->SetActiveHDMIOutoutRediscoveringIfNecessary(true); |
173 } | 166 } |
174 | 167 |
175 void TrayAudio::OnDisplayMetricsChanged(const display::Display& display, | 168 void TrayAudio::OnDisplayMetricsChanged(const display::Display& display, |
176 uint32_t changed_metrics) { | 169 uint32_t changed_metrics) { |
177 if (!display.IsInternal()) | 170 if (!display.IsInternal()) |
178 return; | 171 return; |
179 | 172 |
180 if (changed_metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION) | 173 if (changed_metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION) |
181 ChangeInternalSpeakerChannelMode(); | 174 ChangeInternalSpeakerChannelMode(); |
182 | 175 |
183 // The event could be triggered multiple times during the HDMI display | 176 // The event could be triggered multiple times during the HDMI display |
184 // transition, we don't need to restart HDMI re-discovering grace period | 177 // transition, we don't need to restart HDMI re-discovering grace period |
185 // it is already started earlier. | 178 // it is already started earlier. |
186 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(false); | 179 CrasAudioHandler::Get()->SetActiveHDMIOutoutRediscoveringIfNecessary(false); |
187 } | 180 } |
188 | 181 |
189 void TrayAudio::SuspendDone(const base::TimeDelta& sleep_duration) { | 182 void TrayAudio::SuspendDone(const base::TimeDelta& sleep_duration) { |
190 // This event is triggered when the device resumes after earlier suspension, | 183 // This event is triggered when the device resumes after earlier suspension, |
191 // we should always start or re-start HDMI re-discovering | 184 // we should always start or re-start HDMI re-discovering |
192 // grace period right after this event. | 185 // grace period right after this event. |
193 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true); | 186 CrasAudioHandler::Get()->SetActiveHDMIOutoutRediscoveringIfNecessary(true); |
194 } | 187 } |
195 | 188 |
196 void TrayAudio::Update() { | 189 void TrayAudio::Update() { |
197 if (tray_view()) | 190 if (tray_view()) |
198 tray_view()->SetVisible(GetInitialVisibility()); | 191 tray_view()->SetVisible(GetInitialVisibility()); |
199 if (volume_view_) { | 192 if (volume_view_) { |
200 volume_view_->SetVolumeLevel( | 193 volume_view_->SetVolumeLevel( |
201 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 194 CrasAudioHandler::Get()->GetOutputVolumePercent() / 100.0f); |
202 volume_view_->Update(); | 195 volume_view_->Update(); |
203 } | 196 } |
204 | 197 |
205 if (audio_detail_view_) | 198 if (audio_detail_view_) |
206 audio_detail_view_->Update(); | 199 audio_detail_view_->Update(); |
207 } | 200 } |
208 | 201 |
209 } // namespace ash | 202 } // namespace ash |
OLD | NEW |