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

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

Issue 163953007: Refactor the TrayAudio code so that it can be used by other platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
jennyz 2014/02/14 21:36:43 2012 -> 2014
zturner 2014/02/15 00:57:45 Done.
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/system/chromeos/audio/audio_detailed_view.h"
6
7 #include "ash/system/tray/fixed_sized_scroll_view.h"
8 #include "ash/system/tray/hover_highlight_view.h"
9 #include "ash/system/tray/tray_constants.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chromeos/audio/cras_audio_handler.h"
12 #include "grit/ash_resources.h"
13 #include "grit/ash_strings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/views/border.h"
17 #include "ui/views/controls/label.h"
18
19 namespace {
jennyz 2014/02/14 21:36:43 Add a blank line after namespace {
zturner 2014/02/15 00:57:45 Done.
20 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) {
21 switch(device.type) {
22 case chromeos::AUDIO_TYPE_HEADPHONE:
23 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_HEADPHONE);
24 case chromeos::AUDIO_TYPE_INTERNAL_SPEAKER:
25 return l10n_util::GetStringUTF16(
26 IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_SPEAKER);
27 case chromeos::AUDIO_TYPE_INTERNAL_MIC:
28 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_MIC);
29 case chromeos::AUDIO_TYPE_USB:
30 return l10n_util::GetStringFUTF16(
31 IDS_ASH_STATUS_TRAY_AUDIO_USB_DEVICE,
32 base::UTF8ToUTF16(device.display_name));
33 case chromeos::AUDIO_TYPE_BLUETOOTH:
34 return l10n_util::GetStringFUTF16(
35 IDS_ASH_STATUS_TRAY_AUDIO_BLUETOOTH_DEVICE,
36 base::UTF8ToUTF16(device.display_name));
37 case chromeos::AUDIO_TYPE_HDMI:
38 return l10n_util::GetStringFUTF16(
39 IDS_ASH_STATUS_TRAY_AUDIO_HDMI_DEVICE,
40 base::UTF8ToUTF16(device.display_name));
41 default:
42 return base::UTF8ToUTF16(device.display_name);
43 }
44 }
jennyz 2014/02/14 21:36:43 Add a blank line.
zturner 2014/02/15 00:57:45 Done.
45 }
jennyz 2014/02/14 21:36:43 add // namespace.
zturner 2014/02/15 00:57:45 Done.
46
47 using chromeos::CrasAudioHandler;
48
49 namespace ash {
50 namespace internal {
51 namespace tray {
52
53 AudioDetailedView::AudioDetailedView(SystemTrayItem* owner,
54 user::LoginStatus login)
55 : TrayDetailsView(owner),
56 login_(login) {
57 CreateItems();
58 Update();
59 }
60
61 AudioDetailedView::~AudioDetailedView() {
62 }
63
64 void AudioDetailedView::AddScrollListInfoItem(const base::string16& text) {
65 views::Label* label = new views::Label(
66 text,
67 ui::ResourceBundle::GetSharedInstance().GetFontList(
68 ui::ResourceBundle::BoldFont));
69
70 // Align info item with checkbox items
71 int margin = kTrayPopupPaddingHorizontal +
72 kTrayPopupDetailsLabelExtraLeftMargin;
73 int left_margin = 0;
74 int right_margin = 0;
75 if (base::i18n::IsRTL())
76 right_margin = margin;
77 else
78 left_margin = margin;
79
80 label->SetBorder(views::Border::CreateEmptyBorder(
81 ash::kTrayPopupPaddingBetweenItems,
82 left_margin,
83 ash::kTrayPopupPaddingBetweenItems,
84 right_margin));
85 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
86 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0));
87
88 scroll_content()->AddChildView(label);
89 }
90
91 HoverHighlightView* AudioDetailedView::AddScrollListItem(
92 const base::string16& text,
93 gfx::Font::FontStyle style,
94 bool checked) {
95 HoverHighlightView* container = new HoverHighlightView(this);
96 container->AddCheckableLabel(text, style, checked);
97 scroll_content()->AddChildView(container);
98 return container;
99 }
100
101 void AudioDetailedView::CreateHeaderEntry() {
102 CreateSpecialRow(IDS_ASH_STATUS_TRAY_AUDIO, this);
103 }
104
105 void AudioDetailedView::CreateItems() {
106 CreateScrollableList();
107 CreateHeaderEntry();
108 }
109
110 void AudioDetailedView::Update() {
jennyz 2014/02/14 21:36:43 Move this function after ~AudioDetailedView. The f
zturner 2014/02/15 00:57:45 Done.
111 UpdateAudioDevices();
112 Layout();
113 }
114
115 void AudioDetailedView::UpdateAudioDevices() {
116 output_devices_.clear();
117 input_devices_.clear();
118 chromeos::AudioDeviceList devices;
119 CrasAudioHandler::Get()->GetAudioDevices(&devices);
120 for (size_t i = 0; i < devices.size(); ++i) {
121 if (devices[i].is_input)
122 input_devices_.push_back(devices[i]);
123 else
124 output_devices_.push_back(devices[i]);
125 }
126 UpdateScrollableList();
127 }
128
129 void AudioDetailedView::UpdateScrollableList() {
130 scroll_content()->RemoveAllChildViews(true);
131 device_map_.clear();
132
133 // Add audio output devices.
134 AddScrollListInfoItem(
135 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT));
136 for (size_t i = 0; i < output_devices_.size(); ++i) {
137 HoverHighlightView* container = AddScrollListItem(
138 GetAudioDeviceName(output_devices_[i]),
139 gfx::Font::NORMAL,
140 output_devices_[i].active); /* checkmark if active */
141 device_map_[container] = output_devices_[i];
142 }
143
144 AddScrollSeparator();
145
146 // Add audio input devices.
147 AddScrollListInfoItem(
148 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INPUT));
149 for (size_t i = 0; i < input_devices_.size(); ++i) {
150 HoverHighlightView* container = AddScrollListItem(
151 GetAudioDeviceName(input_devices_[i]),
152 gfx::Font::NORMAL,
153 input_devices_[i].active); /* checkmark if active */
154 device_map_[container] = input_devices_[i];
155 }
156
157 scroll_content()->SizeToPreferredSize();
158 scroller()->Layout();
159 }
160
161 void AudioDetailedView::OnViewClicked(views::View* sender) {
162 if (sender == footer()->content()) {
163 TransitionToDefaultView();
164 } else {
165 AudioDeviceMap::iterator iter = device_map_.find(sender);
166 if (iter == device_map_.end())
167 return;
168 chromeos::AudioDevice& device = iter->second;
169 CrasAudioHandler::Get()->SwitchToDevice(device);
170 }
171 }
172
173 } // namespace tray
174 } // namespace internal
175 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698