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" | 16 #include "ui/gfx/paint_vector_icon.h" |
17 #include "ui/native_theme/native_theme.h" | |
18 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/controls/label.h" | |
20 #include "ui/views/controls/scroll_view.h" | 18 #include "ui/views/controls/scroll_view.h" |
21 #include "ui/views/controls/separator.h" | 19 #include "ui/views/controls/separator.h" |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
25 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { | 23 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { |
26 switch (device.type) { | 24 switch (device.type) { |
27 case chromeos::AUDIO_TYPE_FRONT_MIC: | 25 case chromeos::AUDIO_TYPE_FRONT_MIC: |
28 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_FRONT_MIC); | 26 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_FRONT_MIC); |
29 case chromeos::AUDIO_TYPE_HEADPHONE: | 27 case chromeos::AUDIO_TYPE_HEADPHONE: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 Update(); | 64 Update(); |
67 } | 65 } |
68 | 66 |
69 AudioDetailedView::~AudioDetailedView() {} | 67 AudioDetailedView::~AudioDetailedView() {} |
70 | 68 |
71 void AudioDetailedView::Update() { | 69 void AudioDetailedView::Update() { |
72 UpdateAudioDevices(); | 70 UpdateAudioDevices(); |
73 Layout(); | 71 Layout(); |
74 } | 72 } |
75 | 73 |
76 void AudioDetailedView::AddInputHeader() { | 74 void AudioDetailedView::AddAudioSubHeader(const gfx::VectorIcon& icon, |
77 AddScrollListInfoItem(IDS_ASH_STATUS_TRAY_AUDIO_INPUT, | 75 int text_id) { |
78 kSystemMenuAudioInputIcon); | 76 const base::string16 text = l10n_util::GetStringUTF16(text_id); |
79 } | 77 TriView* header = AddScrollListSubHeader(icon, text); |
tdanderson
2017/04/24 15:43:39
Consider passing in the text_id to AddScrollListSu
mohsen
2017/04/25 05:10:01
Done. I wanted AddScrollListSubHeader() to be more
tdanderson
2017/04/25 14:32:48
Ah I see, I guess we could have gone either way wi
| |
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(); | |
tdanderson
2017/04/24 15:43:39
Just wanted to double-check that this works as int
mohsen
2017/04/25 05:10:01
Yes, different layout managers are installed with
tdanderson
2017/04/25 14:32:48
By 'very similar' do you mean that the implementat
mohsen
2017/04/25 19:23:47
Yes, the label padding was 4 pixels off.
tdanderson
2017/04/25 21:00:27
Yes you're right. I was reading the function as "c
| |
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); | 78 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 } | 79 } |
118 | 80 |
119 void AudioDetailedView::CreateItems() { | 81 void AudioDetailedView::CreateItems() { |
120 CreateScrollableList(); | 82 CreateScrollableList(); |
121 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO); | 83 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO); |
122 } | 84 } |
123 | 85 |
124 void AudioDetailedView::UpdateAudioDevices() { | 86 void AudioDetailedView::UpdateAudioDevices() { |
125 output_devices_.clear(); | 87 output_devices_.clear(); |
126 input_devices_.clear(); | 88 input_devices_.clear(); |
127 chromeos::AudioDeviceList devices; | 89 chromeos::AudioDeviceList devices; |
128 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 90 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
129 audio_handler->GetAudioDevices(&devices); | 91 audio_handler->GetAudioDevices(&devices); |
130 bool has_dual_internal_mic = audio_handler->HasDualInternalMic(); | 92 bool has_dual_internal_mic = audio_handler->HasDualInternalMic(); |
131 bool is_front_or_rear_mic_active = false; | 93 bool is_front_or_rear_mic_active = false; |
132 for (size_t i = 0; i < devices.size(); ++i) { | 94 for (const auto& device : devices) { |
133 // Don't display keyboard mic or aokr type. | 95 // Don't display keyboard mic or aokr type. |
134 if (!devices[i].is_for_simple_usage()) | 96 if (!device.is_for_simple_usage()) |
135 continue; | 97 continue; |
136 if (devices[i].is_input) { | 98 if (device.is_input) { |
137 // Do not expose the internal front and rear mic to UI. | 99 // Do not expose the internal front and rear mic to UI. |
138 if (has_dual_internal_mic && | 100 if (has_dual_internal_mic && audio_handler->IsFrontOrRearMic(device)) { |
139 audio_handler->IsFrontOrRearMic(devices[i])) { | 101 if (device.active) |
140 if (devices[i].active) | |
141 is_front_or_rear_mic_active = true; | 102 is_front_or_rear_mic_active = true; |
142 continue; | 103 continue; |
143 } | 104 } |
144 input_devices_.push_back(devices[i]); | 105 input_devices_.push_back(device); |
145 } else { | 106 } else { |
146 output_devices_.push_back(devices[i]); | 107 output_devices_.push_back(device); |
147 } | 108 } |
148 } | 109 } |
149 | 110 |
150 // Expose the dual internal mics as one device (internal mic) to user. | 111 // Expose the dual internal mics as one device (internal mic) to user. |
151 if (has_dual_internal_mic) { | 112 if (has_dual_internal_mic) { |
152 // Create stub internal mic entry for UI rendering, which representing | 113 // Create stub internal mic entry for UI rendering, which representing |
153 // both internal front and rear mics. | 114 // both internal front and rear mics. |
154 chromeos::AudioDevice internal_mic; | 115 chromeos::AudioDevice internal_mic; |
155 internal_mic.is_input = true; | 116 internal_mic.is_input = true; |
156 internal_mic.stable_device_id_version = 2; | 117 internal_mic.stable_device_id_version = 2; |
157 internal_mic.type = chromeos::AUDIO_TYPE_INTERNAL_MIC; | 118 internal_mic.type = chromeos::AUDIO_TYPE_INTERNAL_MIC; |
158 internal_mic.active = is_front_or_rear_mic_active; | 119 internal_mic.active = is_front_or_rear_mic_active; |
159 input_devices_.push_back(internal_mic); | 120 input_devices_.push_back(internal_mic); |
160 } | 121 } |
161 | 122 |
162 UpdateScrollableList(); | 123 UpdateScrollableList(); |
163 } | 124 } |
164 | 125 |
165 void AudioDetailedView::UpdateScrollableList() { | 126 void AudioDetailedView::UpdateScrollableList() { |
166 scroll_content()->RemoveAllChildViews(true); | 127 scroll_content()->RemoveAllChildViews(true); |
167 device_map_.clear(); | 128 device_map_.clear(); |
168 | 129 |
169 // Add audio output devices. | 130 // Add audio output devices. |
170 const bool has_output_devices = output_devices_.size() > 0; | 131 const bool has_output_devices = output_devices_.size() > 0; |
171 if (has_output_devices) | 132 if (has_output_devices) { |
172 AddOutputHeader(); | 133 AddAudioSubHeader(kSystemMenuAudioOutputIcon, |
134 IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT); | |
135 } | |
173 | 136 |
174 for (size_t i = 0; i < output_devices_.size(); ++i) { | 137 for (const auto& device : output_devices_) { |
175 HoverHighlightView* container = AddScrollListItem( | 138 HoverHighlightView* container = AddScrollListCheckableItem( |
176 GetAudioDeviceName(output_devices_[i]), false /* highlight */, | 139 gfx::kNoneIcon, GetAudioDeviceName(device), device.active); |
177 output_devices_[i].active); /* checkmark if active */ | 140 device_map_[container] = device; |
178 device_map_[container] = output_devices_[i]; | |
179 } | 141 } |
180 | 142 |
181 if (has_output_devices) { | 143 if (has_output_devices) { |
182 scroll_content()->AddChildView( | 144 scroll_content()->AddChildView( |
183 TrayPopupUtils::CreateListSubHeaderSeparator()); | 145 TrayPopupUtils::CreateListSubHeaderSeparator()); |
184 } | 146 } |
185 | 147 |
186 // Add audio input devices. | 148 // Add audio input devices. |
187 const bool has_input_devices = input_devices_.size() > 0; | 149 const bool has_input_devices = input_devices_.size() > 0; |
188 if (has_input_devices) | 150 if (has_input_devices) { |
189 AddInputHeader(); | 151 AddAudioSubHeader(kSystemMenuAudioInputIcon, |
152 IDS_ASH_STATUS_TRAY_AUDIO_INPUT); | |
153 } | |
190 | 154 |
191 for (size_t i = 0; i < input_devices_.size(); ++i) { | 155 for (const auto& device : input_devices_) { |
192 HoverHighlightView* container = AddScrollListItem( | 156 HoverHighlightView* container = AddScrollListCheckableItem( |
193 GetAudioDeviceName(input_devices_[i]), false /* highlight */, | 157 gfx::kNoneIcon, GetAudioDeviceName(device), device.active); |
194 input_devices_[i].active); /* checkmark if active */ | 158 device_map_[container] = device; |
195 device_map_[container] = input_devices_[i]; | |
196 } | 159 } |
197 | 160 |
198 scroll_content()->SizeToPreferredSize(); | 161 scroll_content()->SizeToPreferredSize(); |
199 scroller()->Layout(); | 162 scroller()->Layout(); |
200 } | 163 } |
201 | 164 |
202 void AudioDetailedView::HandleViewClicked(views::View* view) { | 165 void AudioDetailedView::HandleViewClicked(views::View* view) { |
203 AudioDeviceMap::iterator iter = device_map_.find(view); | 166 AudioDeviceMap::iterator iter = device_map_.find(view); |
204 if (iter == device_map_.end()) | 167 if (iter == device_map_.end()) |
205 return; | 168 return; |
206 chromeos::AudioDevice device = iter->second; | 169 chromeos::AudioDevice device = iter->second; |
207 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 170 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
208 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC && | 171 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC && |
209 audio_handler->HasDualInternalMic()) { | 172 audio_handler->HasDualInternalMic()) { |
210 audio_handler->SwitchToFrontOrRearMic(); | 173 audio_handler->SwitchToFrontOrRearMic(); |
211 } else { | 174 } else { |
212 audio_handler->SwitchToDevice(device, true, | 175 audio_handler->SwitchToDevice(device, true, |
213 CrasAudioHandler::ACTIVATE_BY_USER); | 176 CrasAudioHandler::ACTIVATE_BY_USER); |
214 } | 177 } |
215 } | 178 } |
216 | 179 |
217 } // namespace tray | 180 } // namespace tray |
218 } // namespace ash | 181 } // namespace ash |
OLD | NEW |