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