- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / download / download_item_controller.h
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.
4
5 #import <Cocoa/Cocoa.h>
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h"
9
10 @class ChromeUILocalizer;
11 @class DownloadItemCell;
12 @class DownloadItemButton;
13 class DownloadItemMac;
14 class DownloadItemModel;
15 class DownloadShelfContextMenuMac;
16 @class DownloadShelfController;
17 @class GTMWidthBasedTweaker;
18
19 namespace content {
20 class DownloadItem;
21 class PageNavigator;
22 }
23
24 namespace gfx {
25 class FontList;
26 }
27
28 namespace ui {
29 class MenuModel;
30 }
31
32 // A controller class that manages one download item.
33
34 @interface DownloadItemController : NSViewController {
35  @private
36   IBOutlet DownloadItemButton* progressView_;
37   IBOutlet DownloadItemCell* cell_;
38
39   // This is shown instead of progressView_ for dangerous downloads.
40   IBOutlet NSView* dangerousDownloadView_;
41   IBOutlet NSTextField* dangerousDownloadLabel_;
42   IBOutlet NSButton* dangerousDownloadConfirmButton_;
43
44   // Needed to find out how much the tweaker changed sizes to update the
45   // other views.
46   IBOutlet GTMWidthBasedTweaker* buttonTweaker_;
47
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
51   // determined.
52   IBOutlet ChromeUILocalizer* localizer_;
53
54   IBOutlet NSImageView* image_;
55
56   scoped_ptr<DownloadItemMac> bridge_;
57   scoped_ptr<DownloadShelfContextMenuMac> menuBridge_;
58
59   // Weak pointer to the shelf that owns us.
60   DownloadShelfController* shelf_;
61
62   // The time at which this view was created.
63   base::Time creationTime_;
64
65   // Default font list to use for text metrics.
66   scoped_ptr<gfx::FontList> font_list_;
67
68   // The state of this item.
69   enum DownoadItemState {
70     kNormal,
71     kDangerous
72   } state_;
73 };
74
75 // Initialize controller for |downloadItem|.
76 - (id)initWithDownload:(content::DownloadItem*)downloadItem
77                  shelf:(DownloadShelfController*)shelf
78              navigator:(content::PageNavigator*)navigator;
79
80 // Updates the UI and menu state from |downloadModel|.
81 - (void)setStateFromDownload:(DownloadItemModel*)downloadModel;
82
83 // Remove ourself from the download UI.
84 - (void)remove;
85
86 // Update item's visibility depending on if the item is still completely
87 // contained in its parent.
88 - (void)updateVisibility:(id)sender;
89
90 // Called after a download is opened.
91 - (void)downloadWasOpened;
92
93 // Asynchronous icon loading callback.
94 - (void)setIcon:(NSImage*)icon;
95
96 // Download item button clicked
97 - (IBAction)handleButtonClick:(id)sender;
98
99 // Returns the size this item wants to have.
100 - (NSSize)preferredSize;
101
102 // Returns the DownloadItem model object belonging to this item.
103 - (content::DownloadItem*)download;
104
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;
109
110 // Updates the tooltip with the download's path.
111 - (void)updateToolTip;
112
113 // Handling of dangerous downloads
114 - (void)clearDangerousMode;
115 - (BOOL)isDangerousMode;
116 - (IBAction)saveDownload:(id)sender;
117 - (IBAction)discardDownload:(id)sender;
118
119 @end