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

Side by Side Diff: chrome/browser/speech/speech_recognition_tray_icon_controller.cc

Issue 10453101: Convert most of the rest of chrome to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
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 "chrome/browser/speech/speech_recognition_tray_icon_controller.h" 5 #include "chrome/browser/speech/speech_recognition_tray_icon_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 28
29 // Number of volume steps used when rendering the VU meter icon. 29 // Number of volume steps used when rendering the VU meter icon.
30 const int kVolumeSteps = 6; 30 const int kVolumeSteps = 6;
31 31
32 // A lazily initialized singleton to hold all the images used by the 32 // A lazily initialized singleton to hold all the images used by the
33 // notification icon and safely destroy them on exit. 33 // notification icon and safely destroy them on exit.
34 class NotificationTrayImages { 34 class NotificationTrayImages {
35 public: 35 public:
36 SkBitmap* mic_full() { return mic_full_; } 36 gfx::ImageSkia* mic_full() { return mic_full_; }
37 SkBitmap* mic_empty() { return mic_empty_; } 37 gfx::ImageSkia* mic_empty() { return mic_empty_; }
38 SkBitmap* balloon_icon() { return balloon_icon_; } 38 gfx::ImageSkia* balloon_icon() { return balloon_icon_; }
39 39
40 private: 40 private:
41 // Private constructor to enforce singleton. 41 // Private constructor to enforce singleton.
42 friend struct base::DefaultLazyInstanceTraits<NotificationTrayImages>; 42 friend struct base::DefaultLazyInstanceTraits<NotificationTrayImages>;
43 NotificationTrayImages(); 43 NotificationTrayImages();
44 44
45 // These bitmaps are owned by ResourceBundle and need not be destroyed. 45 // These images are owned by ResourceBundle and need not be destroyed.
46 SkBitmap* mic_full_; // Tray mic image with full volume. 46 gfx::ImageSkia* mic_full_; // Tray mic image with full volume.
47 SkBitmap* mic_empty_; // Tray mic image with zero volume. 47 gfx::ImageSkia* mic_empty_; // Tray mic image with zero volume.
48 SkBitmap* balloon_icon_; // High resolution mic for the notification balloon. 48 // High resolution mic for the notification balloon.
49 gfx::ImageSkia* balloon_icon_;
49 }; 50 };
50 51
51 NotificationTrayImages::NotificationTrayImages() { 52 NotificationTrayImages::NotificationTrayImages() {
52 mic_empty_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( 53 mic_empty_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
53 IDR_SPEECH_INPUT_TRAY_MIC_EMPTY); 54 IDR_SPEECH_INPUT_TRAY_MIC_EMPTY);
54 mic_full_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( 55 mic_full_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
55 IDR_SPEECH_INPUT_TRAY_MIC_FULL); 56 IDR_SPEECH_INPUT_TRAY_MIC_FULL);
56 balloon_icon_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( 57 balloon_icon_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
57 IDR_SPEECH_INPUT_TRAY_BALLOON_ICON); 58 IDR_SPEECH_INPUT_TRAY_BALLOON_ICON);
58 } 59 }
59 60
60 base::LazyInstance<NotificationTrayImages> g_images = LAZY_INSTANCE_INITIALIZER; 61 base::LazyInstance<NotificationTrayImages> g_images = LAZY_INSTANCE_INITIALIZER;
61 62
62 } // namespace 63 } // namespace
63 64
64 SpeechRecognitionTrayIconController::SpeechRecognitionTrayIconController() 65 SpeechRecognitionTrayIconController::SpeechRecognitionTrayIconController()
65 : tray_icon_(NULL) { 66 : tray_icon_(NULL) {
66 Initialize(); 67 Initialize();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 159
159 buffer_image_.reset(new SkBitmap()); 160 buffer_image_.reset(new SkBitmap());
160 buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, 161 buffer_image_->setConfig(SkBitmap::kARGB_8888_Config,
161 g_images.Get().mic_empty()->width(), 162 g_images.Get().mic_empty()->width(),
162 g_images.Get().mic_empty()->height()); 163 g_images.Get().mic_empty()->height());
163 buffer_image_->allocPixels(); 164 buffer_image_->allocPixels();
164 } 165 }
165 166
166 void SpeechRecognitionTrayIconController::DrawVolume( 167 void SpeechRecognitionTrayIconController::DrawVolume(
167 SkCanvas* canvas, 168 SkCanvas* canvas,
168 const SkBitmap& bitmap, 169 const gfx::ImageSkia& image,
169 float volume) { 170 float volume) {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
171 buffer_image_->eraseARGB(0, 0, 0, 0); 172 buffer_image_->eraseARGB(0, 0, 0, 0);
172 173
173 int width = mic_image_->width(); 174 int width = mic_image_->width();
174 int height = mic_image_->height(); 175 int height = mic_image_->height();
175 SkCanvas buffer_canvas(*buffer_image_); 176 SkCanvas buffer_canvas(*buffer_image_);
176 177
177 SkScalar clip_top = 178 SkScalar clip_top =
178 (((1.0f - volume) * (height * (kVolumeSteps + 1))) - height) / 179 (((1.0f - volume) * (height * (kVolumeSteps + 1))) - height) /
179 kVolumeSteps; 180 kVolumeSteps;
180 buffer_canvas.clipRect(SkRect::MakeLTRB(0, clip_top, 181 buffer_canvas.clipRect(SkRect::MakeLTRB(0, clip_top,
181 SkIntToScalar(width), SkIntToScalar(height))); 182 SkIntToScalar(width), SkIntToScalar(height)));
182 buffer_canvas.drawBitmap(bitmap, 0, 0); 183 buffer_canvas.drawBitmap(image, 0, 0);
183 184
184 canvas->drawBitmap(*buffer_image_.get(), 0, 0); 185 canvas->drawBitmap(*buffer_image_.get(), 0, 0);
185 } 186 }
186 187
187 void SpeechRecognitionTrayIconController::ShowNotificationBalloon( 188 void SpeechRecognitionTrayIconController::ShowNotificationBalloon(
188 const string16& text) { 189 const string16& text) {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
190 string16 title = l10n_util::GetStringUTF16( 191 string16 title = l10n_util::GetStringUTF16(
191 IDS_SPEECH_INPUT_TRAY_BALLOON_TITLE); 192 IDS_SPEECH_INPUT_TRAY_BALLOON_TITLE);
192 string16 message = l10n_util::GetStringFUTF16( 193 string16 message = l10n_util::GetStringFUTF16(
193 IDS_SPEECH_INPUT_TRAY_BALLOON_BODY, 194 IDS_SPEECH_INPUT_TRAY_BALLOON_BODY,
194 text, 195 text,
195 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 196 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
196 197
197 tray_icon_->DisplayBalloon(*g_images.Get().balloon_icon(), title, message); 198 tray_icon_->DisplayBalloon(*g_images.Get().balloon_icon(), title, message);
198 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698