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

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

Issue 2234823003: Make the mute button in the Ash system menu keyboard focusable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: override GetAccessibleState Created 4 years, 4 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
« no previous file with comments | « ash/ash_strings.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/audio/volume_view.h" 5 #include "ash/common/system/audio/volume_view.h"
6 6
7 #include "ash/common/ash_constants.h" 7 #include "ash/common/ash_constants.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/metrics/user_metrics_action.h" 9 #include "ash/common/metrics/user_metrics_action.h"
10 #include "ash/common/system/audio/tray_audio.h" 10 #include "ash/common/system/audio/tray_audio.h"
11 #include "ash/common/system/audio/tray_audio_delegate.h" 11 #include "ash/common/system/audio/tray_audio_delegate.h"
12 #include "ash/common/system/tray/system_tray_item.h" 12 #include "ash/common/system/tray/system_tray_item.h"
13 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_popup_item_container.h" 14 #include "ash/common/system/tray/tray_popup_item_container.h"
15 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
16 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
17 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
18 #include "ui/accessibility/ax_view_state.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/image/image_skia_operations.h" 21 #include "ui/gfx/image/image_skia_operations.h"
21 #include "ui/gfx/paint_vector_icon.h" 22 #include "ui/gfx/paint_vector_icon.h"
22 #include "ui/gfx/vector_icons_public.h" 23 #include "ui/gfx/vector_icons_public.h"
23 #include "ui/views/background.h" 24 #include "ui/views/background.h"
24 #include "ui/views/border.h" 25 #include "ui/views/border.h"
25 #include "ui/views/controls/button/image_button.h" 26 #include "ui/views/controls/button/image_button.h"
26 #include "ui/views/controls/image_view.h" 27 #include "ui/views/controls/image_view.h"
27 #include "ui/views/controls/separator.h" 28 #include "ui/views/controls/separator.h"
28 #include "ui/views/layout/box_layout.h" 29 #include "ui/views/layout/box_layout.h"
30 #include "ui/views/painter.h"
29 31
30 namespace { 32 namespace {
31 const int kVolumeImageWidth = 25; 33 const int kVolumeImageWidth = 25;
32 const int kVolumeImageHeight = 25; 34 const int kVolumeImageHeight = 25;
33 const int kSeparatorSize = 3; 35 const int kSeparatorSize = 3;
34 const int kSeparatorVerticalInset = 8; 36 const int kSeparatorVerticalInset = 8;
35 const int kSliderRightPaddingToVolumeViewEdge = 17; 37 const int kSliderRightPaddingToVolumeViewEdge = 17;
36 const int kExtraPaddingBetweenBarAndMore = 10; 38 const int kExtraPaddingBetweenBarAndMore = 10;
37 const int kExtraPaddingBetweenIconAndSlider = 8; 39 const int kExtraPaddingBetweenIconAndSlider = 8;
38 const int kBoxLayoutPadding = 2; 40 const int kBoxLayoutPadding = 2;
39 41
40 // IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images, 42 // IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images,
41 // The one for mute is at the 0 index and the other 43 // The one for mute is at the 0 index and the other
42 // four are used for ascending volume levels. 44 // four are used for ascending volume levels.
43 const int kVolumeLevels = 4; 45 const int kVolumeLevels = 4;
44 46
45 } // namespace 47 } // namespace
46 48
47 namespace ash { 49 namespace ash {
48 namespace tray { 50 namespace tray {
49 51
50 class VolumeButton : public views::ToggleImageButton { 52 class VolumeButton : public views::ToggleImageButton {
51 public: 53 public:
52 VolumeButton(views::ButtonListener* listener, 54 VolumeButton(views::ButtonListener* listener,
53 system::TrayAudioDelegate* audio_delegate) 55 system::TrayAudioDelegate* audio_delegate)
54 : views::ToggleImageButton(listener), 56 : views::ToggleImageButton(listener),
55 audio_delegate_(audio_delegate), 57 audio_delegate_(audio_delegate),
56 image_index_(-1) { 58 image_index_(-1) {
59 SetFocusBehavior(FocusBehavior::ALWAYS);
60 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
61 kFocusBorderColor, gfx::Insets(1, 1, 1, 1)));
57 SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); 62 SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
58 image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( 63 image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
59 IDR_AURA_UBER_TRAY_VOLUME_LEVELS); 64 IDR_AURA_UBER_TRAY_VOLUME_LEVELS);
60 Update(); 65 Update();
61 } 66 }
62 67
63 ~VolumeButton() override {} 68 ~VolumeButton() override {}
64 69
65 void Update() { 70 void Update() {
66 float level = 71 float level =
(...skipping 15 matching lines...) Expand all
82 } 87 }
83 88
84 private: 89 private:
85 // views::View: 90 // views::View:
86 gfx::Size GetPreferredSize() const override { 91 gfx::Size GetPreferredSize() const override {
87 gfx::Size size = views::ToggleImageButton::GetPreferredSize(); 92 gfx::Size size = views::ToggleImageButton::GetPreferredSize();
88 size.set_height(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); 93 size.set_height(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
89 return size; 94 return size;
90 } 95 }
91 96
97 void GetAccessibleState(ui::AXViewState* state) override {
98 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
99 state->name = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_VOLUME_MUTE);
100 state->role = ui::AX_ROLE_TOGGLE_BUTTON;
101 if (audio_delegate_->IsOutputAudioMuted())
102 state->AddStateFlag(ui::AX_STATE_PRESSED);
103 }
104
92 // views::CustomButton: 105 // views::CustomButton:
93 void StateChanged() override { 106 void StateChanged() override {
94 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { 107 if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
95 set_background( 108 set_background(
96 views::Background::CreateSolidBackground(kHoverBackgroundColor)); 109 views::Background::CreateSolidBackground(kHoverBackgroundColor));
97 } else { 110 } else {
98 set_background(nullptr); 111 set_background(nullptr);
99 } 112 }
100 } 113 }
101 114
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height())); 303 separator_->SetSize(gfx::Size(kSeparatorSize, bounds().height()));
291 } 304 }
292 305
293 void VolumeView::GetAccessibleState(ui::AXViewState* state) { 306 void VolumeView::GetAccessibleState(ui::AXViewState* state) {
294 // Intentionally overrides ActionableView, leaving |state| unset. A slider 307 // Intentionally overrides ActionableView, leaving |state| unset. A slider
295 // childview exposes accessibility data. 308 // childview exposes accessibility data.
296 } 309 }
297 310
298 } // namespace tray 311 } // namespace tray
299 } // namespace ash 312 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_strings.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698