Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / download / download_shelf.h
blobac105ce7242f7b581f9a19229032c013f62f6ae8
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/time/time.h"
10 #include "build/build_config.h"
12 class Browser;
14 namespace gfx {
15 class Canvas;
16 class ImageSkia;
17 class Rect;
20 namespace content {
21 class DownloadItem;
22 class DownloadManager;
25 #if defined(TOOLKIT_VIEWS)
26 namespace views {
27 class View;
29 #endif
31 // This is an abstract base class for platform specific download shelf
32 // implementations.
33 class DownloadShelf {
34 public:
35 // Reason for closing download shelf.
36 enum CloseReason {
37 // Closing the shelf automatically. E.g.: all remaining downloads in the
38 // shelf have been opened, last download in shelf was removed, or the
39 // browser is switching to full-screen mode.
40 AUTOMATIC,
42 // Closing shelf due to a user selection. E.g.: the user clicked on the
43 // 'close' button on the download shelf, or the shelf is being closed as a
44 // side-effect of the user opening the downloads page.
45 USER_ACTION
48 enum PaintDownloadProgressSize {
49 SMALL = 0,
50 BIG
53 // Download progress animations ----------------------------------------------
55 enum {
56 // Arc sweep angle for use with downloads of unknown size.
57 kUnknownAngleDegrees = 50,
59 // Rate of progress for use with downloads of unknown size.
60 kUnknownIncrementDegrees = 12,
62 // Start angle for downloads with known size (midnight position).
63 kStartAngleDegrees = -90,
65 // A the maximum number of degrees of a circle.
66 kMaxDegrees = 360,
68 // Progress animation timer period, in milliseconds.
69 kProgressRateMs = 150,
71 // XP and Vista must support icons of this size.
72 kSmallIconSize = 16,
73 kBigIconSize = 32,
75 kSmallProgressIconSize = 39,
76 kBigProgressIconSize = 52,
78 kSmallProgressIconOffset = (kSmallProgressIconSize - kSmallIconSize) / 2
81 DownloadShelf();
82 virtual ~DownloadShelf();
84 // Our progress halo around the icon.
85 // Load a language dependent height so that the dangerous download
86 // confirmation message doesn't overlap with the download link label.
87 static int GetBigProgressIconSize();
89 // The offset required to center the icon in the progress images.
90 static int GetBigProgressIconOffset();
92 // Paint the common download animation progress foreground and background,
93 // clipping the foreground to 'percent' full. If percent is -1, then we don't
94 // know the total size, so we just draw a rotating segment until we're done.
96 // |containing_view| is the View subclass within which the progress animation
97 // is drawn (generally either DownloadItemTabView or DownloadItemView). We
98 // require the containing View in addition to the canvas because if we are
99 // drawing in a right-to-left locale, we need to mirror the position of the
100 // progress animation within the containing View.
101 static void PaintCustomDownloadProgress(
102 gfx::Canvas* canvas,
103 const gfx::ImageSkia& background_image,
104 const gfx::ImageSkia& foreground_image,
105 int image_size,
106 const gfx::Rect& bounds,
107 int start_angle,
108 int percent_done);
110 static void PaintDownloadProgress(gfx::Canvas* canvas,
111 #if defined(TOOLKIT_VIEWS)
112 views::View* containing_view,
113 #endif
114 int origin_x,
115 int origin_y,
116 int start_angle,
117 int percent,
118 PaintDownloadProgressSize size);
120 static void PaintDownloadComplete(gfx::Canvas* canvas,
121 #if defined(TOOLKIT_VIEWS)
122 views::View* containing_view,
123 #endif
124 int origin_x,
125 int origin_y,
126 double animation_progress,
127 PaintDownloadProgressSize size);
129 static void PaintDownloadInterrupted(gfx::Canvas* canvas,
130 #if defined(TOOLKIT_VIEWS)
131 views::View* containing_view,
132 #endif
133 int origin_x,
134 int origin_y,
135 double animation_progress,
136 PaintDownloadProgressSize size);
138 // A new download has started. Add it to our shelf and show the download
139 // started animation.
141 // Some downloads are removed from the shelf on completion (See
142 // DownloadItemModel::ShouldRemoveFromShelfWhenComplete()). These transient
143 // downloads are added to the shelf after a delay. If the download completes
144 // before the delay duration, it will not be added to the shelf at all.
145 void AddDownload(content::DownloadItem* download);
147 // The browser view needs to know when we are going away to properly return
148 // the resize corner size to WebKit so that we don't draw on top of it.
149 // This returns the showing state of our animation which is set to true at
150 // the beginning Show and false at the beginning of a Hide.
151 virtual bool IsShowing() const = 0;
153 // Returns whether the download shelf is showing the close animation.
154 virtual bool IsClosing() const = 0;
156 // Opens the shelf.
157 void Show();
159 // Closes the shelf.
160 void Close(CloseReason reason);
162 // Hides the shelf. This closes the shelf if it is currently showing.
163 void Hide();
165 // Unhides the shelf. This will cause the shelf to be opened if it was open
166 // when it was hidden, or was shown while it was hidden.
167 void Unhide();
169 virtual Browser* browser() const = 0;
171 // Returns whether the download shelf is hidden.
172 bool is_hidden() { return is_hidden_; }
174 protected:
175 virtual void DoAddDownload(content::DownloadItem* download) = 0;
176 virtual void DoShow() = 0;
177 virtual void DoClose(CloseReason reason) = 0;
179 // Time delay to wait before adding a transient download to the shelf.
180 // Protected virtual for testing.
181 virtual base::TimeDelta GetTransientDownloadShowDelay();
183 // Returns the DownloadManager associated with this DownloadShelf. All
184 // downloads that are shown on this shelf is expected to belong to this
185 // DownloadManager. Protected virtual for testing.
186 virtual content::DownloadManager* GetDownloadManager();
188 private:
189 // Show the download on the shelf immediately. Also displayes the download
190 // started animation if necessary.
191 void ShowDownload(content::DownloadItem* download);
193 // Similar to ShowDownload() but refers to the download using an ID. This
194 // download should belong to the DownloadManager returned by
195 // GetDownloadManager().
196 void ShowDownloadById(int32 download_id);
198 bool should_show_on_unhide_;
199 bool is_hidden_;
200 base::WeakPtrFactory<DownloadShelf> weak_ptr_factory_;
203 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_