blob: 1b3f7771141223d6cd044c6c09225a5cecfd96c2 [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"
[email protected]6f329092009-03-17 04:56:5517#include "chrome/views/controls/menu/menu.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/views/event.h"
initial.commit09911bf2008-07-26 23:55:2919#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
initial.commit09911bf2008-07-26 23:55:2927// DownloadProgressTask --------------------------------------------------------
28
29// A class for managing the timed progress animations for a download view. The
30// view must implement an UpdateDownloadProgress() method.
31template<class DownloadView>
32class 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]b47da722009-02-23 23:54:1841 DISALLOW_COPY_AND_ASSIGN(DownloadProgressTask);
initial.commit09911bf2008-07-26 23:55:2942};
43
44// Download opening ------------------------------------------------------------
45
46// Whether it is OK to open this download.
47bool CanOpenDownload(DownloadItem* download);
48
49// Open the file associated with this download (wait for the download to
50// complete if it is in progress).
51void OpenDownload(DownloadItem* download);
52
53// Download progress animations ------------------------------------------------
54
55// Arc sweep angle for use with downloads of unknown size
56const int kUnknownAngleDegrees = 50;
57
58// Rate of progress for use with downloads of unknown size
59const int kUnknownIncrementDegrees = 12;
60
61// Start angle for downloads with known size (midnight position)
62const int kStartAngleDegrees = -90;
63
64// A circle
65const int kMaxDegrees = 360;
66
67// Progress animation timer period, in milliseconds.
68const int kProgressRateMs = 150;
69
[email protected]5db2a6e2008-09-12 21:20:0470// XP and Vista must support icons of this size.
71const int kSmallIconSize = 16;
72const int kBigIconSize = 32;
73
[email protected]454dcb82008-10-31 21:11:4174// Our progress halo around the icon.
75int GetBigProgressIconSize();
76
[email protected]5db2a6e2008-09-12 21:20:0477const int kSmallProgressIconSize = 39;
78const int kBigProgressIconSize = 52;
79
80// The offset required to center the icon in the progress bitmaps.
[email protected]454dcb82008-10-31 21:11:4181int GetBigProgressIconOffset();
82
[email protected]5db2a6e2008-09-12 21:20:0483const int kSmallProgressIconOffset =
84 (kSmallProgressIconSize - kSmallIconSize) / 2;
[email protected]5db2a6e2008-09-12 21:20:0485
initial.commit09911bf2008-07-26 23:55:2986enum PaintDownloadProgressSize {
87 SMALL = 0,
88 BIG
89};
90
initial.commit09911bf2008-07-26 23:55:2991// 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.
100void PaintDownloadProgress(ChromeCanvas* canvas,
[email protected]c2dacc92008-10-16 23:51:38101 views::View* containing_view,
initial.commit09911bf2008-07-26 23:55:29102 int origin_x,
103 int origin_y,
104 int start_angle,
105 int percent,
106 PaintDownloadProgressSize size);
107
108void PaintDownloadComplete(ChromeCanvas* canvas,
[email protected]c2dacc92008-10-16 23:51:38109 views::View* containing_view,
initial.commit09911bf2008-07-26 23:55:29110 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.
119void DragDownload(const DownloadItem* download, SkBitmap* icon);
120
121// Executable file support -----------------------------------------------------
122
123// Copy all executable file extensions.
[email protected]64da0b932009-02-24 02:30:04124void InitializeExeTypes(std::set<std::string>* exe_extensions);
initial.commit09911bf2008-07-26 23:55:29125
126} // namespace download_util
127
128
[email protected]b47da722009-02-23 23:54:18129#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_