OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/logging.h" // for NOTREACHED() | 7 #include "base/logging.h" // for NOTREACHED() |
8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "chrome/browser/cocoa/animatable_view.h" | 10 #import "chrome/browser/cocoa/animatable_view.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Force the frame size to be 0 and then start an animation. | 169 // Force the frame size to be 0 and then start an animation. |
170 NSRect frame = [[self view] frame]; | 170 NSRect frame = [[self view] frame]; |
171 CGFloat finalHeight = frame.size.height; | 171 CGFloat finalHeight = frame.size.height; |
172 frame.size.height = 0; | 172 frame.size.height = 0; |
173 [[self view] setFrame:frame]; | 173 [[self view] setFrame:frame]; |
174 [[self animatableView] animateToNewHeight:finalHeight | 174 [[self animatableView] animateToNewHeight:finalHeight |
175 duration:kAnimateOpenDuration]; | 175 duration:kAnimateOpenDuration]; |
176 } | 176 } |
177 | 177 |
178 - (void)close { | 178 - (void)close { |
| 179 delegate_ = NULL; |
| 180 |
179 // Stop any running animations. | 181 // Stop any running animations. |
180 [[self animatableView] stopAnimation]; | 182 [[self animatableView] stopAnimation]; |
181 infoBarClosing_ = YES; | 183 infoBarClosing_ = YES; |
182 [self cleanUpAfterAnimation:YES]; | 184 [self cleanUpAfterAnimation:YES]; |
183 } | 185 } |
184 | 186 |
185 - (void)animateClosed { | 187 - (void)animateClosed { |
| 188 delegate_ = NULL; |
| 189 |
186 // Start animating closed. We will receive a notification when the animation | 190 // Start animating closed. We will receive a notification when the animation |
187 // is done, at which point we can remove our view from the hierarchy and | 191 // is done, at which point we can remove our view from the hierarchy. |
188 // notify the delegate that the infobar was closed. | |
189 [[self animatableView] animateToNewHeight:0 duration:kAnimateCloseDuration]; | 192 [[self animatableView] animateToNewHeight:0 duration:kAnimateCloseDuration]; |
190 | 193 |
191 // The above call may trigger an animationDidStop: notification for any | 194 // The above call may trigger an animationDidStop: notification for any |
192 // currently-running animations, so do not set |infoBarClosing_| until after | 195 // currently-running animations, so do not set |infoBarClosing_| until after |
193 // starting the animation. | 196 // starting the animation. |
194 infoBarClosing_ = YES; | 197 infoBarClosing_ = YES; |
195 } | 198 } |
196 | 199 |
197 - (void)addAdditionalControls { | 200 - (void)addAdditionalControls { |
198 // Default implementation does nothing. | 201 // Default implementation does nothing. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 [label_.get() setDrawsBackground:NO]; | 244 [label_.get() setDrawsBackground:NO]; |
242 [label_.get() setHorizontallyResizable:NO]; | 245 [label_.get() setHorizontallyResizable:NO]; |
243 [label_.get() setVerticallyResizable:NO]; | 246 [label_.get() setVerticallyResizable:NO]; |
244 } | 247 } |
245 | 248 |
246 - (void)removeInfoBar { | 249 - (void)removeInfoBar { |
247 // TODO(rohitrao): This method can be called even if the infobar has already | 250 // TODO(rohitrao): This method can be called even if the infobar has already |
248 // been removed and |delegate_| is NULL. Is there a way to rewrite the code | 251 // been removed and |delegate_| is NULL. Is there a way to rewrite the code |
249 // so that inner event loops don't cause us to try and remove the infobar | 252 // so that inner event loops don't cause us to try and remove the infobar |
250 // twice? http://crbug.com/54253 | 253 // twice? http://crbug.com/54253 |
251 [containerController_ removeDelegate:delegate_]; | 254 if (delegate_ != NULL) |
| 255 [containerController_ removeDelegate:delegate_]; |
252 } | 256 } |
253 | 257 |
254 - (void)cleanUpAfterAnimation:(BOOL)finished { | 258 - (void)cleanUpAfterAnimation:(BOOL)finished { |
255 // Don't need to do any cleanup if the bar was animating open. | 259 // Don't need to do any cleanup if the bar was animating open. |
256 if (!infoBarClosing_) | 260 if (!infoBarClosing_) |
257 return; | 261 return; |
258 | 262 |
259 // Notify the delegate that the infobar was closed. The delegate may delete | |
260 // itself as a result of InfoBarClosed(), so we null out its pointer. | |
261 if (delegate_) { | |
262 delegate_->InfoBarClosed(); | |
263 delegate_ = NULL; | |
264 } | |
265 | |
266 // If the animation ran to completion, then we need to remove ourselves from | 263 // If the animation ran to completion, then we need to remove ourselves from |
267 // the container. If the animation was interrupted, then the container will | 264 // the container. If the animation was interrupted, then the container will |
268 // take care of removing us. | 265 // take care of removing us. |
269 // TODO(rohitrao): UGH! This works for now, but should be cleaner. | 266 // TODO(rohitrao): UGH! This works for now, but should be cleaner. |
270 if (finished) | 267 if (finished) |
271 [containerController_ removeController:self]; | 268 [containerController_ removeController:self]; |
272 } | 269 } |
273 | 270 |
274 - (void)animationDidStop:(NSAnimation*)animation { | 271 - (void)animationDidStop:(NSAnimation*)animation { |
275 [self cleanUpAfterAnimation:NO]; | 272 [self cleanUpAfterAnimation:NO]; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 LinkInfoBarController* controller = | 522 LinkInfoBarController* controller = |
526 [[LinkInfoBarController alloc] initWithDelegate:this]; | 523 [[LinkInfoBarController alloc] initWithDelegate:this]; |
527 return new InfoBar(controller); | 524 return new InfoBar(controller); |
528 } | 525 } |
529 | 526 |
530 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 527 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
531 ConfirmInfoBarController* controller = | 528 ConfirmInfoBarController* controller = |
532 [[ConfirmInfoBarController alloc] initWithDelegate:this]; | 529 [[ConfirmInfoBarController alloc] initWithDelegate:this]; |
533 return new InfoBar(controller); | 530 return new InfoBar(controller); |
534 } | 531 } |
OLD | NEW |