license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | // |
| 5 | // Download utilities. |
| 6 | |
[email protected] | b47da72 | 2009-02-23 23:54:18 | [diff] [blame] | 7 | #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| 8 | #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
| 10 | #include <objidl.h> |
| 11 | |
[email protected] | b47da72 | 2009-02-23 23:54:18 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <string> |
| 14 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "base/basictypes.h" |
| 16 | #include "base/task.h" |
[email protected] | 6f32909 | 2009-03-17 04:56:55 | [diff] [blame] | 17 | #include "chrome/views/controls/menu/menu.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/views/event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | #include "chrome/views/view.h" |
| 20 | |
[email protected] | b47da72 | 2009-02-23 23:54:18 | [diff] [blame] | 21 | class BaseDownloadItemModel; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | class DownloadItem; |
| 23 | class SkBitmap; |
| 24 | |
| 25 | namespace download_util { |
| 26 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | // DownloadProgressTask -------------------------------------------------------- |
| 28 | |
| 29 | // A class for managing the timed progress animations for a download view. The |
| 30 | // view must implement an UpdateDownloadProgress() method. |
| 31 | template<class DownloadView> |
| 32 | class DownloadProgressTask : public Task { |
| 33 | public: |
| 34 | DownloadProgressTask(DownloadView* view) : view_(view) {} |
| 35 | virtual ~DownloadProgressTask() {} |
| 36 | virtual void Run() { |
| 37 | view_->UpdateDownloadProgress(); |
| 38 | } |
| 39 | private: |
| 40 | DownloadView* view_; |
[email protected] | b47da72 | 2009-02-23 23:54:18 | [diff] [blame] | 41 | DISALLOW_COPY_AND_ASSIGN(DownloadProgressTask); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | // Download opening ------------------------------------------------------------ |
| 45 | |
| 46 | // Whether it is OK to open this download. |
| 47 | bool CanOpenDownload(DownloadItem* download); |
| 48 | |
| 49 | // Open the file associated with this download (wait for the download to |
| 50 | // complete if it is in progress). |
| 51 | void OpenDownload(DownloadItem* download); |
| 52 | |
| 53 | // Download progress animations ------------------------------------------------ |
| 54 | |
| 55 | // Arc sweep angle for use with downloads of unknown size |
| 56 | const int kUnknownAngleDegrees = 50; |
| 57 | |
| 58 | // Rate of progress for use with downloads of unknown size |
| 59 | const int kUnknownIncrementDegrees = 12; |
| 60 | |
| 61 | // Start angle for downloads with known size (midnight position) |
| 62 | const int kStartAngleDegrees = -90; |
| 63 | |
| 64 | // A circle |
| 65 | const int kMaxDegrees = 360; |
| 66 | |
| 67 | // Progress animation timer period, in milliseconds. |
| 68 | const int kProgressRateMs = 150; |
| 69 | |
[email protected] | 5db2a6e | 2008-09-12 21:20:04 | [diff] [blame] | 70 | // XP and Vista must support icons of this size. |
| 71 | const int kSmallIconSize = 16; |
| 72 | const int kBigIconSize = 32; |
| 73 | |
[email protected] | 454dcb8 | 2008-10-31 21:11:41 | [diff] [blame] | 74 | // Our progress halo around the icon. |
| 75 | int GetBigProgressIconSize(); |
| 76 | |
[email protected] | 5db2a6e | 2008-09-12 21:20:04 | [diff] [blame] | 77 | const int kSmallProgressIconSize = 39; |
| 78 | const int kBigProgressIconSize = 52; |
| 79 | |
| 80 | // The offset required to center the icon in the progress bitmaps. |
[email protected] | 454dcb8 | 2008-10-31 21:11:41 | [diff] [blame] | 81 | int GetBigProgressIconOffset(); |
| 82 | |
[email protected] | 5db2a6e | 2008-09-12 21:20:04 | [diff] [blame] | 83 | const int kSmallProgressIconOffset = |
| 84 | (kSmallProgressIconSize - kSmallIconSize) / 2; |
[email protected] | 5db2a6e | 2008-09-12 21:20:04 | [diff] [blame] | 85 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | enum PaintDownloadProgressSize { |
| 87 | SMALL = 0, |
| 88 | BIG |
| 89 | }; |
| 90 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 91 | // Paint the common download animation progress foreground and background, |
| 92 | // clipping the foreground to 'percent' full. If percent is -1, then we don't |
| 93 | // know the total size, so we just draw a rotating segment until we're done. |
| 94 | // |
| 95 | // |containing_view| is the View subclass within which the progress animation |
| 96 | // is drawn (generally either DownloadItemTabView or DownloadItemView). We |
| 97 | // require the containing View in addition to the canvas because if we are |
| 98 | // drawing in a right-to-left locale, we need to mirror the position of the |
| 99 | // progress animation within the containing View. |
| 100 | void PaintDownloadProgress(ChromeCanvas* canvas, |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 101 | views::View* containing_view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | int origin_x, |
| 103 | int origin_y, |
| 104 | int start_angle, |
| 105 | int percent, |
| 106 | PaintDownloadProgressSize size); |
| 107 | |
| 108 | void PaintDownloadComplete(ChromeCanvas* canvas, |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 109 | views::View* containing_view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 110 | int origin_x, |
| 111 | int origin_y, |
| 112 | double animation_progress, |
| 113 | PaintDownloadProgressSize size); |
| 114 | |
| 115 | // Drag support ---------------------------------------------------------------- |
| 116 | |
| 117 | // Helper function for download views to use when acting as a drag source for a |
| 118 | // DownloadItem. If 'icon' is NULL, no image will be accompany the drag. |
| 119 | void DragDownload(const DownloadItem* download, SkBitmap* icon); |
| 120 | |
| 121 | // Executable file support ----------------------------------------------------- |
| 122 | |
| 123 | // Copy all executable file extensions. |
[email protected] | 64da0b93 | 2009-02-24 02:30:04 | [diff] [blame] | 124 | void InitializeExeTypes(std::set<std::string>* exe_extensions); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 125 | |
| 126 | } // namespace download_util |
| 127 | |
| 128 | |
[email protected] | b47da72 | 2009-02-23 23:54:18 | [diff] [blame] | 129 | #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |