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

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

Issue 209613002: Download shelf autohides on showing in shell, just same as regular open Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move the 'user acted' flag into DownloadItemModelData and get rid of SetOpened/SetShown in Download… Created 6 years, 6 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
OLDNEW
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 "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/download/download_item_model.h"
10 #include "chrome/browser/download/download_stats.h" 11 #include "chrome/browser/download/download_stats.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h" 13 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/themes/theme_service_factory.h" 14 #include "chrome/browser/themes/theme_service_factory.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/chrome_pages.h" 16 #include "chrome/browser/ui/chrome_pages.h"
16 #import "chrome/browser/ui/cocoa/animatable_view.h" 17 #import "chrome/browser/ui/cocoa/animatable_view.h"
17 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 18 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
19 #include "chrome/browser/ui/cocoa/download/download_item_controller.h" 20 #include "chrome/browser/ui/cocoa/download/download_item_controller.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 [self maybeAutoCloseAfterDelay]; 209 [self maybeAutoCloseAfterDelay];
209 } 210 }
210 } 211 }
211 212
212 - (void)downloadWasOpened:(DownloadItemController*)item_controller { 213 - (void)downloadWasOpened:(DownloadItemController*)item_controller {
213 // This should only be called on the main thead. 214 // This should only be called on the main thead.
214 DCHECK([NSThread isMainThread]); 215 DCHECK([NSThread isMainThread]);
215 [self maybeAutoCloseAfterDelay]; 216 [self maybeAutoCloseAfterDelay];
216 } 217 }
217 218
219 - (void)downloadWasShown:(DownloadItemController*)item_controller {
220 // This should only be called on the main thead.
221 DCHECK([NSThread isMainThread]);
222 [self maybeAutoCloseAfterDelay];
223 }
224
218 // We need to explicitly release our download controllers here since they need 225 // We need to explicitly release our download controllers here since they need
219 // to remove themselves as observers before the remaining shutdown happens. 226 // to remove themselves as observers before the remaining shutdown happens.
220 - (void)exiting { 227 - (void)exiting {
221 [[self animatableView] stopAnimation]; 228 [[self animatableView] stopAnimation];
222 [self removeTrackingArea]; 229 [self removeTrackingArea];
223 [self cancelAutoClose]; 230 [self cancelAutoClose];
224 while ([downloadItemControllers_ count] > 0) { 231 while ([downloadItemControllers_ count] > 0) {
225 [self removeDownload:[downloadItemControllers_ lastObject] 232 [self removeDownload:[downloadItemControllers_ lastObject]
226 isShelfClosing:YES]; 233 isShelfClosing:YES];
227 } 234 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 [downloadItemControllers_ objectAtIndex:i]; 380 [downloadItemControllers_ objectAtIndex:i];
374 DownloadItem* download = [itemController download]; 381 DownloadItem* download = [itemController download];
375 DownloadItem::DownloadState state = download->GetState(); 382 DownloadItem::DownloadState state = download->GetState();
376 bool isTransferDone = state == DownloadItem::COMPLETE || 383 bool isTransferDone = state == DownloadItem::COMPLETE ||
377 state == DownloadItem::CANCELLED || 384 state == DownloadItem::CANCELLED ||
378 state == DownloadItem::INTERRUPTED; 385 state == DownloadItem::INTERRUPTED;
379 if (isTransferDone && !download->IsDangerous()) { 386 if (isTransferDone && !download->IsDangerous()) {
380 [self removeDownload:itemController 387 [self removeDownload:itemController
381 isShelfClosing:YES]; 388 isShelfClosing:YES];
382 } else { 389 } else {
383 // Treat the item as opened when we close. This way if we get shown again 390 // Treat the item as 'acted' when we close. This way if we get shown again
384 // the user need not open this item for the shelf to auto-close. 391 // the user need not open this item for the shelf to auto-close.
385 download->SetOpened(true); 392 DownloadItemModel(download).SetUserActed(true);
386 ++i; 393 ++i;
387 } 394 }
388 } 395 }
389 } 396 }
390 397
391 - (void)mouseEntered:(NSEvent*)event { 398 - (void)mouseEntered:(NSEvent*)event {
392 isMouseInsideView_ = YES; 399 isMouseInsideView_ = YES;
393 // If the mouse re-enters the download shelf, cancel the auto-close. Further 400 // If the mouse re-enters the download shelf, cancel the auto-close. Further
394 // mouse exits should not trigger autoclose. 401 // mouse exits should not trigger autoclose.
395 if (shouldCloseOnMouseExit_) { 402 if (shouldCloseOnMouseExit_) {
(...skipping 24 matching lines...) Expand all
420 selector:@selector(autoClose) 427 selector:@selector(autoClose)
421 object:nil]; 428 object:nil];
422 } 429 }
423 430
424 - (void)maybeAutoCloseAfterDelay { 431 - (void)maybeAutoCloseAfterDelay {
425 // We can close the shelf automatically if all the downloads on the shelf have 432 // We can close the shelf automatically if all the downloads on the shelf have
426 // been opened. 433 // been opened.
427 for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) { 434 for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) {
428 DownloadItemController* itemController = 435 DownloadItemController* itemController =
429 [downloadItemControllers_ objectAtIndex:i]; 436 [downloadItemControllers_ objectAtIndex:i];
430 if (![itemController download]->GetOpened()) 437 DownloadItem* download = [itemController download];
438 if (!DownloadItemModel(download).GetUserActed())
431 return; 439 return;
432 } 440 }
433 441
434 if ([self isVisible] && [downloadItemControllers_ count] > 0 && 442 if ([self isVisible] && [downloadItemControllers_ count] > 0 &&
435 isMouseInsideView_) { 443 isMouseInsideView_) {
436 // If there are download items on the shelf and the user is potentially stil 444 // If there are download items on the shelf and the user is potentially stil
437 // interacting with them, schedule an auto close after the user moves the 445 // interacting with them, schedule an auto close after the user moves the
438 // mouse off the shelf. 446 // mouse off the shelf.
439 shouldCloseOnMouseExit_ = YES; 447 shouldCloseOnMouseExit_ = YES;
440 } else { 448 } else {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 510 }
503 511
504 // Set the tracking off to create a new tracking area for the control. 512 // Set the tracking off to create a new tracking area for the control.
505 // When changing the bounds/frame on a HoverButton, the tracking isn't updated 513 // When changing the bounds/frame on a HoverButton, the tracking isn't updated
506 // correctly, it needs to be turned off and back on. 514 // correctly, it needs to be turned off and back on.
507 [hoverCloseButton_ setTrackingEnabled:NO]; 515 [hoverCloseButton_ setTrackingEnabled:NO];
508 [hoverCloseButton_ setFrame:bounds]; 516 [hoverCloseButton_ setFrame:bounds];
509 [hoverCloseButton_ setTrackingEnabled:YES]; 517 [hoverCloseButton_ setTrackingEnabled:YES];
510 } 518 }
511 @end 519 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698