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"
26 class DownloadManager
;
33 // This is an abstract base class for platform specific download shelf
37 // Reason for closing download shelf.
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.
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.
50 // Download progress animations ----------------------------------------------
53 // Progress animation timer period, in milliseconds.
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
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
,
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
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;
105 void Close(CloseReason reason
);
107 // Hides the shelf. This closes the shelf if it is currently showing.
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.
114 virtual Browser
* browser() const = 0;
116 // Returns whether the download shelf is hidden.
117 bool is_hidden() { return is_hidden_
; }
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();
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_
;
145 base::WeakPtrFactory
<DownloadShelf
> weak_ptr_factory_
;
148 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_