Home | History | Annotate | Download | only in download
      1 // Copyright (c) 2011 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 #import "base/mac/cocoa_protocols.h"
      8 #include "base/memory/scoped_nsobject.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #import "chrome/browser/ui/cocoa/view_resizer.h"
     11 
     12 @class AnimatableView;
     13 class BaseDownloadItemModel;
     14 class Browser;
     15 @class BrowserWindowController;
     16 @class DownloadItemController;
     17 class DownloadShelf;
     18 @class DownloadShelfView;
     19 @class HyperlinkButtonCell;
     20 @class HoverButton;
     21 
     22 // A controller class that manages the download shelf for one window. It is
     23 // responsible for the behavior of the shelf itself (showing/hiding, handling
     24 // the link, layout) as well as for managing the download items it contains.
     25 //
     26 // All the files in cocoa/downloads_* are related as follows:
     27 //
     28 // download_shelf_mac bridges calls from chromium's c++ world to the objc
     29 // download_shelf_controller for the shelf (this file). The shelf's background
     30 // is drawn by download_shelf_view. Every item in a shelf is controlled by a
     31 // download_item_controller.
     32 //
     33 // download_item_mac bridges calls from chromium's c++ world to the objc
     34 // download_item_controller, which is responsible for managing a single item
     35 // on the shelf. The item controller loads its UI from a xib file, where the
     36 // UI of an item itself is represented by a button that is drawn by
     37 // download_item_cell.
     38 
     39 @interface DownloadShelfController : NSViewController<NSTextViewDelegate> {
     40  @private
     41   IBOutlet HyperlinkButtonCell* showAllDownloadsCell_;
     42 
     43   IBOutlet NSImageView* image_;
     44 
     45   IBOutlet HoverButton* hoverCloseButton_;
     46 
     47   BOOL barIsVisible_;
     48 
     49   BOOL isFullscreen_;
     50 
     51   scoped_ptr<DownloadShelf> bridge_;
     52 
     53   // Height of the shelf when it's fully visible.
     54   CGFloat maxShelfHeight_;
     55 
     56   // Current height of the shelf. Changes while the shelf is animating in or
     57   // out.
     58   CGFloat currentShelfHeight_;
     59 
     60   // Used to autoclose the shelf when the mouse is moved off it.  Is non-nil
     61   // only when a subsequent mouseExited event can trigger autoclose or when a
     62   // subsequent mouseEntered event will cancel autoclose.  Is nil otherwise.
     63   scoped_nsobject<NSTrackingArea> trackingArea_;
     64 
     65   // The download items we have added to our shelf.
     66   scoped_nsobject<NSMutableArray> downloadItemControllers_;
     67 
     68   // The container that contains (and clamps) all the download items.
     69   IBOutlet NSView* itemContainerView_;
     70 
     71   // Delegate that handles resizing our view.
     72   id<ViewResizer> resizeDelegate_;
     73 };
     74 
     75 - (id)initWithBrowser:(Browser*)browser
     76        resizeDelegate:(id<ViewResizer>)resizeDelegate;
     77 
     78 - (IBAction)showDownloadsTab:(id)sender;
     79 
     80 // Returns our view cast as an AnimatableView.
     81 - (AnimatableView*)animatableView;
     82 
     83 - (DownloadShelf*)bridge;
     84 - (BOOL)isVisible;
     85 
     86 - (IBAction)show:(id)sender;
     87 
     88 // Run when the user clicks the close button on the right side of the shelf.
     89 - (IBAction)hide:(id)sender;
     90 
     91 - (void)addDownloadItem:(BaseDownloadItemModel*)model;
     92 
     93 // Remove a download, possibly via clearing browser data.
     94 - (void)remove:(DownloadItemController*)download;
     95 
     96 // Called by individual item controllers when their downloads are opened.
     97 - (void)downloadWasOpened:(DownloadItemController*)download;
     98 
     99 // Notification that we are closing and should release our downloads.
    100 - (void)exiting;
    101 
    102 // Return the height of the download shelf.
    103 - (float)height;
    104 
    105 // Re-layouts all download items based on their current state.
    106 - (void)layoutItems;
    107 
    108 @end
    109