Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/cocoa/download_shelf_controller.mm

Issue 159060: Use a real download item.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: first round of review comments addressed Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/cocoa/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 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #import "chrome/browser/cocoa/browser_window_controller.h" 11 #import "chrome/browser/cocoa/browser_window_controller.h"
12 #include "chrome/browser/cocoa/browser_window_cocoa.h" 12 #include "chrome/browser/cocoa/browser_window_cocoa.h"
13 #include "chrome/browser/cocoa/download_item_controller.h" 13 #include "chrome/browser/cocoa/download_item_controller.h"
14 #include "chrome/browser/cocoa/download_shelf_mac.h" 14 #include "chrome/browser/cocoa/download_shelf_mac.h"
15 #import "chrome/browser/cocoa/download_shelf_view.h" 15 #import "chrome/browser/cocoa/download_shelf_view.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 17
18 namespace { 18 namespace {
19 19
20 // TODO(thakis): These are all temporary until there's a download item view. 20 // Border padding of a download item.
21 const int kDownloadItemBorderPadding = 3;
21 22
22 // Border padding of a download item. 23 // Width of a download item, must match width in DownloadItem.xib.
23 const int kDownloadItemBorderPadding = 4;
24
25 // Width of a download item.
26 const int kDownloadItemWidth = 200; 24 const int kDownloadItemWidth = 200;
27 25
28 // Height of a download item. 26 // Height of a download item, must match height in DownloadItem.xib.
29 const int kDownloadItemHeight = 32; 27 const int kDownloadItemHeight = 34;
30 28
31 // Horizontal padding between two download items. 29 // Horizontal padding between two download items.
32 const int kDownloadItemPadding = 10; 30 const int kDownloadItemPadding = 10;
33 31
32 // Duration for the open-new-leftmost-item animation, in seconds.
33 const NSTimeInterval kDownloadItemOpenDuration = 0.8;
34
34 } // namespace 35 } // namespace
35 36
36 @interface DownloadShelfController(Private) 37 @interface DownloadShelfController(Private)
37 - (void)applyContentAreaOffset:(BOOL)apply; 38 - (void)applyContentAreaOffset:(BOOL)apply;
38 - (void)positionBar; 39 - (void)positionBar;
39 - (void)showDownloadShelf:(BOOL)enable; 40 - (void)showDownloadShelf:(BOOL)enable;
40 @end 41 @end
41 42
42 43
43 @implementation DownloadShelfController 44 @implementation DownloadShelfController
(...skipping 18 matching lines...) Expand all
62 63
63 - (void)awakeFromNib { 64 - (void)awakeFromNib {
64 // Initialize "Show all downloads" link. 65 // Initialize "Show all downloads" link.
65 66
66 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 67 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
67 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); 68 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]);
68 // TODO(thakis): left-align for RTL languages? 69 // TODO(thakis): left-align for RTL languages?
69 [paragraphStyle.get() setAlignment:NSRightTextAlignment]; 70 [paragraphStyle.get() setAlignment:NSRightTextAlignment];
70 71
71 NSDictionary* linkAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 72 NSDictionary* linkAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
72 self, NSLinkAttributeName, 73 @"", NSLinkAttributeName,
73 [NSCursor pointingHandCursor], NSCursorAttributeName, 74 [NSCursor pointingHandCursor], NSCursorAttributeName,
74 paragraphStyle.get(), NSParagraphStyleAttributeName, 75 paragraphStyle.get(), NSParagraphStyleAttributeName,
75 nil]; 76 nil];
76 NSString* text = 77 NSString* text =
77 base::SysWideToNSString(l10n_util::GetString(IDS_SHOW_ALL_DOWNLOADS)); 78 base::SysWideToNSString(l10n_util::GetString(IDS_SHOW_ALL_DOWNLOADS));
78 scoped_nsobject<NSAttributedString> linkText([[NSAttributedString alloc] 79 scoped_nsobject<NSAttributedString> linkText([[NSAttributedString alloc]
79 initWithString:text attributes:linkAttributes]); 80 initWithString:text attributes:linkAttributes]);
80 81
81 [[showAllDownloadsLink_ textStorage] setAttributedString:linkText.get()]; 82 [[showAllDownloadsLink_ textStorage] setAttributedString:linkText.get()];
82 [showAllDownloadsLink_ setDelegate:self]; 83 [showAllDownloadsLink_ setDelegate:self];
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 175
175 - (void)show:(id)sender { 176 - (void)show:(id)sender {
176 [self showDownloadShelf:YES]; 177 [self showDownloadShelf:YES];
177 } 178 }
178 179
179 - (void)hide:(id)sender { 180 - (void)hide:(id)sender {
180 [self showDownloadShelf:NO]; 181 [self showDownloadShelf:NO];
181 } 182 }
182 183
183 - (void)addDownloadItem:(BaseDownloadItemModel*)model { 184 - (void)addDownloadItem:(BaseDownloadItemModel*)model {
184 // TODO(thakis): we need to delete these at some point. There's no explicit
185 // mass delete on windows, figure out where they do it.
186
187 // TODO(thakis): RTL support? 185 // TODO(thakis): RTL support?
188 // (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 186 // (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
189 int startX = kDownloadItemBorderPadding + 187 // Shift all existing items to the right
190 (kDownloadItemWidth + kDownloadItemPadding) * 188 for (DownloadItemController* itemController in downloadItemControllers_.get()) {
191 [downloadItemControllers_ count]; 189 NSRect frame = [[itemController view] frame];
190 frame.origin.x += kDownloadItemWidth + kDownloadItemPadding;
191 [[[itemController view] animator] setFrame:frame];
192 }
192 193
194 // Insert new item at the left
195 int startX = kDownloadItemBorderPadding;
196
197 // Start at width 0...
193 NSRect position = NSMakeRect(startX, kDownloadItemBorderPadding, 198 NSRect position = NSMakeRect(startX, kDownloadItemBorderPadding,
194 kDownloadItemWidth, kDownloadItemHeight); 199 0, kDownloadItemHeight);
195 scoped_nsobject<DownloadItemController> controller( 200 scoped_nsobject<DownloadItemController> controller(
196 [[DownloadItemController alloc] initWithFrame:position 201 [[DownloadItemController alloc] initWithFrame:position
197 model:model 202 model:model
198 shelf:self]); 203 shelf:self]);
199 [downloadItemControllers_ addObject:controller.get()]; 204 [downloadItemControllers_ addObject:controller.get()];
200 205
201 [[self view] addSubview:[controller.get() view]]; 206 [[self view] addSubview:[controller.get() view]];
207
208 // ...then animate in
209 NSRect frame = [[controller.get() view] frame];
210 frame.size.width = kDownloadItemWidth;
211
212 [NSAnimationContext beginGrouping];
213 [[NSAnimationContext currentContext] setDuration:kDownloadItemOpenDuration];
214 [[[controller.get() view] animator] setFrame:frame];
215 [NSAnimationContext endGrouping];
202 } 216 }
203 217
204 @end 218 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/download_item_controller.mm ('k') | chrome/browser/cocoa/gradient_button_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698