| OLD | NEW |
| 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_shelf.h" | 7 #include "chrome/browser/download/download_shelf.h" |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/download/download_started_animation.h" | 22 #include "chrome/browser/download/download_started_animation.h" |
| 23 #include "chrome/browser/platform_util.h" | 23 #include "chrome/browser/platform_util.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/themes/theme_properties.h" | 25 #include "chrome/browser/themes/theme_properties.h" |
| 26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/download_item.h" | 29 #include "content/public/browser/download_item.h" |
| 30 #include "content/public/browser/download_manager.h" | 30 #include "content/public/browser/download_manager.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "third_party/skia/include/core/SkPaint.h" | |
| 33 #include "third_party/skia/include/core/SkPath.h" | 32 #include "third_party/skia/include/core/SkPath.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "ui/base/theme_provider.h" | 34 #include "ui/base/theme_provider.h" |
| 36 #include "ui/gfx/animation/animation.h" | 35 #include "ui/gfx/animation/animation.h" |
| 37 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
| 38 | 37 |
| 39 using content::DownloadItem; | 38 using content::DownloadItem; |
| 40 | 39 |
| 41 namespace { | 40 namespace { |
| 42 | 41 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 | 67 |
| 69 // Download progress painting -------------------------------------------------- | 68 // Download progress painting -------------------------------------------------- |
| 70 | 69 |
| 71 // static | 70 // static |
| 72 void DownloadShelf::PaintDownloadProgress( | 71 void DownloadShelf::PaintDownloadProgress( |
| 73 gfx::Canvas* canvas, | 72 gfx::Canvas* canvas, |
| 74 const ui::ThemeProvider& theme_provider, | 73 const ui::ThemeProvider& theme_provider, |
| 75 const base::TimeDelta& progress_time, | 74 const base::TimeDelta& progress_time, |
| 76 int percent_done) { | 75 int percent_done) { |
| 77 // Draw background (light blue circle). | 76 // Draw background (light blue circle). |
| 78 cc::PaintFlags bg_paint; | 77 cc::PaintFlags bg_flags; |
| 79 bg_paint.setStyle(cc::PaintFlags::kFill_Style); | 78 bg_flags.setStyle(cc::PaintFlags::kFill_Style); |
| 80 SkColor indicator_color = | 79 SkColor indicator_color = |
| 81 theme_provider.GetColor(ThemeProperties::COLOR_TAB_THROBBER_SPINNING); | 80 theme_provider.GetColor(ThemeProperties::COLOR_TAB_THROBBER_SPINNING); |
| 82 bg_paint.setColor(SkColorSetA(indicator_color, 0x33)); | 81 bg_flags.setColor(SkColorSetA(indicator_color, 0x33)); |
| 83 bg_paint.setAntiAlias(true); | 82 bg_flags.setAntiAlias(true); |
| 84 const SkScalar kCenterPoint = kProgressIndicatorSize / 2.f; | 83 const SkScalar kCenterPoint = kProgressIndicatorSize / 2.f; |
| 85 SkPath bg; | 84 SkPath bg; |
| 86 bg.addCircle(kCenterPoint, kCenterPoint, kCenterPoint); | 85 bg.addCircle(kCenterPoint, kCenterPoint, kCenterPoint); |
| 87 canvas->DrawPath(bg, bg_paint); | 86 canvas->DrawPath(bg, bg_flags); |
| 88 | 87 |
| 89 // Calculate progress. | 88 // Calculate progress. |
| 90 SkScalar sweep_angle = 0.f; | 89 SkScalar sweep_angle = 0.f; |
| 91 // Start at 12 o'clock. | 90 // Start at 12 o'clock. |
| 92 SkScalar start_pos = SkIntToScalar(270); | 91 SkScalar start_pos = SkIntToScalar(270); |
| 93 if (percent_done < 0) { | 92 if (percent_done < 0) { |
| 94 // For unknown size downloads, draw a 50 degree sweep that moves at | 93 // For unknown size downloads, draw a 50 degree sweep that moves at |
| 95 // 0.08 degrees per millisecond. | 94 // 0.08 degrees per millisecond. |
| 96 sweep_angle = 50.f; | 95 sweep_angle = 50.f; |
| 97 start_pos += static_cast<SkScalar>(progress_time.InMilliseconds() * 0.08); | 96 start_pos += static_cast<SkScalar>(progress_time.InMilliseconds() * 0.08); |
| 98 } else if (percent_done > 0) { | 97 } else if (percent_done > 0) { |
| 99 sweep_angle = static_cast<SkScalar>(360 * percent_done / 100.0); | 98 sweep_angle = static_cast<SkScalar>(360 * percent_done / 100.0); |
| 100 } | 99 } |
| 101 | 100 |
| 102 // Draw progress. | 101 // Draw progress. |
| 103 SkPath progress; | 102 SkPath progress; |
| 104 progress.addArc( | 103 progress.addArc( |
| 105 SkRect::MakeLTRB(0, 0, kProgressIndicatorSize, kProgressIndicatorSize), | 104 SkRect::MakeLTRB(0, 0, kProgressIndicatorSize, kProgressIndicatorSize), |
| 106 start_pos, sweep_angle); | 105 start_pos, sweep_angle); |
| 107 cc::PaintFlags progress_paint; | 106 cc::PaintFlags progress_flags; |
| 108 progress_paint.setColor(indicator_color); | 107 progress_flags.setColor(indicator_color); |
| 109 progress_paint.setStyle(cc::PaintFlags::kStroke_Style); | 108 progress_flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 110 progress_paint.setStrokeWidth(1.7f); | 109 progress_flags.setStrokeWidth(1.7f); |
| 111 progress_paint.setAntiAlias(true); | 110 progress_flags.setAntiAlias(true); |
| 112 canvas->DrawPath(progress, progress_paint); | 111 canvas->DrawPath(progress, progress_flags); |
| 113 } | 112 } |
| 114 | 113 |
| 115 // static | 114 // static |
| 116 void DownloadShelf::PaintDownloadComplete( | 115 void DownloadShelf::PaintDownloadComplete( |
| 117 gfx::Canvas* canvas, | 116 gfx::Canvas* canvas, |
| 118 const ui::ThemeProvider& theme_provider, | 117 const ui::ThemeProvider& theme_provider, |
| 119 double animation_progress) { | 118 double animation_progress) { |
| 120 // Start at full opacity, then loop back and forth five times before ending | 119 // Start at full opacity, then loop back and forth five times before ending |
| 121 // at zero opacity. | 120 // at zero opacity. |
| 122 canvas->SaveLayerAlpha(GetOpacity(animation_progress)); | 121 canvas->SaveLayerAlpha(GetOpacity(animation_progress)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 content::DownloadManager* download_manager = GetDownloadManager(); | 230 content::DownloadManager* download_manager = GetDownloadManager(); |
| 232 if (!download_manager) | 231 if (!download_manager) |
| 233 return; | 232 return; |
| 234 | 233 |
| 235 DownloadItem* download = download_manager->GetDownload(download_id); | 234 DownloadItem* download = download_manager->GetDownload(download_id); |
| 236 if (!download) | 235 if (!download) |
| 237 return; | 236 return; |
| 238 | 237 |
| 239 ShowDownload(download); | 238 ShowDownload(download); |
| 240 } | 239 } |
| OLD | NEW |