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 tweakers changed sizes to update the other
46 IBOutlet GTMWidthBasedTweaker
* dangerousButtonTweaker_
;
47 IBOutlet GTMWidthBasedTweaker
* maliciousButtonTweaker_
;
49 // Because the confirm text and button for dangerous downloads are determined
50 // at runtime, an outlet to the localizer is needed to construct the layout
51 // tweaker in awakeFromNib in order to adjust the UI after all strings are
53 IBOutlet ChromeUILocalizer
* localizer_
;
55 IBOutlet NSImageView
* image_
;
57 scoped_ptr
<DownloadItemMac
> bridge_
;
58 scoped_ptr
<DownloadShelfContextMenuMac
> menuBridge_
;
60 // Weak pointer to the shelf that owns us.
61 DownloadShelfController
* shelf_
;
63 // The time at which this view was created.
64 base::Time creationTime_
;
66 // Default font list to use for text metrics.
67 scoped_ptr
<gfx::FontList
> font_list_
;
69 // The state of this item.
70 enum DownoadItemState
{
76 // Initialize controller for |downloadItem|.
77 - (id
)initWithDownload
:(content::DownloadItem
*)downloadItem
78 shelf
:(DownloadShelfController
*)shelf
79 navigator
:(content::PageNavigator
*)navigator
;
81 // Updates the UI and menu state from |downloadModel|.
82 - (void)setStateFromDownload
:(DownloadItemModel
*)downloadModel
;
84 // Remove ourself from the download UI.
87 // Update item's visibility depending on if the item is still completely
88 // contained in its parent.
89 - (void)updateVisibility
:(id
)sender
;
91 // Called after a download is opened.
92 - (void)downloadWasOpened
;
94 // Asynchronous icon loading callback.
95 - (void)setIcon
:(NSImage
*)icon
;
97 // Download item button clicked
98 - (IBAction
)handleButtonClick
:(id
)sender
;
100 // Returns the size this item wants to have.
101 - (NSSize
)preferredSize
;
103 // Returns the DownloadItem model object belonging to this item.
104 - (content::DownloadItem
*)download
;
106 // Returns the MenuModel for the download item context menu. The returned
107 // MenuModel is owned by the DownloadItemController and will be valid until the
108 // DownloadItemController is destroyed.
109 - (ui::MenuModel
*)contextMenuModel
;
111 // Updates the tooltip with the download's path.
112 - (void)updateToolTip
;
114 // Handling of dangerous downloads
115 - (void)clearDangerousMode
;
116 - (BOOL
)isDangerousMode
;
117 - (IBAction
)saveDownload
:(id
)sender
;
118 - (IBAction
)discardDownload
:(id
)sender
;
119 - (IBAction
)dismissMaliciousDownload
:(id
)sender
;
120 - (IBAction
)showContextMenu
:(id
)sender
;