| 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" | 8 #include "ash/common/system/chromeos/audio/tray_audio_delegate_chromeos.h" |
| 9 #include "ash/common/system/chromeos/audio/volume_view.h" | 9 #include "ash/common/system/chromeos/audio/volume_view.h" |
| 10 #include "ash/common/system/tray/system_tray_notifier.h" | 10 #include "ash/common/system/tray/system_tray.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/wm_root_window_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/common/wm_window.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 15 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
| 16 #include "ui/display/manager/managed_display_info.h" | 18 #include "ui/display/manager/managed_display_info.h" |
| 17 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 18 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 19 | 21 |
| 20 namespace ash { | 22 namespace ash { |
| 21 | 23 |
| 24 using chromeos::CrasAudioHandler; |
| 22 using chromeos::DBusThreadManager; | 25 using chromeos::DBusThreadManager; |
| 23 using system::TrayAudioDelegate; | 26 using system::TrayAudioDelegate; |
| 24 using system::TrayAudioDelegateChromeOs; | 27 using system::TrayAudioDelegateChromeOs; |
| 25 | 28 |
| 26 TrayAudio::TrayAudio(SystemTray* system_tray) | 29 TrayAudio::TrayAudio(SystemTray* system_tray) |
| 27 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), | 30 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), |
| 28 audio_delegate_(new TrayAudioDelegateChromeOs()), | 31 audio_delegate_(new TrayAudioDelegateChromeOs()), |
| 29 volume_view_(nullptr), | 32 volume_view_(nullptr), |
| 30 pop_up_volume_view_(false), | 33 pop_up_volume_view_(false), |
| 31 audio_detail_view_(nullptr) { | 34 audio_detail_view_(nullptr) { |
| 32 WmShell::Get()->system_tray_notifier()->AddAudioObserver(this); | 35 if (CrasAudioHandler::IsInitialized()) |
| 36 CrasAudioHandler::Get()->AddAudioObserver(this); |
| 33 display::Screen::GetScreen()->AddObserver(this); | 37 display::Screen::GetScreen()->AddObserver(this); |
| 34 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 38 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 35 } | 39 } |
| 36 | 40 |
| 37 TrayAudio::~TrayAudio() { | 41 TrayAudio::~TrayAudio() { |
| 38 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 42 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 39 display::Screen::GetScreen()->RemoveObserver(this); | 43 display::Screen::GetScreen()->RemoveObserver(this); |
| 40 WmShell::Get()->system_tray_notifier()->RemoveAudioObserver(this); | 44 if (CrasAudioHandler::IsInitialized()) |
| 45 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
| 46 } |
| 47 |
| 48 // static |
| 49 void TrayAudio::ShowPopUpVolumeView() { |
| 50 // Show the popup on all monitors with a system tray. |
| 51 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { |
| 52 SystemTray* system_tray = root->GetRootWindowController()->GetSystemTray(); |
| 53 if (!system_tray) |
| 54 continue; |
| 55 // Show the popup by simulating a volume change. The provided node id and |
| 56 // volume value are ignored. |
| 57 system_tray->GetTrayAudio()->OnOutputNodeVolumeChanged(0, 0); |
| 58 } |
| 41 } | 59 } |
| 42 | 60 |
| 43 bool TrayAudio::GetInitialVisibility() { | 61 bool TrayAudio::GetInitialVisibility() { |
| 44 return audio_delegate_->IsOutputAudioMuted(); | 62 return audio_delegate_->IsOutputAudioMuted(); |
| 45 } | 63 } |
| 46 | 64 |
| 47 views::View* TrayAudio::CreateDefaultView(LoginStatus status) { | 65 views::View* TrayAudio::CreateDefaultView(LoginStatus status) { |
| 48 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true); | 66 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true); |
| 49 return volume_view_; | 67 return volume_view_; |
| 50 } | 68 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 76 | 94 |
| 77 bool TrayAudio::ShouldHideArrow() const { | 95 bool TrayAudio::ShouldHideArrow() const { |
| 78 return true; | 96 return true; |
| 79 } | 97 } |
| 80 | 98 |
| 81 bool TrayAudio::ShouldShowShelf() const { | 99 bool TrayAudio::ShouldShowShelf() const { |
| 82 return !pop_up_volume_view_; | 100 return !pop_up_volume_view_; |
| 83 } | 101 } |
| 84 | 102 |
| 85 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, | 103 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, |
| 86 double /* volume */) { | 104 int /* volume */) { |
| 87 float percent = | 105 float percent = |
| 88 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | 106 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; |
| 89 if (tray_view()) | 107 if (tray_view()) |
| 90 tray_view()->SetVisible(GetInitialVisibility()); | 108 tray_view()->SetVisible(GetInitialVisibility()); |
| 91 | 109 |
| 92 if (volume_view_) { | 110 if (volume_view_) { |
| 93 volume_view_->SetVolumeLevel(percent); | 111 volume_view_->SetVolumeLevel(percent); |
| 94 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 112 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
| 95 return; | 113 return; |
| 96 } | 114 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 volume_view_->SetVolumeLevel( | 205 volume_view_->SetVolumeLevel( |
| 188 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 206 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
| 189 volume_view_->Update(); | 207 volume_view_->Update(); |
| 190 } | 208 } |
| 191 | 209 |
| 192 if (audio_detail_view_) | 210 if (audio_detail_view_) |
| 193 audio_detail_view_->Update(); | 211 audio_detail_view_->Update(); |
| 194 } | 212 } |
| 195 | 213 |
| 196 } // namespace ash | 214 } // namespace ash |
| OLD | NEW |