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

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

Issue 9873018: ash: Update icons for disconnected wifi, and muted audio in the tray. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | « no previous file | chrome/app/theme/statusbar_network_arcs_dark.png » ('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 "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ash::SystemTrayDelegate* delegate = 53 ash::SystemTrayDelegate* delegate =
54 ash::Shell::GetInstance()->tray_delegate(); 54 ash::Shell::GetInstance()->tray_delegate();
55 int level = static_cast<int>(delegate->GetVolumeLevel() * 100); 55 int level = static_cast<int>(delegate->GetVolumeLevel() * 100);
56 int image_index = level / (100 / kVolumeLevel); 56 int image_index = level / (100 / kVolumeLevel);
57 if (level > 0 && image_index == 0) 57 if (level > 0 && image_index == 0)
58 ++image_index; 58 ++image_index;
59 if (level == 100) 59 if (level == 100)
60 image_index = kVolumeLevel - 1; 60 image_index = kVolumeLevel - 1;
61 else if (image_index == kVolumeLevel - 1) 61 else if (image_index == kVolumeLevel - 1)
62 --image_index; 62 --image_index;
63 // Index 0 is reserved for mute.
64 if (delegate->IsAudioMuted())
65 image_index = 0;
66 else
67 ++image_index;
63 if (image_index != image_index_) { 68 if (image_index != image_index_) {
64 SkIRect region = SkIRect::MakeXYWH(0, image_index * kVolumeImageHeight, 69 SkIRect region = SkIRect::MakeXYWH(0, image_index * kVolumeImageHeight,
65 kVolumeImageWidth, kVolumeImageHeight); 70 kVolumeImageWidth, kVolumeImageHeight);
66 SkBitmap bitmap; 71 SkBitmap bitmap;
67 image_.ToSkBitmap()->extractSubset(&bitmap, region); 72 image_.ToSkBitmap()->extractSubset(&bitmap, region);
68 SetImage(views::CustomButton::BS_NORMAL, &bitmap); 73 SetImage(views::CustomButton::BS_NORMAL, &bitmap);
69 image_index_ = image_index; 74 image_index_ = image_index;
70 } 75 }
71 SchedulePaint(); 76 SchedulePaint();
72 } 77 }
73 78
74 private: 79 private:
75 // Overridden from views::View. 80 // Overridden from views::View.
76 virtual gfx::Size GetPreferredSize() OVERRIDE { 81 virtual gfx::Size GetPreferredSize() OVERRIDE {
77 gfx::Size size = views::ToggleImageButton::GetPreferredSize(); 82 gfx::Size size = views::ToggleImageButton::GetPreferredSize();
78 size.set_height(kTrayPopupItemHeight); 83 size.set_height(kTrayPopupItemHeight);
79 return size; 84 return size;
80 } 85 }
81 86
82 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
83 views::ToggleImageButton::OnPaint(canvas);
84
85 ash::SystemTrayDelegate* delegate =
86 ash::Shell::GetInstance()->tray_delegate();
87 if (!delegate->IsAudioMuted())
88 return;
89
90 SkPaint paint;
91 paint.setColor(SkColorSetARGB(63, 0, 0, 0));
92 paint.setStrokeWidth(SkIntToScalar(3));
93 canvas->sk_canvas()->drawLine(SkIntToScalar(width()),
94 SkIntToScalar(10), SkIntToScalar(0), SkIntToScalar(height() - 10),
95 paint);
96 }
97
98 gfx::Image image_; 87 gfx::Image image_;
99 int image_index_; 88 int image_index_;
100 89
101 DISALLOW_COPY_AND_ASSIGN(VolumeButton); 90 DISALLOW_COPY_AND_ASSIGN(VolumeButton);
102 }; 91 };
103 92
104 class VolumeView : public views::View, 93 class VolumeView : public views::View,
105 public views::ButtonListener, 94 public views::ButtonListener,
106 public views::SliderListener { 95 public views::SliderListener {
107 public: 96 public:
(...skipping 13 matching lines...) Expand all
121 IDS_ASH_STATUS_TRAY_VOLUME)); 110 IDS_ASH_STATUS_TRAY_VOLUME));
122 AddChildView(slider_); 111 AddChildView(slider_);
123 } 112 }
124 113
125 virtual ~VolumeView() {} 114 virtual ~VolumeView() {}
126 115
127 void SetVolumeLevel(float percent) { 116 void SetVolumeLevel(float percent) {
128 slider_->SetValue(percent); 117 slider_->SetValue(percent);
129 // It is possible that the volume was (un)muted, but the actual volume level 118 // It is possible that the volume was (un)muted, but the actual volume level
130 // did not change. In that case, setting the value of the slider won't 119 // did not change. In that case, setting the value of the slider won't
131 // trigger a repaint. So explicitly trigger a repaint. 120 // trigger an update. So explicitly trigger an update.
132 icon_->SchedulePaint(); 121 icon_->Update();
133 } 122 }
134 123
135 private: 124 private:
136 // Overridden from views::View. 125 // Overridden from views::View.
137 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE { 126 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE {
138 int w = width() - slider_->x(); 127 int w = width() - slider_->x();
139 slider_->SetSize(gfx::Size(w, slider_->height())); 128 slider_->SetSize(gfx::Size(w, slider_->height()));
140 } 129 }
141 130
142 // Overridden from views::ButtonListener. 131 // Overridden from views::ButtonListener.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 if (volume_view_.get()) { 196 if (volume_view_.get()) {
208 volume_view_->SetVolumeLevel(percent); 197 volume_view_->SetVolumeLevel(percent);
209 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); 198 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
210 return; 199 return;
211 } 200 }
212 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); 201 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
213 } 202 }
214 203
215 } // namespace internal 204 } // namespace internal
216 } // namespace ash 205 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/app/theme/statusbar_network_arcs_dark.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698