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

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

Issue 2482043002: [ash-md] Updated layout of Brightness and Audio system menu rows to the material design spec. (Closed)
Patch Set: Fixed the volume slider to transition to the detailed view on <return> keypress. Created 4 years, 1 month 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 <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" 25 #include "ui/events/keycodes/keyboard_codes.h"
22 #include "ui/gfx/image/image_skia_operations.h" 26 #include "ui/gfx/image/image_skia_operations.h"
23 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
24 #include "ui/gfx/vector_icon_types.h" 28 #include "ui/gfx/vector_icon_types.h"
25 #include "ui/views/background.h" 29 #include "ui/views/background.h"
26 #include "ui/views/border.h" 30 #include "ui/views/border.h"
27 #include "ui/views/controls/button/image_button.h" 31 #include "ui/views/controls/button/custom_button.h"
28 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
29 #include "ui/views/controls/separator.h" 33 #include "ui/views/controls/separator.h"
30 #include "ui/views/controls/slider.h" 34 #include "ui/views/controls/slider.h"
35 #include "ui/views/focus/focus_manager.h"
31 #include "ui/views/layout/box_layout.h" 36 #include "ui/views/layout/box_layout.h"
32 #include "ui/views/painter.h" 37 #include "ui/views/layout/fill_layout.h"
33 38
34 namespace { 39 namespace {
35 const int kVolumeImageWidth = 25; 40 const int kVolumeImageWidth = 25;
36 const int kVolumeImageHeight = 25; 41 const int kVolumeImageHeight = 25;
37 const int kSeparatorSize = 3; 42 const int kSeparatorSize = 3;
38 const int kSeparatorVerticalInset = 8; 43 const int kSeparatorVerticalInset = 8;
39 const int kSliderRightPaddingToVolumeViewEdge = 17;
40 const int kExtraPaddingBetweenBarAndMore = 10;
41 const int kExtraPaddingBetweenIconAndSlider = 8;
42 const int kBoxLayoutPadding = 2; 44 const int kBoxLayoutPadding = 2;
43 45
44 // IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images, 46 // IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images,
45 // The one for mute is at the 0 index and the other 47 // The one for mute is at the 0 index and the other
46 // four are used for ascending volume levels. 48 // four are used for ascending volume levels.
47 const int kVolumeLevels = 4; 49 const int kVolumeLevels = 4;
48 50
49 const gfx::VectorIcon* const kVolumeLevelIcons[] = { 51 const gfx::VectorIcon* const kVolumeLevelIcons[] = {
50 &ash::kSystemMenuVolumeMuteIcon, // Muted. 52 &ash::kSystemMenuVolumeMuteIcon, // Muted.
51 &ash::kSystemMenuVolumeLowIcon, // Low volume. 53 &ash::kSystemMenuVolumeLowIcon, // Low volume.
52 &ash::kSystemMenuVolumeMediumIcon, // Medium volume. 54 &ash::kSystemMenuVolumeMediumIcon, // Medium volume.
53 &ash::kSystemMenuVolumeHighIcon, // High volume. 55 &ash::kSystemMenuVolumeHighIcon, // High volume.
54 &ash::kSystemMenuVolumeHighIcon, // Full volume. 56 &ash::kSystemMenuVolumeHighIcon, // Full volume.
55 }; 57 };
56 58
57 } // namespace 59 } // namespace
58 60
59 namespace ash { 61 namespace ash {
60 namespace tray { 62 namespace tray {
61 63
62 class VolumeButton : public views::ToggleImageButton { 64 class VolumeButton : public ButtonListenerActionableView {
63 public: 65 public:
64 VolumeButton(views::ButtonListener* listener, 66 VolumeButton(SystemTrayItem* owner,
67 views::ButtonListener* listener,
65 system::TrayAudioDelegate* audio_delegate) 68 system::TrayAudioDelegate* audio_delegate)
66 : views::ToggleImageButton(listener), 69 : ButtonListenerActionableView(owner, listener),
67 audio_delegate_(audio_delegate), 70 audio_delegate_(audio_delegate),
71 image_(TrayPopupUtils::CreateMainImageView()),
68 image_index_(-1) { 72 image_index_(-1) {
73 TrayPopupUtils::ConfigureContainer(TriView::Container::START, this);
69 SetFocusBehavior(FocusBehavior::ALWAYS); 74 SetFocusBehavior(FocusBehavior::ALWAYS);
70 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 75 AddChildView(image_);
71 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); 76 if (MaterialDesignController::IsSystemTrayMenuMaterial())
72 SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); 77 SetInkDropMode(InkDropMode::ON);
73 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) {
74 image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
75 IDR_AURA_UBER_TRAY_VOLUME_LEVELS);
76 }
77 Update(); 78 Update();
79
80 set_notify_enter_exit_on_child(true);
78 } 81 }
79 82
80 ~VolumeButton() override {} 83 ~VolumeButton() override {}
81 84
82 void Update() { 85 void Update() {
83 float level = 86 float level =
84 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; 87 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f;
85 int volume_levels = MaterialDesignController::IsSystemTrayMenuMaterial() 88 int volume_levels = MaterialDesignController::IsSystemTrayMenuMaterial()
86 ? arraysize(kVolumeLevelIcons) - 1 89 ? arraysize(kVolumeLevelIcons) - 1
87 : kVolumeLevels; 90 : kVolumeLevels;
88 int image_index = 91 int image_index =
89 audio_delegate_->IsOutputAudioMuted() 92 audio_delegate_->IsOutputAudioMuted()
90 ? 0 93 ? 0
91 : (level == 1.0 ? volume_levels 94 : (level == 1.0 ? volume_levels
92 : std::max(1, static_cast<int>(std::ceil( 95 : std::max(1, static_cast<int>(std::ceil(
93 level * (volume_levels - 1))))); 96 level * (volume_levels - 1)))));
94 if (image_index != image_index_) { 97 if (image_index != image_index_) {
95 gfx::ImageSkia image_skia; 98 gfx::ImageSkia image_skia;
96 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 99 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
97 image_skia = gfx::CreateVectorIcon(*kVolumeLevelIcons[image_index], 100 image_skia = gfx::CreateVectorIcon(*kVolumeLevelIcons[image_index],
98 kMenuIconColor); 101 kMenuIconColor);
99 } else { 102 } else {
100 gfx::Rect region(0, image_index * kVolumeImageHeight, kVolumeImageWidth, 103 gfx::Rect region(0, image_index * kVolumeImageHeight, kVolumeImageWidth,
101 kVolumeImageHeight); 104 kVolumeImageHeight);
105 gfx::Image image =
106 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
107 IDR_AURA_UBER_TRAY_VOLUME_LEVELS);
102 image_skia = gfx::ImageSkiaOperations::ExtractSubset( 108 image_skia = gfx::ImageSkiaOperations::ExtractSubset(
103 *(image_.ToImageSkia()), region); 109 *(image.ToImageSkia()), region);
104 } 110 }
105 SetImage(views::CustomButton::STATE_NORMAL, &image_skia); 111 image_->SetImage(&image_skia);
106 image_index_ = image_index; 112 image_index_ = image_index;
107 } 113 }
108 } 114 }
109 115
110 private: 116 private:
111 // views::View: 117 // 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 { 118 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
119 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 119 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
120 node_data->SetName( 120 node_data->SetName(
121 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_VOLUME_MUTE)); 121 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_VOLUME_MUTE));
122 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; 122 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON;
123 if (audio_delegate_->IsOutputAudioMuted()) 123 if (audio_delegate_->IsOutputAudioMuted())
124 node_data->AddStateFlag(ui::AX_STATE_PRESSED); 124 node_data->AddStateFlag(ui::AX_STATE_PRESSED);
125 } 125 }
126 126
127 // views::CustomButton: 127 // views::CustomButton:
128 void StateChanged() override { 128 void StateChanged() override {
129 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { 129 if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
130 set_background( 130 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) {
131 views::Background::CreateSolidBackground(kHoverBackgroundColor)); 131 set_background(
132 views::Background::CreateSolidBackground(kHoverBackgroundColor));
133 }
132 } else { 134 } else {
133 set_background(nullptr); 135 set_background(nullptr);
134 } 136 }
135 } 137 }
136 138
137 system::TrayAudioDelegate* audio_delegate_; 139 system::TrayAudioDelegate* audio_delegate_;
138 gfx::Image image_; 140 views::ImageView* image_;
139 int image_index_; 141 int image_index_;
140 142
141 DISALLOW_COPY_AND_ASSIGN(VolumeButton); 143 DISALLOW_COPY_AND_ASSIGN(VolumeButton);
142 }; 144 };
143 145
144 VolumeView::VolumeView(SystemTrayItem* owner, 146 VolumeView::VolumeView(SystemTrayItem* owner,
145 system::TrayAudioDelegate* audio_delegate, 147 system::TrayAudioDelegate* audio_delegate,
146 bool is_default_view) 148 bool is_default_view)
147 : ActionableView(owner), 149 : owner_(owner),
150 tri_view_(TrayPopupUtils::CreateMultiTargetRowView()),
148 audio_delegate_(audio_delegate), 151 audio_delegate_(audio_delegate),
149 icon_(NULL), 152 more_button_(nullptr),
150 slider_(NULL), 153 icon_(nullptr),
151 device_type_(NULL), 154 slider_(nullptr),
152 more_(NULL), 155 separator_(nullptr),
156 device_type_(nullptr),
153 is_default_view_(is_default_view) { 157 is_default_view_(is_default_view) {
154 SetFocusBehavior(FocusBehavior::NEVER); 158 SetFocusBehavior(FocusBehavior::NEVER);
155 views::BoxLayout* box_layout = new views::BoxLayout( 159 SetLayoutManager(new views::FillLayout);
156 views::BoxLayout::kHorizontal, 0, 0, kBoxLayoutPadding); 160 AddChildView(tri_view_);
157 box_layout->SetDefaultFlex(0);
158 SetLayoutManager(box_layout);
159 161
160 icon_ = new VolumeButton(this, audio_delegate_); 162 icon_ = new VolumeButton(owner, this, audio_delegate_);
161 icon_->SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 163 tri_view_->AddView(TriView::Container::START, icon_);
162 kExtraPaddingBetweenIconAndSlider));
163 AddChildView(icon_);
164 slider_ = views::Slider::CreateSlider(
165 ash::MaterialDesignController::IsSystemTrayMenuMaterial(), this);
166 164
167 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { 165 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( 166 slider_->SetValue(
177 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); 167 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f);
178 slider_->SetAccessibleName( 168 slider_->SetAccessibleName(
179 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 169 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
180 IDS_ASH_STATUS_TRAY_VOLUME)); 170 IDS_ASH_STATUS_TRAY_VOLUME));
181 AddChildView(slider_); 171 tri_view_->AddView(TriView::Container::CENTER, slider_);
182 box_layout->SetFlexForView(slider_, 1);
183
184 separator_ = new views::Separator(views::Separator::VERTICAL);
185 separator_->SetColor(kButtonStrokeColor);
186 separator_->SetPreferredSize(kSeparatorSize);
187 separator_->SetBorder(views::CreateEmptyBorder(
188 kSeparatorVerticalInset, 0, kSeparatorVerticalInset, kBoxLayoutPadding));
189
190 more_region_ = new TrayPopupItemContainer(separator_, true);
191 more_region_->SetBorder(
192 views::CreateEmptyBorder(0, 0, 0, kTrayPopupPaddingBetweenItems));
193 AddChildView(more_region_);
194
195 device_type_ = new views::ImageView;
196 more_region_->AddChildView(device_type_);
197
198 more_ = new views::ImageView;
199 more_->EnableCanvasFlippingForRTLUI(true);
200
201 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
202 more_->SetImage(
203 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor));
204 } else {
205 more_->SetImage(ui::ResourceBundle::GetSharedInstance()
206 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE)
207 .ToImageSkia());
208 }
209
210 more_region_->AddChildView(more_);
211 172
212 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 173 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
213 174
175 if (!is_default_view_) {
176 tri_view_->SetContainerVisible(TriView::Container::END, false);
177 Update();
178 return;
179 }
180
181 more_button_ = new ButtonListenerActionableView(owner_, this);
182 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
183 more_button_->SetFocusBehavior(FocusBehavior::NEVER);
184
185 device_type_ = TrayPopupUtils::CreateMoreImageView();
186 more_button_->AddChildView(device_type_);
187
188 views::ImageView* more_arrow = TrayPopupUtils::CreateMoreImageView();
189 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
190 more_arrow->SetImage(
191 gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, kMenuIconColor));
192 } else {
193 more_arrow->SetImage(ui::ResourceBundle::GetSharedInstance()
194 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE)
195 .ToImageSkia());
196 }
197 more_button_->AddChildView(more_arrow);
198
199 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
200 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
201 tri_view_->AddView(TriView::Container::END, more_button_);
202 } else {
203 separator_ = new views::Separator(views::Separator::VERTICAL);
204 separator_->SetColor(kButtonStrokeColor);
205 separator_->SetPreferredSize(kSeparatorSize);
206 separator_->SetBorder(views::CreateEmptyBorder(kSeparatorVerticalInset, 0,
207 kSeparatorVerticalInset,
208 kBoxLayoutPadding));
209
210 TrayPopupItemContainer* more_container =
211 new TrayPopupItemContainer(separator_, true);
212 more_container->SetLayoutManager(
213 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
214 more_container->AddChildView(more_button_);
215 tri_view_->AddView(TriView::Container::END, more_container);
216 }
217
214 Update(); 218 Update();
215 } 219 }
216 220
217 VolumeView::~VolumeView() {} 221 VolumeView::~VolumeView() {}
218 222
219 void VolumeView::Update() { 223 void VolumeView::Update() {
220 icon_->Update(); 224 icon_->Update();
221 slider_->UpdateState(!audio_delegate_->IsOutputAudioMuted()); 225 slider_->UpdateState(!audio_delegate_->IsOutputAudioMuted());
222 UpdateDeviceTypeAndMore(); 226 UpdateDeviceTypeAndMore();
223 Layout(); 227 Layout();
(...skipping 10 matching lines...) Expand all
234 // It is possible that the volume was (un)muted, but the actual volume level 238 // 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 239 // did not change. In that case, setting the value of the slider won't
236 // trigger an update. So explicitly trigger an update. 240 // trigger an update. So explicitly trigger an update.
237 Update(); 241 Update();
238 slider_->set_enable_accessibility_events(true); 242 slider_->set_enable_accessibility_events(true);
239 } 243 }
240 244
241 void VolumeView::UpdateDeviceTypeAndMore() { 245 void VolumeView::UpdateDeviceTypeAndMore() {
242 bool show_more = is_default_view_ && TrayAudio::ShowAudioDeviceMenu() && 246 bool show_more = is_default_view_ && TrayAudio::ShowAudioDeviceMenu() &&
243 audio_delegate_->HasAlternativeSources(); 247 audio_delegate_->HasAlternativeSources();
244 if (!ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { 248
245 slider_->SetBorder(views::CreateEmptyBorder( 249 if (!show_more)
246 0, 0, 0, show_more ? kTrayPopupPaddingBetweenItems
247 : kSliderRightPaddingToVolumeViewEdge));
248 }
249 if (!show_more) {
250 more_region_->SetVisible(false);
251 return; 250 return;
252 }
253 251
254 // Show output device icon if necessary. 252 // Show output device icon if necessary.
255 device_type_->SetVisible(false); 253 device_type_->SetVisible(false);
256 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 254 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
257 const gfx::VectorIcon& device_icon = 255 const gfx::VectorIcon& device_icon =
258 audio_delegate_->GetActiveOutputDeviceVectorIcon(); 256 audio_delegate_->GetActiveOutputDeviceVectorIcon();
259 if (!device_icon.is_empty()) { 257 if (!device_icon.is_empty()) {
260 device_type_->SetImage( 258 device_type_->SetImage(
261 gfx::CreateVectorIcon(device_icon, kMenuIconColor)); 259 gfx::CreateVectorIcon(device_icon, kMenuIconColor));
262 device_type_->SetVisible(true); 260 device_type_->SetVisible(true);
263 } 261 }
264 } else { 262 } else {
265 int device_icon = audio_delegate_->GetActiveOutputDeviceIconId(); 263 int device_icon = audio_delegate_->GetActiveOutputDeviceIconId();
266 if (device_icon != system::TrayAudioDelegate::kNoAudioDeviceIcon) { 264 if (device_icon != system::TrayAudioDelegate::kNoAudioDeviceIcon) {
267 device_type_->SetImage(ui::ResourceBundle::GetSharedInstance() 265 device_type_->SetImage(ui::ResourceBundle::GetSharedInstance()
268 .GetImageNamed(device_icon) 266 .GetImageNamed(device_icon)
269 .ToImageSkia()); 267 .ToImageSkia());
270 device_type_->SetVisible(true); 268 device_type_->SetVisible(true);
271 } 269 }
272 } 270 }
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 } 271 }
280 272
281 void VolumeView::HandleVolumeUp(float level) { 273 void VolumeView::HandleVolumeUp(float level) {
282 audio_delegate_->SetOutputVolumeLevel(level); 274 audio_delegate_->SetOutputVolumeLevel(level);
283 if (audio_delegate_->IsOutputAudioMuted() && 275 if (audio_delegate_->IsOutputAudioMuted() &&
284 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { 276 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) {
285 audio_delegate_->SetOutputAudioIsMuted(false); 277 audio_delegate_->SetOutputAudioIsMuted(false);
286 } 278 }
287 } 279 }
288 280
289 void VolumeView::HandleVolumeDown(float level) { 281 void VolumeView::HandleVolumeDown(float level) {
290 audio_delegate_->SetOutputVolumeLevel(level); 282 audio_delegate_->SetOutputVolumeLevel(level);
291 if (!audio_delegate_->IsOutputAudioMuted() && 283 if (!audio_delegate_->IsOutputAudioMuted() &&
292 level <= audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { 284 level <= audio_delegate_->GetOutputDefaultVolumeMuteLevel()) {
293 audio_delegate_->SetOutputAudioIsMuted(true); 285 audio_delegate_->SetOutputAudioIsMuted(true);
294 } else if (audio_delegate_->IsOutputAudioMuted() && 286 } else if (audio_delegate_->IsOutputAudioMuted() &&
295 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) { 287 level > audio_delegate_->GetOutputDefaultVolumeMuteLevel()) {
296 audio_delegate_->SetOutputAudioIsMuted(false); 288 audio_delegate_->SetOutputAudioIsMuted(false);
297 } 289 }
298 } 290 }
299 291
300 void VolumeView::ButtonPressed(views::Button* sender, const ui::Event& event) { 292 void VolumeView::ButtonPressed(views::Button* sender, const ui::Event& event) {
301 if (sender != icon_) { 293 if (sender == icon_) {
302 ActionableView::ButtonPressed(sender, event); 294 bool mute_on = !audio_delegate_->IsOutputAudioMuted();
303 return; 295 audio_delegate_->SetOutputAudioIsMuted(mute_on);
296 if (!mute_on)
297 audio_delegate_->AdjustOutputVolumeToAudibleLevel();
298 icon_->Update();
299 } else if (sender == more_button_) {
300 owner_->TransitionDetailedView();
301 } else {
302 NOTREACHED() << "Unexpected sender=" << sender->GetClassName() << ".";
304 } 303 }
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 } 304 }
312 305
313 void VolumeView::SliderValueChanged(views::Slider* sender, 306 void VolumeView::SliderValueChanged(views::Slider* sender,
314 float value, 307 float value,
315 float old_value, 308 float old_value,
316 views::SliderChangeReason reason) { 309 views::SliderChangeReason reason) {
317 if (reason == views::VALUE_CHANGED_BY_USER) { 310 if (reason == views::VALUE_CHANGED_BY_USER) {
318 float new_volume = value * 100.0f; 311 float new_volume = value * 100.0f;
319 float current_volume = audio_delegate_->GetOutputVolumeLevel(); 312 float current_volume = audio_delegate_->GetOutputVolumeLevel();
320 // Do not call change audio volume if the difference is less than 313 // 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. 314 // 1%, which is beyond cras audio api's granularity for output volume.
322 if (std::abs(new_volume - current_volume) < 1.0f) 315 if (std::abs(new_volume - current_volume) < 1.0f)
323 return; 316 return;
324 WmShell::Get()->RecordUserMetricsAction( 317 WmShell::Get()->RecordUserMetricsAction(
325 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU 318 is_default_view_ ? UMA_STATUS_AREA_CHANGED_VOLUME_MENU
326 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); 319 : UMA_STATUS_AREA_CHANGED_VOLUME_POPUP);
327 if (new_volume > current_volume) 320 if (new_volume > current_volume)
328 HandleVolumeUp(new_volume); 321 HandleVolumeUp(new_volume);
329 else 322 else
330 HandleVolumeDown(new_volume); 323 HandleVolumeDown(new_volume);
331 } 324 }
332 icon_->Update(); 325 icon_->Update();
333 } 326 }
334 327
335 bool VolumeView::PerformAction(const ui::Event& event) { 328 bool VolumeView::OnKeyPressed(const ui::KeyEvent& event) {
336 if (!more_region_->visible()) 329 const views::FocusManager* focus_manager = GetFocusManager();
337 return false; 330 if (enabled() && is_default_view_ && event.key_code() == ui::VKEY_RETURN &&
338 owner()->TransitionDetailedView(); 331 focus_manager && focus_manager->GetFocusedView() == slider_) {
339 return true; 332 owner_->TransitionDetailedView();
333 return true;
334 }
335 return View::OnKeyPressed(event);
340 } 336 }
341 337
342 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 338 void VolumeView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
343 // Separator's prefered size is based on set bounds. When an empty bounds is 339 // 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 340 // 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. 341 // its height on each bounds change so that it is laid out properly.
346 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); 342 if (separator_)
347 } 343 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 } 344 }
353 345
354 } // namespace tray 346 } // namespace tray
355 } // namespace ash 347 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/audio/volume_view.h ('k') | ash/common/system/chromeos/brightness/tray_brightness.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698