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