| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
| 11 #endif | 11 #endif |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
| 15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/i18n/rtl.h" | 17 #include "base/i18n/rtl.h" |
| 18 #include "base/i18n/time_formatting.h" | 18 #include "base/i18n/time_formatting.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/singleton.h" | 20 #include "base/singleton.h" |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/download/download_item_model.h" | 25 #include "chrome/browser/download/download_item_model.h" |
| 26 #include "chrome/browser/download/download_manager.h" | 26 #include "chrome/browser/download/download_manager.h" |
| 27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/time_format.h" | 29 #include "chrome/common/time_format.h" |
| 30 #include "gfx/canvas.h" | 30 #include "gfx/canvas_skia.h" |
| 31 #include "gfx/rect.h" | 31 #include "gfx/rect.h" |
| 32 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 33 #include "grit/locale_settings.h" | 33 #include "grit/locale_settings.h" |
| 34 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
| 35 #include "net/base/mime_util.h" | 35 #include "net/base/mime_util.h" |
| 36 #include "skia/ext/image_operations.h" | 36 #include "skia/ext/image_operations.h" |
| 37 #include "third_party/skia/include/core/SkPath.h" | 37 #include "third_party/skia/include/core/SkPath.h" |
| 38 #include "third_party/skia/include/core/SkShader.h" | 38 #include "third_party/skia/include/core/SkShader.h" |
| 39 | 39 |
| 40 #if defined(TOOLKIT_VIEWS) | 40 #if defined(TOOLKIT_VIEWS) |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 SkShader::CreateBitmapShader(*foreground, | 218 SkShader::CreateBitmapShader(*foreground, |
| 219 SkShader::kClamp_TileMode, | 219 SkShader::kClamp_TileMode, |
| 220 SkShader::kClamp_TileMode); | 220 SkShader::kClamp_TileMode); |
| 221 SkMatrix shader_scale; | 221 SkMatrix shader_scale; |
| 222 shader_scale.setTranslate(SkIntToScalar(foreground_bounds.x()), | 222 shader_scale.setTranslate(SkIntToScalar(foreground_bounds.x()), |
| 223 SkIntToScalar(foreground_bounds.y())); | 223 SkIntToScalar(foreground_bounds.y())); |
| 224 shader->setLocalMatrix(shader_scale); | 224 shader->setLocalMatrix(shader_scale); |
| 225 foreground_paint.setShader(shader); | 225 foreground_paint.setShader(shader); |
| 226 foreground_paint.setAntiAlias(true); | 226 foreground_paint.setAntiAlias(true); |
| 227 shader->unref(); | 227 shader->unref(); |
| 228 canvas->drawPath(path, foreground_paint); | 228 canvas->AsCanvasSkia()->drawPath(path, foreground_paint); |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 | 231 |
| 232 canvas->DrawBitmapInt(*foreground, | 232 canvas->DrawBitmapInt(*foreground, |
| 233 foreground_bounds.x(), | 233 foreground_bounds.x(), |
| 234 foreground_bounds.y(), | 234 foreground_bounds.y(), |
| 235 foreground_paint); | 235 foreground_paint); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void PaintDownloadComplete(gfx::Canvas* canvas, | 238 void PaintDownloadComplete(gfx::Canvas* canvas, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 264 // at zero opacity. | 264 // at zero opacity. |
| 265 static const double PI = 3.141592653589793; | 265 static const double PI = 3.141592653589793; |
| 266 double opacity = sin(animation_progress * PI * kCompleteAnimationCycles + | 266 double opacity = sin(animation_progress * PI * kCompleteAnimationCycles + |
| 267 PI/2) / 2 + 0.5; | 267 PI/2) / 2 + 0.5; |
| 268 | 268 |
| 269 SkRect bounds; | 269 SkRect bounds; |
| 270 bounds.set(SkIntToScalar(complete_bounds.x()), | 270 bounds.set(SkIntToScalar(complete_bounds.x()), |
| 271 SkIntToScalar(complete_bounds.y()), | 271 SkIntToScalar(complete_bounds.y()), |
| 272 SkIntToScalar(complete_bounds.x() + complete_bounds.width()), | 272 SkIntToScalar(complete_bounds.x() + complete_bounds.width()), |
| 273 SkIntToScalar(complete_bounds.y() + complete_bounds.height())); | 273 SkIntToScalar(complete_bounds.y() + complete_bounds.height())); |
| 274 canvas->saveLayerAlpha(&bounds, | 274 canvas->AsCanvasSkia()->saveLayerAlpha( |
| 275 static_cast<int>(255.0 * opacity), | 275 &bounds, |
| 276 SkCanvas::kARGB_ClipLayer_SaveFlag); | 276 static_cast<int>(255.0 * opacity), |
| 277 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | 277 SkCanvas::kARGB_ClipLayer_SaveFlag); |
| 278 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
| 278 canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); | 279 canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); |
| 279 canvas->restore(); | 280 canvas->AsCanvasSkia()->restore(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 // Load a language dependent height so that the dangerous download confirmation | 283 // Load a language dependent height so that the dangerous download confirmation |
| 283 // message doesn't overlap with the download link label. | 284 // message doesn't overlap with the download link label. |
| 284 int GetBigProgressIconSize() { | 285 int GetBigProgressIconSize() { |
| 285 static int big_progress_icon_size = 0; | 286 static int big_progress_icon_size = 0; |
| 286 if (big_progress_icon_size == 0) { | 287 if (big_progress_icon_size == 0) { |
| 287 string16 locale_size_str = | 288 string16 locale_size_str = |
| 288 WideToUTF16Hack(l10n_util::GetString(IDS_DOWNLOAD_BIG_PROGRESS_SIZE)); | 289 WideToUTF16Hack(l10n_util::GetString(IDS_DOWNLOAD_BIG_PROGRESS_SIZE)); |
| 289 bool rc = StringToInt(locale_size_str, &big_progress_icon_size); | 290 bool rc = StringToInt(locale_size_str, &big_progress_icon_size); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 AppendNumberToPath(&new_path, count); | 517 AppendNumberToPath(&new_path, count); |
| 517 | 518 |
| 518 if (!file_util::PathExists(new_path)) | 519 if (!file_util::PathExists(new_path)) |
| 519 return count; | 520 return count; |
| 520 } | 521 } |
| 521 | 522 |
| 522 return -1; | 523 return -1; |
| 523 } | 524 } |
| 524 | 525 |
| 525 } // namespace download_util | 526 } // namespace download_util |
| OLD | NEW |