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

Side by Side Diff: ash/system/audio/volume_view.cc

Issue 2812223005: Display current output device icon in the floating volume row when switching output devices (Closed)
Patch Set: Address comments. Created 3 years, 8 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/system/audio/volume_view.h" 5 #include "ash/system/audio/volume_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/metrics/user_metrics_action.h" 9 #include "ash/metrics/user_metrics_action.h"
10 #include "ash/resources/vector_icons/vector_icons.h" 10 #include "ash/resources/vector_icons/vector_icons.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 icon_ = new VolumeButton(owner, this); 124 icon_ = new VolumeButton(owner, this);
125 tri_view_->AddView(TriView::Container::START, icon_); 125 tri_view_->AddView(TriView::Container::START, icon_);
126 126
127 slider_ = TrayPopupUtils::CreateSlider(this); 127 slider_ = TrayPopupUtils::CreateSlider(this);
128 slider_->SetValue(CrasAudioHandler::Get()->GetOutputVolumePercent() / 100.0f); 128 slider_->SetValue(CrasAudioHandler::Get()->GetOutputVolumePercent() / 100.0f);
129 slider_->SetAccessibleName( 129 slider_->SetAccessibleName(
130 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VOLUME)); 130 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VOLUME));
131 tri_view_->AddView(TriView::Container::CENTER, slider_); 131 tri_view_->AddView(TriView::Container::CENTER, slider_);
132 132
133 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 133 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
134
135 if (!is_default_view_) {
136 tri_view_->SetContainerVisible(TriView::Container::END, false);
137 Update();
138 return;
139 }
140
141 more_button_ = new ButtonListenerActionableView(
142 owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this);
143 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
144
145 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
146 more_button_->SetBorder(views::CreateEmptyBorder(gfx::Insets(
147 0, kTrayPopupButtonEndMargin)));
148 tri_view_->AddView(TriView::Container::END, more_button_);
149
150 device_type_ = TrayPopupUtils::CreateMoreImageView();
151 device_type_->SetVisible(false);
152 more_button_->AddChildView(device_type_);
153
154 more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView());
155 more_button_->SetAccessibleName(
156 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO));
157 Update(); 134 Update();
158 } 135 }
159 136
160 VolumeView::~VolumeView() {} 137 VolumeView::~VolumeView() {}
161 138
162 void VolumeView::Update() { 139 void VolumeView::Update() {
163 icon_->Update(); 140 icon_->Update();
164 slider_->UpdateState(!CrasAudioHandler::Get()->IsOutputMuted()); 141 slider_->UpdateState(!CrasAudioHandler::Get()->IsOutputMuted());
165 UpdateDeviceTypeAndMore(); 142 UpdateDeviceTypeAndMore();
166 Layout(); 143 Layout();
(...skipping 12 matching lines...) Expand all
179 slider_->SetValue(percent); 156 slider_->SetValue(percent);
180 // It is possible that the volume was (un)muted, but the actual volume level 157 // It is possible that the volume was (un)muted, but the actual volume level
181 // did not change. In that case, setting the value of the slider won't 158 // did not change. In that case, setting the value of the slider won't
182 // trigger an update. So explicitly trigger an update. 159 // trigger an update. So explicitly trigger an update.
183 Update(); 160 Update();
184 slider_->set_enable_accessibility_events(true); 161 slider_->set_enable_accessibility_events(true);
185 } 162 }
186 163
187 void VolumeView::UpdateDeviceTypeAndMore() { 164 void VolumeView::UpdateDeviceTypeAndMore() {
188 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); 165 CrasAudioHandler* audio_handler = CrasAudioHandler::Get();
189 bool show_more = 166 // There is no point in letting the user open the audio detailed submenu if
190 is_default_view_ && (audio_handler->has_alternative_output() || 167 // there are no alternative output devices present, so do not show the 'more'
tdanderson 2017/04/18 23:50:29 nit: "if there are no alternative input or output
191 audio_handler->has_alternative_input()); 168 // button in the default audio row.
192 169 if (is_default_view_ && !audio_handler->has_alternative_output() &&
tdanderson 2017/04/18 23:50:29 nit: can you run 'git cl format ash' on this? I th
minch1 2017/04/19 00:01:41 I run 'git cl format' before upload the cl. It sti
tdanderson 2017/04/19 15:18:09 Ah OK, if git cl format is fine with it, then I'm
193 if (!show_more) 170 !audio_handler->has_alternative_input()) {
171 tri_view_->SetContainerVisible(TriView::Container::END, false);
172 // TODO(tdanderson): TriView itself should trigger a relayout when the
173 // visibility of one of its containers is changed.
174 tri_view_->InvalidateLayout();
194 return; 175 return;
176 }
195 177
196 const gfx::VectorIcon& device_icon = GetActiveOutputDeviceVectorIcon(); 178 const gfx::VectorIcon& device_icon = GetActiveOutputDeviceVectorIcon();
197 const bool target_visibility = !device_icon.is_empty(); 179 const bool device_icon_visibility = !device_icon.is_empty();
198 if (target_visibility) 180
181 if (is_default_view_) {
182 if (!more_button_) {
183 more_button_ = new ButtonListenerActionableView(
184 owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this);
185 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
186
187 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
188 more_button_->SetBorder(
189 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupButtonEndMargin)));
190 tri_view_->AddView(TriView::Container::END, more_button_);
191
192 device_type_ = TrayPopupUtils::CreateMoreImageView();
193 device_type_->SetVisible(false);
194 more_button_->AddChildView(device_type_);
195
196 more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView());
197 more_button_->SetAccessibleName(
198 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO));
199 }
200 tri_view_->SetContainerVisible(TriView::Container::END, true);
tdanderson 2017/04/18 23:50:29 Lines 200-201 and lines 213-214 are identical and
201 tri_view_->InvalidateLayout();
202 } else {
203 if (!device_icon_visibility) {
204 tri_view_->SetContainerVisible(TriView::Container::END, false);
205 tri_view_->InvalidateLayout();
206 return;
207 }
208 if (!device_type_) {
209 device_type_ = TrayPopupUtils::CreateMoreImageView();
210 device_type_->SetVisible(false);
211 tri_view_->AddView(TriView::Container::END, device_type_);
212 }
213 tri_view_->SetContainerVisible(TriView::Container::END, true);
214 tri_view_->InvalidateLayout();
215 }
216
217 if (device_icon_visibility)
199 device_type_->SetImage(gfx::CreateVectorIcon(device_icon, kMenuIconColor)); 218 device_type_->SetImage(gfx::CreateVectorIcon(device_icon, kMenuIconColor));
200 if (device_type_->visible() != target_visibility) { 219 if (device_type_->visible() != device_icon_visibility) {
201 device_type_->SetVisible(target_visibility); 220 device_type_->SetVisible(device_icon_visibility);
202 device_type_->InvalidateLayout(); 221 device_type_->InvalidateLayout();
203 } 222 }
204 } 223 }
205 224
206 void VolumeView::HandleVolumeUp(int level) { 225 void VolumeView::HandleVolumeUp(int level) {
207 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); 226 CrasAudioHandler* audio_handler = CrasAudioHandler::Get();
208 audio_handler->SetOutputVolumePercent(level); 227 audio_handler->SetOutputVolumePercent(level);
209 if (audio_handler->IsOutputMuted() && 228 if (audio_handler->IsOutputMuted() &&
210 level > audio_handler->GetOutputDefaultVolumeMuteThreshold()) { 229 level > audio_handler->GetOutputDefaultVolumeMuteThreshold()) {
211 audio_handler->SetOutputMute(false); 230 audio_handler->SetOutputMute(false);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (new_volume > current_volume) 273 if (new_volume > current_volume)
255 HandleVolumeUp(new_volume); 274 HandleVolumeUp(new_volume);
256 else 275 else
257 HandleVolumeDown(new_volume); 276 HandleVolumeDown(new_volume);
258 } 277 }
259 icon_->Update(); 278 icon_->Update();
260 } 279 }
261 280
262 } // namespace tray 281 } // namespace tray
263 } // namespace ash 282 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/brightness/tray_brightness.cc » ('j') | ash/system/brightness/tray_brightness.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698