• 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_DOWNLOAD_DOWNLOAD_SHELF_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/string16.h"
12 #include "ui/base/models/simple_menu_model.h"
13 
14 class BaseDownloadItemModel;
15 class Browser;
16 class DownloadItem;
17 
18 // DownloadShelf is an interface for platform-specific download shelf views.
19 class DownloadShelf {
20  public:
~DownloadShelf()21   virtual ~DownloadShelf() {}
22 
23   // A new download has started, so add it to our shelf. This object will
24   // take ownership of |download_model|. Also make the shelf visible.
25   virtual void AddDownload(BaseDownloadItemModel* download_model) = 0;
26 
27   // The browser view needs to know when we are going away to properly return
28   // the resize corner size to WebKit so that we don't draw on top of it.
29   // This returns the showing state of our animation which is set to true at
30   // the beginning Show and false at the beginning of a Hide.
31   virtual bool IsShowing() const = 0;
32 
33   // Returns whether the download shelf is showing the close animation.
34   virtual bool IsClosing() const = 0;
35 
36   // Opens the shelf.
37   virtual void Show() = 0;
38 
39   // Closes the shelf.
40   virtual void Close() = 0;
41 
42   virtual Browser* browser() const = 0;
43 };
44 
45 // Logic for the download shelf context menu. Platform specific subclasses are
46 // responsible for creating and running the menu.
47 class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate {
48  public:
49   virtual ~DownloadShelfContextMenu();
50 
51   virtual DownloadItem* download() const;
52 
53   enum ContextMenuCommands {
54     SHOW_IN_FOLDER = 1,  // Open a file explorer window with the item selected.
55     OPEN_WHEN_COMPLETE,  // Open the download when it's finished.
56     ALWAYS_OPEN_TYPE,    // Default this file extension to always open.
57     CANCEL,              // Cancel the download.
58     TOGGLE_PAUSE,        // Temporarily pause a download.
59     MENU_LAST
60   };
61 
62  protected:
63   explicit DownloadShelfContextMenu(BaseDownloadItemModel* download_model);
64 
65   ui::SimpleMenuModel* GetInProgressMenuModel();
66   ui::SimpleMenuModel* GetFinishedMenuModel();
67   // Information source.
68   DownloadItem* download_;
69 
70   // ui::SimpleMenuModel::Delegate implementation:
71   virtual bool IsCommandIdEnabled(int command_id) const;
72   virtual bool IsCommandIdChecked(int command_id) const;
73   virtual void ExecuteCommand(int command_id);
74   virtual bool GetAcceleratorForCommandId(int command_id,
75                                           ui::Accelerator* accelerator);
76   virtual bool IsItemForCommandIdDynamic(int command_id) const;
77   virtual string16 GetLabelForCommandId(int command_id) const;
78 
79   // A model to control the cancel behavior.
80   BaseDownloadItemModel* model_;
81 
82  private:
83   // We show slightly different menus if the download is in progress vs. if the
84   // download has finished.
85   scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_;
86   scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_;
87 
88   DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu);
89 };
90 
91 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_
92