| 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 "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 // Max number of download views we'll contain. Any time a view is added and | 20 // Max number of download views we'll contain. Any time a view is added and |
| 21 // we already have this many download views, one is removed. | 21 // we already have this many download views, one is removed. |
| 22 const size_t kMaxDownloadItemCount = 16; | 22 const size_t kMaxDownloadItemCount = 16; |
| 23 | 23 |
| 24 // Border padding of a download item. | |
| 25 const int kDownloadItemBorderPadding = 3; | |
| 26 | |
| 27 // Horizontal padding between two download items. | 24 // Horizontal padding between two download items. |
| 28 const int kDownloadItemPadding = 10; | 25 const int kDownloadItemPadding = 2; |
| 29 | 26 |
| 30 // Duration for the open-new-leftmost-item animation, in seconds. | 27 // Duration for the open-new-leftmost-item animation, in seconds. |
| 31 const NSTimeInterval kDownloadItemOpenDuration = 0.8; | 28 const NSTimeInterval kDownloadItemOpenDuration = 0.8; |
| 32 | 29 |
| 33 } // namespace | 30 } // namespace |
| 34 | 31 |
| 35 @interface DownloadShelfController(Private) | 32 @interface DownloadShelfController(Private) |
| 36 - (void)applyContentAreaOffset:(BOOL)apply; | 33 - (void)applyContentAreaOffset:(BOOL)apply; |
| 37 - (void)showDownloadShelf:(BOOL)enable; | 34 - (void)showDownloadShelf:(BOOL)enable; |
| 38 - (void)resizeDownloadLinkToFit; | 35 - (void)resizeDownloadLinkToFit; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 name:NSViewFrameDidChangeNotification | 221 name:NSViewFrameDidChangeNotification |
| 225 object:[controller view]]; | 222 object:[controller view]]; |
| 226 [[NSNotificationCenter defaultCenter] | 223 [[NSNotificationCenter defaultCenter] |
| 227 addObserver:controller | 224 addObserver:controller |
| 228 selector:@selector(updateVisibility:) | 225 selector:@selector(updateVisibility:) |
| 229 name:NSViewFrameDidChangeNotification | 226 name:NSViewFrameDidChangeNotification |
| 230 object:itemContainerView_]; | 227 object:itemContainerView_]; |
| 231 | 228 |
| 232 // Start at width 0... | 229 // Start at width 0... |
| 233 NSSize size = [controller.get() preferredSize]; | 230 NSSize size = [controller.get() preferredSize]; |
| 234 NSRect frame = NSMakeRect(0, kDownloadItemBorderPadding, 0, size.height); | 231 NSRect frame = NSMakeRect(0, 0, 0, size.height); |
| 235 [[controller.get() view] setFrame:frame]; | 232 [[controller.get() view] setFrame:frame]; |
| 236 | 233 |
| 237 // ...then animate in | 234 // ...then animate in |
| 238 frame.size.width = size.width; | 235 frame.size.width = size.width; |
| 239 [NSAnimationContext beginGrouping]; | 236 [NSAnimationContext beginGrouping]; |
| 240 [[NSAnimationContext currentContext] setDuration:kDownloadItemOpenDuration]; | 237 [[NSAnimationContext currentContext] setDuration:kDownloadItemOpenDuration]; |
| 241 [[[controller.get() view] animator] setFrame:frame]; | 238 [[[controller.get() view] animator] setFrame:frame]; |
| 242 [NSAnimationContext endGrouping]; | 239 [NSAnimationContext endGrouping]; |
| 243 | 240 |
| 244 // Keep only a limited number of items in the shelf. | 241 // Keep only a limited number of items in the shelf. |
| 245 if ([downloadItemControllers_ count] > kMaxDownloadItemCount) { | 242 if ([downloadItemControllers_ count] > kMaxDownloadItemCount) { |
| 246 DCHECK(kMaxDownloadItemCount > 0); | 243 DCHECK(kMaxDownloadItemCount > 0); |
| 247 | 244 |
| 248 // Since no user will ever see the item being removed (needs a horizontal | 245 // Since no user will ever see the item being removed (needs a horizontal |
| 249 // screen resolution greater than 3200 at 16 items at 200 pixels each), | 246 // screen resolution greater than 3200 at 16 items at 200 pixels each), |
| 250 // there's no point in animating the removal. | 247 // there's no point in animating the removal. |
| 251 [self remove:[downloadItemControllers_ lastObject]]; | 248 [self remove:[downloadItemControllers_ lastObject]]; |
| 252 } | 249 } |
| 253 | 250 |
| 254 // Finally, move the remaining items to the right. Skip the first item when | 251 // Finally, move the remaining items to the right. Skip the first item when |
| 255 // laying out the items, so that the longer animation duration we set up above | 252 // laying out the items, so that the longer animation duration we set up above |
| 256 // is not overwritten. | 253 // is not overwritten. |
| 257 [self layoutItems:YES]; | 254 [self layoutItems:YES]; |
| 258 } | 255 } |
| 259 | 256 |
| 260 @end | 257 @end |
| OLD | NEW |