| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 "download_shelf_controller.h" |
| 6 |
| 7 #include "base/mac_util.h" |
| 8 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 9 #include "chrome/browser/cocoa/browser_window_cocoa.h" |
| 10 #include "chrome/browser/cocoa/download_shelf_mac.h" |
| 11 #import "chrome/browser/cocoa/download_shelf_view.h" |
| 12 |
| 13 |
| 14 @interface DownloadShelfController(Private) |
| 15 - (void)applyContentAreaOffset:(BOOL)apply; |
| 16 - (void)positionBar; |
| 17 - (void)showDownloadShelf:(BOOL)enable; |
| 18 @end |
| 19 |
| 20 |
| 21 @implementation DownloadShelfController |
| 22 |
| 23 - (id)initWithBrowser:(Browser*)browser |
| 24 contentArea:(NSView*)content { |
| 25 if ((self = [super initWithNibName:@"DownloadShelf" |
| 26 bundle:mac_util::MainAppBundle()])) { |
| 27 contentArea_ = content; |
| 28 shelfHeight_ = [[self view] bounds].size.height; |
| 29 |
| 30 [self positionBar]; |
| 31 [[[contentArea_ window] contentView] addSubview:[self view]]; |
| 32 |
| 33 // This calls show:, so it needs to be last. |
| 34 bridge_.reset(new DownloadShelfMac(browser, self)); |
| 35 } |
| 36 return self; |
| 37 } |
| 38 |
| 39 // Initializes the download shelf at the bottom edge of |contentArea_|. |
| 40 - (void)positionBar { |
| 41 // Set the bar's height to zero and position it at the bottom of the |
| 42 // content area, within the window's content view (as opposed to the |
| 43 // tab strip, which is a sibling). We'll enlarge it and slide the |
| 44 // content area up when we need to show this strip. |
| 45 NSRect contentFrame = [contentArea_ frame]; |
| 46 NSRect barFrame = NSMakeRect(0, 0, |
| 47 contentFrame.size.width, shelfHeight_); |
| 48 [[self view] setFrame:barFrame]; |
| 49 } |
| 50 |
| 51 // Called when the contentArea's frame changes. Enlarge the view to |
| 52 // stay with the bottom of the contentArea. |
| 53 - (void)resizeDownloadShelf { |
| 54 NSRect barFrame = [[self view] frame]; |
| 55 barFrame.origin.y = 0; |
| 56 barFrame.size.height = NSMinY([contentArea_ frame]); |
| 57 [[self view] setFrame:barFrame]; |
| 58 } |
| 59 |
| 60 // Show or hide the bar based on the value of |enable|. Handles animating the |
| 61 // resize of the content view. |
| 62 - (void)showDownloadShelf:(BOOL)enable { |
| 63 contentAreaHasOffset_ = enable; |
| 64 [[self view] setHidden:enable ? NO : YES]; |
| 65 [self applyContentAreaOffset:enable]; |
| 66 |
| 67 barIsVisible_ = enable; |
| 68 } |
| 69 |
| 70 // Apply a contents box offset to make (or remove) room for the |
| 71 // download shelf. If apply==YES, always make room (the contentView_ is |
| 72 // "full size"). If apply==NO we are trying to undo an offset. If no |
| 73 // offset there is nothing to undo. |
| 74 - (void)applyContentAreaOffset:(BOOL)apply { |
| 75 if (!contentAreaHasOffset_ && apply) { |
| 76 // There is no offset to unconditionally apply. |
| 77 return; |
| 78 } |
| 79 |
| 80 NSRect frame = [contentArea_ frame]; |
| 81 if (apply) { |
| 82 frame.origin.y += shelfHeight_; |
| 83 frame.size.height -= shelfHeight_; |
| 84 } else { |
| 85 frame.origin.y -= shelfHeight_; |
| 86 frame.size.height += shelfHeight_; |
| 87 } |
| 88 |
| 89 [[contentArea_ animator] setFrame:frame]; |
| 90 [[self view] setNeedsDisplay:YES]; |
| 91 [contentArea_ setNeedsDisplay:YES]; |
| 92 } |
| 93 |
| 94 - (DownloadShelf*)bridge { |
| 95 return bridge_.get(); |
| 96 } |
| 97 |
| 98 - (BOOL)isVisible { |
| 99 return barIsVisible_; |
| 100 } |
| 101 |
| 102 - (void)show:(id)sender { |
| 103 [self showDownloadShelf:YES]; |
| 104 } |
| 105 |
| 106 - (void)hide:(id)sender { |
| 107 [self showDownloadShelf:NO]; |
| 108 } |
| 109 |
| 110 - (void)addDownloadItem:(NSView*)view { |
| 111 [[self view] addSubview:view]; |
| 112 } |
| 113 |
| 114 @end |
| OLD | NEW |