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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_animation.h"
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
10 @implementation CustomConstrainedWindowSheet
12 - (id)initWithCustomWindow:(NSWindow*)customWindow {
13 if ((self = [super init])) {
14 customWindow_.reset([customWindow retain]);
19 - (void)showSheetForWindow:(NSWindow*)window {
20 base::scoped_nsobject<NSAnimation> animation(
21 [[ConstrainedWindowAnimationShow alloc] initWithWindow:customWindow_]);
22 [window addChildWindow:customWindow_
23 ordered:NSWindowAbove];
25 [self updateSheetPosition];
26 [customWindow_ makeKeyAndOrderFront:nil];
27 [animation startAnimation];
30 - (void)closeSheetWithAnimation:(BOOL)withAnimation {
32 base::scoped_nsobject<NSAnimation> animation(
33 [[ConstrainedWindowAnimationHide alloc] initWithWindow:customWindow_]);
34 [animation startAnimation];
37 [[customWindow_ parentWindow] removeChildWindow:customWindow_];
38 [customWindow_ close];
42 // 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
44 // cause a Spaces change or window ordering change.
45 [customWindow_ setAlphaValue:0.0];
46 for (NSWindow* window : [customWindow_ childWindows]) {
47 [window setAlphaValue:0.0];
52 [customWindow_ setAlphaValue:1.0];
53 for (NSWindow* window : [customWindow_ childWindows]) {
54 [window setAlphaValue:1.0];
59 base::scoped_nsobject<NSAnimation> animation(
60 [[ConstrainedWindowAnimationPulse alloc] initWithWindow:customWindow_]);
61 [animation startAnimation];
64 - (void)makeSheetKeyAndOrderFront {
65 [customWindow_ makeKeyAndOrderFront:nil];
68 - (void)updateSheetPosition {
69 ConstrainedWindowSheetController* controller =
70 [ConstrainedWindowSheetController controllerForSheet:self];
71 NSPoint origin = [controller originForSheet:self
72 withWindowSize:[customWindow_ frame].size];
73 [customWindow_ setFrameOrigin:origin];