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

Side by Side Diff: chrome/browser/download/download_util.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 // Download utility implementation 5 // Download utility implementation
6 6
7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
8 8
9 #include "chrome/browser/download/download_util.h" 9 #include "chrome/browser/download/download_util.h"
10 10
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 *generated_name = net::GenerateFileName(download_item.GetURL(), 176 *generated_name = net::GenerateFileName(download_item.GetURL(),
177 download_item.GetContentDisposition(), 177 download_item.GetContentDisposition(),
178 download_item.GetReferrerCharset(), 178 download_item.GetReferrerCharset(),
179 download_item.GetSuggestedFilename(), 179 download_item.GetSuggestedFilename(),
180 download_item.GetMimeType(), 180 download_item.GetMimeType(),
181 default_file_name); 181 default_file_name);
182 } 182 }
183 183
184 // Download progress painting -------------------------------------------------- 184 // Download progress painting --------------------------------------------------
185 185
186 // Common bitmaps used for download progress animations. We load them once the 186 // Common images used for download progress animations. We load them once the
187 // first time we do a progress paint, then reuse them as they are always the 187 // first time we do a progress paint, then reuse them as they are always the
188 // same. 188 // same.
189 SkBitmap* g_foreground_16 = NULL; 189 gfx::ImageSkia* g_foreground_16 = NULL;
190 SkBitmap* g_background_16 = NULL; 190 gfx::ImageSkia* g_background_16 = NULL;
191 SkBitmap* g_foreground_32 = NULL; 191 gfx::ImageSkia* g_foreground_32 = NULL;
192 SkBitmap* g_background_32 = NULL; 192 gfx::ImageSkia* g_background_32 = NULL;
193 193
194 void PaintDownloadProgress(gfx::Canvas* canvas, 194 void PaintDownloadProgress(gfx::Canvas* canvas,
195 #if defined(TOOLKIT_VIEWS) 195 #if defined(TOOLKIT_VIEWS)
196 views::View* containing_view, 196 views::View* containing_view,
197 #endif 197 #endif
198 int origin_x, 198 int origin_x,
199 int origin_y, 199 int origin_y,
200 int start_angle, 200 int start_angle,
201 int percent_done, 201 int percent_done,
202 PaintDownloadProgressSize size) { 202 PaintDownloadProgressSize size) {
203 // Load up our common bitmaps 203 // Load up our common images
204 if (!g_background_16) { 204 if (!g_background_16) {
205 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 205 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
206 g_foreground_16 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16); 206 g_foreground_16 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16);
207 g_background_16 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_BACKGROUND_16); 207 g_background_16 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_BACKGROUND_16);
208 g_foreground_32 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32); 208 g_foreground_32 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32);
209 g_background_32 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_BACKGROUND_32); 209 g_background_32 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_BACKGROUND_32);
210 } 210 }
211 211
212 SkBitmap* background = (size == BIG) ? g_background_32 : g_background_16; 212 gfx::ImageSkia* background =
213 SkBitmap* foreground = (size == BIG) ? g_foreground_32 : g_foreground_16; 213 (size == BIG) ? g_background_32 : g_background_16;
214 gfx::ImageSkia* foreground =
215 (size == BIG) ? g_foreground_32 : g_foreground_16;
214 216
215 const int kProgressIconSize = (size == BIG) ? kBigProgressIconSize : 217 const int kProgressIconSize = (size == BIG) ? kBigProgressIconSize :
216 kSmallProgressIconSize; 218 kSmallProgressIconSize;
217 219
218 // We start by storing the bounds of the background and foreground bitmaps 220 // We start by storing the bounds of the background and foreground images
219 // so that it is easy to mirror the bounds if the UI layout is RTL. 221 // so that it is easy to mirror the bounds if the UI layout is RTL.
220 gfx::Rect background_bounds(origin_x, origin_y, 222 gfx::Rect background_bounds(origin_x, origin_y,
221 background->width(), background->height()); 223 background->width(), background->height());
222 gfx::Rect foreground_bounds(origin_x, origin_y, 224 gfx::Rect foreground_bounds(origin_x, origin_y,
223 foreground->width(), foreground->height()); 225 foreground->width(), foreground->height());
224 226
225 #if defined(TOOLKIT_VIEWS) 227 #if defined(TOOLKIT_VIEWS)
226 // Mirror the positions if necessary. 228 // Mirror the positions if necessary.
227 int mirrored_x = containing_view->GetMirroredXForRect(background_bounds); 229 int mirrored_x = containing_view->GetMirroredXForRect(background_bounds);
228 background_bounds.set_x(mirrored_x); 230 background_bounds.set_x(mirrored_x);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 293 }
292 294
293 void PaintDownloadComplete(gfx::Canvas* canvas, 295 void PaintDownloadComplete(gfx::Canvas* canvas,
294 #if defined(TOOLKIT_VIEWS) 296 #if defined(TOOLKIT_VIEWS)
295 views::View* containing_view, 297 views::View* containing_view,
296 #endif 298 #endif
297 int origin_x, 299 int origin_x,
298 int origin_y, 300 int origin_y,
299 double animation_progress, 301 double animation_progress,
300 PaintDownloadProgressSize size) { 302 PaintDownloadProgressSize size) {
301 // Load up our common bitmaps. 303 // Load up our common images.
302 if (!g_foreground_16) { 304 if (!g_foreground_16) {
303 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 305 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
304 g_foreground_16 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16); 306 g_foreground_16 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16);
305 g_foreground_32 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32); 307 g_foreground_32 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32);
306 } 308 }
307 309
308 SkBitmap* complete = (size == BIG) ? g_foreground_32 : g_foreground_16; 310 gfx::ImageSkia* complete = (size == BIG) ? g_foreground_32 : g_foreground_16;
309 311
310 gfx::Rect complete_bounds(origin_x, origin_y, 312 gfx::Rect complete_bounds(origin_x, origin_y,
311 complete->width(), complete->height()); 313 complete->width(), complete->height());
312 #if defined(TOOLKIT_VIEWS) 314 #if defined(TOOLKIT_VIEWS)
313 // Mirror the positions if necessary. 315 // Mirror the positions if necessary.
314 complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds)); 316 complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds));
315 #endif 317 #endif
316 318
317 // Start at full opacity, then loop back and forth five times before ending 319 // Start at full opacity, then loop back and forth five times before ending
318 // at zero opacity. 320 // at zero opacity.
319 canvas->SaveLayerAlpha(GetOpacity(animation_progress), complete_bounds); 321 canvas->SaveLayerAlpha(GetOpacity(animation_progress), complete_bounds);
320 canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); 322 canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
321 canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); 323 canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y());
322 canvas->Restore(); 324 canvas->Restore();
323 } 325 }
324 326
325 void PaintDownloadInterrupted(gfx::Canvas* canvas, 327 void PaintDownloadInterrupted(gfx::Canvas* canvas,
326 #if defined(TOOLKIT_VIEWS) 328 #if defined(TOOLKIT_VIEWS)
327 views::View* containing_view, 329 views::View* containing_view,
328 #endif 330 #endif
329 int origin_x, 331 int origin_x,
330 int origin_y, 332 int origin_y,
331 double animation_progress, 333 double animation_progress,
332 PaintDownloadProgressSize size) { 334 PaintDownloadProgressSize size) {
333 // Load up our common bitmaps. 335 // Load up our common images.
334 if (!g_foreground_16) { 336 if (!g_foreground_16) {
335 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 337 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
336 g_foreground_16 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16); 338 g_foreground_16 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16);
337 g_foreground_32 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32); 339 g_foreground_32 = rb.GetImageSkiaNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32);
338 } 340 }
339 341
340 SkBitmap* complete = (size == BIG) ? g_foreground_32 : g_foreground_16; 342 gfx::ImageSkia* complete = (size == BIG) ? g_foreground_32 : g_foreground_16;
341 343
342 gfx::Rect complete_bounds(origin_x, origin_y, 344 gfx::Rect complete_bounds(origin_x, origin_y,
343 complete->width(), complete->height()); 345 complete->width(), complete->height());
344 #if defined(TOOLKIT_VIEWS) 346 #if defined(TOOLKIT_VIEWS)
345 // Mirror the positions if necessary. 347 // Mirror the positions if necessary.
346 complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds)); 348 complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds));
347 #endif 349 #endif
348 350
349 // Start at zero opacity, then loop back and forth five times before ending 351 // Start at zero opacity, then loop back and forth five times before ending
350 // at full opacity. 352 // at full opacity.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 UMA_HISTOGRAM_ENUMERATION( 658 UMA_HISTOGRAM_ENUMERATION(
657 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 659 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
658 } 660 }
659 661
660 void RecordDownloadSource(ChromeDownloadSource source) { 662 void RecordDownloadSource(ChromeDownloadSource source) {
661 UMA_HISTOGRAM_ENUMERATION( 663 UMA_HISTOGRAM_ENUMERATION(
662 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); 664 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
663 } 665 }
664 666
665 } // namespace download_util 667 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/extensions/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698