| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_ |
| 6 #define CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_ | 6 #define CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
| 10 #include "chrome/browser/download/download_shelf.h" | 10 #include "chrome/browser/download/download_shelf.h" |
| 11 #include "views/controls/button/button.h" | 11 #include "views/controls/button/button.h" |
| 12 #include "views/controls/link.h" | 12 #include "views/controls/link.h" |
| 13 #include "views/mouse_watcher.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 class ImageButton; | 16 class ImageButton; |
| 16 class ImageView; | 17 class ImageView; |
| 17 } | 18 } |
| 18 | 19 |
| 19 class BaseDownloadItemModel; | 20 class BaseDownloadItemModel; |
| 20 class Browser; | 21 class Browser; |
| 21 class BrowserView; | 22 class BrowserView; |
| 22 | 23 |
| 23 class DownloadAnimation; | 24 class DownloadAnimation; |
| 24 class DownloadItemView; | 25 class DownloadItemView; |
| 25 | 26 |
| 26 // DownloadShelfView is a view that contains individual views for each download, | 27 // DownloadShelfView is a view that contains individual views for each download, |
| 27 // as well as a close button and a link to show all downloads. | 28 // as well as a close button and a link to show all downloads. |
| 28 // | 29 // |
| 29 // DownloadShelfView does not hold an infinite number of download views, rather | 30 // DownloadShelfView does not hold an infinite number of download views, rather |
| 30 // it'll automatically remove views once a certain point is reached. | 31 // it'll automatically remove views once a certain point is reached. |
| 31 class DownloadShelfView : public DownloadShelf, | 32 class DownloadShelfView : public AnimationDelegate, |
| 32 public views::View, | 33 public DownloadShelf, |
| 33 public views::ButtonListener, | 34 public views::ButtonListener, |
| 34 public views::LinkController, | 35 public views::LinkController, |
| 35 public AnimationDelegate { | 36 public views::MouseWatcherListener, |
| 37 public views::View { |
| 36 public: | 38 public: |
| 37 DownloadShelfView(Browser* browser, BrowserView* parent); | 39 DownloadShelfView(Browser* browser, BrowserView* parent); |
| 38 virtual ~DownloadShelfView(); | 40 virtual ~DownloadShelfView(); |
| 39 | 41 |
| 42 // Sent from the DownloadItemView when the user opens an item. |
| 43 void OpenedDownload(DownloadItemView* view); |
| 44 |
| 40 // Implementation of View. | 45 // Implementation of View. |
| 41 virtual gfx::Size GetPreferredSize(); | 46 virtual gfx::Size GetPreferredSize(); |
| 42 virtual void Layout(); | 47 virtual void Layout(); |
| 43 virtual void Paint(gfx::Canvas* canvas); | 48 virtual void Paint(gfx::Canvas* canvas); |
| 44 | 49 |
| 45 // Implementation of AnimationDelegate. | 50 // Implementation of AnimationDelegate. |
| 46 virtual void AnimationProgressed(const Animation* animation); | 51 virtual void AnimationProgressed(const Animation* animation); |
| 47 virtual void AnimationEnded(const Animation* animation); | 52 virtual void AnimationEnded(const Animation* animation); |
| 48 | 53 |
| 49 // Implementation of LinkController. | 54 // Implementation of LinkController. |
| 50 // Invoked when the user clicks the 'show all downloads' link button. | 55 // Invoked when the user clicks the 'show all downloads' link button. |
| 51 virtual void LinkActivated(views::Link* source, int event_flags); | 56 virtual void LinkActivated(views::Link* source, int event_flags); |
| 52 | 57 |
| 53 // Implementation of ButtonListener. | 58 // Implementation of ButtonListener. |
| 54 // Invoked when the user clicks the close button. Asks the browser to | 59 // Invoked when the user clicks the close button. Asks the browser to |
| 55 // hide the download shelf. | 60 // hide the download shelf. |
| 56 virtual void ButtonPressed(views::Button* button, const views::Event& event); | 61 virtual void ButtonPressed(views::Button* button, const views::Event& event); |
| 57 | 62 |
| 58 // Implementation of DownloadShelf. | 63 // Implementation of DownloadShelf. |
| 59 virtual void AddDownload(BaseDownloadItemModel* download_model); | 64 virtual void AddDownload(BaseDownloadItemModel* download_model); |
| 60 virtual bool IsShowing() const; | 65 virtual bool IsShowing() const; |
| 61 virtual bool IsClosing() const; | 66 virtual bool IsClosing() const; |
| 62 virtual void Show(); | 67 virtual void Show(); |
| 63 virtual void Close(); | 68 virtual void Close(); |
| 64 virtual Browser* browser() const { return browser_; } | 69 virtual Browser* browser() const { return browser_; } |
| 65 | 70 |
| 71 // Implementation of MouseWatcherDelegate. |
| 72 virtual void MouseMovedOutOfView(); |
| 73 |
| 66 // Removes a specified download view. The supplied view is deleted after | 74 // Removes a specified download view. The supplied view is deleted after |
| 67 // it's removed. | 75 // it's removed. |
| 68 void RemoveDownloadView(views::View* view); | 76 void RemoveDownloadView(views::View* view); |
| 69 | 77 |
| 70 private: | 78 private: |
| 71 void Init(); | 79 void Init(); |
| 72 | 80 |
| 73 // Adds a View representing a download to this DownloadShelfView. | 81 // Adds a View representing a download to this DownloadShelfView. |
| 74 // DownloadShelfView takes ownership of the View, and will delete it as | 82 // DownloadShelfView takes ownership of the View, and will delete it as |
| 75 // necessary. | 83 // necessary. |
| 76 void AddDownloadView(DownloadItemView* view); | 84 void AddDownloadView(DownloadItemView* view); |
| 77 | 85 |
| 78 // Paints the border. | 86 // Paints the border. |
| 79 void PaintBorder(gfx::Canvas* canvas); | 87 void PaintBorder(gfx::Canvas* canvas); |
| 80 | 88 |
| 81 // Returns true if the shelf is wide enough to show the first download item. | 89 // Returns true if the shelf is wide enough to show the first download item. |
| 82 bool CanFitFirstDownloadItem(); | 90 bool CanFitFirstDownloadItem(); |
| 83 | 91 |
| 84 // Called on theme change. | 92 // Called on theme change. |
| 85 void UpdateButtonColors(); | 93 void UpdateButtonColors(); |
| 86 | 94 |
| 87 // Overridden from views::View. | 95 // Overridden from views::View. |
| 88 virtual void OnThemeChanged(); | 96 virtual void OnThemeChanged(); |
| 89 | 97 |
| 90 // Called when the "close shelf" animation ended. | 98 // Called when the "close shelf" animation ended. |
| 91 void Closed(); | 99 void Closed(); |
| 92 | 100 |
| 101 // Returns true if we can auto close. We can auto-close if all the items on |
| 102 // the shelf have been opened. |
| 103 bool CanAutoClose(); |
| 104 |
| 93 // The browser for this shelf. | 105 // The browser for this shelf. |
| 94 Browser* browser_; | 106 Browser* browser_; |
| 95 | 107 |
| 96 // The animation for adding new items to the shelf. | 108 // The animation for adding new items to the shelf. |
| 97 scoped_ptr<SlideAnimation> new_item_animation_; | 109 scoped_ptr<SlideAnimation> new_item_animation_; |
| 98 | 110 |
| 99 // The show/hide animation for the shelf itself. | 111 // The show/hide animation for the shelf itself. |
| 100 scoped_ptr<SlideAnimation> shelf_animation_; | 112 scoped_ptr<SlideAnimation> shelf_animation_; |
| 101 | 113 |
| 102 // The download views. These are also child Views, and deleted when | 114 // The download views. These are also child Views, and deleted when |
| 103 // the DownloadShelfView is deleted. | 115 // the DownloadShelfView is deleted. |
| 104 std::vector<DownloadItemView*> download_views_; | 116 std::vector<DownloadItemView*> download_views_; |
| 105 | 117 |
| 106 // An image displayed on the right of the "Show all downloads..." link. | 118 // An image displayed on the right of the "Show all downloads..." link. |
| 107 views::ImageView* arrow_image_; | 119 views::ImageView* arrow_image_; |
| 108 | 120 |
| 109 // Link for showing all downloads. This is contained as a child, and deleted | 121 // Link for showing all downloads. This is contained as a child, and deleted |
| 110 // by View. | 122 // by View. |
| 111 views::Link* show_all_view_; | 123 views::Link* show_all_view_; |
| 112 | 124 |
| 113 // Button for closing the downloads. This is contained as a child, and | 125 // Button for closing the downloads. This is contained as a child, and |
| 114 // deleted by View. | 126 // deleted by View. |
| 115 views::ImageButton* close_button_; | 127 views::ImageButton* close_button_; |
| 116 | 128 |
| 117 // The window this shelf belongs to. | 129 // The window this shelf belongs to. |
| 118 BrowserView* parent_; | 130 BrowserView* parent_; |
| 119 | 131 |
| 132 views::MouseWatcher mouse_watcher_; |
| 133 |
| 120 DISALLOW_COPY_AND_ASSIGN(DownloadShelfView); | 134 DISALLOW_COPY_AND_ASSIGN(DownloadShelfView); |
| 121 }; | 135 }; |
| 122 | 136 |
| 123 #endif // CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_ | 137 #endif // CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_ |
| OLD | NEW |