Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: ash/common/system/chromeos/audio/audio_detailed_view.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/system/chromeos/audio/audio_detailed_view.h"
6
7 #include "ash/common/system/tray/hover_highlight_view.h"
8 #include "ash/common/system/tray/tray_popup_utils.h"
9 #include "ash/common/system/tray/tri_view.h"
10 #include "ash/strings/grit/ash_strings.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chromeos/audio/cras_audio_handler.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/gfx/color_palette.h"
15 #include "ui/gfx/paint_vector_icon.h"
16 #include "ui/gfx/vector_icons_public.h"
17 #include "ui/native_theme/native_theme.h"
18 #include "ui/views/controls/image_view.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/controls/scroll_view.h"
21 #include "ui/views/controls/separator.h"
22
23 namespace {
24
25 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) {
26 switch (device.type) {
27 case chromeos::AUDIO_TYPE_FRONT_MIC:
28 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_FRONT_MIC);
29 case chromeos::AUDIO_TYPE_HEADPHONE:
30 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_HEADPHONE);
31 case chromeos::AUDIO_TYPE_INTERNAL_SPEAKER:
32 return l10n_util::GetStringUTF16(
33 IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_SPEAKER);
34 case chromeos::AUDIO_TYPE_INTERNAL_MIC:
35 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_MIC);
36 case chromeos::AUDIO_TYPE_REAR_MIC:
37 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_REAR_MIC);
38 case chromeos::AUDIO_TYPE_USB:
39 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_AUDIO_USB_DEVICE,
40 base::UTF8ToUTF16(device.display_name));
41 case chromeos::AUDIO_TYPE_BLUETOOTH:
42 return l10n_util::GetStringFUTF16(
43 IDS_ASH_STATUS_TRAY_AUDIO_BLUETOOTH_DEVICE,
44 base::UTF8ToUTF16(device.display_name));
45 case chromeos::AUDIO_TYPE_HDMI:
46 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_AUDIO_HDMI_DEVICE,
47 base::UTF8ToUTF16(device.display_name));
48 case chromeos::AUDIO_TYPE_MIC:
49 return l10n_util::GetStringUTF16(
50 IDS_ASH_STATUS_TRAY_AUDIO_MIC_JACK_DEVICE);
51 default:
52 return base::UTF8ToUTF16(device.display_name);
53 }
54 }
55
56 } // namespace
57
58 using chromeos::CrasAudioHandler;
59
60 namespace ash {
61 namespace tray {
62
63 AudioDetailedView::AudioDetailedView(SystemTrayItem* owner)
64 : TrayDetailsView(owner) {
65 CreateItems();
66 Update();
67 }
68
69 AudioDetailedView::~AudioDetailedView() {}
70
71 void AudioDetailedView::Update() {
72 UpdateAudioDevices();
73 Layout();
74 }
75
76 void AudioDetailedView::AddInputHeader() {
77 AddScrollListInfoItem(IDS_ASH_STATUS_TRAY_AUDIO_INPUT,
78 kSystemMenuAudioInputIcon);
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);
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->AddLabelRowMd(text);
113 if (checked) {
114 gfx::ImageSkia check_mark = gfx::CreateVectorIcon(
115 gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700);
116 container->AddRightIcon(check_mark, check_mark.width());
117 container->SetRightViewVisible(true);
118 container->SetAccessiblityState(
119 HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
120 } else {
121 container->SetAccessiblityState(
122 HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
123 }
124
125 scroll_content()->AddChildView(container);
126 return container;
127 }
128
129 void AudioDetailedView::CreateItems() {
130 CreateScrollableList();
131 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO);
132 }
133
134 void AudioDetailedView::UpdateAudioDevices() {
135 output_devices_.clear();
136 input_devices_.clear();
137 chromeos::AudioDeviceList devices;
138 CrasAudioHandler::Get()->GetAudioDevices(&devices);
139 for (size_t i = 0; i < devices.size(); ++i) {
140 // Don't display keyboard mic or aokr type.
141 if (!devices[i].is_for_simple_usage())
142 continue;
143 if (devices[i].is_input)
144 input_devices_.push_back(devices[i]);
145 else
146 output_devices_.push_back(devices[i]);
147 }
148 UpdateScrollableList();
149 }
150
151 void AudioDetailedView::UpdateScrollableList() {
152 scroll_content()->RemoveAllChildViews(true);
153 device_map_.clear();
154
155 // Add audio output devices.
156 const bool has_output_devices = output_devices_.size() > 0;
157 if (has_output_devices)
158 AddOutputHeader();
159
160 for (size_t i = 0; i < output_devices_.size(); ++i) {
161 HoverHighlightView* container = AddScrollListItem(
162 GetAudioDeviceName(output_devices_[i]), false /* highlight */,
163 output_devices_[i].active); /* checkmark if active */
164 device_map_[container] = output_devices_[i];
165 }
166
167 if (has_output_devices) {
168 scroll_content()->AddChildView(
169 TrayPopupUtils::CreateListSubHeaderSeparator());
170 }
171
172 // Add audio input devices.
173 const bool has_input_devices = input_devices_.size() > 0;
174 if (has_input_devices)
175 AddInputHeader();
176
177 for (size_t i = 0; i < input_devices_.size(); ++i) {
178 HoverHighlightView* container = AddScrollListItem(
179 GetAudioDeviceName(input_devices_[i]), false /* highlight */,
180 input_devices_[i].active); /* checkmark if active */
181 device_map_[container] = input_devices_[i];
182 }
183
184 scroll_content()->SizeToPreferredSize();
185 scroller()->Layout();
186 }
187
188 void AudioDetailedView::HandleViewClicked(views::View* view) {
189 AudioDeviceMap::iterator iter = device_map_.find(view);
190 if (iter == device_map_.end())
191 return;
192 chromeos::AudioDevice device = iter->second;
193 CrasAudioHandler::Get()->SwitchToDevice(device, true,
194 CrasAudioHandler::ACTIVATE_BY_USER);
195 }
196
197 } // namespace tray
198 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/audio/audio_detailed_view.h ('k') | ash/common/system/chromeos/audio/tray_audio.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698