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/system/audio/tray_audio.h" | 5 #include "ash/system/audio/tray_audio.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
10 #include "ash/display/display_manager.h" | |
10 #include "ash/metrics/user_metrics_recorder.h" | 11 #include "ash/metrics/user_metrics_recorder.h" |
11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
12 #include "ash/system/audio/tray_audio_delegate.h" | 13 #include "ash/system/audio/tray_audio_delegate.h" |
13 #include "ash/system/audio/volume_view.h" | 14 #include "ash/system/audio/volume_view.h" |
14 #include "ash/system/tray/actionable_view.h" | 15 #include "ash/system/tray/actionable_view.h" |
15 #include "ash/system/tray/fixed_sized_scroll_view.h" | 16 #include "ash/system/tray/fixed_sized_scroll_view.h" |
16 #include "ash/system/tray/hover_highlight_view.h" | 17 #include "ash/system/tray/hover_highlight_view.h" |
17 #include "ash/system/tray/system_tray.h" | 18 #include "ash/system/tray/system_tray.h" |
18 #include "ash/system/tray/system_tray_delegate.h" | 19 #include "ash/system/tray/system_tray_delegate.h" |
19 #include "ash/system/tray/system_tray_notifier.h" | 20 #include "ash/system/tray/system_tray_notifier.h" |
20 #include "ash/system/tray/tray_constants.h" | 21 #include "ash/system/tray/tray_constants.h" |
21 #include "ash/volume_control_delegate.h" | 22 #include "ash/volume_control_delegate.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "grit/ash_resources.h" | 24 #include "grit/ash_resources.h" |
24 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
25 #include "third_party/skia/include/core/SkPaint.h" | 26 #include "third_party/skia/include/core/SkPaint.h" |
26 #include "third_party/skia/include/core/SkRect.h" | 27 #include "third_party/skia/include/core/SkRect.h" |
27 #include "third_party/skia/include/effects/SkGradientShader.h" | 28 #include "third_party/skia/include/effects/SkGradientShader.h" |
28 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
30 #include "ui/gfx/display.h" | |
29 #include "ui/gfx/font_list.h" | 31 #include "ui/gfx/font_list.h" |
30 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
31 #include "ui/gfx/image/image_skia_operations.h" | 33 #include "ui/gfx/image/image_skia_operations.h" |
32 #include "ui/views/controls/button/image_button.h" | 34 #include "ui/views/controls/button/image_button.h" |
33 #include "ui/views/controls/image_view.h" | 35 #include "ui/views/controls/image_view.h" |
34 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
35 #include "ui/views/controls/slider.h" | 37 #include "ui/views/controls/slider.h" |
36 #include "ui/views/layout/box_layout.h" | 38 #include "ui/views/layout/box_layout.h" |
37 #include "ui/views/view.h" | 39 #include "ui/views/view.h" |
38 | 40 |
39 namespace ash { | 41 namespace ash { |
40 | 42 |
41 TrayAudio::TrayAudio(SystemTray* system_tray, | 43 TrayAudio::TrayAudio(SystemTray* system_tray, |
42 scoped_ptr<system::TrayAudioDelegate> audio_delegate) | 44 scoped_ptr<system::TrayAudioDelegate> audio_delegate) |
43 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE), | 45 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE), |
44 audio_delegate_(audio_delegate.Pass()), | 46 audio_delegate_(audio_delegate.Pass()), |
45 volume_view_(NULL), | 47 volume_view_(NULL), |
46 pop_up_volume_view_(false) { | 48 pop_up_volume_view_(false) { |
47 Shell::GetInstance()->system_tray_notifier()->AddAudioObserver(this); | 49 Shell::GetInstance()->system_tray_notifier()->AddAudioObserver(this); |
50 Shell::GetScreen()->AddObserver(this); | |
48 } | 51 } |
49 | 52 |
50 TrayAudio::~TrayAudio() { | 53 TrayAudio::~TrayAudio() { |
54 Shell::GetScreen()->RemoveObserver(this); | |
51 Shell::GetInstance()->system_tray_notifier()->RemoveAudioObserver(this); | 55 Shell::GetInstance()->system_tray_notifier()->RemoveAudioObserver(this); |
52 } | 56 } |
53 | 57 |
54 // static | 58 // static |
55 bool TrayAudio::ShowAudioDeviceMenu() { | 59 bool TrayAudio::ShowAudioDeviceMenu() { |
56 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
57 return true; | 61 return true; |
58 #else | 62 #else |
59 return false; | 63 return false; |
60 #endif | 64 #endif |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 } | 130 } |
127 | 131 |
128 void TrayAudio::OnActiveOutputNodeChanged() { | 132 void TrayAudio::OnActiveOutputNodeChanged() { |
129 Update(); | 133 Update(); |
130 } | 134 } |
131 | 135 |
132 void TrayAudio::OnActiveInputNodeChanged() { | 136 void TrayAudio::OnActiveInputNodeChanged() { |
133 Update(); | 137 Update(); |
134 } | 138 } |
135 | 139 |
140 void TrayAudio::OnDisplayAdded(const gfx::Display& new_display) { | |
oshima
2014/10/01 21:53:55
you should do the same here, in case the device ca
jennyz
2014/10/01 22:03:50
Done.
| |
141 } | |
142 | |
143 void TrayAudio::OnDisplayRemoved(const gfx::Display& old_display) { | |
144 if (old_display.id() != gfx::Display::InternalDisplayId()) | |
145 return; | |
146 ChangeInternalSpeakerChannelMode(); | |
147 } | |
148 | |
149 void TrayAudio::OnDisplayMetricsChanged(const gfx::Display& display, | |
150 uint32_t changed_metrics) { | |
151 if (display.id() != gfx::Display::InternalDisplayId()) | |
152 return; | |
153 | |
154 if (changed_metrics & gfx::DisplayObserver::DISPLAY_METRIC_ROTATION) | |
155 ChangeInternalSpeakerChannelMode(); | |
156 } | |
157 | |
158 void TrayAudio::ChangeInternalSpeakerChannelMode() { | |
159 // Swap left/right channel only if it is in Yoga mode. | |
160 system::TrayAudioDelegate::AudioChannelMode channel_mode = | |
161 system::TrayAudioDelegate::NORMAL; | |
162 if (gfx::Display::InternalDisplayId() != gfx::Display::kInvalidDisplayID) { | |
163 const DisplayInfo& display_info = | |
164 Shell::GetInstance()->display_manager()->GetDisplayInfo( | |
165 gfx::Display::InternalDisplayId()); | |
166 if (display_info.rotation() == gfx::Display::ROTATE_180) | |
167 channel_mode = system::TrayAudioDelegate::LEFT_RIGHT_SWAPPED; | |
168 } | |
169 | |
170 audio_delegate_->SetInternalSpeakerChannelMode(channel_mode); | |
171 } | |
172 | |
136 void TrayAudio::Update() { | 173 void TrayAudio::Update() { |
137 if (tray_view()) | 174 if (tray_view()) |
138 tray_view()->SetVisible(GetInitialVisibility()); | 175 tray_view()->SetVisible(GetInitialVisibility()); |
139 if (volume_view_) { | 176 if (volume_view_) { |
140 volume_view_->SetVolumeLevel( | 177 volume_view_->SetVolumeLevel( |
141 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 178 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
142 volume_view_->Update(); | 179 volume_view_->Update(); |
143 } | 180 } |
144 } | 181 } |
145 | 182 |
146 } // namespace ash | 183 } // namespace ash |
OLD | NEW |