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/audio_detailed_view.h" | 5 #include "ash/system/audio/audio_detailed_view.h" |
6 | 6 |
7 #include "ash/resources/vector_icons/vector_icons.h" | 7 #include "ash/resources/vector_icons/vector_icons.h" |
8 #include "ash/strings/grit/ash_strings.h" | 8 #include "ash/strings/grit/ash_strings.h" |
9 #include "ash/system/tray/hover_highlight_view.h" | 9 #include "ash/system/tray/hover_highlight_view.h" |
10 #include "ash/system/tray/tray_popup_utils.h" | 10 #include "ash/system/tray/tray_popup_utils.h" |
11 #include "ash/system/tray/tri_view.h" | 11 #include "ash/system/tray/tri_view.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chromeos/audio/cras_audio_handler.h" | 13 #include "chromeos/audio/cras_audio_handler.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/gfx/color_palette.h" | 15 #include "ui/gfx/color_palette.h" |
16 #include "ui/gfx/paint_vector_icon.h" | |
17 #include "ui/native_theme/native_theme.h" | |
18 #include "ui/views/controls/image_view.h" | 16 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/controls/label.h" | |
20 #include "ui/views/controls/scroll_view.h" | 17 #include "ui/views/controls/scroll_view.h" |
21 #include "ui/views/controls/separator.h" | 18 #include "ui/views/controls/separator.h" |
22 | 19 |
23 namespace { | 20 namespace { |
24 | 21 |
25 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { | 22 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { |
26 switch (device.type) { | 23 switch (device.type) { |
27 case chromeos::AUDIO_TYPE_FRONT_MIC: | 24 case chromeos::AUDIO_TYPE_FRONT_MIC: |
28 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_FRONT_MIC); | 25 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_FRONT_MIC); |
29 case chromeos::AUDIO_TYPE_HEADPHONE: | 26 case chromeos::AUDIO_TYPE_HEADPHONE: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 Update(); | 63 Update(); |
67 } | 64 } |
68 | 65 |
69 AudioDetailedView::~AudioDetailedView() {} | 66 AudioDetailedView::~AudioDetailedView() {} |
70 | 67 |
71 void AudioDetailedView::Update() { | 68 void AudioDetailedView::Update() { |
72 UpdateAudioDevices(); | 69 UpdateAudioDevices(); |
73 Layout(); | 70 Layout(); |
74 } | 71 } |
75 | 72 |
76 void AudioDetailedView::AddInputHeader() { | 73 void AudioDetailedView::AddAudioSubHeader(const gfx::VectorIcon& icon, |
77 AddScrollListInfoItem(IDS_ASH_STATUS_TRAY_AUDIO_INPUT, | 74 int text_id) { |
78 kSystemMenuAudioInputIcon); | 75 TriView* header = AddScrollListSubHeader(icon, text_id); |
79 } | |
80 | |
81 void AudioDetailedView::AddOutputHeader() { | |
82 AddScrollListInfoItem(IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT, | |
83 kSystemMenuAudioOutputIcon); | |
84 } | |
85 | |
86 void AudioDetailedView::AddScrollListInfoItem(int text_id, | |
87 const gfx::VectorIcon& icon) { | |
88 TriView* header = TrayPopupUtils::CreateDefaultRowView(); | |
89 TrayPopupUtils::ConfigureAsStickyHeader(header); | |
90 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView(); | |
91 image_view->SetImage(gfx::CreateVectorIcon( | |
92 icon, GetNativeTheme()->GetSystemColor( | |
93 ui::NativeTheme::kColorId_ProminentButtonColor))); | |
94 header->AddView(TriView::Container::START, image_view); | |
95 | |
96 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | |
97 label->SetText(l10n_util::GetStringUTF16(text_id)); | |
98 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | |
99 style.SetupLabel(label); | |
100 header->AddView(TriView::Container::CENTER, label); | |
101 | |
102 header->SetContainerVisible(TriView::Container::END, false); | 76 header->SetContainerVisible(TriView::Container::END, false); |
103 scroll_content()->AddChildView(header); | |
104 } | |
105 | |
106 HoverHighlightView* AudioDetailedView::AddScrollListItem( | |
107 const base::string16& text, | |
108 bool highlight, | |
109 bool checked) { | |
110 HoverHighlightView* container = new HoverHighlightView(this); | |
111 | |
112 container->AddLabelRow(text); | |
113 TrayPopupUtils::InitializeAsCheckableRow(container, checked); | |
114 | |
115 scroll_content()->AddChildView(container); | |
116 return container; | |
117 } | 77 } |
118 | 78 |
119 void AudioDetailedView::CreateItems() { | 79 void AudioDetailedView::CreateItems() { |
120 CreateScrollableList(); | 80 CreateScrollableList(); |
121 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO); | 81 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO); |
122 } | 82 } |
123 | 83 |
124 void AudioDetailedView::UpdateAudioDevices() { | 84 void AudioDetailedView::UpdateAudioDevices() { |
125 output_devices_.clear(); | 85 output_devices_.clear(); |
126 input_devices_.clear(); | 86 input_devices_.clear(); |
127 chromeos::AudioDeviceList devices; | 87 chromeos::AudioDeviceList devices; |
128 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 88 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
129 audio_handler->GetAudioDevices(&devices); | 89 audio_handler->GetAudioDevices(&devices); |
130 bool has_dual_internal_mic = audio_handler->HasDualInternalMic(); | 90 bool has_dual_internal_mic = audio_handler->HasDualInternalMic(); |
131 bool is_front_or_rear_mic_active = false; | 91 bool is_front_or_rear_mic_active = false; |
132 for (size_t i = 0; i < devices.size(); ++i) { | 92 for (const auto& device : devices) { |
133 // Don't display keyboard mic or aokr type. | 93 // Don't display keyboard mic or aokr type. |
134 if (!devices[i].is_for_simple_usage()) | 94 if (!device.is_for_simple_usage()) |
135 continue; | 95 continue; |
136 if (devices[i].is_input) { | 96 if (device.is_input) { |
137 // Do not expose the internal front and rear mic to UI. | 97 // Do not expose the internal front and rear mic to UI. |
138 if (has_dual_internal_mic && | 98 if (has_dual_internal_mic && audio_handler->IsFrontOrRearMic(device)) { |
139 audio_handler->IsFrontOrRearMic(devices[i])) { | 99 if (device.active) |
140 if (devices[i].active) | |
141 is_front_or_rear_mic_active = true; | 100 is_front_or_rear_mic_active = true; |
142 continue; | 101 continue; |
143 } | 102 } |
144 input_devices_.push_back(devices[i]); | 103 input_devices_.push_back(device); |
145 } else { | 104 } else { |
146 output_devices_.push_back(devices[i]); | 105 output_devices_.push_back(device); |
147 } | 106 } |
148 } | 107 } |
149 | 108 |
150 // Expose the dual internal mics as one device (internal mic) to user. | 109 // Expose the dual internal mics as one device (internal mic) to user. |
151 if (has_dual_internal_mic) { | 110 if (has_dual_internal_mic) { |
152 // Create stub internal mic entry for UI rendering, which representing | 111 // Create stub internal mic entry for UI rendering, which representing |
153 // both internal front and rear mics. | 112 // both internal front and rear mics. |
154 chromeos::AudioDevice internal_mic; | 113 chromeos::AudioDevice internal_mic; |
155 internal_mic.is_input = true; | 114 internal_mic.is_input = true; |
156 internal_mic.stable_device_id_version = 2; | 115 internal_mic.stable_device_id_version = 2; |
157 internal_mic.type = chromeos::AUDIO_TYPE_INTERNAL_MIC; | 116 internal_mic.type = chromeos::AUDIO_TYPE_INTERNAL_MIC; |
158 internal_mic.active = is_front_or_rear_mic_active; | 117 internal_mic.active = is_front_or_rear_mic_active; |
159 input_devices_.push_back(internal_mic); | 118 input_devices_.push_back(internal_mic); |
160 } | 119 } |
161 | 120 |
162 UpdateScrollableList(); | 121 UpdateScrollableList(); |
163 } | 122 } |
164 | 123 |
165 void AudioDetailedView::UpdateScrollableList() { | 124 void AudioDetailedView::UpdateScrollableList() { |
166 scroll_content()->RemoveAllChildViews(true); | 125 scroll_content()->RemoveAllChildViews(true); |
167 device_map_.clear(); | 126 device_map_.clear(); |
168 | 127 |
169 // Add audio output devices. | 128 // Add audio output devices. |
170 const bool has_output_devices = output_devices_.size() > 0; | 129 const bool has_output_devices = output_devices_.size() > 0; |
171 if (has_output_devices) | 130 if (has_output_devices) { |
172 AddOutputHeader(); | 131 AddAudioSubHeader(kSystemMenuAudioOutputIcon, |
| 132 IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT); |
| 133 } |
173 | 134 |
174 for (size_t i = 0; i < output_devices_.size(); ++i) { | 135 for (const auto& device : output_devices_) { |
175 HoverHighlightView* container = AddScrollListItem( | 136 HoverHighlightView* container = |
176 GetAudioDeviceName(output_devices_[i]), false /* highlight */, | 137 AddScrollListCheckableItem(GetAudioDeviceName(device), device.active); |
177 output_devices_[i].active); /* checkmark if active */ | 138 device_map_[container] = device; |
178 device_map_[container] = output_devices_[i]; | |
179 } | 139 } |
180 | 140 |
181 if (has_output_devices) { | 141 if (has_output_devices) { |
182 scroll_content()->AddChildView( | 142 scroll_content()->AddChildView( |
183 TrayPopupUtils::CreateListSubHeaderSeparator()); | 143 TrayPopupUtils::CreateListSubHeaderSeparator()); |
184 } | 144 } |
185 | 145 |
186 // Add audio input devices. | 146 // Add audio input devices. |
187 const bool has_input_devices = input_devices_.size() > 0; | 147 const bool has_input_devices = input_devices_.size() > 0; |
188 if (has_input_devices) | 148 if (has_input_devices) { |
189 AddInputHeader(); | 149 AddAudioSubHeader(kSystemMenuAudioInputIcon, |
| 150 IDS_ASH_STATUS_TRAY_AUDIO_INPUT); |
| 151 } |
190 | 152 |
191 for (size_t i = 0; i < input_devices_.size(); ++i) { | 153 for (const auto& device : input_devices_) { |
192 HoverHighlightView* container = AddScrollListItem( | 154 HoverHighlightView* container = |
193 GetAudioDeviceName(input_devices_[i]), false /* highlight */, | 155 AddScrollListCheckableItem(GetAudioDeviceName(device), device.active); |
194 input_devices_[i].active); /* checkmark if active */ | 156 device_map_[container] = device; |
195 device_map_[container] = input_devices_[i]; | |
196 } | 157 } |
197 | 158 |
198 scroll_content()->SizeToPreferredSize(); | 159 scroll_content()->SizeToPreferredSize(); |
199 scroller()->Layout(); | 160 scroller()->Layout(); |
200 } | 161 } |
201 | 162 |
202 void AudioDetailedView::HandleViewClicked(views::View* view) { | 163 void AudioDetailedView::HandleViewClicked(views::View* view) { |
203 AudioDeviceMap::iterator iter = device_map_.find(view); | 164 AudioDeviceMap::iterator iter = device_map_.find(view); |
204 if (iter == device_map_.end()) | 165 if (iter == device_map_.end()) |
205 return; | 166 return; |
206 chromeos::AudioDevice device = iter->second; | 167 chromeos::AudioDevice device = iter->second; |
207 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 168 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
208 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC && | 169 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC && |
209 audio_handler->HasDualInternalMic()) { | 170 audio_handler->HasDualInternalMic()) { |
210 audio_handler->SwitchToFrontOrRearMic(); | 171 audio_handler->SwitchToFrontOrRearMic(); |
211 } else { | 172 } else { |
212 audio_handler->SwitchToDevice(device, true, | 173 audio_handler->SwitchToDevice(device, true, |
213 CrasAudioHandler::ACTIVATE_BY_USER); | 174 CrasAudioHandler::ACTIVATE_BY_USER); |
214 } | 175 } |
215 } | 176 } |
216 | 177 |
217 } // namespace tray | 178 } // namespace tray |
218 } // namespace ash | 179 } // namespace ash |
OLD | NEW |