Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / download / download_shelf.h
blob7ae50215788768b94aef6c8a5422a1f66f44cac7
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 base {
15 class TimeTicks;
18 namespace gfx {
19 class Canvas;
20 class ImageSkia;
21 class Rect;
24 namespace content {
25 class DownloadItem;
26 class DownloadManager;
29 namespace ui {
30 class ThemeProvider;
33 // This is an abstract base class for platform specific download shelf
34 // implementations.
35 class DownloadShelf {
36 public:
37 // Reason for closing download shelf.
38 enum CloseReason {
39 // Closing the shelf automatically. E.g.: all remaining downloads in the
40 // shelf have been opened, last download in shelf was removed, or the
41 // browser is switching to full-screen mode.
42 AUTOMATIC,
44 // Closing shelf due to a user selection. E.g.: the user clicked on the
45 // 'close' button on the download shelf, or the shelf is being closed as a
46 // side-effect of the user opening the downloads page.
47 USER_ACTION
50 // Download progress animations ----------------------------------------------
52 enum {
53 // Progress animation timer period, in milliseconds.
54 kProgressRateMs = 30,
56 // Size of the space used for the progress indicator, including padding.
57 kProgressIndicatorSize = 39,
59 // x/y offset for the file type icon.
60 kFiletypeIconOffset = (kProgressIndicatorSize - 16) / 2
63 DownloadShelf();
64 virtual ~DownloadShelf();
66 // Paint the common download animation progress foreground and background,
67 // clipping the foreground to 'percent' full. If percent is -1, then we don't
68 // know the total size, so we just draw a rotating segment until we're done.
69 // |progress_time| is only used for these unknown size downloads.
70 static void PaintDownloadProgress(gfx::Canvas* canvas,
71 const ui::ThemeProvider& theme_provider,
72 const base::TimeDelta& progress_time,
73 int percent);
75 static void PaintDownloadComplete(gfx::Canvas* canvas,
76 const ui::ThemeProvider& theme_provider,
77 double animation_progress);
79 static void PaintDownloadInterrupted(gfx::Canvas* canvas,
80 const ui::ThemeProvider& theme_provider,
81 double animation_progress);
83 // A new download has started. Add it to our shelf and show the download
84 // started animation.
86 // Some downloads are removed from the shelf on completion (See
87 // DownloadItemModel::ShouldRemoveFromShelfWhenComplete()). These transient
88 // downloads are added to the shelf after a delay. If the download completes
89 // before the delay duration, it will not be added to the shelf at all.
90 void AddDownload(content::DownloadItem* download);
92 // The browser view needs to know when we are going away to properly return
93 // the resize corner size to WebKit so that we don't draw on top of it.
94 // This returns the showing state of our animation which is set to true at
95 // the beginning Show and false at the beginning of a Hide.
96 virtual bool IsShowing() const = 0;
98 // Returns whether the download shelf is showing the close animation.
99 virtual bool IsClosing() const = 0;
101 // Opens the shelf.
102 void Show();
104 // Closes the shelf.
105 void Close(CloseReason reason);
107 // Hides the shelf. This closes the shelf if it is currently showing.
108 void Hide();
110 // Unhides the shelf. This will cause the shelf to be opened if it was open
111 // when it was hidden, or was shown while it was hidden.
112 void Unhide();
114 virtual Browser* browser() const = 0;
116 // Returns whether the download shelf is hidden.
117 bool is_hidden() { return is_hidden_; }
119 protected:
120 virtual void DoAddDownload(content::DownloadItem* download) = 0;
121 virtual void DoShow() = 0;
122 virtual void DoClose(CloseReason reason) = 0;
124 // Time delay to wait before adding a transient download to the shelf.
125 // Protected virtual for testing.
126 virtual base::TimeDelta GetTransientDownloadShowDelay();
128 // Returns the DownloadManager associated with this DownloadShelf. All
129 // downloads that are shown on this shelf is expected to belong to this
130 // DownloadManager. Protected virtual for testing.
131 virtual content::DownloadManager* GetDownloadManager();
133 private:
134 // Show the download on the shelf immediately. Also displayes the download
135 // started animation if necessary.
136 void ShowDownload(content::DownloadItem* download);
138 // Similar to ShowDownload() but refers to the download using an ID. This
139 // download should belong to the DownloadManager returned by
140 // GetDownloadManager().
141 void ShowDownloadById(int32 download_id);
143 bool should_show_on_unhide_;
144 bool is_hidden_;
145 base::WeakPtrFactory<DownloadShelf> weak_ptr_factory_;
148 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_