OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Cocoa/Cocoa.h> |
| 6 #import <QuartzCore/QuartzCore.h> |
| 7 |
| 8 #include "base/logging.h" |
| 9 #include "base/mac_util.h" |
| 10 #include "base/scoped_nsobject.h" |
| 11 #import "chrome/browser/cocoa/confirm_quit_panel_controller.h" |
| 12 |
| 13 @interface ConfirmQuitPanelController (Private) |
| 14 - (void)animateFadeOut; |
| 15 @end |
| 16 |
| 17 @implementation ConfirmQuitPanelController |
| 18 |
| 19 - (id)init { |
| 20 NSString* nibPath = |
| 21 [mac_util::MainAppBundle() pathForResource:@"ConfirmQuitPanel" |
| 22 ofType:@"nib"]; |
| 23 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| 24 } |
| 25 return self; |
| 26 } |
| 27 |
| 28 - (void)awakeFromNib { |
| 29 DCHECK([self window]); |
| 30 DCHECK_EQ(self, [[self window] delegate]); |
| 31 } |
| 32 |
| 33 - (void)windowWillClose:(NSNotification*)notif { |
| 34 // Release all animations because CAAnimation retains its delegate (self), |
| 35 // which will cause a retain cycle. Break it! |
| 36 [[self window] setAnimations:[NSDictionary dictionary]]; |
| 37 [self autorelease]; |
| 38 } |
| 39 |
| 40 - (void)showWindow:(id)sender { |
| 41 [[self window] center]; |
| 42 [[self window] setAlphaValue:1.0]; |
| 43 [super showWindow:sender]; |
| 44 } |
| 45 |
| 46 - (void)dismissPanel { |
| 47 [self performSelector:@selector(animateFadeOut) |
| 48 withObject:nil |
| 49 afterDelay:1.0]; |
| 50 } |
| 51 |
| 52 - (void)animateFadeOut { |
| 53 NSWindow* window = [self window]; |
| 54 scoped_nsobject<CAAnimation> animation( |
| 55 [[window animationForKey:@"alphaValue"] copy]); |
| 56 [animation setDelegate:self]; |
| 57 [animation setDuration:0.2]; |
| 58 NSMutableDictionary* dictionary = |
| 59 [NSMutableDictionary dictionaryWithDictionary:[window animations]]; |
| 60 [dictionary setObject:animation forKey:@"alphaValue"]; |
| 61 [window setAnimations:dictionary]; |
| 62 [[window animator] setAlphaValue:0.0]; |
| 63 } |
| 64 |
| 65 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag { |
| 66 [self close]; |
| 67 } |
| 68 |
| 69 @end |
OLD | NEW |