| 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/constrained_window/constrained_window_custom_sh
eet.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 8 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 8 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
| 9 | 9 |
| 10 // Length of the animation in seconds. |
| 11 const NSTimeInterval kAnimationDuration = 0.18; |
| 12 |
| 10 @implementation CustomConstrainedWindowSheet | 13 @implementation CustomConstrainedWindowSheet |
| 11 | 14 |
| 12 - (id)initWithCustomWindow:(NSWindow*)customWindow { | 15 - (id)initWithCustomWindow:(NSWindow*)customWindow { |
| 13 if ((self = [super init])) { | 16 if ((self = [super init])) { |
| 14 customWindow_.reset([customWindow retain]); | 17 customWindow_.reset([customWindow retain]); |
| 15 } | 18 } |
| 16 return self; | 19 return self; |
| 17 } | 20 } |
| 18 | 21 |
| 19 - (void)showSheetForWindow:(NSWindow*)window { | 22 - (void)showSheetForWindow:(NSWindow*)window { |
| 20 base::scoped_nsobject<NSAnimation> animation( | |
| 21 [[ConstrainedWindowAnimationShow alloc] initWithWindow:customWindow_]); | |
| 22 [window addChildWindow:customWindow_ | 23 [window addChildWindow:customWindow_ |
| 23 ordered:NSWindowAbove]; | 24 ordered:NSWindowAbove]; |
| 24 [self unhideSheet]; | 25 [self unhideSheet]; |
| 25 [self updateSheetPosition]; | 26 [self updateSheetPosition]; |
| 26 [customWindow_ makeKeyAndOrderFront:nil]; | 27 [customWindow_ makeKeyAndOrderFront:nil]; |
| 27 [animation startAnimation]; | 28 [customWindow_ setAlphaValue:0.0]; |
| 29 [[NSAnimationContext currentContext] setDuration:kAnimationDuration]; |
| 30 [[customWindow_ animator] setAlphaValue:1.0]; |
| 28 } | 31 } |
| 29 | 32 |
| 30 - (void)closeSheetWithAnimation:(BOOL)withAnimation { | 33 - (void)closeSheetWithAnimation:(BOOL)withAnimation { |
| 31 if (withAnimation) { | 34 if (withAnimation) { |
| 35 // Use a blocking animation, rather than -[NSWindow animator]. |
| 36 NSArray* animationArray = @[ |
| 37 @{ |
| 38 NSViewAnimationTargetKey : customWindow_, |
| 39 NSViewAnimationEffectKey : NSViewAnimationFadeOutEffect, |
| 40 } |
| 41 ]; |
| 32 base::scoped_nsobject<NSAnimation> animation( | 42 base::scoped_nsobject<NSAnimation> animation( |
| 33 [[ConstrainedWindowAnimationHide alloc] initWithWindow:customWindow_]); | 43 [[NSViewAnimation alloc] initWithViewAnimations:animationArray]); |
| 44 [animation setDuration:kAnimationDuration]; |
| 45 [animation setAnimationBlockingMode:NSAnimationBlocking]; |
| 34 [animation startAnimation]; | 46 [animation startAnimation]; |
| 35 } | 47 } |
| 36 | 48 |
| 37 [[customWindow_ parentWindow] removeChildWindow:customWindow_]; | 49 [[customWindow_ parentWindow] removeChildWindow:customWindow_]; |
| 38 [customWindow_ close]; | 50 [customWindow_ close]; |
| 39 } | 51 } |
| 40 | 52 |
| 41 - (void)hideSheet { | 53 - (void)hideSheet { |
| 42 // Hide the sheet window, and any of its direct child windows, by setting the | 54 // Hide the sheet window, and any of its direct child windows, by setting the |
| 43 // alpha to 0. This technique is used instead of -orderOut: because that may | 55 // alpha to 0. This technique is used instead of -orderOut: because that may |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 87 |
| 76 - (void)resizeWithNewSize:(NSSize)size { | 88 - (void)resizeWithNewSize:(NSSize)size { |
| 77 // NOOP | 89 // NOOP |
| 78 } | 90 } |
| 79 | 91 |
| 80 - (NSWindow*)sheetWindow { | 92 - (NSWindow*)sheetWindow { |
| 81 return customWindow_; | 93 return customWindow_; |
| 82 } | 94 } |
| 83 | 95 |
| 84 @end | 96 @end |
| OLD | NEW |