[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / download / download_shelf_view.h
blob8f4f22e0402e9f13a4ff61c7ba8d76016ef9ce45
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_
8 #include <vector>
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"
19 class Browser;
20 class BrowserView;
21 class DownloadItemView;
23 namespace content {
24 class DownloadItem;
25 class PageNavigator;
28 namespace gfx {
29 class SlideAnimation;
32 namespace views {
33 class ImageButton;
34 class ImageView;
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,
44 public DownloadShelf,
45 public views::ButtonListener,
46 public views::LinkListener,
47 public views::MouseWatcherListener {
48 public:
49 DownloadShelfView(Browser* browser, BrowserView* parent);
50 virtual ~DownloadShelfView();
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 virtual gfx::Size GetPreferredSize() const OVERRIDE;
64 virtual void Layout() OVERRIDE;
65 virtual void ViewHierarchyChanged(
66 const ViewHierarchyChangedDetails& details) OVERRIDE;
68 // Implementation of gfx::AnimationDelegate.
69 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
70 virtual 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 virtual 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 virtual void ButtonPressed(views::Button* button,
80 const ui::Event& event) OVERRIDE;
82 // Implementation of DownloadShelf.
83 virtual bool IsShowing() const OVERRIDE;
84 virtual bool IsClosing() const OVERRIDE;
85 virtual Browser* browser() const OVERRIDE;
87 // Implementation of MouseWatcherListener OVERRIDE.
88 virtual void MouseMovedOutOfHost() OVERRIDE;
90 // Removes a specified download view. The supplied view is deleted after
91 // it's removed.
92 void RemoveDownloadView(views::View* view);
94 protected:
95 // Implementation of DownloadShelf.
96 virtual void DoAddDownload(content::DownloadItem* download) OVERRIDE;
97 virtual void DoShow() OVERRIDE;
98 virtual void DoClose(CloseReason reason) OVERRIDE;
100 // From AccessiblePaneView
101 virtual views::View* GetDefaultFocusableChild() OVERRIDE;
103 private:
104 // Adds a View representing a download to this DownloadShelfView.
105 // DownloadShelfView takes ownership of the View, and will delete it as
106 // necessary.
107 void AddDownloadView(DownloadItemView* view);
109 // Paints the border.
110 virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE;
112 // Returns true if the shelf is wide enough to show the first download item.
113 bool CanFitFirstDownloadItem();
115 // Called on theme change.
116 void UpdateColorsFromTheme();
118 // Overridden from views::View.
119 virtual void OnThemeChanged() OVERRIDE;
121 // Called when the "close shelf" animation ended.
122 void Closed();
124 // Returns true if we can auto close. We can auto-close if all the items on
125 // the shelf have been opened.
126 bool CanAutoClose();
128 // The browser for this shelf.
129 Browser* browser_;
131 // The animation for adding new items to the shelf.
132 scoped_ptr<gfx::SlideAnimation> new_item_animation_;
134 // The show/hide animation for the shelf itself.
135 scoped_ptr<gfx::SlideAnimation> shelf_animation_;
137 // The download views. These are also child Views, and deleted when
138 // the DownloadShelfView is deleted.
139 std::vector<DownloadItemView*> download_views_;
141 // An image displayed on the right of the "Show all downloads..." link.
142 views::ImageView* arrow_image_;
144 // Link for showing all downloads. This is contained as a child, and deleted
145 // by View.
146 views::Link* show_all_view_;
148 // Button for closing the downloads. This is contained as a child, and
149 // deleted by View.
150 views::ImageButton* close_button_;
152 // The window this shelf belongs to.
153 BrowserView* parent_;
155 views::MouseWatcher mouse_watcher_;
157 DISALLOW_COPY_AND_ASSIGN(DownloadShelfView);
160 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_