| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/download/download_shelf_controller.h" | 5 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" | 
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" | 
|  | 11 #include "chrome/browser/download/download_item_model.h" | 
| 11 #include "chrome/browser/download/download_stats.h" | 12 #include "chrome/browser/download/download_stats.h" | 
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" | 
| 13 #include "chrome/browser/themes/theme_service.h" | 14 #include "chrome/browser/themes/theme_service.h" | 
| 14 #include "chrome/browser/themes/theme_service_factory.h" | 15 #include "chrome/browser/themes/theme_service_factory.h" | 
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" | 
| 16 #include "chrome/browser/ui/chrome_pages.h" | 17 #include "chrome/browser/ui/chrome_pages.h" | 
| 17 #import "chrome/browser/ui/cocoa/animatable_view.h" | 18 #import "chrome/browser/ui/cocoa/animatable_view.h" | 
| 18 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 19 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 
| 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 20 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 
| 20 #include "chrome/browser/ui/cocoa/download/download_item_controller.h" | 21 #include "chrome/browser/ui/cocoa/download/download_item_controller.h" | 
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 213 | 214 | 
| 214   if (!isShelfClosing) { | 215   if (!isShelfClosing) { | 
| 215     [self layoutItems]; | 216     [self layoutItems]; | 
| 216 | 217 | 
| 217     // If there are no more downloads or if all the remaining downloads have | 218     // If there are no more downloads or if all the remaining downloads have | 
| 218     // been opened, we can close the shelf. | 219     // been opened, we can close the shelf. | 
| 219     [self maybeAutoCloseAfterDelay]; | 220     [self maybeAutoCloseAfterDelay]; | 
| 220   } | 221   } | 
| 221 } | 222 } | 
| 222 | 223 | 
| 223 - (void)downloadWasOpened:(DownloadItemController*)item_controller { | 224 - (void)downloadWasOpenedOrShown:(DownloadItemController*)item_controller { | 
| 224   // This should only be called on the main thead. | 225   // This should only be called on the main thead. | 
| 225   DCHECK([NSThread isMainThread]); | 226   DCHECK([NSThread isMainThread]); | 
| 226   [self maybeAutoCloseAfterDelay]; | 227   [self maybeAutoCloseAfterDelay]; | 
| 227 } | 228 } | 
| 228 | 229 | 
| 229 - (void)showDownloadShelf:(BOOL)show | 230 - (void)showDownloadShelf:(BOOL)show | 
| 230              isUserAction:(BOOL)isUserAction { | 231              isUserAction:(BOOL)isUserAction { | 
| 231   [self cancelAutoClose]; | 232   [self cancelAutoClose]; | 
| 232   shouldCloseOnMouseExit_ = NO; | 233   shouldCloseOnMouseExit_ = NO; | 
| 233 | 234 | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 377     DownloadItem::DownloadState state = download->GetState(); | 378     DownloadItem::DownloadState state = download->GetState(); | 
| 378     bool isTransferDone = state == DownloadItem::COMPLETE || | 379     bool isTransferDone = state == DownloadItem::COMPLETE || | 
| 379                           state == DownloadItem::CANCELLED || | 380                           state == DownloadItem::CANCELLED || | 
| 380                           state == DownloadItem::INTERRUPTED; | 381                           state == DownloadItem::INTERRUPTED; | 
| 381     if (isTransferDone && !download->IsDangerous()) { | 382     if (isTransferDone && !download->IsDangerous()) { | 
| 382       [self removeDownload:itemController | 383       [self removeDownload:itemController | 
| 383             isShelfClosing:YES]; | 384             isShelfClosing:YES]; | 
| 384     } else { | 385     } else { | 
| 385       // Treat the item as opened when we close. This way if we get shown again | 386       // Treat the item as opened when we close. This way if we get shown again | 
| 386       // the user need not open this item for the shelf to auto-close. | 387       // the user need not open this item for the shelf to auto-close. | 
| 387       download->SetOpened(true); | 388       DownloadItemModel(download).SetOpenedOrShown(true); | 
| 388       ++i; | 389       ++i; | 
| 389     } | 390     } | 
| 390   } | 391   } | 
| 391 } | 392 } | 
| 392 | 393 | 
| 393 - (void)mouseEntered:(NSEvent*)event { | 394 - (void)mouseEntered:(NSEvent*)event { | 
| 394   isMouseInsideView_ = YES; | 395   isMouseInsideView_ = YES; | 
| 395   // If the mouse re-enters the download shelf, cancel the auto-close.  Further | 396   // If the mouse re-enters the download shelf, cancel the auto-close.  Further | 
| 396   // mouse exits should not trigger autoclose. | 397   // mouse exits should not trigger autoclose. | 
| 397   if (shouldCloseOnMouseExit_) { | 398   if (shouldCloseOnMouseExit_) { | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 422                                            selector:@selector(autoClose) | 423                                            selector:@selector(autoClose) | 
| 423                                              object:nil]; | 424                                              object:nil]; | 
| 424 } | 425 } | 
| 425 | 426 | 
| 426 - (void)maybeAutoCloseAfterDelay { | 427 - (void)maybeAutoCloseAfterDelay { | 
| 427   // We can close the shelf automatically if all the downloads on the shelf have | 428   // We can close the shelf automatically if all the downloads on the shelf have | 
| 428   // been opened. | 429   // been opened. | 
| 429   for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) { | 430   for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) { | 
| 430     DownloadItemController* itemController = | 431     DownloadItemController* itemController = | 
| 431         [downloadItemControllers_ objectAtIndex:i]; | 432         [downloadItemControllers_ objectAtIndex:i]; | 
| 432     if (![itemController download]->GetOpened()) | 433     if (!DownloadItemModel([itemController download]).GetOpenedOrShown()) | 
| 433       return; | 434       return; | 
| 434   } | 435   } | 
| 435 | 436 | 
| 436   if ([self isVisible] && [downloadItemControllers_ count] > 0 && | 437   if ([self isVisible] && [downloadItemControllers_ count] > 0 && | 
| 437       isMouseInsideView_) { | 438       isMouseInsideView_) { | 
| 438     // If there are download items on the shelf and the user is potentially stil | 439     // If there are download items on the shelf and the user is potentially stil | 
| 439     // interacting with them, schedule an auto close after the user moves the | 440     // interacting with them, schedule an auto close after the user moves the | 
| 440     // mouse off the shelf. | 441     // mouse off the shelf. | 
| 441     shouldCloseOnMouseExit_ = YES; | 442     shouldCloseOnMouseExit_ = YES; | 
| 442   } else { | 443   } else { | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 506   } | 507   } | 
| 507 | 508 | 
| 508   // Set the tracking off to create a new tracking area for the control. | 509   // Set the tracking off to create a new tracking area for the control. | 
| 509   // When changing the bounds/frame on a HoverButton, the tracking isn't updated | 510   // When changing the bounds/frame on a HoverButton, the tracking isn't updated | 
| 510   // correctly, it needs to be turned off and back on. | 511   // correctly, it needs to be turned off and back on. | 
| 511   [hoverCloseButton_ setTrackingEnabled:NO]; | 512   [hoverCloseButton_ setTrackingEnabled:NO]; | 
| 512   [hoverCloseButton_ setFrame:bounds]; | 513   [hoverCloseButton_ setFrame:bounds]; | 
| 513   [hoverCloseButton_ setTrackingEnabled:YES]; | 514   [hoverCloseButton_ setTrackingEnabled:YES]; | 
| 514 } | 515 } | 
| 515 @end | 516 @end | 
| OLD | NEW | 
|---|