• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #pragma once
8 
9 #include "chrome/browser/download/download_shelf.h"
10 #include "chrome/browser/ui/views/accessible_pane_view.h"
11 #include "ui/base/animation/animation_delegate.h"
12 #include "views/controls/button/button.h"
13 #include "views/controls/link.h"
14 #include "views/mouse_watcher.h"
15 
16 class BaseDownloadItemModel;
17 class Browser;
18 class BrowserView;
19 class DownloadAnimation;
20 class DownloadItemView;
21 
22 namespace ui {
23 class SlideAnimation;
24 }
25 
26 namespace views {
27 class ImageButton;
28 class ImageView;
29 }
30 
31 // DownloadShelfView is a view that contains individual views for each download,
32 // as well as a close button and a link to show all downloads.
33 //
34 // DownloadShelfView does not hold an infinite number of download views, rather
35 // it'll automatically remove views once a certain point is reached.
36 class DownloadShelfView : public AccessiblePaneView,
37                           public ui::AnimationDelegate,
38                           public DownloadShelf,
39                           public views::ButtonListener,
40                           public views::LinkController,
41                           public views::MouseWatcherListener {
42  public:
43   DownloadShelfView(Browser* browser, BrowserView* parent);
44   virtual ~DownloadShelfView();
45 
46   // Sent from the DownloadItemView when the user opens an item.
47   void OpenedDownload(DownloadItemView* view);
48 
49   // Implementation of View.
50   virtual gfx::Size GetPreferredSize();
51   virtual void Layout();
52   virtual void OnPaint(gfx::Canvas* canvas);
53 
54   // Implementation of ui::AnimationDelegate.
55   virtual void AnimationProgressed(const ui::Animation* animation);
56   virtual void AnimationEnded(const ui::Animation* animation);
57 
58   // Implementation of LinkController.
59   // Invoked when the user clicks the 'show all downloads' link button.
60   virtual void LinkActivated(views::Link* source, int event_flags);
61 
62   // Implementation of ButtonListener.
63   // Invoked when the user clicks the close button. Asks the browser to
64   // hide the download shelf.
65   virtual void ButtonPressed(views::Button* button, const views::Event& event);
66 
67   // Implementation of DownloadShelf.
68   virtual void AddDownload(BaseDownloadItemModel* download_model);
69   virtual bool IsShowing() const;
70   virtual bool IsClosing() const;
71   virtual void Show();
72   virtual void Close();
73   virtual Browser* browser() const;
74 
75   // Implementation of MouseWatcherDelegate.
76   virtual void MouseMovedOutOfView();
77 
78   // Override views::FocusChangeListener method from AccessiblePaneView.
79   virtual void FocusWillChange(View* focused_before,
80                                View* focused_now);
81 
82   // Removes a specified download view. The supplied view is deleted after
83   // it's removed.
84   void RemoveDownloadView(views::View* view);
85 
86  protected:
87   // From AccessiblePaneView
88   virtual views::View* GetDefaultFocusableChild();
89 
90  private:
91   void Init();
92 
93   // Adds a View representing a download to this DownloadShelfView.
94   // DownloadShelfView takes ownership of the View, and will delete it as
95   // necessary.
96   void AddDownloadView(DownloadItemView* view);
97 
98   // Paints the border.
99   virtual void OnPaintBorder(gfx::Canvas* canvas);
100 
101   // Returns true if the shelf is wide enough to show the first download item.
102   bool CanFitFirstDownloadItem();
103 
104   // Called on theme change.
105   void UpdateButtonColors();
106 
107   // Overridden from views::View.
108   virtual void OnThemeChanged();
109 
110   // Called when the "close shelf" animation ended.
111   void Closed();
112 
113   // Returns true if we can auto close. We can auto-close if all the items on
114   // the shelf have been opened.
115   bool CanAutoClose();
116 
117   // Called when any view |view| gains or loses focus. If it's one of our
118   // DownloadItemView children, call SchedulePaint on its bounds
119   // so that its focus rect is repainted.
120   void SchedulePaintForDownloadItem(views::View* view);
121 
122   // Get the rect that perfectly surrounds a DownloadItemView so we can
123   // draw a focus rect around it.
124   gfx::Rect GetFocusRectBounds(const DownloadItemView* download_item_view);
125 
126   // The browser for this shelf.
127   Browser* browser_;
128 
129   // The animation for adding new items to the shelf.
130   scoped_ptr<ui::SlideAnimation> new_item_animation_;
131 
132   // The show/hide animation for the shelf itself.
133   scoped_ptr<ui::SlideAnimation> shelf_animation_;
134 
135   // The download views. These are also child Views, and deleted when
136   // the DownloadShelfView is deleted.
137   std::vector<DownloadItemView*> download_views_;
138 
139   // An image displayed on the right of the "Show all downloads..." link.
140   views::ImageView* arrow_image_;
141 
142   // Link for showing all downloads. This is contained as a child, and deleted
143   // by View.
144   views::Link* show_all_view_;
145 
146   // Button for closing the downloads. This is contained as a child, and
147   // deleted by View.
148   views::ImageButton* close_button_;
149 
150   // The window this shelf belongs to.
151   BrowserView* parent_;
152 
153   views::MouseWatcher mouse_watcher_;
154 
155   DISALLOW_COPY_AND_ASSIGN(DownloadShelfView);
156 };
157 
158 #endif  // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
159