summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/download_shelf_controller.mm
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-18 21:57:57 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-18 21:57:57 +0000
commitc0d33cd059a742b2daf283965392700328b80a81 (patch)
treee28615904b0e6496c55802016f8c7c2e27d9ff52 /chrome/browser/cocoa/download_shelf_controller.mm
parentfad9ef5cb3f55eba164ff4e63db803c5a7fa17a5 (diff)
downloadchromium_src-c0d33cd059a742b2daf283965392700328b80a81.zip
chromium_src-c0d33cd059a742b2daf283965392700328b80a81.tar.gz
chromium_src-c0d33cd059a742b2daf283965392700328b80a81.tar.bz2
Initial download shelf on OS X.
This has lots of missing stuff (e.g. a custom download item view that shows download progress, the popup is the same for in-progress and completed downloads, no animation, everything looks ugly, the info bubble overlaps the shelf when it's visible, no "open download manager page" link, etc), but the basic functionality is hooked up: The shelf appears when files are downloaded, and something ugly is added to the shelf for each download. The popup's "Reveral in Finder" even works. The shelf is per-window as it should be. BUG=12500 TEST=Download something and check the shelf appears. Click the close button and make sure it disappears again. Review URL: http://codereview.chromium.org/93129 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/download_shelf_controller.mm')
-rw-r--r--chrome/browser/cocoa/download_shelf_controller.mm114
1 files changed, 114 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/download_shelf_controller.mm b/chrome/browser/cocoa/download_shelf_controller.mm
new file mode 100644
index 0000000..b82f67f
--- /dev/null
+++ b/chrome/browser/cocoa/download_shelf_controller.mm
@@ -0,0 +1,114 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "download_shelf_controller.h"
+
+#include "base/mac_util.h"
+#import "chrome/browser/cocoa/browser_window_controller.h"
+#include "chrome/browser/cocoa/browser_window_cocoa.h"
+#include "chrome/browser/cocoa/download_shelf_mac.h"
+#import "chrome/browser/cocoa/download_shelf_view.h"
+
+
+@interface DownloadShelfController(Private)
+- (void)applyContentAreaOffset:(BOOL)apply;
+- (void)positionBar;
+- (void)showDownloadShelf:(BOOL)enable;
+@end
+
+
+@implementation DownloadShelfController
+
+- (id)initWithBrowser:(Browser*)browser
+ contentArea:(NSView*)content {
+ if ((self = [super initWithNibName:@"DownloadShelf"
+ bundle:mac_util::MainAppBundle()])) {
+ contentArea_ = content;
+ shelfHeight_ = [[self view] bounds].size.height;
+
+ [self positionBar];
+ [[[contentArea_ window] contentView] addSubview:[self view]];
+
+ // This calls show:, so it needs to be last.
+ bridge_.reset(new DownloadShelfMac(browser, self));
+ }
+ return self;
+}
+
+// Initializes the download shelf at the bottom edge of |contentArea_|.
+- (void)positionBar {
+ // Set the bar's height to zero and position it at the bottom of the
+ // content area, within the window's content view (as opposed to the
+ // tab strip, which is a sibling). We'll enlarge it and slide the
+ // content area up when we need to show this strip.
+ NSRect contentFrame = [contentArea_ frame];
+ NSRect barFrame = NSMakeRect(0, 0,
+ contentFrame.size.width, shelfHeight_);
+ [[self view] setFrame:barFrame];
+}
+
+// Called when the contentArea's frame changes. Enlarge the view to
+// stay with the bottom of the contentArea.
+- (void)resizeDownloadShelf {
+ NSRect barFrame = [[self view] frame];
+ barFrame.origin.y = 0;
+ barFrame.size.height = NSMinY([contentArea_ frame]);
+ [[self view] setFrame:barFrame];
+}
+
+// Show or hide the bar based on the value of |enable|. Handles animating the
+// resize of the content view.
+- (void)showDownloadShelf:(BOOL)enable {
+ contentAreaHasOffset_ = enable;
+ [[self view] setHidden:enable ? NO : YES];
+ [self applyContentAreaOffset:enable];
+
+ barIsVisible_ = enable;
+}
+
+// Apply a contents box offset to make (or remove) room for the
+// download shelf. If apply==YES, always make room (the contentView_ is
+// "full size"). If apply==NO we are trying to undo an offset. If no
+// offset there is nothing to undo.
+- (void)applyContentAreaOffset:(BOOL)apply {
+ if (!contentAreaHasOffset_ && apply) {
+ // There is no offset to unconditionally apply.
+ return;
+ }
+
+ NSRect frame = [contentArea_ frame];
+ if (apply) {
+ frame.origin.y += shelfHeight_;
+ frame.size.height -= shelfHeight_;
+ } else {
+ frame.origin.y -= shelfHeight_;
+ frame.size.height += shelfHeight_;
+ }
+
+ [[contentArea_ animator] setFrame:frame];
+ [[self view] setNeedsDisplay:YES];
+ [contentArea_ setNeedsDisplay:YES];
+}
+
+- (DownloadShelf*)bridge {
+ return bridge_.get();
+}
+
+- (BOOL)isVisible {
+ return barIsVisible_;
+}
+
+- (void)show:(id)sender {
+ [self showDownloadShelf:YES];
+}
+
+- (void)hide:(id)sender {
+ [self showDownloadShelf:NO];
+}
+
+- (void)addDownloadItem:(NSView*)view {
+ [[self view] addSubview:view];
+}
+
+@end