Chromium Code Reviews| 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. |
|
tdanderson
2017/04/13 16:15:52
nit: Please wrap the lines in the CL description a
| |
| 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" |
| 11 #include "ash/shell_port.h" | 11 #include "ash/shell_port.h" |
| 12 #include "ash/strings/grit/ash_strings.h" | 12 #include "ash/strings/grit/ash_strings.h" |
| 13 #include "ash/system/tray/actionable_view.h" | 13 #include "ash/system/tray/actionable_view.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 // None output device is connected |
|
tdanderson
2017/04/13 16:15:52
I really appreciate that you are including comment
| |
| 190 is_default_view_ && (audio_handler->has_alternative_output() || | 167 if (is_default_view_ && !audio_handler->has_alternative_output()) { |
|
tdanderson
2017/04/13 16:15:52
I'm not sure I understand why you aren't also chec
minch1
2017/04/13 17:47:39
If I check !audio_handler->has_alternative_input()
tdanderson
2017/04/13 20:54:56
Ah, now I understand. I think what you're suggesti
| |
| 191 audio_handler->has_alternative_input()); | 168 tri_view_->SetContainerVisible(TriView::Container::END, false); |
| 192 | 169 if (more_button_) |
| 193 if (!show_more) | 170 more_button_->InvalidateLayout(); |
|
tdanderson
2017/04/13 16:15:52
What happens if you don't invalidate the layout he
minch1
2017/04/13 17:47:39
Open the ash system menu,
1. No alternative output
tdanderson
2017/04/13 20:54:56
Thanks for the detailed explanation. Can you try c
minch1
2017/04/13 23:16:01
Yes, tri_view_->InvalidateLayout() has the same ef
| |
| 194 return; | 171 return; |
| 172 } | |
| 195 | 173 |
| 196 const gfx::VectorIcon& device_icon = GetActiveOutputDeviceVectorIcon(); | 174 const gfx::VectorIcon& device_icon = GetActiveOutputDeviceVectorIcon(); |
| 197 const bool target_visibility = !device_icon.is_empty(); | 175 const bool target_visibility = !device_icon.is_empty(); |
| 176 | |
| 177 if (!is_default_view_) { | |
|
tdanderson
2017/04/13 16:15:52
minor nit: it is usually preferred from a style an
| |
| 178 // Floating audio menu with Speaker(internal) output | |
| 179 if (!target_visibility) { | |
|
tdanderson
2017/04/13 16:15:52
I find this variable to be a bit awkwardly-named a
minch1
2017/04/13 17:47:39
Yeap, I think so. I moved this from the constructo
minch1
2017/04/13 23:16:01
I forgot |target_visibility| will be used in line
| |
| 180 tri_view_->SetContainerVisible(TriView::Container::END, false); | |
| 181 return; | |
| 182 } | |
| 183 device_type_ = TrayPopupUtils::CreateMoreImageView(); | |
| 184 device_type_->SetVisible(false); | |
|
tdanderson
2017/04/13 16:15:52
I'm not sure why you're setting visibility to fals
minch1
2017/04/13 17:47:39
Actually I think to initialize device_type_ as Cre
tdanderson
2017/04/13 20:54:56
Ah yes, you're right. I missed the fact that Creat
| |
| 185 tri_view_->AddView(TriView::Container::END, device_type_); | |
|
tdanderson
2017/04/13 16:15:52
It might be a good idea to call tri_view_->SetCont
minch1
2017/04/13 17:47:39
For the floating audio row. I think It will create
tdanderson
2017/04/13 20:54:56
The only time I could see there being a potential
minch1
2017/04/13 23:16:01
Yes, you are right. I forgot to plug or unplug the
| |
| 186 } else { | |
| 187 if (!more_button_) { | |
| 188 more_button_ = new ButtonListenerActionableView( | |
| 189 owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this); | |
| 190 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_); | |
| 191 | |
| 192 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON); | |
| 193 more_button_->SetBorder( | |
| 194 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupButtonEndMargin))); | |
| 195 tri_view_->AddView(TriView::Container::END, more_button_); | |
| 196 | |
| 197 device_type_ = TrayPopupUtils::CreateMoreImageView(); | |
| 198 device_type_->SetVisible(false); | |
| 199 more_button_->AddChildView(device_type_); | |
| 200 | |
| 201 more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView()); | |
| 202 more_button_->SetAccessibleName( | |
| 203 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO)); | |
| 204 } | |
| 205 | |
| 206 tri_view_->SetContainerVisible(TriView::Container::END, true); | |
| 207 more_button_->InvalidateLayout(); | |
| 208 } | |
| 209 | |
| 198 if (target_visibility) | 210 if (target_visibility) |
| 199 device_type_->SetImage(gfx::CreateVectorIcon(device_icon, kMenuIconColor)); | 211 device_type_->SetImage(gfx::CreateVectorIcon(device_icon, kMenuIconColor)); |
| 200 if (device_type_->visible() != target_visibility) { | 212 if (device_type_->visible() != target_visibility) { |
| 201 device_type_->SetVisible(target_visibility); | 213 device_type_->SetVisible(target_visibility); |
| 202 device_type_->InvalidateLayout(); | 214 device_type_->InvalidateLayout(); |
| 203 } | 215 } |
| 204 } | 216 } |
| 205 | 217 |
| 206 void VolumeView::HandleVolumeUp(int level) { | 218 void VolumeView::HandleVolumeUp(int level) { |
| 207 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 219 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 if (new_volume > current_volume) | 266 if (new_volume > current_volume) |
| 255 HandleVolumeUp(new_volume); | 267 HandleVolumeUp(new_volume); |
| 256 else | 268 else |
| 257 HandleVolumeDown(new_volume); | 269 HandleVolumeDown(new_volume); |
| 258 } | 270 } |
| 259 icon_->Update(); | 271 icon_->Update(); |
| 260 } | 272 } |
| 261 | 273 |
| 262 } // namespace tray | 274 } // namespace tray |
| 263 } // namespace ash | 275 } // namespace ash |
| OLD | NEW |