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

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

Issue 10808080: Implement new volume mute button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ash/ash_strings.grd ('k') | ash/system/tray/tray_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tray_volume.h" 5 #include "ash/system/audio/tray_volume.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h" 8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 9 #include "ash/system/tray/tray_constants.h"
10 #include "ash/system/tray/tray_views.h" 10 #include "ash/system/tray/tray_views.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 size.set_height(kTrayPopupItemHeight); 84 size.set_height(kTrayPopupItemHeight);
85 return size; 85 return size;
86 } 86 }
87 87
88 gfx::Image image_; 88 gfx::Image image_;
89 int image_index_; 89 int image_index_;
90 90
91 DISALLOW_COPY_AND_ASSIGN(VolumeButton); 91 DISALLOW_COPY_AND_ASSIGN(VolumeButton);
92 }; 92 };
93 93
94 class MuteButton : public ash::internal::TrayBarButtonWithTitle {
95 public:
96 explicit MuteButton(views::ButtonListener* listener)
97 : TrayBarButtonWithTitle(listener,
98 IDS_ASH_STATUS_TRAY_VOLUME_MUTE,
99 kTrayBarButtonWidth) {
100 Update();
101 }
102 virtual ~MuteButton() {}
103
104 void Update() {
105 ash::SystemTrayDelegate* delegate =
106 ash::Shell::GetInstance()->tray_delegate();
107 UpdateButton(delegate->IsAudioMuted());
108 SchedulePaint();
109 }
110
111 DISALLOW_COPY_AND_ASSIGN(MuteButton);
112 };
113
94 class VolumeView : public views::View, 114 class VolumeView : public views::View,
95 public views::ButtonListener, 115 public views::ButtonListener,
96 public views::SliderListener { 116 public views::SliderListener {
97 public: 117 public:
98 VolumeView() { 118 VolumeView() {
99 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 119 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
100 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); 120 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems));
101 121
102 icon_ = new VolumeButton(this); 122 icon_ = new VolumeButton(this);
103 AddChildView(icon_); 123 AddChildView(icon_);
104 124
125 mute_ = new MuteButton(this);
126 AddChildView(mute_);
127
105 ash::SystemTrayDelegate* delegate = 128 ash::SystemTrayDelegate* delegate =
106 ash::Shell::GetInstance()->tray_delegate(); 129 ash::Shell::GetInstance()->tray_delegate();
107 slider_ = new views::Slider(this, views::Slider::HORIZONTAL); 130 slider_ = new views::Slider(this, views::Slider::HORIZONTAL);
108 slider_->set_focus_border_color(kFocusBorderColor); 131 slider_->set_focus_border_color(kFocusBorderColor);
109 slider_->SetValue( 132 slider_->SetValue(
110 delegate->IsAudioMuted() ? 0.0 : delegate->GetVolumeLevel()); 133 delegate->IsAudioMuted() ? 0.0 : delegate->GetVolumeLevel());
111 slider_->SetAccessibleName( 134 slider_->SetAccessibleName(
112 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 135 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
113 IDS_ASH_STATUS_TRAY_VOLUME)); 136 IDS_ASH_STATUS_TRAY_VOLUME));
114 AddChildView(slider_); 137 AddChildView(slider_);
115 } 138 }
116 139
117 virtual ~VolumeView() {} 140 virtual ~VolumeView() {}
118 141
119 void SetVolumeLevel(float percent) { 142 void SetVolumeLevel(float percent) {
120 // The change in volume will be reflected via accessibility system events, 143 // The change in volume will be reflected via accessibility system events,
121 // so we prevent the UI event from being sent here. 144 // so we prevent the UI event from being sent here.
122 slider_->set_enable_accessibility_events(false); 145 slider_->set_enable_accessibility_events(false);
123 slider_->SetValue(percent); 146 slider_->SetValue(percent);
124 // It is possible that the volume was (un)muted, but the actual volume level 147 // It is possible that the volume was (un)muted, but the actual volume level
125 // did not change. In that case, setting the value of the slider won't 148 // did not change. In that case, setting the value of the slider won't
126 // trigger an update. So explicitly trigger an update. 149 // trigger an update. So explicitly trigger an update.
127 icon_->Update(); 150 icon_->Update();
151 mute_->Update();
128 slider_->set_enable_accessibility_events(true); 152 slider_->set_enable_accessibility_events(true);
129 } 153 }
130 154
131 private: 155 private:
132 // Overridden from views::View. 156 // Overridden from views::View.
133 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE { 157 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE {
134 int w = width() - slider_->x(); 158 int w = width() - slider_->x();
135 slider_->SetSize(gfx::Size(w, slider_->height())); 159 slider_->SetSize(gfx::Size(w, slider_->height()));
136 } 160 }
137 161
138 // Overridden from views::ButtonListener. 162 // Overridden from views::ButtonListener.
139 virtual void ButtonPressed(views::Button* sender, 163 virtual void ButtonPressed(views::Button* sender,
140 const views::Event& event) OVERRIDE { 164 const views::Event& event) OVERRIDE {
141 CHECK(sender == icon_); 165 CHECK(sender == icon_ || sender == mute_);
142 ash::SystemTrayDelegate* delegate = 166 ash::SystemTrayDelegate* delegate =
143 ash::Shell::GetInstance()->tray_delegate(); 167 ash::Shell::GetInstance()->tray_delegate();
144 delegate->SetAudioMuted(!delegate->IsAudioMuted()); 168 delegate->SetAudioMuted(!delegate->IsAudioMuted());
145 } 169 }
146 170
147 // Overridden from views:SliderListener. 171 // Overridden from views:SliderListener.
148 virtual void SliderValueChanged(views::Slider* sender, 172 virtual void SliderValueChanged(views::Slider* sender,
149 float value, 173 float value,
150 float old_value, 174 float old_value,
151 views::SliderChangeReason reason) OVERRIDE { 175 views::SliderChangeReason reason) OVERRIDE {
152 if (reason == views::VALUE_CHANGED_BY_USER) { 176 if (reason == views::VALUE_CHANGED_BY_USER) {
153 ash::SystemTrayDelegate* delegate = 177 ash::SystemTrayDelegate* delegate =
154 ash::Shell::GetInstance()->tray_delegate(); 178 ash::Shell::GetInstance()->tray_delegate();
155 delegate->SetVolumeLevel(value); 179 delegate->SetVolumeLevel(value);
156 } 180 }
157 icon_->Update(); 181 icon_->Update();
158 } 182 }
159 183
160 VolumeButton* icon_; 184 VolumeButton* icon_;
185 MuteButton* mute_;
161 views::Slider* slider_; 186 views::Slider* slider_;
162 187
163 DISALLOW_COPY_AND_ASSIGN(VolumeView); 188 DISALLOW_COPY_AND_ASSIGN(VolumeView);
164 }; 189 };
165 190
166 } // namespace tray 191 } // namespace tray
167 192
168 TrayVolume::TrayVolume() 193 TrayVolume::TrayVolume()
169 : TrayImageItem(IDR_AURA_UBER_TRAY_VOLUME_MUTE), 194 : TrayImageItem(IDR_AURA_UBER_TRAY_VOLUME_MUTE),
170 volume_view_(NULL), 195 volume_view_(NULL),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 percent = 0.0; 236 percent = 0.0;
212 volume_view_->SetVolumeLevel(percent); 237 volume_view_->SetVolumeLevel(percent);
213 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); 238 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
214 return; 239 return;
215 } 240 }
216 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); 241 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
217 } 242 }
218 243
219 } // namespace internal 244 } // namespace internal
220 } // namespace ash 245 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_strings.grd ('k') | ash/system/tray/tray_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698