download_shelf_view.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
7
8#include <vector>
9
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"
18
19class Browser;
20class BrowserView;
21class DownloadItemView;
22
23namespace content {
24class DownloadItem;
25class PageNavigator;
26}
27
28namespace gfx {
29class SlideAnimation;
30}
31
32namespace views {
33class ImageButton;
34class ImageView;
35}
36
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.
39//
40// DownloadShelfView does not hold an infinite number of download views, rather
41// it'll automatically remove views once a certain point is reached.
42class 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();
51
52  // Sent from the DownloadItemView when the user opens an item.
53  void OpenedDownload(DownloadItemView* view);
54
55  // Returns the relevant containing object that can load pages.
56  // i.e. the |browser_|.
57  content::PageNavigator* GetNavigator();
58
59  // Implementation of View.
60  virtual gfx::Size GetPreferredSize() OVERRIDE;
61  virtual void Layout() OVERRIDE;
62  virtual void ViewHierarchyChanged(
63      const ViewHierarchyChangedDetails& details) OVERRIDE;
64
65  // Implementation of gfx::AnimationDelegate.
66  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
67  virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
68
69  // Implementation of views::LinkListener.
70  // Invoked when the user clicks the 'show all downloads' link button.
71  virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
72
73  // Implementation of ButtonListener.
74  // Invoked when the user clicks the close button. Asks the browser to
75  // hide the download shelf.
76  virtual void ButtonPressed(views::Button* button,
77                             const ui::Event& event) OVERRIDE;
78
79  // Implementation of DownloadShelf.
80  virtual bool IsShowing() const OVERRIDE;
81  virtual bool IsClosing() const OVERRIDE;
82  virtual Browser* browser() const OVERRIDE;
83
84  // Implementation of MouseWatcherListener OVERRIDE.
85  virtual void MouseMovedOutOfHost() OVERRIDE;
86
87  // Removes a specified download view. The supplied view is deleted after
88  // it's removed.
89  void RemoveDownloadView(views::View* view);
90
91 protected:
92  // Implementation of DownloadShelf.
93  virtual void DoAddDownload(content::DownloadItem* download) OVERRIDE;
94  virtual void DoShow() OVERRIDE;
95  virtual void DoClose(CloseReason reason) OVERRIDE;
96
97  // From AccessiblePaneView
98  virtual views::View* GetDefaultFocusableChild() OVERRIDE;
99
100 private:
101  // Adds a View representing a download to this DownloadShelfView.
102  // DownloadShelfView takes ownership of the View, and will delete it as
103  // necessary.
104  void AddDownloadView(DownloadItemView* view);
105
106  // Paints the border.
107  virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE;
108
109  // Returns true if the shelf is wide enough to show the first download item.
110  bool CanFitFirstDownloadItem();
111
112  // Called on theme change.
113  void UpdateColorsFromTheme();
114
115  // Overridden from views::View.
116  virtual void OnThemeChanged() OVERRIDE;
117
118  // Called when the "close shelf" animation ended.
119  void Closed();
120
121  // Returns true if we can auto close. We can auto-close if all the items on
122  // the shelf have been opened.
123  bool CanAutoClose();
124
125  // The browser for this shelf.
126  Browser* browser_;
127
128  // The animation for adding new items to the shelf.
129  scoped_ptr<gfx::SlideAnimation> new_item_animation_;
130
131  // The show/hide animation for the shelf itself.
132  scoped_ptr<gfx::SlideAnimation> shelf_animation_;
133
134  // The download views. These are also child Views, and deleted when
135  // the DownloadShelfView is deleted.
136  std::vector<DownloadItemView*> download_views_;
137
138  // An image displayed on the right of the "Show all downloads..." link.
139  views::ImageView* arrow_image_;
140
141  // Link for showing all downloads. This is contained as a child, and deleted
142  // by View.
143  views::Link* show_all_view_;
144
145  // Button for closing the downloads. This is contained as a child, and
146  // deleted by View.
147  views::ImageButton* close_button_;
148
149  // The window this shelf belongs to.
150  BrowserView* parent_;
151
152  views::MouseWatcher mouse_watcher_;
153
154  DISALLOW_COPY_AND_ASSIGN(DownloadShelfView);
155};
156
157#endif  // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
158