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_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/download/download_shelf.h"
13 #include "ui/gfx/animation/animation_delegate.h"
14 #include "ui/views/accessible_pane_view.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/controls/link_listener.h"
17 #include "ui/views/mouse_watcher.h"
21 class DownloadItemView
;
37 // DownloadShelfView is a view that contains individual views for each download,
38 // as well as a close button and a link to show all downloads.
40 // DownloadShelfView does not hold an infinite number of download views, rather
41 // it'll automatically remove views once a certain point is reached.
42 class DownloadShelfView
: public views::AccessiblePaneView
,
43 public gfx::AnimationDelegate
,
45 public views::ButtonListener
,
46 public views::LinkListener
,
47 public views::MouseWatcherListener
{
49 DownloadShelfView(Browser
* browser
, BrowserView
* parent
);
50 ~DownloadShelfView() override
;
52 // Sent from the DownloadItemView when the user opens an item.
53 void OpenedDownload(DownloadItemView
* view
);
55 // Returns the relevant containing object that can load pages.
56 // i.e. the |browser_|.
57 content::PageNavigator
* GetNavigator();
59 // Returns the parent_.
60 BrowserView
* get_parent() { return parent_
; }
62 // Implementation of View.
63 gfx::Size
GetPreferredSize() const override
;
64 void Layout() override
;
65 void ViewHierarchyChanged(
66 const ViewHierarchyChangedDetails
& details
) override
;
68 // Implementation of gfx::AnimationDelegate.
69 void AnimationProgressed(const gfx::Animation
* animation
) override
;
70 void AnimationEnded(const gfx::Animation
* animation
) override
;
72 // Implementation of views::LinkListener.
73 // Invoked when the user clicks the 'show all downloads' link button.
74 void LinkClicked(views::Link
* source
, int event_flags
) override
;
76 // Implementation of ButtonListener.
77 // Invoked when the user clicks the close button. Asks the browser to
78 // hide the download shelf.
79 void ButtonPressed(views::Button
* button
, const ui::Event
& event
) override
;
81 // Implementation of DownloadShelf.
82 bool IsShowing() const override
;
83 bool IsClosing() const override
;
84 Browser
* browser() const override
;
86 // Implementation of MouseWatcherListener override.
87 void MouseMovedOutOfHost() override
;
89 // Removes a specified download view. The supplied view is deleted after
91 void RemoveDownloadView(views::View
* view
);
94 // Implementation of DownloadShelf.
95 void DoAddDownload(content::DownloadItem
* download
) override
;
96 void DoShow() override
;
97 void DoClose(CloseReason reason
) override
;
99 // From AccessiblePaneView
100 views::View
* GetDefaultFocusableChild() override
;
103 // Adds a View representing a download to this DownloadShelfView.
104 // DownloadShelfView takes ownership of the View, and will delete it as
106 void AddDownloadView(DownloadItemView
* view
);
108 // Paints the border.
109 void OnPaintBorder(gfx::Canvas
* canvas
) override
;
111 // Returns true if the shelf is wide enough to show the first download item.
112 bool CanFitFirstDownloadItem();
114 // Called on theme change.
115 void UpdateColorsFromTheme();
117 // Overridden from views::View.
118 void OnThemeChanged() override
;
120 // Called when the "close shelf" animation ended.
123 // Returns true if we can auto close. We can auto-close if all the items on
124 // the shelf have been opened.
127 // The browser for this shelf.
130 // The animation for adding new items to the shelf.
131 scoped_ptr
<gfx::SlideAnimation
> new_item_animation_
;
133 // The show/hide animation for the shelf itself.
134 scoped_ptr
<gfx::SlideAnimation
> shelf_animation_
;
136 // The download views. These are also child Views, and deleted when
137 // the DownloadShelfView is deleted.
138 std::vector
<DownloadItemView
*> download_views_
;
140 // An image displayed on the right of the "Show all downloads..." link.
141 views::ImageView
* arrow_image_
;
143 // Link for showing all downloads. This is contained as a child, and deleted
145 views::Link
* show_all_view_
;
147 // Button for closing the downloads. This is contained as a child, and
149 views::ImageButton
* close_button_
;
151 // The window this shelf belongs to.
152 BrowserView
* parent_
;
154 views::MouseWatcher mouse_watcher_
;
156 DISALLOW_COPY_AND_ASSIGN(DownloadShelfView
);
159 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_