OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "download_shelf_controller.h" | 5 #import "chrome/browser/cocoa/download_shelf_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "chrome/browser/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/cocoa/browser_window_controller.h" |
11 #include "chrome/browser/cocoa/browser_window_cocoa.h" | 11 #include "chrome/browser/cocoa/browser_window_cocoa.h" |
| 12 #include "chrome/browser/cocoa/download_item_controller.h" |
12 #include "chrome/browser/cocoa/download_shelf_mac.h" | 13 #include "chrome/browser/cocoa/download_shelf_mac.h" |
13 #import "chrome/browser/cocoa/download_shelf_view.h" | 14 #import "chrome/browser/cocoa/download_shelf_view.h" |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 | 16 |
| 17 namespace { |
| 18 |
| 19 // TODO(thakis): These are all temporary until there's a download item view. |
| 20 |
| 21 // Border padding of a download item. |
| 22 const int kDownloadItemBorderPadding = 4; |
| 23 |
| 24 // Width of a download item. |
| 25 const int kDownloadItemWidth = 200; |
| 26 |
| 27 // Height of a download item. |
| 28 const int kDownloadItemHeight = 32; |
| 29 |
| 30 // Horizontal padding between two download items. |
| 31 const int kDownloadItemPadding = 10; |
| 32 |
| 33 } // namespace |
16 | 34 |
17 @interface DownloadShelfController(Private) | 35 @interface DownloadShelfController(Private) |
18 - (void)applyContentAreaOffset:(BOOL)apply; | 36 - (void)applyContentAreaOffset:(BOOL)apply; |
19 - (void)positionBar; | 37 - (void)positionBar; |
20 - (void)showDownloadShelf:(BOOL)enable; | 38 - (void)showDownloadShelf:(BOOL)enable; |
21 @end | 39 @end |
22 | 40 |
23 | 41 |
24 @implementation DownloadShelfController | 42 @implementation DownloadShelfController |
25 | 43 |
26 - (id)initWithBrowser:(Browser*)browser | 44 - (id)initWithBrowser:(Browser*)browser |
27 contentArea:(NSView*)content { | 45 contentArea:(NSView*)content { |
28 if ((self = [super initWithNibName:@"DownloadShelf" | 46 if ((self = [super initWithNibName:@"DownloadShelf" |
29 bundle:mac_util::MainAppBundle()])) { | 47 bundle:mac_util::MainAppBundle()])) { |
30 contentArea_ = content; | 48 contentArea_ = content; |
31 shelfHeight_ = [[self view] bounds].size.height; | 49 shelfHeight_ = [[self view] bounds].size.height; |
32 | 50 |
33 [self positionBar]; | 51 [self positionBar]; |
34 [[[contentArea_ window] contentView] addSubview:[self view]]; | 52 [[[contentArea_ window] contentView] addSubview:[self view]]; |
35 | 53 |
| 54 downloadItemControllers_.reset([[NSMutableArray alloc] init]); |
| 55 |
36 // This calls show:, so it needs to be last. | 56 // This calls show:, so it needs to be last. |
37 bridge_.reset(new DownloadShelfMac(browser, self)); | 57 bridge_.reset(new DownloadShelfMac(browser, self)); |
38 } | 58 } |
39 return self; | 59 return self; |
40 } | 60 } |
41 | 61 |
42 - (void)awakeFromNib { | 62 - (void)awakeFromNib { |
43 // Initialize "Show all downloads" link. | 63 // Initialize "Show all downloads" link. |
44 | 64 |
45 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 65 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
(...skipping 17 matching lines...) Expand all Loading... |
63 | 83 |
64 - (BOOL)textView:(NSTextView *)aTextView | 84 - (BOOL)textView:(NSTextView *)aTextView |
65 clickedOnLink:(id)link | 85 clickedOnLink:(id)link |
66 atIndex:(NSUInteger)charIndex { | 86 atIndex:(NSUInteger)charIndex { |
67 bridge_->ShowAllDownloads(); | 87 bridge_->ShowAllDownloads(); |
68 return YES; | 88 return YES; |
69 } | 89 } |
70 | 90 |
71 // Initializes the download shelf at the bottom edge of |contentArea_|. | 91 // Initializes the download shelf at the bottom edge of |contentArea_|. |
72 - (void)positionBar { | 92 - (void)positionBar { |
73 // Set the bar's height to zero and position it at the bottom of the | 93 // Set the bar's height to zero and position it at the bottom of the content |
74 // content area, within the window's content view (as opposed to the | 94 // area, within the window's content view (as opposed to the tab strip, which |
75 // tab strip, which is a sibling). We'll enlarge it and slide the | 95 // is a sibling). We'll enlarge it and slide the content area up when we need |
76 // content area up when we need to show this strip. | 96 // to show this strip. |
77 NSRect contentFrame = [contentArea_ frame]; | 97 NSRect contentFrame = [contentArea_ frame]; |
78 NSRect barFrame = NSMakeRect(0, 0, | 98 NSRect barFrame = NSMakeRect(0, 0, contentFrame.size.width, shelfHeight_); |
79 contentFrame.size.width, shelfHeight_); | |
80 [[self view] setFrame:barFrame]; | 99 [[self view] setFrame:barFrame]; |
81 } | 100 } |
82 | 101 |
83 // Called when the contentArea's frame changes. Enlarge the view to | 102 // Called when the contentArea's frame changes. Enlarge the view to stay with |
84 // stay with the bottom of the contentArea. | 103 // the bottom of the contentArea. |
85 - (void)resizeDownloadShelf { | 104 - (void)resizeDownloadShelf { |
86 NSRect barFrame = [[self view] frame]; | 105 NSRect barFrame = [[self view] frame]; |
87 barFrame.origin.y = 0; | 106 barFrame.origin.y = 0; |
88 barFrame.size.height = NSMinY([contentArea_ frame]); | 107 barFrame.size.height = NSMinY([contentArea_ frame]); |
89 [[self view] setFrame:barFrame]; | 108 [[self view] setFrame:barFrame]; |
90 } | 109 } |
91 | 110 |
92 // Show or hide the bar based on the value of |enable|. Handles animating the | 111 // Show or hide the bar based on the value of |enable|. Handles animating the |
93 // resize of the content view. | 112 // resize of the content view. |
94 - (void)showDownloadShelf:(BOOL)enable { | 113 - (void)showDownloadShelf:(BOOL)enable { |
95 if ([self isVisible] == enable) | 114 if ([self isVisible] == enable) |
96 return; | 115 return; |
97 | 116 |
98 contentAreaHasOffset_ = enable; | 117 contentAreaHasOffset_ = enable; |
99 [[self view] setHidden:enable ? NO : YES]; | 118 [[self view] setHidden:enable ? NO : YES]; |
100 [self applyContentAreaOffset:enable]; | 119 [self applyContentAreaOffset:enable]; |
101 | 120 |
102 barIsVisible_ = enable; | 121 barIsVisible_ = enable; |
103 } | 122 } |
104 | 123 |
105 // Apply a contents box offset to make (or remove) room for the | 124 // Apply a contents box offset to make (or remove) room for the download shelf. |
106 // download shelf. If apply==YES, always make room (the contentView_ is | 125 // If apply is YES, always make room (the contentView_ is "full size"). If apply |
107 // "full size"). If apply==NO we are trying to undo an offset. If no | 126 // is NO, we are trying to undo an offset. If no offset there is nothing to undo
. |
108 // offset there is nothing to undo. | |
109 - (void)applyContentAreaOffset:(BOOL)apply { | 127 - (void)applyContentAreaOffset:(BOOL)apply { |
110 if (!contentAreaHasOffset_ && apply) { | 128 if (!contentAreaHasOffset_ && apply) { |
111 // There is no offset to unconditionally apply. | 129 // There is no offset to unconditionally apply. |
112 return; | 130 return; |
113 } | 131 } |
114 | 132 |
115 NSRect frame = [contentArea_ frame]; | 133 NSRect frame = [contentArea_ frame]; |
116 if (apply) { | 134 if (apply) { |
117 frame.origin.y += shelfHeight_; | 135 frame.origin.y += shelfHeight_; |
118 frame.size.height -= shelfHeight_; | 136 frame.size.height -= shelfHeight_; |
(...skipping 16 matching lines...) Expand all Loading... |
135 } | 153 } |
136 | 154 |
137 - (void)show:(id)sender { | 155 - (void)show:(id)sender { |
138 [self showDownloadShelf:YES]; | 156 [self showDownloadShelf:YES]; |
139 } | 157 } |
140 | 158 |
141 - (void)hide:(id)sender { | 159 - (void)hide:(id)sender { |
142 [self showDownloadShelf:NO]; | 160 [self showDownloadShelf:NO]; |
143 } | 161 } |
144 | 162 |
145 - (void)addDownloadItem:(NSView*)view { | 163 - (void)addDownloadItem:(BaseDownloadItemModel*)model { |
146 [[self view] addSubview:view]; | 164 // TODO(thakis): we need to delete these at some point. There's no explicit |
| 165 // mass delete on windows, figure out where they do it. |
| 166 |
| 167 // TODO(thakis): RTL support? |
| 168 // (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) |
| 169 int startX = kDownloadItemBorderPadding + |
| 170 (kDownloadItemWidth + kDownloadItemPadding) * |
| 171 [downloadItemControllers_ count]; |
| 172 |
| 173 NSRect position = NSMakeRect(startX, kDownloadItemBorderPadding, |
| 174 kDownloadItemWidth, kDownloadItemHeight); |
| 175 scoped_nsobject<DownloadItemController> controller( |
| 176 [[DownloadItemController alloc] initWithFrame:position model:model]); |
| 177 [downloadItemControllers_ addObject:controller.get()]; |
| 178 |
| 179 [[self view] addSubview:[controller.get() view]]; |
147 } | 180 } |
148 | 181 |
149 @end | 182 @end |
OLD | NEW |