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.
5 #import <Cocoa/Cocoa.h>
7 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h"
10 @class ChromeUILocalizer;
11 @class DownloadItemCell;
12 @class DownloadItemButton;
13 class DownloadItemMac;
14 class DownloadItemModel;
15 class DownloadShelfContextMenuMac;
16 @class DownloadShelfController;
17 @class GTMWidthBasedTweaker;
32 // A controller class that manages one download item.
34 @interface DownloadItemController : NSViewController {
36 IBOutlet DownloadItemButton* progressView_;
37 IBOutlet DownloadItemCell* cell_;
39 // This is shown instead of progressView_ for dangerous downloads.
40 IBOutlet NSView* dangerousDownloadView_;
41 IBOutlet NSTextField* dangerousDownloadLabel_;
42 IBOutlet NSButton* dangerousDownloadConfirmButton_;
44 // Needed to find out how much the tweaker changed sizes to update the
46 IBOutlet GTMWidthBasedTweaker* buttonTweaker_;
48 // Because the confirm text and button for dangerous downloads are determined
49 // at runtime, an outlet to the localizer is needed to construct the layout
50 // tweaker in awakeFromNib in order to adjust the UI after all strings are
52 IBOutlet ChromeUILocalizer* localizer_;
54 IBOutlet NSImageView* image_;
56 scoped_ptr<DownloadItemMac> bridge_;
57 scoped_ptr<DownloadShelfContextMenuMac> menuBridge_;
59 // Weak pointer to the shelf that owns us.
60 DownloadShelfController* shelf_;
62 // The time at which this view was created.
63 base::Time creationTime_;
65 // Default font list to use for text metrics.
66 scoped_ptr<gfx::FontList> font_list_;
68 // The state of this item.
69 enum DownoadItemState {
75 // Initialize controller for |downloadItem|.
76 - (id)initWithDownload:(content::DownloadItem*)downloadItem
77 shelf:(DownloadShelfController*)shelf
78 navigator:(content::PageNavigator*)navigator;
80 // Updates the UI and menu state from |downloadModel|.
81 - (void)setStateFromDownload:(DownloadItemModel*)downloadModel;
83 // Remove ourself from the download UI.
86 // Update item's visibility depending on if the item is still completely
87 // contained in its parent.
88 - (void)updateVisibility:(id)sender;
90 // Called after a download is opened.
91 - (void)downloadWasOpened;
93 // Asynchronous icon loading callback.
94 - (void)setIcon:(NSImage*)icon;
96 // Download item button clicked
97 - (IBAction)handleButtonClick:(id)sender;
99 // Returns the size this item wants to have.
100 - (NSSize)preferredSize;
102 // Returns the DownloadItem model object belonging to this item.
103 - (content::DownloadItem*)download;
105 // Returns the MenuModel for the download item context menu. The returned
106 // MenuModel is owned by the DownloadItemController and will be valid until the
107 // DownloadItemController is destroyed.
108 - (ui::MenuModel*)contextMenuModel;
110 // Updates the tooltip with the download's path.
111 - (void)updateToolTip;
113 // Handling of dangerous downloads
114 - (void)clearDangerousMode;
115 - (BOOL)isDangerousMode;
116 - (IBAction)saveDownload:(id)sender;
117 - (IBAction)discardDownload:(id)sender;