OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 - (void)closed { | 346 - (void)closed { |
347 NSUInteger i = 0; | 347 NSUInteger i = 0; |
348 while (i < [downloadItemControllers_ count]) { | 348 while (i < [downloadItemControllers_ count]) { |
349 DownloadItemController* itemController = | 349 DownloadItemController* itemController = |
350 [downloadItemControllers_ objectAtIndex:i]; | 350 [downloadItemControllers_ objectAtIndex:i]; |
351 DownloadItem* download = [itemController download]; | 351 DownloadItem* download = [itemController download]; |
352 bool isTransferDone = download->IsComplete() || | 352 bool isTransferDone = download->IsComplete() || |
353 download->IsCancelled() || | 353 download->IsCancelled() || |
354 download->IsInterrupted(); | 354 download->IsInterrupted(); |
355 if (isTransferDone && | 355 if (isTransferDone && |
356 download->safety_state() != DownloadItem::DANGEROUS) { | 356 download->GetSafetyState() != DownloadItem::DANGEROUS) { |
357 [self remove:itemController]; | 357 [self remove:itemController]; |
358 } else { | 358 } else { |
359 // Treat the item as opened when we close. This way if we get shown again | 359 // Treat the item as opened when we close. This way if we get shown again |
360 // the user need not open this item for the shelf to auto-close. | 360 // the user need not open this item for the shelf to auto-close. |
361 download->set_opened(true); | 361 download->SetOpened(true); |
362 ++i; | 362 ++i; |
363 } | 363 } |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 - (void)mouseEntered:(NSEvent*)event { | 367 - (void)mouseEntered:(NSEvent*)event { |
368 // If the mouse re-enters the download shelf, cancel the auto-close. Further | 368 // If the mouse re-enters the download shelf, cancel the auto-close. Further |
369 // mouse exits should not trigger autoclose, so also remove the tracking area. | 369 // mouse exits should not trigger autoclose, so also remove the tracking area. |
370 [self cancelAutoCloseAndRemoveTrackingArea]; | 370 [self cancelAutoCloseAndRemoveTrackingArea]; |
371 } | 371 } |
372 | 372 |
373 - (void)mouseExited:(NSEvent*)event { | 373 - (void)mouseExited:(NSEvent*)event { |
374 // Cancel any previous hide requests, just to be safe. | 374 // Cancel any previous hide requests, just to be safe. |
375 [NSObject cancelPreviousPerformRequestsWithTarget:self | 375 [NSObject cancelPreviousPerformRequestsWithTarget:self |
376 selector:@selector(hide:) | 376 selector:@selector(hide:) |
377 object:self]; | 377 object:self]; |
378 | 378 |
379 // Schedule an autoclose after a delay. If the mouse is moved back into the | 379 // Schedule an autoclose after a delay. If the mouse is moved back into the |
380 // view, or if an item is added to the shelf, the timer will be canceled. | 380 // view, or if an item is added to the shelf, the timer will be canceled. |
381 [self performSelector:@selector(hide:) | 381 [self performSelector:@selector(hide:) |
382 withObject:self | 382 withObject:self |
383 afterDelay:kAutoCloseDelaySeconds]; | 383 afterDelay:kAutoCloseDelaySeconds]; |
384 } | 384 } |
385 | 385 |
386 - (BOOL)canAutoClose { | 386 - (BOOL)canAutoClose { |
387 for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) { | 387 for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) { |
388 DownloadItemController* itemController = | 388 DownloadItemController* itemController = |
389 [downloadItemControllers_ objectAtIndex:i]; | 389 [downloadItemControllers_ objectAtIndex:i]; |
390 if (![itemController download]->opened()) | 390 if (![itemController download]->GetOpened()) |
391 return NO; | 391 return NO; |
392 } | 392 } |
393 return YES; | 393 return YES; |
394 } | 394 } |
395 | 395 |
396 - (void)installTrackingArea { | 396 - (void)installTrackingArea { |
397 // Install the tracking area to listen for mouseExited messages and trigger | 397 // Install the tracking area to listen for mouseExited messages and trigger |
398 // the shelf autoclose. | 398 // the shelf autoclose. |
399 if (trackingArea_.get()) | 399 if (trackingArea_.get()) |
400 return; | 400 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 449 } |
450 | 450 |
451 // Set the tracking off to create a new tracking area for the control. | 451 // Set the tracking off to create a new tracking area for the control. |
452 // When changing the bounds/frame on a HoverButton, the tracking isn't updated | 452 // When changing the bounds/frame on a HoverButton, the tracking isn't updated |
453 // correctly, it needs to be turned off and back on. | 453 // correctly, it needs to be turned off and back on. |
454 [hoverCloseButton_ setTrackingEnabled:NO]; | 454 [hoverCloseButton_ setTrackingEnabled:NO]; |
455 [hoverCloseButton_ setFrame:bounds]; | 455 [hoverCloseButton_ setFrame:bounds]; |
456 [hoverCloseButton_ setTrackingEnabled:YES]; | 456 [hoverCloseButton_ setTrackingEnabled:YES]; |
457 } | 457 } |
458 @end | 458 @end |
OLD | NEW |