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. |
| 4 | 4 |
| 5 #include <algorithm> | |
| 6 | |
| 5 #include "ash/common/system/audio/volume_view.h" | 7 #include "ash/common/system/audio/volume_view.h" |
| 6 | 8 |
| 7 #include "ash/common/ash_constants.h" | |
| 8 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/metrics/user_metrics_action.h" | 10 #include "ash/common/metrics/user_metrics_action.h" |
| 10 #include "ash/common/system/audio/tray_audio.h" | 11 #include "ash/common/system/audio/tray_audio.h" |
| 11 #include "ash/common/system/audio/tray_audio_delegate.h" | 12 #include "ash/common/system/audio/tray_audio_delegate.h" |
| 13 #include "ash/common/system/tray/actionable_view.h" | |
| 12 #include "ash/common/system/tray/system_tray_item.h" | 14 #include "ash/common/system/tray/system_tray_item.h" |
| 13 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/system/tray/tray_popup_item_container.h" | 16 #include "ash/common/system/tray/tray_popup_item_container.h" |
| 17 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 18 #include "ash/common/system/tray/tri_view.h" | |
| 15 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 16 #include "ash/resources/vector_icons/vector_icons.h" | 20 #include "ash/resources/vector_icons/vector_icons.h" |
| 17 #include "grit/ash_resources.h" | 21 #include "grit/ash_resources.h" |
| 18 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
| 19 #include "ui/accessibility/ax_node_data.h" | 23 #include "ui/accessibility/ax_node_data.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/canvas.h" | |
| 22 #include "ui/gfx/image/image_skia_operations.h" | 25 #include "ui/gfx/image/image_skia_operations.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | 26 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/gfx/vector_icon_types.h" | 27 #include "ui/gfx/vector_icon_types.h" |
| 25 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
| 26 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
| 27 #include "ui/views/controls/button/image_button.h" | 30 #include "ui/views/controls/button/custom_button.h" |
| 28 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 29 #include "ui/views/controls/separator.h" | 32 #include "ui/views/controls/separator.h" |
| 30 #include "ui/views/controls/slider.h" | 33 #include "ui/views/controls/slider.h" |
| 31 #include "ui/views/layout/box_layout.h" | 34 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/painter.h" | 35 #include "ui/views/layout/fill_layout.h" |
| 33 | 36 |
| 34 namespace { | 37 namespace { |
| 35 const int kVolumeImageWidth = 25; | 38 const int kVolumeImageWidth = 25; |
| 36 const int kVolumeImageHeight = 25; | 39 const int kVolumeImageHeight = 25; |
| 37 const int kSeparatorSize = 3; | 40 const int kSeparatorSize = 3; |
| 38 const int kSeparatorVerticalInset = 8; | 41 const int kSeparatorVerticalInset = 8; |
| 39 const int kSliderRightPaddingToVolumeViewEdge = 17; | |
| 40 const int kExtraPaddingBetweenBarAndMore = 10; | |
| 41 const int kExtraPaddingBetweenIconAndSlider = 8; | |
| 42 const int kBoxLayoutPadding = 2; | 42 const int kBoxLayoutPadding = 2; |
| 43 | 43 |
| 44 // IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images, | 44 // IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images, |
| 45 // The one for mute is at the 0 index and the other | 45 // The one for mute is at the 0 index and the other |
| 46 // four are used for ascending volume levels. | 46 // four are used for ascending volume levels. |
| 47 const int kVolumeLevels = 4; | 47 const int kVolumeLevels = 4; |
| 48 | 48 |
| 49 const gfx::VectorIcon* const kVolumeLevelIcons[] = { | 49 const gfx::VectorIcon* const kVolumeLevelIcons[] = { |
| 50 &ash::kSystemMenuVolumeMuteIcon, // Muted. | 50 &ash::kSystemMenuVolumeMuteIcon, // Muted. |
| 51 &ash::kSystemMenuVolumeLowIcon, // Low volume. | 51 &ash::kSystemMenuVolumeLowIcon, // Low volume. |
| 52 &ash::kSystemMenuVolumeMediumIcon, // Medium volume. | 52 &ash::kSystemMenuVolumeMediumIcon, // Medium volume. |
| 53 &ash::kSystemMenuVolumeHighIcon, // High volume. | 53 &ash::kSystemMenuVolumeHighIcon, // High volume. |
| 54 &ash::kSystemMenuVolumeHighIcon, // Full volume. | 54 &ash::kSystemMenuVolumeHighIcon, // Full volume. |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 namespace ash { | 59 namespace ash { |
| 60 namespace tray { | 60 namespace tray { |
| 61 | 61 |
| 62 class VolumeButton : public views::ToggleImageButton { | 62 class VolumeButton : public ButtonListenerActionableView { |
| 63 public: | 63 public: |
| 64 VolumeButton(views::ButtonListener* listener, | 64 VolumeButton(SystemTrayItem* owner, |
| 65 views::ButtonListener* listener, | |
| 65 system::TrayAudioDelegate* audio_delegate) | 66 system::TrayAudioDelegate* audio_delegate) |
| 66 : views::ToggleImageButton(listener), | 67 : ButtonListenerActionableView(owner, listener), |
| 67 audio_delegate_(audio_delegate), | 68 audio_delegate_(audio_delegate), |
| 69 image_(TrayPopupUtils::CreateMainImageView()), | |
| 68 image_index_(-1) { | 70 image_index_(-1) { |
| 71 TrayPopupUtils::ConfigureContainer(TriView::Container::START, this); | |
| 69 SetFocusBehavior(FocusBehavior::ALWAYS); | 72 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 70 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 73 AddChildView(image_); |
|
tdanderson
2016/11/09 01:38:33
Looks like you're inheriting the focus painter fro
bruthig
2016/11/10 02:54:54
Yes the Mute button maintains the correct keyboard
| |
| 71 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 74 if (MaterialDesignController::IsSystemTrayMenuMaterial()) |
| 72 SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); | 75 SetInkDropMode(InkDropMode::ON); |
| 73 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 74 image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 75 IDR_AURA_UBER_TRAY_VOLUME_LEVELS); | |
| 76 } | |
| 77 Update(); | 76 Update(); |
| 77 | |
| 78 set_notify_enter_exit_on_child(true); | |
| 78 } | 79 } |
| 79 | 80 |
| 80 ~VolumeButton() override {} | 81 ~VolumeButton() override {} |
| 81 | 82 |
| 82 void Update() { | 83 void Update() { |
| 83 float level = | 84 float level = |
| 84 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | 85 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; |
| 85 int volume_levels = MaterialDesignController::IsSystemTrayMenuMaterial() | 86 int volume_levels = MaterialDesignController::IsSystemTrayMenuMaterial() |
| 86 ? arraysize(kVolumeLevelIcons) - 1 | 87 ? arraysize(kVolumeLevelIcons) - 1 |
| 87 : kVolumeLevels; | 88 : kVolumeLevels; |
| 88 int image_index = | 89 int image_index = |
| 89 audio_delegate_->IsOutputAudioMuted() | 90 audio_delegate_->IsOutputAudioMuted() |
| 90 ? 0 | 91 ? 0 |
| 91 : (level == 1.0 ? volume_levels | 92 : (level == 1.0 ? volume_levels |
| 92 : std::max(1, static_cast<int>(std::ceil( | 93 : std::max(1, static_cast<int>(std::ceil( |
| 93 level * (volume_levels - 1))))); | 94 level * (volume_levels - 1))))); |
| 94 if (image_index != image_index_) { | 95 if (image_index != image_index_) { |
| 95 gfx::ImageSkia image_skia; | 96 gfx::ImageSkia image_skia; |
| 96 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 97 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 97 image_skia = gfx::CreateVectorIcon(*kVolumeLevelIcons[image_index], | 98 image_skia = gfx::CreateVectorIcon(*kVolumeLevelIcons[image_index], |
| 98 kMenuIconColor); | 99 kMenuIconColor); |
| 99 } else { | 100 } else { |
| 100 gfx::Rect region(0, image_index * kVolumeImageHeight, kVolumeImageWidth, | 101 gfx::Rect region(0, image_index * kVolumeImageHeight, kVolumeImageWidth, |
| 101 kVolumeImageHeight); | 102 kVolumeImageHeight); |
| 103 gfx::Image image = | |
| 104 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 105 IDR_AURA_UBER_TRAY_VOLUME_LEVELS); | |
| 102 image_skia = gfx::ImageSkiaOperations::ExtractSubset( | 106 image_skia = gfx::ImageSkiaOperations::ExtractSubset( |
| 103 *(image_.ToImageSkia()), region); | 107 *(image.ToImageSkia()), region); |
| 104 } | 108 } |
| 105 SetImage(views::CustomButton::STATE_NORMAL, &image_skia); | 109 image_->SetImage(&image_skia); |
| 106 image_index_ = image_index; | 110 image_index_ = image_index; |
| 107 } | 111 } |
| 108 } | 112 } |
| 109 | 113 |
| 110 private: | 114 private: |
| 111 // views::View: | 115 // views::View: |
| 112 gfx::Size GetPreferredSize() const override { | |
| 113 gfx::Size size = views::ToggleImageButton::GetPreferredSize(); | |
| 114 size.set_height(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
| 115 return size; | |
| 116 } | |
| 117 | |
| 118 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { | 116 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
| 119 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 117 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 120 node_data->SetName( | 118 node_data->SetName( |
| 121 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_VOLUME_MUTE)); | 119 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_VOLUME_MUTE)); |
| 122 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; | 120 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; |
| 123 if (audio_delegate_->IsOutputAudioMuted()) | 121 if (audio_delegate_->IsOutputAudioMuted()) |
| 124 node_data->AddStateFlag(ui::AX_STATE_PRESSED); | 122 node_data->AddStateFlag(ui::AX_STATE_PRESSED); |
| 125 } | 123 } |
| 126 | 124 |
| 127 // views::CustomButton: | 125 // views::CustomButton: |
| 128 void StateChanged() override { | 126 void StateChanged() override { |
| 129 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 127 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
| 130 set_background( | 128 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 131 views::Background::CreateSolidBackground(kHoverBackgroundColor)); | 129 set_background( |
| 130 views::Background::CreateSolidBackground(kHoverBackgroundColor)); | |
| 131 } | |
| 132 } else { | 132 } else { |
| 133 set_background(nullptr); | 133 set_background(nullptr); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 system::TrayAudioDelegate* audio_delegate_; | 137 system::TrayAudioDelegate* audio_delegate_; |
| 138 gfx::Image image_; | 138 views::ImageView* image_; |
| 139 int image_index_; | 139 int image_index_; |
| 140 | 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(VolumeButton); | 141 DISALLOW_COPY_AND_ASSIGN(VolumeButton); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 VolumeView::VolumeView(SystemTrayItem* owner, | 144 VolumeView::VolumeView(SystemTrayItem* owner, |
| 145 system::TrayAudioDelegate* audio_delegate, | 145 system::TrayAudioDelegate* audio_delegate, |
| 146 bool is_default_view) | 146 bool is_default_view) |
| 147 : ActionableView(owner), | 147 : owner_(owner), |
| 148 tri_view_(TrayPopupUtils::CreateMultiTargetRowView()), | |
| 148 audio_delegate_(audio_delegate), | 149 audio_delegate_(audio_delegate), |
| 149 icon_(NULL), | 150 more_button_(nullptr), |
| 150 slider_(NULL), | 151 icon_(nullptr), |
| 151 device_type_(NULL), | 152 slider_(nullptr), |
| 152 more_(NULL), | 153 separator_(nullptr), |
| 154 device_type_(nullptr), | |
| 153 is_default_view_(is_default_view) { | 155 is_default_view_(is_default_view) { |
| 154 SetFocusBehavior(FocusBehavior::NEVER); | 156 SetFocusBehavior(FocusBehavior::NEVER); |
| 155 views::BoxLayout* box_layout = new views::BoxLayout( | 157 SetLayoutManager(new views::FillLayout); |
| 156 views::BoxLayout::kHorizontal, 0, 0, kBoxLayoutPadding); | 158 AddChildView(tri_view_); |
| 157 box_layout->SetDefaultFlex(0); | |
| 158 SetLayoutManager(box_layout); | |
| 159 | 159 |
| 160 icon_ = new VolumeButton(this, audio_delegate_); | 160 icon_ = new VolumeButton(owner, this, audio_delegate_); |
| 161 icon_->SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, | 161 tri_view_->AddView(TriView::Container::START, icon_); |
| 162 kExtraPaddingBetweenIconAndSlider)); | |
| 163 AddChildView(icon_); | |
| 164 slider_ = views::Slider::CreateSlider( | |
| 165 ash::MaterialDesignController::IsSystemTrayMenuMaterial(), this); | |
| 166 | 162 |
| 167 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { | 163 slider_ = TrayPopupUtils::CreateSlider(this); |
| 168 slider_->SetBorder(views::CreateEmptyBorder( | |
| 169 gfx::Insets(0, kTrayPopupSliderPaddingMD) + slider_->GetInsets())); | |
| 170 } else { | |
| 171 slider_->SetBorder( | |
| 172 views::CreateEmptyBorder(0, 0, 0, kTrayPopupPaddingBetweenItems)); | |
| 173 } | |
| 174 | |
| 175 slider_->set_focus_border_color(kFocusBorderColor); | |
| 176 slider_->SetValue( | 164 slider_->SetValue( |
| 177 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 165 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
| 178 slider_->SetAccessibleName( | 166 slider_->SetAccessibleName( |
| 179 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 167 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 180 IDS_ASH_STATUS_TRAY_VOLUME)); | 168 IDS_ASH_STATUS_TRAY_VOLUME)); |
| 181 AddChildView(slider_); | 169 tri_view_->AddView(TriView::Container::CENTER, slider_); |
| 182 box_layout->SetFlexForView(slider_, 1); | |
| 183 | 170 |
| 184 separator_ = new views::Separator(views::Separator::VERTICAL); | 171 more_button_ = new ButtonListenerActionableView(owner_, this); |
| 185 separator_->SetColor(kButtonStrokeColor); | 172 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_); |
| 186 separator_->SetPreferredSize(kSeparatorSize); | |
| 187 separator_->SetBorder(views::CreateEmptyBorder( | |
| 188 kSeparatorVerticalInset, 0, kSeparatorVerticalInset, kBoxLayoutPadding)); | |
| 189 | 173 |
| 190 more_region_ = new TrayPopupItemContainer(separator_, true); | 174 device_type_ = TrayPopupUtils::CreateMoreImageView(); |
| 191 more_region_->SetBorder( | 175 more_button_->AddChildView(device_type_); |
| 192 views::CreateEmptyBorder(0, 0, 0, kTrayPopupPaddingBetweenItems)); | |
| 193 AddChildView(more_region_); | |
| 194 | 176 |
| 195 device_type_ = new views::ImageView; | 177 views::ImageView* more_arrow = TrayPopupUtils::CreateMoreImageView(); |
| 196 more_region_->AddChildView(device_type_); | 178 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 197 | 179 more_arrow->SetImage( |
| 198 more_ = new views::ImageView; | 180 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor)); |
|
tdanderson
2016/11/09 01:38:33
The arrow color may possibly change if the row is
bruthig
2016/11/10 02:54:54
I will defer that work but I have updated the spre
| |
| 199 more_->EnableCanvasFlippingForRTLUI(true); | 181 } else { |
| 182 more_arrow->SetImage(ui::ResourceBundle::GetSharedInstance() | |
| 183 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) | |
| 184 .ToImageSkia()); | |
| 185 } | |
| 186 more_button_->AddChildView(more_arrow); | |
| 200 | 187 |
| 201 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 188 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 202 more_->SetImage( | 189 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON); |
| 203 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor)); | 190 tri_view_->AddView(TriView::Container::END, more_button_); |
| 204 } else { | 191 } else { |
| 205 more_->SetImage(ui::ResourceBundle::GetSharedInstance() | 192 separator_ = new views::Separator(views::Separator::VERTICAL); |
| 206 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) | 193 separator_->SetColor(kButtonStrokeColor); |
| 207 .ToImageSkia()); | 194 separator_->SetPreferredSize(kSeparatorSize); |
| 195 separator_->SetBorder(views::CreateEmptyBorder(kSeparatorVerticalInset, 0, | |
| 196 kSeparatorVerticalInset, | |
| 197 kBoxLayoutPadding)); | |
| 198 | |
| 199 TrayPopupItemContainer* more_container_ = | |
|
tdanderson
2016/11/09 01:38:33
If you mean for this to be local, remove the trail
bruthig
2016/11/10 02:54:54
Done.
| |
| 200 new TrayPopupItemContainer(separator_, true); | |
| 201 more_container_->SetLayoutManager( | |
| 202 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 203 more_container_->AddChildView(more_button_); | |
| 204 tri_view_->AddView(TriView::Container::END, more_container_); | |
| 208 } | 205 } |
| 209 | 206 |
| 210 more_region_->AddChildView(more_); | 207 if (!is_default_view_) |
|
tdanderson
2016/11/09 01:38:33
Consider moving this earlier (before line 171) as
bruthig
2016/11/10 02:54:53
Done.
| |
| 208 tri_view_->SetContainerVisible(TriView::Container::END, false); | |
| 211 | 209 |
| 212 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 210 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 213 | 211 |
| 214 Update(); | 212 Update(); |
| 215 } | 213 } |
| 216 | 214 |
| 217 VolumeView::~VolumeView() {} | 215 VolumeView::~VolumeView() {} |
| 218 | 216 |
| 219 void VolumeView::Update() { | 217 void VolumeView::Update() { |
| 220 icon_->Update(); | 218 icon_->Update(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 234 // It is possible that the volume was (un)muted, but the actual volume level | 232 // It is possible that the volume was (un)muted, but the actual volume level |
| 235 // did not change. In that case, setting the value of the slider won't | 233 // did not change. In that case, setting the value of the slider won't |
| 236 // trigger an update. So explicitly trigger an update. | 234 // trigger an update. So explicitly trigger an update. |
| 237 Update(); | 235 Update(); |
| 238 slider_->set_enable_accessibility_events(true); | 236 slider_->set_enable_accessibility_events(true); |
| 239 } | 237 } |
| 240 | 238 |
| 241 void VolumeView::UpdateDeviceTypeAndMore() { | 239 void VolumeView::UpdateDeviceTypeAndMore() { |
| 242 bool show_more = is_default_view_ && TrayAudio::ShowAudioDeviceMenu() && | 240 bool show_more = is_default_view_ && TrayAudio::ShowAudioDeviceMenu() && |
| 243 audio_delegate_->HasAlternativeSources(); | 241 audio_delegate_->HasAlternativeSources(); |
| 244 if (!ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { | 242 |
| 245 slider_->SetBorder(views::CreateEmptyBorder( | 243 if (!show_more) |
| 246 0, 0, 0, show_more ? kTrayPopupPaddingBetweenItems | |
| 247 : kSliderRightPaddingToVolumeViewEdge)); | |
| 248 } | |
| 249 if (!show_more) { | |
| 250 more_region_->SetVisible(false); | |
| 251 return; | 244 return; |
| 252 } | |
| 253 | 245 |
| 254 // Show output device icon if necessary. | 246 // Show output device icon if necessary. |
| 255 device_type_->SetVisible(false); | 247 device_type_->SetVisible(false); |
| 256 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 248 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 257 const gfx::VectorIcon& device_icon = | 249 const gfx::VectorIcon& device_icon = |
| 258 audio_delegate_->GetActiveOutputDeviceVectorIcon(); | 250 audio_delegate_->GetActiveOutputDeviceVectorIcon(); |
| 259 if (!device_icon.is_empty()) { | 251 if (!device_icon.is_empty()) { |
| 260 device_type_->SetImage( | 252 device_type_->SetImage( |
| 261 gfx::CreateVectorIcon(device_icon, kMenuIconColor)); | 253 gfx::CreateVectorIcon(device_icon, kMenuIconColor)); |
| 262 device_type_->SetVisible(true); | 254 device_type_->SetVisible(true); |
| 263 } | 255 } |
| 264 } else { | 256 } else { |
| 265 int device_icon = audio_delegate_->GetActiveOutputDeviceIconId(); | 257 int device_icon = audio_delegate_->GetActiveOutputDeviceIconId(); |
| 266 if (device_icon != system::TrayAudioDelegate::kNoAudioDeviceIcon) { | 258 if (device_icon != system::TrayAudioDelegate::kNoAudioDeviceIcon) { |
| 267 device_type_->SetImage(ui::ResourceBundle::GetSharedInstance() | 259 device_type_->SetImage(ui::ResourceBundle::GetSharedInstance() |
| 268 .GetImageNamed(device_icon) | 260 .GetImageNamed(device_icon) |
| 269 .ToImageSkia()); | 261 .ToImageSkia()); |
| 270 device_type_->SetVisible(true); | 262 device_type_->SetVisible(true); |
| 271 } | 263 } |
| 272 } | 264 } |
| 273 int spacing = kTrayPopupPaddingBetweenItems; | |
| 274 if (!device_type_->visible()) | |
| 275 spacing += kExtraPaddingBetweenBarAndMore; | |
| 276 more_region_->SetLayoutManager( | |
| 277 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, spacing)); | |
| 278 more_region_->SetVisible(true); | |
| 279 } | 265 } |
| 280 | 266 |
| 281 void VolumeView::HandleVolumeUp(float level) { | 267 void VolumeView::HandleVolumeUp(float level) { |
| 282 audio_delegate_->SetOutputVolumeLevel(level); | 268 audio_delegate_->SetOutputVolumeLevel(level); |
| 283 if (audio_delegate_->IsOutputAudioMuted() && | 269 if (audio_delegate_->IsOutputAudioMuted() && |
| 284 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { | 270 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { |
| 285 audio_delegate_->SetOutputAudioIsMuted(false); | 271 audio_delegate_->SetOutputAudioIsMuted(false); |
| 286 } | 272 } |
| 287 } | 273 } |
| 288 | 274 |
| 289 void VolumeView::HandleVolumeDown(float level) { | 275 void VolumeView::HandleVolumeDown(float level) { |
| 290 audio_delegate_->SetOutputVolumeLevel(level); | 276 audio_delegate_->SetOutputVolumeLevel(level); |
| 291 if (!audio_delegate_->IsOutputAudioMuted() && | 277 if (!audio_delegate_->IsOutputAudioMuted() && |
| 292 level <= audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { | 278 level <= audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { |
| 293 audio_delegate_->SetOutputAudioIsMuted(true); | 279 audio_delegate_->SetOutputAudioIsMuted(true); |
| 294 } else if (audio_delegate_->IsOutputAudioMuted() && | 280 } else if (audio_delegate_->IsOutputAudioMuted() && |
| 295 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { | 281 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { |
| 296 audio_delegate_->SetOutputAudioIsMuted(false); | 282 audio_delegate_->SetOutputAudioIsMuted(false); |
| 297 } | 283 } |
| 298 } | 284 } |
| 299 | 285 |
| 300 void VolumeView::ButtonPressed(views::Button* sender, const ui::Event& event) { | 286 void VolumeView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 301 if (sender != icon_) { | 287 if (sender == icon_) { |
| 302 ActionableView::ButtonPressed(sender, event); | 288 bool mute_on = !audio_delegate_->IsOutputAudioMuted(); |
| 303 return; | 289 audio_delegate_->SetOutputAudioIsMuted(mute_on); |
| 290 if (!mute_on) | |
| 291 audio_delegate_->AdjustOutputVolumeToAudibleLevel(); | |
| 292 icon_->Update(); | |
| 293 } else if (sender == more_button_) { | |
| 294 if (!more_button_->visible()) | |
|
tdanderson
2016/11/09 01:38:33
Consider restructuring as 'else if (sender == more
bruthig
2016/11/10 02:54:54
Good point, dropped the visible() condition.
| |
| 295 return; | |
| 296 owner_->TransitionDetailedView(); | |
| 304 } | 297 } |
|
tdanderson
2016/11/09 01:38:33
optional nit: else NOTREACHED() ?
bruthig
2016/11/10 02:54:54
Done.
| |
| 305 | |
| 306 bool mute_on = !audio_delegate_->IsOutputAudioMuted(); | |
| 307 audio_delegate_->SetOutputAudioIsMuted(mute_on); | |
| 308 if (!mute_on) | |
| 309 audio_delegate_->AdjustOutputVolumeToAudibleLevel(); | |
| 310 icon_->Update(); | |
| 311 } | 298 } |
| 312 | 299 |
| 313 void VolumeView::SliderValueChanged(views::Slider* sender, | 300 void VolumeView::SliderValueChanged(views::Slider* sender, |
| 314 float value, | 301 float value, |
| 315 float old_value, | 302 float old_value, |
| 316 views::SliderChangeReason reason) { | 303 views::SliderChangeReason reason) { |
| 317 if (reason == views::VALUE_CHANGED_BY_USER) { | 304 if (reason == views::VALUE_CHANGED_BY_USER) { |
| 318 float new_volume = value * 100.0f; | 305 float new_volume = value * 100.0f; |
| 319 float current_volume = audio_delegate_->GetOutputVolumeLevel(); | 306 float current_volume = audio_delegate_->GetOutputVolumeLevel(); |
| 320 // Do not call change audio volume if the difference is less than | 307 // Do not call change audio volume if the difference is less than |
| 321 // 1%, which is beyond cras audio api's granularity for output volume. | 308 // 1%, which is beyond cras audio api's granularity for output volume. |
| 322 if (std::abs(new_volume - current_volume) < 1.0f) | 309 if (std::abs(new_volume - current_volume) < 1.0f) |
| 323 return; | 310 return; |
| 324 WmShell::Get()->RecordUserMetricsAction( | 311 WmShell::Get()->RecordUserMetricsAction( |
| 325 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU | 312 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU |
| 326 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); | 313 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); |
| 327 if (new_volume > current_volume) | 314 if (new_volume > current_volume) |
| 328 HandleVolumeUp(new_volume); | 315 HandleVolumeUp(new_volume); |
| 329 else | 316 else |
| 330 HandleVolumeDown(new_volume); | 317 HandleVolumeDown(new_volume); |
| 331 } | 318 } |
| 332 icon_->Update(); | 319 icon_->Update(); |
| 333 } | 320 } |
| 334 | 321 |
| 335 bool VolumeView::PerformAction(const ui::Event& event) { | |
| 336 if (!more_region_->visible()) | |
| 337 return false; | |
| 338 owner()->TransitionDetailedView(); | |
| 339 return true; | |
| 340 } | |
| 341 | |
| 342 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 322 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 343 // Separator's prefered size is based on set bounds. When an empty bounds is | 323 // Separator's prefered size is based on set bounds. When an empty bounds is |
| 344 // set on first layout this causes BoxLayout to ignore the separator. Reset | 324 // set on first layout this causes BoxLayout to ignore the separator. Reset |
| 345 // its height on each bounds change so that it is laid out properly. | 325 // its height on each bounds change so that it is laid out properly. |
| 346 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); | 326 if (separator_) |
| 347 } | 327 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); |
| 348 | |
| 349 void VolumeView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 350 // Intentionally overrides ActionableView, leaving |state| unset. A slider | |
| 351 // childview exposes accessibility data. | |
| 352 } | 328 } |
| 353 | 329 |
| 354 } // namespace tray | 330 } // namespace tray |
| 355 } // namespace ash | 331 } // namespace ash |
| OLD | NEW |