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 "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/download/download_stats.h" | 9 #include "chrome/browser/download/download_stats.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 selector:@selector(willEnterFullscreen) | 134 selector:@selector(willEnterFullscreen) |
135 name:kWillEnterFullscreenNotification | 135 name:kWillEnterFullscreenNotification |
136 object:nil]; | 136 object:nil]; |
137 [defaultCenter addObserver:self | 137 [defaultCenter addObserver:self |
138 selector:@selector(willLeaveFullscreen) | 138 selector:@selector(willLeaveFullscreen) |
139 name:kWillLeaveFullscreenNotification | 139 name:kWillLeaveFullscreenNotification |
140 object:nil]; | 140 object:nil]; |
141 [self installTrackingArea]; | 141 [self installTrackingArea]; |
142 } | 142 } |
143 | 143 |
144 - (void)dealloc { | 144 - (void)browserWillBeDestroyed { |
145 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 145 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 146 |
| 147 // We need to explicitly release our download controllers here since they need |
| 148 // to remove themselves as observers before the remaining shutdown happens. |
| 149 [[self animatableView] stopAnimation]; |
| 150 [self removeTrackingArea]; |
146 [self cancelAutoClose]; | 151 [self cancelAutoClose]; |
147 [self removeTrackingArea]; | 152 while ([downloadItemControllers_ count] > 0) { |
| 153 [self removeDownload:[downloadItemControllers_ lastObject] |
| 154 isShelfClosing:YES]; |
| 155 } |
| 156 downloadItemControllers_.reset(); |
148 | 157 |
149 // The controllers will unregister themselves as observers when they are | 158 bridge_.reset(); |
150 // deallocated. No need to do that here. | 159 navigator_ = nullptr; |
151 [super dealloc]; | |
152 } | 160 } |
153 | 161 |
154 // Called after the frame's rect has changed; usually when the height is | 162 // Called after the frame's rect has changed; usually when the height is |
155 // animated. | 163 // animated. |
156 - (void)viewFrameDidChange:(NSNotification*)notification { | 164 - (void)viewFrameDidChange:(NSNotification*)notification { |
157 // Anchor subviews at the top of |view|, so that it looks like the shelf | 165 // Anchor subviews at the top of |view|, so that it looks like the shelf |
158 // is sliding out. | 166 // is sliding out. |
159 CGFloat newShelfHeight = NSHeight([[self view] frame]); | 167 CGFloat newShelfHeight = NSHeight([[self view] frame]); |
160 if (newShelfHeight == currentShelfHeight_) | 168 if (newShelfHeight == currentShelfHeight_) |
161 return; | 169 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 [self maybeAutoCloseAfterDelay]; | 214 [self maybeAutoCloseAfterDelay]; |
207 } | 215 } |
208 } | 216 } |
209 | 217 |
210 - (void)downloadWasOpened:(DownloadItemController*)item_controller { | 218 - (void)downloadWasOpened:(DownloadItemController*)item_controller { |
211 // This should only be called on the main thead. | 219 // This should only be called on the main thead. |
212 DCHECK([NSThread isMainThread]); | 220 DCHECK([NSThread isMainThread]); |
213 [self maybeAutoCloseAfterDelay]; | 221 [self maybeAutoCloseAfterDelay]; |
214 } | 222 } |
215 | 223 |
216 // We need to explicitly release our download controllers here since they need | |
217 // to remove themselves as observers before the remaining shutdown happens. | |
218 - (void)exiting { | |
219 [[self animatableView] stopAnimation]; | |
220 [self removeTrackingArea]; | |
221 [self cancelAutoClose]; | |
222 while ([downloadItemControllers_ count] > 0) { | |
223 [self removeDownload:[downloadItemControllers_ lastObject] | |
224 isShelfClosing:YES]; | |
225 } | |
226 downloadItemControllers_.reset(); | |
227 } | |
228 | |
229 - (void)showDownloadShelf:(BOOL)show | 224 - (void)showDownloadShelf:(BOOL)show |
230 isUserAction:(BOOL)isUserAction { | 225 isUserAction:(BOOL)isUserAction { |
231 [self cancelAutoClose]; | 226 [self cancelAutoClose]; |
232 shouldCloseOnMouseExit_ = NO; | 227 shouldCloseOnMouseExit_ = NO; |
233 | 228 |
234 if ([self isVisible] == show) | 229 if ([self isVisible] == show) |
235 return; | 230 return; |
236 | 231 |
237 if (!show) { | 232 if (!show) { |
238 int numInProgress = 0; | 233 int numInProgress = 0; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 499 } |
505 | 500 |
506 // Set the tracking off to create a new tracking area for the control. | 501 // Set the tracking off to create a new tracking area for the control. |
507 // When changing the bounds/frame on a HoverButton, the tracking isn't updated | 502 // When changing the bounds/frame on a HoverButton, the tracking isn't updated |
508 // correctly, it needs to be turned off and back on. | 503 // correctly, it needs to be turned off and back on. |
509 [hoverCloseButton_ setTrackingEnabled:NO]; | 504 [hoverCloseButton_ setTrackingEnabled:NO]; |
510 [hoverCloseButton_ setFrame:bounds]; | 505 [hoverCloseButton_ setFrame:bounds]; |
511 [hoverCloseButton_ setTrackingEnabled:YES]; | 506 [hoverCloseButton_ setTrackingEnabled:YES]; |
512 } | 507 } |
513 @end | 508 @end |
OLD | NEW |