Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 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 namespace ash { | 41 namespace ash { |
| 42 | 42 |
| 43 TrayAudio::TrayAudio(SystemTray* system_tray, | 43 TrayAudio::TrayAudio(SystemTray* system_tray, |
| 44 std::unique_ptr<system::TrayAudioDelegate> audio_delegate) | 44 std::unique_ptr<system::TrayAudioDelegate> audio_delegate) |
| 45 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), | 45 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), |
| 46 audio_delegate_(std::move(audio_delegate)), | 46 audio_delegate_(std::move(audio_delegate)), |
| 47 volume_view_(NULL), | 47 volume_view_(NULL), |
| 48 pop_up_volume_view_(false) { | 48 pop_up_volume_view_(false), |
| 49 WmShell::Get()->system_tray_notifier()->AddAudioObserver(this); | 49 hide_popup_(false) { |
| 50 SystemTrayNotifier* notifier = WmShell::Get()->system_tray_notifier(); | |
| 51 notifier->AddAudioObserver(this); | |
| 52 notifier->AddMaximizeModeScreenshotObserver(this); | |
| 50 display::Screen::GetScreen()->AddObserver(this); | 53 display::Screen::GetScreen()->AddObserver(this); |
| 51 } | 54 } |
| 52 | 55 |
| 53 TrayAudio::~TrayAudio() { | 56 TrayAudio::~TrayAudio() { |
| 54 display::Screen::GetScreen()->RemoveObserver(this); | 57 display::Screen::GetScreen()->RemoveObserver(this); |
| 55 WmShell::Get()->system_tray_notifier()->RemoveAudioObserver(this); | 58 SystemTrayNotifier* notifier = WmShell::Get()->system_tray_notifier(); |
| 59 notifier->RemoveMaximizeModeScreenshotObserver(this); | |
| 60 notifier->RemoveAudioObserver(this); | |
| 56 } | 61 } |
| 57 | 62 |
| 58 // static | 63 // static |
| 59 bool TrayAudio::ShowAudioDeviceMenu() { | 64 bool TrayAudio::ShowAudioDeviceMenu() { |
| 60 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
| 61 return true; | 66 return true; |
| 62 #else | 67 #else |
| 63 return false; | 68 return false; |
| 64 #endif | 69 #endif |
| 65 } | 70 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | 108 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; |
| 104 if (tray_view()) | 109 if (tray_view()) |
| 105 tray_view()->SetVisible(GetInitialVisibility()); | 110 tray_view()->SetVisible(GetInitialVisibility()); |
| 106 | 111 |
| 107 if (volume_view_) { | 112 if (volume_view_) { |
| 108 volume_view_->SetVolumeLevel(percent); | 113 volume_view_->SetVolumeLevel(percent); |
| 109 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 114 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
| 110 return; | 115 return; |
| 111 } | 116 } |
| 112 pop_up_volume_view_ = true; | 117 pop_up_volume_view_ = true; |
| 113 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 118 // When the OutputNodeVolumeChanged is caused by a volume restore after |
| 119 // maximize mode screenshot, it should not cause UI popup. | |
| 120 if (!hide_popup_) | |
| 121 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | |
| 122 else | |
| 123 hide_popup_ = false; | |
|
Daniel Erat
2016/07/28 04:45:00
this approach (hiding the next popup) feels a bit
Qiang(Joe) Xu
2016/07/28 20:25:02
done by moving the logic to cras_audio_handler
| |
| 114 } | 124 } |
| 115 | 125 |
| 116 void TrayAudio::OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) { | 126 void TrayAudio::OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) { |
| 117 if (tray_view()) | 127 if (tray_view()) |
| 118 tray_view()->SetVisible(GetInitialVisibility()); | 128 tray_view()->SetVisible(GetInitialVisibility()); |
| 119 | 129 |
| 120 if (volume_view_) { | 130 if (volume_view_) { |
| 121 volume_view_->Update(); | 131 volume_view_->Update(); |
| 122 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 132 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
| 123 } else if (!system_adjust) { | 133 } else if (!system_adjust) { |
| 124 pop_up_volume_view_ = true; | 134 pop_up_volume_view_ = true; |
| 125 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 135 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
| 126 } | 136 } |
| 127 } | 137 } |
| 128 | 138 |
| 129 void TrayAudio::OnAudioNodesChanged() { | 139 void TrayAudio::OnAudioNodesChanged() { |
| 130 Update(); | 140 Update(); |
| 131 } | 141 } |
| 132 | 142 |
| 133 void TrayAudio::OnActiveOutputNodeChanged() { | 143 void TrayAudio::OnActiveOutputNodeChanged() { |
| 134 Update(); | 144 Update(); |
| 135 } | 145 } |
| 136 | 146 |
| 137 void TrayAudio::OnActiveInputNodeChanged() { | 147 void TrayAudio::OnActiveInputNodeChanged() { |
| 138 Update(); | 148 Update(); |
| 139 } | 149 } |
| 140 | 150 |
| 151 void TrayAudio::OnWillTakeScreenshotInMaximizeMode() { | |
| 152 HideDetailedView(); | |
| 153 hide_popup_ = true; | |
| 154 } | |
| 155 | |
| 141 void TrayAudio::ChangeInternalSpeakerChannelMode() { | 156 void TrayAudio::ChangeInternalSpeakerChannelMode() { |
| 142 // Swap left/right channel only if it is in Yoga mode. | 157 // Swap left/right channel only if it is in Yoga mode. |
| 143 system::TrayAudioDelegate::AudioChannelMode channel_mode = | 158 system::TrayAudioDelegate::AudioChannelMode channel_mode = |
| 144 system::TrayAudioDelegate::NORMAL; | 159 system::TrayAudioDelegate::NORMAL; |
| 145 if (display::Display::HasInternalDisplay()) { | 160 if (display::Display::HasInternalDisplay()) { |
| 146 const DisplayInfo& display_info = | 161 const DisplayInfo& display_info = |
| 147 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); | 162 WmShell::Get()->GetDisplayInfo(display::Display::InternalDisplayId()); |
| 148 if (display_info.GetActiveRotation() == display::Display::ROTATE_180) | 163 if (display_info.GetActiveRotation() == display::Display::ROTATE_180) |
| 149 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; | 164 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; |
| 150 } | 165 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 177 if (tray_view()) | 192 if (tray_view()) |
| 178 tray_view()->SetVisible(GetInitialVisibility()); | 193 tray_view()->SetVisible(GetInitialVisibility()); |
| 179 if (volume_view_) { | 194 if (volume_view_) { |
| 180 volume_view_->SetVolumeLevel( | 195 volume_view_->SetVolumeLevel( |
| 181 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 196 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
| 182 volume_view_->Update(); | 197 volume_view_->Update(); |
| 183 } | 198 } |
| 184 } | 199 } |
| 185 | 200 |
| 186 } // namespace ash | 201 } // namespace ash |
| OLD | NEW |