| OLD | NEW |
| (Empty) |
| 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. | |
| 4 // | |
| 5 // Download utilities. | |
| 6 | |
| 7 #ifndef CHROME_BROWSER_DOWNLOAD_UTIL_H__ | |
| 8 #define CHROME_BROWSER_DOWNLOAD_UTIL_H__ | |
| 9 | |
| 10 #include <objidl.h> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/task.h" | |
| 14 #include "chrome/browser/views/download_item_view.h" | |
| 15 #include "chrome/views/event.h" | |
| 16 #include "chrome/views/menu.h" | |
| 17 #include "chrome/views/view.h" | |
| 18 | |
| 19 class DownloadItem; | |
| 20 class SkBitmap; | |
| 21 | |
| 22 namespace download_util { | |
| 23 | |
| 24 // DownloadContextMenu --------------------------------------------------------- | |
| 25 | |
| 26 // The base class of context menus that provides the various commands. | |
| 27 // Subclasses are responsible for creating and running the menu. | |
| 28 class BaseContextMenu : public Menu::Delegate { | |
| 29 public: | |
| 30 explicit BaseContextMenu(DownloadItem* download); | |
| 31 virtual ~BaseContextMenu(); | |
| 32 | |
| 33 enum ContextMenuCommands { | |
| 34 SHOW_IN_FOLDER = 1, // Open an Explorer window with the item highlighted | |
| 35 COPY_LINK, // Copy the download's URL to the clipboard | |
| 36 COPY_PATH, // Copy the download's full path to the clipboard | |
| 37 COPY_FILE, // Copy the downloaded file to the clipboard | |
| 38 OPEN_WHEN_COMPLETE, // Open the download when it's finished | |
| 39 ALWAYS_OPEN_TYPE, // Default this file extension to always open | |
| 40 REMOVE_ITEM, // Remove the download | |
| 41 CANCEL, // Cancel the download | |
| 42 MENU_LAST | |
| 43 }; | |
| 44 | |
| 45 // Menu::Delegate interface | |
| 46 virtual bool IsItemChecked(int id) const; | |
| 47 virtual bool IsItemDefault(int id) const; | |
| 48 virtual std::wstring GetLabel(int id) const; | |
| 49 virtual bool SupportsCommand(int id) const; | |
| 50 virtual bool IsCommandEnabled(int id) const; | |
| 51 virtual void ExecuteCommand(int id); | |
| 52 | |
| 53 protected: | |
| 54 // Information source. | |
| 55 DownloadItem* download_; | |
| 56 | |
| 57 private: | |
| 58 DISALLOW_EVIL_CONSTRUCTORS(BaseContextMenu); | |
| 59 }; | |
| 60 | |
| 61 // Menu for the download shelf. | |
| 62 class DownloadShelfContextMenu : public BaseContextMenu { | |
| 63 public: | |
| 64 DownloadShelfContextMenu(DownloadItem* download, | |
| 65 HWND window, | |
| 66 DownloadItemView::BaseDownloadItemModel* model, | |
| 67 const CPoint& point); | |
| 68 virtual ~DownloadShelfContextMenu(); | |
| 69 | |
| 70 virtual bool IsItemDefault(int id) const; | |
| 71 virtual void ExecuteCommand(int id); | |
| 72 | |
| 73 private: | |
| 74 // A model to control the cancel behavior. | |
| 75 DownloadItemView::BaseDownloadItemModel* model_; | |
| 76 | |
| 77 DISALLOW_EVIL_CONSTRUCTORS(DownloadShelfContextMenu); | |
| 78 }; | |
| 79 | |
| 80 // Menu for the download destination view. | |
| 81 class DownloadDestinationContextMenu : public BaseContextMenu { | |
| 82 public: | |
| 83 DownloadDestinationContextMenu(DownloadItem* download, | |
| 84 HWND window, | |
| 85 const CPoint& point); | |
| 86 virtual ~DownloadDestinationContextMenu(); | |
| 87 | |
| 88 private: | |
| 89 DISALLOW_EVIL_CONSTRUCTORS(DownloadDestinationContextMenu); | |
| 90 }; | |
| 91 | |
| 92 // DownloadProgressTask -------------------------------------------------------- | |
| 93 | |
| 94 // A class for managing the timed progress animations for a download view. The | |
| 95 // view must implement an UpdateDownloadProgress() method. | |
| 96 template<class DownloadView> | |
| 97 class DownloadProgressTask : public Task { | |
| 98 public: | |
| 99 DownloadProgressTask(DownloadView* view) : view_(view) {} | |
| 100 virtual ~DownloadProgressTask() {} | |
| 101 virtual void Run() { | |
| 102 view_->UpdateDownloadProgress(); | |
| 103 } | |
| 104 private: | |
| 105 DownloadView* view_; | |
| 106 DISALLOW_EVIL_CONSTRUCTORS(DownloadProgressTask); | |
| 107 }; | |
| 108 | |
| 109 // Download opening ------------------------------------------------------------ | |
| 110 | |
| 111 // Whether it is OK to open this download. | |
| 112 bool CanOpenDownload(DownloadItem* download); | |
| 113 | |
| 114 // Open the file associated with this download (wait for the download to | |
| 115 // complete if it is in progress). | |
| 116 void OpenDownload(DownloadItem* download); | |
| 117 | |
| 118 // Download progress animations ------------------------------------------------ | |
| 119 | |
| 120 // Arc sweep angle for use with downloads of unknown size | |
| 121 const int kUnknownAngleDegrees = 50; | |
| 122 | |
| 123 // Rate of progress for use with downloads of unknown size | |
| 124 const int kUnknownIncrementDegrees = 12; | |
| 125 | |
| 126 // Start angle for downloads with known size (midnight position) | |
| 127 const int kStartAngleDegrees = -90; | |
| 128 | |
| 129 // A circle | |
| 130 const int kMaxDegrees = 360; | |
| 131 | |
| 132 // Progress animation timer period, in milliseconds. | |
| 133 const int kProgressRateMs = 150; | |
| 134 | |
| 135 // XP and Vista must support icons of this size. | |
| 136 const int kSmallIconSize = 16; | |
| 137 const int kBigIconSize = 32; | |
| 138 | |
| 139 // Our progress halo around the icon | |
| 140 const int kSmallProgressIconSize = 39; | |
| 141 const int kBigProgressIconSize = 52; | |
| 142 | |
| 143 // The offset required to center the icon in the progress bitmaps. | |
| 144 const int kSmallProgressIconOffset = | |
| 145 (kSmallProgressIconSize - kSmallIconSize) / 2; | |
| 146 const int kBigProgressIconOffset = (kBigProgressIconSize - kBigIconSize) / 2; | |
| 147 | |
| 148 enum PaintDownloadProgressSize { | |
| 149 SMALL = 0, | |
| 150 BIG | |
| 151 }; | |
| 152 | |
| 153 // Paint the common download animation progress foreground and background, | |
| 154 // clipping the foreground to 'percent' full. If percent is -1, then we don't | |
| 155 // know the total size, so we just draw a rotating segment until we're done. | |
| 156 // | |
| 157 // |containing_view| is the View subclass within which the progress animation | |
| 158 // is drawn (generally either DownloadItemTabView or DownloadItemView). We | |
| 159 // require the containing View in addition to the canvas because if we are | |
| 160 // drawing in a right-to-left locale, we need to mirror the position of the | |
| 161 // progress animation within the containing View. | |
| 162 void PaintDownloadProgress(ChromeCanvas* canvas, | |
| 163 ChromeViews::View* containing_view, | |
| 164 int origin_x, | |
| 165 int origin_y, | |
| 166 int start_angle, | |
| 167 int percent, | |
| 168 PaintDownloadProgressSize size); | |
| 169 | |
| 170 void PaintDownloadComplete(ChromeCanvas* canvas, | |
| 171 ChromeViews::View* containing_view, | |
| 172 int origin_x, | |
| 173 int origin_y, | |
| 174 double animation_progress, | |
| 175 PaintDownloadProgressSize size); | |
| 176 | |
| 177 // Drag support ---------------------------------------------------------------- | |
| 178 | |
| 179 // Helper function for download views to use when acting as a drag source for a | |
| 180 // DownloadItem. If 'icon' is NULL, no image will be accompany the drag. | |
| 181 void DragDownload(const DownloadItem* download, SkBitmap* icon); | |
| 182 | |
| 183 // Executable file support ----------------------------------------------------- | |
| 184 | |
| 185 // Copy all executable file extensions. | |
| 186 void InitializeExeTypes(std::set<std::wstring>* exe_extensions); | |
| 187 | |
| 188 } // namespace download_util | |
| 189 | |
| 190 | |
| 191 #endif // CHROME_BROWSER_DOWNLOAD_UTIL_H__ | |
| 192 | |
| OLD | NEW |