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

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

Issue 2724963002: Remove non-MD code from AudioDetailedView (Closed)
Patch Set: Rebased 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
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/common/system/chromeos/audio/audio_detailed_view.h" 5 #include "ash/common/system/chromeos/audio/audio_detailed_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/system/tray/hover_highlight_view.h" 7 #include "ash/common/system/tray/hover_highlight_view.h"
9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/tray_popup_utils.h" 8 #include "ash/common/system/tray/tray_popup_utils.h"
11 #include "ash/common/system/tray/tri_view.h" 9 #include "ash/common/system/tray/tri_view.h"
12 #include "ash/strings/grit/ash_strings.h" 10 #include "ash/strings/grit/ash_strings.h"
13 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
14 #include "chromeos/audio/cras_audio_handler.h" 12 #include "chromeos/audio/cras_audio_handler.h"
15 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/color_palette.h" 14 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
19 #include "ui/gfx/vector_icons_public.h" 16 #include "ui/gfx/vector_icons_public.h"
20 #include "ui/native_theme/native_theme.h" 17 #include "ui/native_theme/native_theme.h"
21 #include "ui/views/border.h"
22 #include "ui/views/controls/image_view.h" 18 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/scroll_view.h" 20 #include "ui/views/controls/scroll_view.h"
25 #include "ui/views/controls/separator.h" 21 #include "ui/views/controls/separator.h"
26 22
27 namespace { 23 namespace {
28 24
29 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { 25 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) {
30 switch (device.type) { 26 switch (device.type) {
31 case chromeos::AUDIO_TYPE_FRONT_MIC: 27 case chromeos::AUDIO_TYPE_FRONT_MIC:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 kSystemMenuAudioInputIcon); 78 kSystemMenuAudioInputIcon);
83 } 79 }
84 80
85 void AudioDetailedView::AddOutputHeader() { 81 void AudioDetailedView::AddOutputHeader() {
86 AddScrollListInfoItem(IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT, 82 AddScrollListInfoItem(IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT,
87 kSystemMenuAudioOutputIcon); 83 kSystemMenuAudioOutputIcon);
88 } 84 }
89 85
90 void AudioDetailedView::AddScrollListInfoItem(int text_id, 86 void AudioDetailedView::AddScrollListInfoItem(int text_id,
91 const gfx::VectorIcon& icon) { 87 const gfx::VectorIcon& icon) {
92 const base::string16 text = l10n_util::GetStringUTF16(text_id); 88 TriView* header = TrayPopupUtils::CreateDefaultRowView();
93 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 89 TrayPopupUtils::ConfigureAsStickyHeader(header);
94 TriView* header = TrayPopupUtils::CreateDefaultRowView(); 90 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView();
95 TrayPopupUtils::ConfigureAsStickyHeader(header); 91 image_view->SetImage(gfx::CreateVectorIcon(
96 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView(); 92 icon, GetNativeTheme()->GetSystemColor(
97 image_view->SetImage(gfx::CreateVectorIcon( 93 ui::NativeTheme::kColorId_ProminentButtonColor)));
98 icon, GetNativeTheme()->GetSystemColor( 94 header->AddView(TriView::Container::START, image_view);
99 ui::NativeTheme::kColorId_ProminentButtonColor)));
100 header->AddView(TriView::Container::START, image_view);
101 95
102 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); 96 views::Label* label = TrayPopupUtils::CreateDefaultLabel();
103 label->SetText(text); 97 label->SetText(l10n_util::GetStringUTF16(text_id));
104 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); 98 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER);
105 style.SetupLabel(label); 99 style.SetupLabel(label);
106 header->AddView(TriView::Container::CENTER, label); 100 header->AddView(TriView::Container::CENTER, label);
107 101
108 header->SetContainerVisible(TriView::Container::END, false); 102 header->SetContainerVisible(TriView::Container::END, false);
109 scroll_content()->AddChildView(header); 103 scroll_content()->AddChildView(header);
110 } else {
111 views::Label* label = new views::Label(
112 text, ui::ResourceBundle::GetSharedInstance().GetFontList(
113 ui::ResourceBundle::BoldFont));
114
115 // Align info item with checkbox items
116 int margin =
117 kTrayPopupPaddingHorizontal + kTrayPopupDetailsLabelExtraLeftMargin;
118 int left_margin = 0;
119 int right_margin = 0;
120 if (base::i18n::IsRTL())
121 right_margin = margin;
122 else
123 left_margin = margin;
124
125 label->SetBorder(views::CreateEmptyBorder(
126 ash::kTrayPopupPaddingBetweenItems, left_margin,
127 ash::kTrayPopupPaddingBetweenItems, right_margin));
128 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
129 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0));
130 scroll_content()->AddChildView(label);
131 }
132 } 104 }
133 105
134 HoverHighlightView* AudioDetailedView::AddScrollListItem( 106 HoverHighlightView* AudioDetailedView::AddScrollListItem(
135 const base::string16& text, 107 const base::string16& text,
136 bool highlight, 108 bool highlight,
137 bool checked) { 109 bool checked) {
138 HoverHighlightView* container = new HoverHighlightView(this); 110 HoverHighlightView* container = new HoverHighlightView(this);
139 111
140 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 112 container->AddLabelRowMd(text);
141 container->AddLabelRowMd(text); 113 if (checked) {
142 if (checked) { 114 gfx::ImageSkia check_mark = gfx::CreateVectorIcon(
143 gfx::ImageSkia check_mark = gfx::CreateVectorIcon( 115 gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700);
144 gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700); 116 container->AddRightIcon(check_mark, check_mark.width());
145 container->AddRightIcon(check_mark, check_mark.width()); 117 container->SetRightViewVisible(true);
146 container->SetRightViewVisible(true); 118 container->SetAccessiblityState(
147 container->SetAccessiblityState( 119 HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
148 HoverHighlightView::AccessibilityState::CHECKED_CHECKBOX);
149 } else {
150 container->SetAccessiblityState(
151 HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
152 }
153 } else { 120 } else {
154 container->AddCheckableLabel(text, highlight, checked); 121 container->SetAccessiblityState(
122 HoverHighlightView::AccessibilityState::UNCHECKED_CHECKBOX);
155 } 123 }
156 124
157 scroll_content()->AddChildView(container); 125 scroll_content()->AddChildView(container);
158 return container; 126 return container;
159 } 127 }
160 128
161 void AudioDetailedView::CreateItems() { 129 void AudioDetailedView::CreateItems() {
162 CreateScrollableList(); 130 CreateScrollableList();
163 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO); 131 CreateTitleRow(IDS_ASH_STATUS_TRAY_AUDIO);
164 } 132 }
(...skipping 13 matching lines...) Expand all
178 output_devices_.push_back(devices[i]); 146 output_devices_.push_back(devices[i]);
179 } 147 }
180 UpdateScrollableList(); 148 UpdateScrollableList();
181 } 149 }
182 150
183 void AudioDetailedView::UpdateScrollableList() { 151 void AudioDetailedView::UpdateScrollableList() {
184 scroll_content()->RemoveAllChildViews(true); 152 scroll_content()->RemoveAllChildViews(true);
185 device_map_.clear(); 153 device_map_.clear();
186 154
187 // Add audio output devices. 155 // Add audio output devices.
188 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial();
189 const bool has_output_devices = output_devices_.size() > 0; 156 const bool has_output_devices = output_devices_.size() > 0;
190 if (!use_md || has_output_devices) 157 if (has_output_devices)
191 AddOutputHeader(); 158 AddOutputHeader();
192 159
193 for (size_t i = 0; i < output_devices_.size(); ++i) { 160 for (size_t i = 0; i < output_devices_.size(); ++i) {
194 HoverHighlightView* container = AddScrollListItem( 161 HoverHighlightView* container = AddScrollListItem(
195 GetAudioDeviceName(output_devices_[i]), false /* highlight */, 162 GetAudioDeviceName(output_devices_[i]), false /* highlight */,
196 output_devices_[i].active); /* checkmark if active */ 163 output_devices_[i].active); /* checkmark if active */
197 device_map_[container] = output_devices_[i]; 164 device_map_[container] = output_devices_[i];
198 } 165 }
199 166
200 if (!use_md) { 167 if (has_output_devices) {
201 AddScrollSeparator();
202 } else if (has_output_devices) {
203 scroll_content()->AddChildView( 168 scroll_content()->AddChildView(
204 TrayPopupUtils::CreateListSubHeaderSeparator()); 169 TrayPopupUtils::CreateListSubHeaderSeparator());
205 } 170 }
206 171
207 // Add audio input devices. 172 // Add audio input devices.
208 const bool has_input_devices = input_devices_.size() > 0; 173 const bool has_input_devices = input_devices_.size() > 0;
209 if (!use_md || has_input_devices) 174 if (has_input_devices)
210 AddInputHeader(); 175 AddInputHeader();
211 176
212 for (size_t i = 0; i < input_devices_.size(); ++i) { 177 for (size_t i = 0; i < input_devices_.size(); ++i) {
213 HoverHighlightView* container = AddScrollListItem( 178 HoverHighlightView* container = AddScrollListItem(
214 GetAudioDeviceName(input_devices_[i]), false /* highlight */, 179 GetAudioDeviceName(input_devices_[i]), false /* highlight */,
215 input_devices_[i].active); /* checkmark if active */ 180 input_devices_[i].active); /* checkmark if active */
216 device_map_[container] = input_devices_[i]; 181 device_map_[container] = input_devices_[i];
217 } 182 }
218 183
219 scroll_content()->SizeToPreferredSize(); 184 scroll_content()->SizeToPreferredSize();
220 scroller()->Layout(); 185 scroller()->Layout();
221 } 186 }
222 187
223 void AudioDetailedView::HandleViewClicked(views::View* view) { 188 void AudioDetailedView::HandleViewClicked(views::View* view) {
224 AudioDeviceMap::iterator iter = device_map_.find(view); 189 AudioDeviceMap::iterator iter = device_map_.find(view);
225 if (iter == device_map_.end()) 190 if (iter == device_map_.end())
226 return; 191 return;
227 chromeos::AudioDevice device = iter->second; 192 chromeos::AudioDevice device = iter->second;
228 CrasAudioHandler::Get()->SwitchToDevice(device, true, 193 CrasAudioHandler::Get()->SwitchToDevice(device, true,
229 CrasAudioHandler::ACTIVATE_BY_USER); 194 CrasAudioHandler::ACTIVATE_BY_USER);
230 } 195 }
231 196
232 } // namespace tray 197 } // namespace tray
233 } // namespace ash 198 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/audio/audio_detailed_view.h ('k') | ash/common/system/chromeos/audio/volume_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698