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/chromeos/audio/tray_audio.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include "ash/common/system/chromeos/audio/audio_detailed_view.h" |
| 8 #include <utility> | 8 #include "ash/common/system/chromeos/audio/tray_audio_delegate_chromeos.h" |
| 9 | 9 #include "ash/common/system/chromeos/audio/volume_view.h" |
| 10 #include "ash/common/ash_constants.h" | |
| 11 #include "ash/common/system/audio/tray_audio_delegate.h" | |
| 12 #include "ash/common/system/audio/volume_view.h" | |
| 13 #include "ash/common/system/tray/actionable_view.h" | |
| 14 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | |
| 15 #include "ash/common/system/tray/hover_highlight_view.h" | |
| 16 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 17 #include "ash/common/system/tray/system_tray_notifier.h" | 10 #include "ash/common/system/tray/system_tray_notifier.h" |
| 18 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 19 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 21 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
| 22 #include "third_party/skia/include/core/SkCanvas.h" | |
| 23 #include "third_party/skia/include/core/SkPaint.h" | |
| 24 #include "third_party/skia/include/core/SkRect.h" | |
| 25 #include "third_party/skia/include/effects/SkGradientShader.h" | |
| 26 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 27 #include "ui/display/manager/managed_display_info.h" | 16 #include "ui/display/manager/managed_display_info.h" |
| 28 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 29 #include "ui/gfx/canvas.h" | |
| 30 #include "ui/gfx/font_list.h" | |
| 31 #include "ui/gfx/image/image.h" | |
| 32 #include "ui/gfx/image/image_skia_operations.h" | |
| 33 #include "ui/views/controls/button/image_button.h" | |
| 34 #include "ui/views/controls/image_view.h" | |
| 35 #include "ui/views/controls/label.h" | |
| 36 #include "ui/views/layout/box_layout.h" | |
| 37 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 38 | 19 |
| 39 namespace ash { | 20 namespace ash { |
| 40 | 21 |
| 41 TrayAudio::TrayAudio(SystemTray* system_tray, | 22 using chromeos::DBusThreadManager; |
| 42 std::unique_ptr<system::TrayAudioDelegate> audio_delegate) | 23 using system::TrayAudioDelegate; |
| 24 using system::TrayAudioDelegateChromeOs; | |
| 25 | |
| 26 TrayAudio::TrayAudio(SystemTray* system_tray) | |
| 43 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), | 27 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE, UMA_AUDIO), |
| 44 audio_delegate_(std::move(audio_delegate)), | 28 audio_delegate_(new TrayAudioDelegateChromeOs()), |
| 45 volume_view_(NULL), | 29 volume_view_(nullptr), |
| 46 pop_up_volume_view_(false) { | 30 pop_up_volume_view_(false), |
| 31 audio_detail_view_(nullptr) { | |
| 47 WmShell::Get()->system_tray_notifier()->AddAudioObserver(this); | 32 WmShell::Get()->system_tray_notifier()->AddAudioObserver(this); |
| 48 display::Screen::GetScreen()->AddObserver(this); | 33 display::Screen::GetScreen()->AddObserver(this); |
| 34 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
| 49 } | 35 } |
| 50 | 36 |
| 51 TrayAudio::~TrayAudio() { | 37 TrayAudio::~TrayAudio() { |
| 38 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 52 display::Screen::GetScreen()->RemoveObserver(this); | 39 display::Screen::GetScreen()->RemoveObserver(this); |
| 53 WmShell::Get()->system_tray_notifier()->RemoveAudioObserver(this); | 40 WmShell::Get()->system_tray_notifier()->RemoveAudioObserver(this); |
| 54 } | 41 } |
| 55 | 42 |
| 56 // static | |
| 57 bool TrayAudio::ShowAudioDeviceMenu() { | |
| 58 #if defined(OS_CHROMEOS) | |
| 59 return true; | |
| 60 #else | |
| 61 return false; | |
| 62 #endif | |
| 63 } | |
| 64 | |
| 65 bool TrayAudio::GetInitialVisibility() { | 43 bool TrayAudio::GetInitialVisibility() { |
| 66 return audio_delegate_->IsOutputAudioMuted(); | 44 return audio_delegate_->IsOutputAudioMuted(); |
| 67 } | 45 } |
| 68 | 46 |
| 69 views::View* TrayAudio::CreateDefaultView(LoginStatus status) { | 47 views::View* TrayAudio::CreateDefaultView(LoginStatus status) { |
| 70 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true); | 48 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), true); |
| 71 return volume_view_; | 49 return volume_view_; |
| 72 } | 50 } |
| 73 | 51 |
| 74 views::View* TrayAudio::CreateDetailedView(LoginStatus status) { | 52 views::View* TrayAudio::CreateDetailedView(LoginStatus status) { |
| 75 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), false); | 53 if (pop_up_volume_view_) { |
| 76 return volume_view_; | 54 volume_view_ = new tray::VolumeView(this, audio_delegate_.get(), false); |
| 55 return volume_view_; | |
| 56 } else { | |
| 57 WmShell::Get()->RecordUserMetricsAction( | |
| 58 UMA_STATUS_AREA_DETAILED_AUDIO_VIEW); | |
| 59 audio_detail_view_ = new tray::AudioDetailedView(this); | |
| 60 return audio_detail_view_; | |
| 61 } | |
| 77 } | 62 } |
| 78 | 63 |
| 79 void TrayAudio::DestroyDefaultView() { | 64 void TrayAudio::DestroyDefaultView() { |
| 80 volume_view_ = NULL; | 65 volume_view_ = NULL; |
| 81 } | 66 } |
| 82 | 67 |
| 83 void TrayAudio::DestroyDetailedView() { | 68 void TrayAudio::DestroyDetailedView() { |
| 84 if (volume_view_) { | 69 if (audio_detail_view_) { |
| 70 audio_detail_view_ = nullptr; | |
| 71 } else if (volume_view_) { | |
| 85 volume_view_ = NULL; | 72 volume_view_ = NULL; |
|
jennyz
2016/11/11 00:07:55
NULL -> nullptr
James Cook
2016/11/11 01:32:44
Done.
| |
| 86 pop_up_volume_view_ = false; | 73 pop_up_volume_view_ = false; |
| 87 } | 74 } |
| 88 } | 75 } |
| 89 | 76 |
| 90 bool TrayAudio::ShouldHideArrow() const { | 77 bool TrayAudio::ShouldHideArrow() const { |
| 91 return true; | 78 return true; |
| 92 } | 79 } |
| 93 | 80 |
| 94 bool TrayAudio::ShouldShowShelf() const { | 81 bool TrayAudio::ShouldShowShelf() const { |
| 95 return TrayAudio::ShowAudioDeviceMenu() && !pop_up_volume_view_; | 82 return !pop_up_volume_view_; |
| 96 } | 83 } |
| 97 | 84 |
| 98 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, | 85 void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, |
| 99 double /* volume */) { | 86 double /* volume */) { |
| 100 float percent = | 87 float percent = |
| 101 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | 88 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; |
| 102 if (tray_view()) | 89 if (tray_view()) |
| 103 tray_view()->SetVisible(GetInitialVisibility()); | 90 tray_view()->SetVisible(GetInitialVisibility()); |
| 104 | 91 |
| 105 if (volume_view_) { | 92 if (volume_view_) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; | 134 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; |
| 148 } | 135 } |
| 149 | 136 |
| 150 audio_delegate_->SetInternalSpeakerChannelMode(channel_mode); | 137 audio_delegate_->SetInternalSpeakerChannelMode(channel_mode); |
| 151 } | 138 } |
| 152 | 139 |
| 153 void TrayAudio::OnDisplayAdded(const display::Display& new_display) { | 140 void TrayAudio::OnDisplayAdded(const display::Display& new_display) { |
| 154 if (!new_display.IsInternal()) | 141 if (!new_display.IsInternal()) |
| 155 return; | 142 return; |
| 156 ChangeInternalSpeakerChannelMode(); | 143 ChangeInternalSpeakerChannelMode(); |
| 144 | |
| 145 // This event will be triggered when the lid of the device is opened to exit | |
| 146 // the docked mode, we should always start or re-start HDMI re-discovering | |
| 147 // grace period right after this event. | |
| 148 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true); | |
| 157 } | 149 } |
| 158 | 150 |
| 159 void TrayAudio::OnDisplayRemoved(const display::Display& old_display) { | 151 void TrayAudio::OnDisplayRemoved(const display::Display& old_display) { |
| 160 if (!old_display.IsInternal()) | 152 if (!old_display.IsInternal()) |
| 161 return; | 153 return; |
| 162 ChangeInternalSpeakerChannelMode(); | 154 ChangeInternalSpeakerChannelMode(); |
| 155 | |
| 156 // This event will be triggered when the lid of the device is closed to enter | |
| 157 // the docked mode, we should always start or re-start HDMI re-discovering | |
| 158 // grace period right after this event. | |
| 159 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true); | |
| 163 } | 160 } |
| 164 | 161 |
| 165 void TrayAudio::OnDisplayMetricsChanged(const display::Display& display, | 162 void TrayAudio::OnDisplayMetricsChanged(const display::Display& display, |
| 166 uint32_t changed_metrics) { | 163 uint32_t changed_metrics) { |
| 167 if (!display.IsInternal()) | 164 if (!display.IsInternal()) |
| 168 return; | 165 return; |
| 169 | 166 |
| 170 if (changed_metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION) | 167 if (changed_metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION) |
| 171 ChangeInternalSpeakerChannelMode(); | 168 ChangeInternalSpeakerChannelMode(); |
| 169 | |
| 170 // The event could be triggered multiple times during the HDMI display | |
| 171 // transition, we don't need to restart HDMI re-discovering grace period | |
| 172 // it is already started earlier. | |
| 173 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(false); | |
| 174 } | |
| 175 | |
| 176 void TrayAudio::SuspendDone(const base::TimeDelta& sleep_duration) { | |
| 177 // This event is triggered when the device resumes after earlier suspension, | |
| 178 // we should always start or re-start HDMI re-discovering | |
| 179 // grace period right after this event. | |
| 180 audio_delegate_->SetActiveHDMIOutoutRediscoveringIfNecessary(true); | |
| 172 } | 181 } |
| 173 | 182 |
| 174 void TrayAudio::Update() { | 183 void TrayAudio::Update() { |
| 175 if (tray_view()) | 184 if (tray_view()) |
| 176 tray_view()->SetVisible(GetInitialVisibility()); | 185 tray_view()->SetVisible(GetInitialVisibility()); |
| 177 if (volume_view_) { | 186 if (volume_view_) { |
| 178 volume_view_->SetVolumeLevel( | 187 volume_view_->SetVolumeLevel( |
| 179 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 188 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
| 180 volume_view_->Update(); | 189 volume_view_->Update(); |
| 181 } | 190 } |
| 191 | |
| 192 if (audio_detail_view_) | |
| 193 audio_detail_view_->Update(); | |
| 182 } | 194 } |
| 183 | 195 |
| 184 } // namespace ash | 196 } // namespace ash |
| OLD | NEW |