Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / download / download_shelf_controller.h
blob13e2a710371ff1d7d3f1bd80e752886c6c68b4b7
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/mac/scoped_nsobject.h"
8 #include "base/memory/scoped_ptr.h"
9 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
10 #import "chrome/browser/ui/cocoa/view_resizer.h"
11 #include "ui/base/cocoa/tracking_area.h"
13 @class AnimatableView;
14 class Browser;
15 @class BrowserWindowController;
16 @class DownloadItemController;
17 class DownloadShelf;
18 @class DownloadShelfView;
19 @class HyperlinkButtonCell;
20 @class HoverButton;
22 namespace content {
23 class DownloadItem;
24 class PageNavigator;
27 // A controller class that manages the download shelf for one window. It is
28 // responsible for the behavior of the shelf itself (showing/hiding, handling
29 // the link, layout) as well as for managing the download items it contains.
31 // All the files in cocoa/downloads_* are related as follows:
33 // download_shelf_mac bridges calls from chromium's c++ world to the objc
34 // download_shelf_controller for the shelf (this file). The shelf's background
35 // is drawn by download_shelf_view. Every item in a shelf is controlled by a
36 // download_item_controller.
38 // download_item_mac bridges calls from chromium's c++ world to the objc
39 // download_item_controller, which is responsible for managing a single item
40 // on the shelf. The item controller loads its UI from a xib file, where the
41 // UI of an item itself is represented by a button that is drawn by
42 // download_item_cell.
44 @interface DownloadShelfController
45 : NSViewController<NSTextViewDelegate, HasWeakBrowserPointer> {
46 @private
47 IBOutlet HoverButton* hoverCloseButton_;
49 // YES if the download shelf is intended to be displayed. The shelf animates
50 // out when it is closing. During this time, barIsVisible_ is NO although the
51 // shelf is still visible on screen.
52 BOOL barIsVisible_;
54 // YES if the containing browser window is fullscreen.
55 BOOL isFullscreen_;
57 // YES if the shelf should be closed when the mouse leaves the shelf.
58 BOOL shouldCloseOnMouseExit_;
60 // YES if the mouse is currently over the download shelf.
61 BOOL isMouseInsideView_;
63 scoped_ptr<DownloadShelf> bridge_;
65 // Height of the shelf when it's fully visible.
66 CGFloat maxShelfHeight_;
68 // Current height of the shelf. Changes while the shelf is animating in or
69 // out.
70 CGFloat currentShelfHeight_;
72 // Used to autoclose the shelf when the mouse is moved off it.
73 ui::ScopedCrTrackingArea trackingArea_;
75 // The download items we have added to our shelf.
76 base::scoped_nsobject<NSMutableArray> downloadItemControllers_;
78 // The container that contains (and clamps) all the download items.
79 IBOutlet NSView* itemContainerView_;
81 // Delegate that handles resizing our view.
82 id<ViewResizer> resizeDelegate_;
84 // Used for loading pages.
85 content::PageNavigator* navigator_;
88 - (id)initWithBrowser:(Browser*)browser
89 resizeDelegate:(id<ViewResizer>)resizeDelegate;
91 // Run when the user clicks the 'Show All' button.
92 - (IBAction)showDownloadsTab:(id)sender;
94 // Run when the user clicks the close button on the right side of the shelf.
95 - (IBAction)handleClose:(id)sender;
97 // Shows or hides the download shelf based on the value of |show|.
98 // |isUserAction| should be YES if the operation is being triggered based on a
99 // user action (currently only relevant when hiding the shelf).
100 // Note: This is intended to be invoked from DownloadShelfMac. If invoked
101 // directly, the shelf visibility state maintained by DownloadShelf and the
102 // owning Browser will not be updated.
103 - (void)showDownloadShelf:(BOOL)show
104 isUserAction:(BOOL)isUserAction;
106 // Returns our view cast as an AnimatableView.
107 - (AnimatableView*)animatableView;
109 - (DownloadShelf*)bridge;
110 - (BOOL)isVisible;
112 // Add a new download item to the leftmost position of the download shelf. The
113 // item should not have been already added to this shelf.
114 - (void)addDownloadItem:(content::DownloadItem*)downloadItem;
116 // Similar to addDownloadItem above, but adds a DownloadItemController.
117 - (void)add:(DownloadItemController*)download;
119 // Remove a download, possibly via clearing browser data.
120 - (void)remove:(DownloadItemController*)download;
122 // Called by individual item controllers when their downloads are opened.
123 - (void)downloadWasOpened:(DownloadItemController*)download;
125 // Return the height of the download shelf.
126 - (float)height;
128 // Re-layouts all download items based on their current state.
129 - (void)layoutItems;
131 @end