15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/download_shelf.h" 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/animation_delegate.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/accessible_pane_view.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/button/button.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/link_listener.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/mouse_watcher.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserView; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DownloadItemView; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DownloadItem; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageNavigator; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace gfx { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SlideAnimation; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImageButton; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImageView; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DownloadShelfView is a view that contains individual views for each download, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// as well as a close button and a link to show all downloads. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DownloadShelfView does not hold an infinite number of download views, rather 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// it'll automatically remove views once a certain point is reached. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DownloadShelfView : public views::AccessiblePaneView, 43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public gfx::AnimationDelegate, 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public DownloadShelf, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::ButtonListener, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::LinkListener, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::MouseWatcherListener { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadShelfView(Browser* browser, BrowserView* parent); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DownloadShelfView(); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sent from the DownloadItemView when the user opens an item. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OpenedDownload(DownloadItemView* view); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the relevant containing object that can load pages. 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // i.e. the |browser_|. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PageNavigator* GetNavigator(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns the parent_. 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BrowserView* get_parent() { return parent_; } 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of View. 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Layout() OVERRIDE; 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void ViewHierarchyChanged( 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const ViewHierarchyChangedDetails& details) OVERRIDE; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Implementation of gfx::AnimationDelegate. 69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of views::LinkListener. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the user clicks the 'show all downloads' link button. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of ButtonListener. 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the user clicks the close button. Asks the browser to 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // hide the download shelf. 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ButtonPressed(views::Button* button, 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ui::Event& event) OVERRIDE; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of DownloadShelf. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsShowing() const OVERRIDE; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsClosing() const OVERRIDE; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual Browser* browser() const OVERRIDE; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of MouseWatcherListener OVERRIDE. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void MouseMovedOutOfHost() OVERRIDE; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes a specified download view. The supplied view is deleted after 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it's removed. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveDownloadView(views::View* view); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of DownloadShelf. 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DoAddDownload(content::DownloadItem* download) OVERRIDE; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DoShow() OVERRIDE; 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void DoClose(CloseReason reason) OVERRIDE; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // From AccessiblePaneView 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual views::View* GetDefaultFocusableChild() OVERRIDE; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds a View representing a download to this DownloadShelfView. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // DownloadShelfView takes ownership of the View, and will delete it as 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // necessary. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddDownloadView(DownloadItemView* view); 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Paints the border. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the shelf is wide enough to show the first download item. 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanFitFirstDownloadItem(); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called on theme change. 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateColorsFromTheme(); 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::View. 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnThemeChanged() OVERRIDE; 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the "close shelf" animation ended. 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Closed(); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if we can auto close. We can auto-close if all the items on 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the shelf have been opened. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanAutoClose(); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The browser for this shelf. 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Browser* browser_; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The animation for adding new items to the shelf. 132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scoped_ptr<gfx::SlideAnimation> new_item_animation_; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The show/hide animation for the shelf itself. 135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scoped_ptr<gfx::SlideAnimation> shelf_animation_; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The download views. These are also child Views, and deleted when 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the DownloadShelfView is deleted. 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<DownloadItemView*> download_views_; 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // An image displayed on the right of the "Show all downloads..." link. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::ImageView* arrow_image_; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Link for showing all downloads. This is contained as a child, and deleted 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by View. 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::Link* show_all_view_; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Button for closing the downloads. This is contained as a child, and 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // deleted by View. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::ImageButton* close_button_; 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The window this shelf belongs to. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserView* parent_; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::MouseWatcher mouse_watcher_; 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DownloadShelfView); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_ 161