| Index: chrome/browser/cocoa/download_shelf_controller.mm
|
| ===================================================================
|
| --- chrome/browser/cocoa/download_shelf_controller.mm (revision 20197)
|
| +++ chrome/browser/cocoa/download_shelf_controller.mm (working copy)
|
| @@ -2,18 +2,36 @@
|
| // 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"
|
| +#import "chrome/browser/cocoa/download_shelf_controller.h"
|
|
|
| #include "app/l10n_util.h"
|
| #include "base/mac_util.h"
|
| #include "base/sys_string_conversions.h"
|
| #import "chrome/browser/cocoa/browser_window_controller.h"
|
| #include "chrome/browser/cocoa/browser_window_cocoa.h"
|
| +#include "chrome/browser/cocoa/download_item_controller.h"
|
| #include "chrome/browser/cocoa/download_shelf_mac.h"
|
| #import "chrome/browser/cocoa/download_shelf_view.h"
|
| #include "grit/generated_resources.h"
|
|
|
| +namespace {
|
|
|
| +// TODO(thakis): These are all temporary until there's a download item view.
|
| +
|
| +// Border padding of a download item.
|
| +const int kDownloadItemBorderPadding = 4;
|
| +
|
| +// Width of a download item.
|
| +const int kDownloadItemWidth = 200;
|
| +
|
| +// Height of a download item.
|
| +const int kDownloadItemHeight = 32;
|
| +
|
| +// Horizontal padding between two download items.
|
| +const int kDownloadItemPadding = 10;
|
| +
|
| +} // namespace
|
| +
|
| @interface DownloadShelfController(Private)
|
| - (void)applyContentAreaOffset:(BOOL)apply;
|
| - (void)positionBar;
|
| @@ -33,6 +51,8 @@
|
| [self positionBar];
|
| [[[contentArea_ window] contentView] addSubview:[self view]];
|
|
|
| + downloadItemControllers_.reset([[NSMutableArray alloc] init]);
|
| +
|
| // This calls show:, so it needs to be last.
|
| bridge_.reset(new DownloadShelfMac(browser, self));
|
| }
|
| @@ -70,18 +90,17 @@
|
|
|
| // 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.
|
| + // 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_);
|
| + 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.
|
| +// 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;
|
| @@ -102,10 +121,9 @@
|
| 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.
|
| +// Apply a contents box offset to make (or remove) room for the download shelf.
|
| +// If apply is YES, always make room (the contentView_ is "full size"). If apply
|
| +// is 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.
|
| @@ -142,8 +160,23 @@
|
| [self showDownloadShelf:NO];
|
| }
|
|
|
| -- (void)addDownloadItem:(NSView*)view {
|
| - [[self view] addSubview:view];
|
| +- (void)addDownloadItem:(BaseDownloadItemModel*)model {
|
| + // TODO(thakis): we need to delete these at some point. There's no explicit
|
| + // mass delete on windows, figure out where they do it.
|
| +
|
| + // TODO(thakis): RTL support?
|
| + // (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
|
| + int startX = kDownloadItemBorderPadding +
|
| + (kDownloadItemWidth + kDownloadItemPadding) *
|
| + [downloadItemControllers_ count];
|
| +
|
| + NSRect position = NSMakeRect(startX, kDownloadItemBorderPadding,
|
| + kDownloadItemWidth, kDownloadItemHeight);
|
| + scoped_nsobject<DownloadItemController> controller(
|
| + [[DownloadItemController alloc] initWithFrame:position model:model]);
|
| + [downloadItemControllers_ addObject:controller.get()];
|
| +
|
| + [[self view] addSubview:[controller.get() view]];
|
| }
|
|
|
| @end
|
|
|