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" |
11 #include "chrome/browser/themes/theme_service_factory.h" | 11 #include "chrome/browser/themes/theme_service_factory.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #import "chrome/browser/ui/cocoa/animatable_view.h" | 13 #import "chrome/browser/ui/cocoa/animatable_view.h" |
14 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 14 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
15 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
16 #include "chrome/browser/ui/cocoa/download/download_item_controller.h" | 16 #include "chrome/browser/ui/cocoa/download/download_item_controller.h" |
17 #include "chrome/browser/ui/cocoa/download/download_shelf_mac.h" | 17 #include "chrome/browser/ui/cocoa/download/download_shelf_mac.h" |
18 #import "chrome/browser/ui/cocoa/download/download_shelf_view.h" | 18 #import "chrome/browser/ui/cocoa/download/download_shelf_view.h" |
19 #import "chrome/browser/ui/cocoa/hover_button.h" | 19 #import "chrome/browser/ui/cocoa/hover_button.h" |
20 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 20 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
21 #include "content/browser/download/download_item.h" | 21 #include "content/browser/download/download_item.h" |
22 #include "content/browser/download/download_manager.h" | 22 #include "content/browser/download/download_manager.h" |
| 23 #include "content/browser/download/download_stats.h" |
23 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 24 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 | 26 |
26 // Download shelf autoclose behavior: | 27 // Download shelf autoclose behavior: |
27 // | 28 // |
28 // The download shelf autocloses if all of this is true: | 29 // The download shelf autocloses if all of this is true: |
29 // 1) An item on the shelf has just been opened. | 30 // 1) An item on the shelf has just been opened. |
30 // 2) All remaining items on the shelf have been opened in the past. | 31 // 2) All remaining items on the shelf have been opened in the past. |
31 // 3) The mouse leaves the shelf and remains off the shelf for 5 seconds. | 32 // 3) The mouse leaves the shelf and remains off the shelf for 5 seconds. |
32 // | 33 // |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 - (void)show:(id)sender { | 237 - (void)show:(id)sender { |
237 [self showDownloadShelf:YES]; | 238 [self showDownloadShelf:YES]; |
238 } | 239 } |
239 | 240 |
240 - (void)hide:(id)sender { | 241 - (void)hide:(id)sender { |
241 [self cancelAutoCloseAndRemoveTrackingArea]; | 242 [self cancelAutoCloseAndRemoveTrackingArea]; |
242 | 243 |
243 // If |sender| isn't nil, then we're being closed from the UI by the user and | 244 // If |sender| isn't nil, then we're being closed from the UI by the user and |
244 // we need to tell our shelf implementation to close. Otherwise, we're being | 245 // we need to tell our shelf implementation to close. Otherwise, we're being |
245 // closed programmatically by our shelf implementation. | 246 // closed programmatically by our shelf implementation. |
246 if (sender) | 247 bool auto_closed = (sender == nil); |
| 248 |
| 249 int numInProgress = 0; |
| 250 for (NSUInteger i = 0; i < [downloadItemControllers_ count]; ++i) { |
| 251 if ([[downloadItemControllers_ objectAtIndex:i]download]->IsInProgress()) |
| 252 ++numInProgress; |
| 253 } |
| 254 download_stats::RecordShelfClose( |
| 255 [downloadItemControllers_ count], numInProgress, auto_closed); |
| 256 if (auto_closed) |
| 257 [self showDownloadShelf:NO]; |
| 258 else |
247 bridge_->Close(); | 259 bridge_->Close(); |
248 else | |
249 [self showDownloadShelf:NO]; | |
250 } | 260 } |
251 | 261 |
252 - (void)animationDidEnd:(NSAnimation*)animation { | 262 - (void)animationDidEnd:(NSAnimation*)animation { |
253 if (![self isVisible]) | 263 if (![self isVisible]) |
254 [self closed]; | 264 [self closed]; |
255 } | 265 } |
256 | 266 |
257 - (float)height { | 267 - (float)height { |
258 return maxShelfHeight_; | 268 return maxShelfHeight_; |
259 } | 269 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 449 } |
440 | 450 |
441 // 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. |
442 // 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 |
443 // correctly, it needs to be turned off and back on. | 453 // correctly, it needs to be turned off and back on. |
444 [hoverCloseButton_ setTrackingEnabled:NO]; | 454 [hoverCloseButton_ setTrackingEnabled:NO]; |
445 [hoverCloseButton_ setFrame:bounds]; | 455 [hoverCloseButton_ setFrame:bounds]; |
446 [hoverCloseButton_ setTrackingEnabled:YES]; | 456 [hoverCloseButton_ setTrackingEnabled:YES]; |
447 } | 457 } |
448 @end | 458 @end |
OLD | NEW |