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/audio/tray_audio.h" | 5 #include "ash/common/system/audio/tray_audio.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/common/ash_constants.h" | 10 #include "ash/common/ash_constants.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "ui/gfx/font_list.h" | 31 #include "ui/gfx/font_list.h" |
32 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
33 #include "ui/gfx/image/image_skia_operations.h" | 33 #include "ui/gfx/image/image_skia_operations.h" |
34 #include "ui/views/controls/button/image_button.h" | 34 #include "ui/views/controls/button/image_button.h" |
35 #include "ui/views/controls/image_view.h" | 35 #include "ui/views/controls/image_view.h" |
36 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
37 #include "ui/views/controls/slider.h" | 37 #include "ui/views/controls/slider.h" |
38 #include "ui/views/layout/box_layout.h" | 38 #include "ui/views/layout/box_layout.h" |
39 #include "ui/views/view.h" | 39 #include "ui/views/view.h" |
40 | 40 |
| 41 #if defined(OS_CHROMEOS) |
| 42 #include "chromeos/audio/cras_audio_handler.h" |
| 43 #endif |
| 44 |
41 namespace ash { | 45 namespace ash { |
42 | 46 |
43 TrayAudio::TrayAudio(SystemTray* system_tray, | 47 TrayAudio::TrayAudio(SystemTray* system_tray, |
44 std::unique_ptr<system::TrayAudioDelegate> audio_delegate) | 48 std::unique_ptr<system::TrayAudioDelegate> audio_delegate) |
45 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), | 49 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), |
46 audio_delegate_(std::move(audio_delegate)), | 50 audio_delegate_(std::move(audio_delegate)), |
47 volume_view_(NULL), | 51 volume_view_(NULL), |
48 pop_up_volume_view_(false) { | 52 pop_up_volume_view_(false), |
49 WmShell::Get()->system_tray_notifier()->AddAudioObserver(this); | 53 hide_popup_(false), |
| 54 saved_volume_percent_(0) { |
| 55 SystemTrayNotifier* notifier = WmShell::Get()->system_tray_notifier(); |
| 56 notifier->AddAudioObserver(this); |
| 57 notifier->AddMaxModeScreenshotObserver(this); |
50 display::Screen::GetScreen()->AddObserver(this); | 58 display::Screen::GetScreen()->AddObserver(this); |
51 } | 59 } |
52 | 60 |
53 TrayAudio::~TrayAudio() { | 61 TrayAudio::~TrayAudio() { |
54 display::Screen::GetScreen()->RemoveObserver(this); | 62 display::Screen::GetScreen()->RemoveObserver(this); |
55 WmShell::Get()->system_tray_notifier()->RemoveAudioObserver(this); | 63 SystemTrayNotifier* notifier = WmShell::Get()->system_tray_notifier(); |
| 64 notifier->RemoveMaxModeScreenshotObserver(this); |
| 65 notifier->RemoveAudioObserver(this); |
56 } | 66 } |
57 | 67 |
58 // static | 68 // static |
59 bool TrayAudio::ShowAudioDeviceMenu() { | 69 bool TrayAudio::ShowAudioDeviceMenu() { |
60 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
61 return true; | 71 return true; |
62 #else | 72 #else |
63 return false; | 73 return false; |
64 #endif | 74 #endif |
65 } | 75 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | 113 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; |
104 if (tray_view()) | 114 if (tray_view()) |
105 tray_view()->SetVisible(GetInitialVisibility()); | 115 tray_view()->SetVisible(GetInitialVisibility()); |
106 | 116 |
107 if (volume_view_) { | 117 if (volume_view_) { |
108 volume_view_->SetVolumeLevel(percent); | 118 volume_view_->SetVolumeLevel(percent); |
109 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 119 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
110 return; | 120 return; |
111 } | 121 } |
112 pop_up_volume_view_ = true; | 122 pop_up_volume_view_ = true; |
113 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 123 // When the OutputNodeVolumeChanged is caused by a volume restore after |
| 124 // maximize mode screenshot, it should not cause UI popup. |
| 125 if (!hide_popup_) |
| 126 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
| 127 else |
| 128 hide_popup_ = false; |
114 } | 129 } |
115 | 130 |
116 void TrayAudio::OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) { | 131 void TrayAudio::OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) { |
117 if (tray_view()) | 132 if (tray_view()) |
118 tray_view()->SetVisible(GetInitialVisibility()); | 133 tray_view()->SetVisible(GetInitialVisibility()); |
119 | 134 |
120 if (volume_view_) { | 135 if (volume_view_) { |
121 volume_view_->Update(); | 136 volume_view_->Update(); |
122 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 137 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
123 } else if (!system_adjust) { | 138 } else if (!system_adjust) { |
124 pop_up_volume_view_ = true; | 139 pop_up_volume_view_ = true; |
125 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 140 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
126 } | 141 } |
127 } | 142 } |
128 | 143 |
129 void TrayAudio::OnAudioNodesChanged() { | 144 void TrayAudio::OnAudioNodesChanged() { |
130 Update(); | 145 Update(); |
131 } | 146 } |
132 | 147 |
133 void TrayAudio::OnActiveOutputNodeChanged() { | 148 void TrayAudio::OnActiveOutputNodeChanged() { |
134 Update(); | 149 Update(); |
135 } | 150 } |
136 | 151 |
137 void TrayAudio::OnActiveInputNodeChanged() { | 152 void TrayAudio::OnActiveInputNodeChanged() { |
138 Update(); | 153 Update(); |
139 } | 154 } |
140 | 155 |
| 156 void TrayAudio::OnWillTakeScreenshot(int volume_percent) { |
| 157 saved_volume_percent_ = volume_percent; |
| 158 HideDetailedView(); |
| 159 } |
| 160 |
| 161 void TrayAudio::OnDidTakeScreenshot() { |
| 162 hide_popup_ = true; |
| 163 #if defined(OS_CHROMEOS) |
| 164 // Restore the volume to the value before volume-down modifier key is pressed |
| 165 // to wait for power button. |
| 166 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); |
| 167 DCHECK(audio_handler->IsInitialized()); |
| 168 audio_handler->SetOutputVolumePercent(saved_volume_percent_); |
| 169 #endif |
| 170 } |
| 171 |
141 void TrayAudio::ChangeInternalSpeakerChannelMode() { | 172 void TrayAudio::ChangeInternalSpeakerChannelMode() { |
142 // Swap left/right channel only if it is in Yoga mode. | 173 // Swap left/right channel only if it is in Yoga mode. |
143 system::TrayAudioDelegate::AudioChannelMode channel_mode = | 174 system::TrayAudioDelegate::AudioChannelMode channel_mode = |
144 system::TrayAudioDelegate::NORMAL; | 175 system::TrayAudioDelegate::NORMAL; |
145 if (display::Display::HasInternalDisplay()) { | 176 if (display::Display::HasInternalDisplay()) { |
146 const DisplayInfo& display_info = | 177 const DisplayInfo& display_info = |
147 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); | 178 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); |
148 if (display_info.GetActiveRotation() == display::Display::ROTATE_180) | 179 if (display_info.GetActiveRotation() == display::Display::ROTATE_180) |
149 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; | 180 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; |
150 } | 181 } |
(...skipping 26 matching lines...) Expand all Loading... |
177 if (tray_view()) | 208 if (tray_view()) |
178 tray_view()->SetVisible(GetInitialVisibility()); | 209 tray_view()->SetVisible(GetInitialVisibility()); |
179 if (volume_view_) { | 210 if (volume_view_) { |
180 volume_view_->SetVolumeLevel( | 211 volume_view_->SetVolumeLevel( |
181 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 212 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
182 volume_view_->Update(); | 213 volume_view_->Update(); |
183 } | 214 } |
184 } | 215 } |
185 | 216 |
186 } // namespace ash | 217 } // namespace ash |
OLD | NEW |