Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.mm

Issue 1787553003: mac: Remove uses of a CoreGraphics private API that causes WindowServer crashes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add semicolons. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
22 - (void)setUseSimpleAnimations:(BOOL)simpleAnimations {
23 useSimpleAnimations_ = simpleAnimations;
24 }
25
19 - (void)showSheetForWindow:(NSWindow*)window { 26 - (void)showSheetForWindow:(NSWindow*)window {
20 base::scoped_nsobject<NSAnimation> animation( 27 base::scoped_nsobject<NSAnimation> animation;
21 [[ConstrainedWindowAnimationShow alloc] initWithWindow:customWindow_]); 28 if (!useSimpleAnimations_) {
29 animation.reset(
30 [[ConstrainedWindowAnimationShow alloc] initWithWindow:customWindow_]);
31 }
22 [window addChildWindow:customWindow_ 32 [window addChildWindow:customWindow_
23 ordered:NSWindowAbove]; 33 ordered:NSWindowAbove];
24 [self unhideSheet]; 34 [self unhideSheet];
25 [self updateSheetPosition]; 35 [self updateSheetPosition];
26 [customWindow_ makeKeyAndOrderFront:nil]; 36 [customWindow_ makeKeyAndOrderFront:nil];
27 [animation startAnimation]; 37
38 if (useSimpleAnimations_) {
39 [customWindow_ setAlphaValue:0.0];
40 [NSAnimationContext beginGrouping];
41 [[NSAnimationContext currentContext] setDuration:kAnimationDuration];
42 [[customWindow_ animator] setAlphaValue:1.0];
43 [NSAnimationContext endGrouping];
44 } else {
45 [animation startAnimation];
46 }
28 } 47 }
29 48
30 - (void)closeSheetWithAnimation:(BOOL)withAnimation { 49 - (void)closeSheetWithAnimation:(BOOL)withAnimation {
31 if (withAnimation) { 50 if (withAnimation) {
32 base::scoped_nsobject<NSAnimation> animation( 51 base::scoped_nsobject<NSAnimation> animation;
33 [[ConstrainedWindowAnimationHide alloc] initWithWindow:customWindow_]); 52 if (useSimpleAnimations_) {
53 // Use a blocking animation, rather than -[NSWindow animator].
54 NSArray* animationArray = @[ @{
55 NSViewAnimationTargetKey : customWindow_,
56 NSViewAnimationEffectKey : NSViewAnimationFadeOutEffect,
57 } ];
58 animation.reset(
59 [[NSViewAnimation alloc] initWithViewAnimations:animationArray]);
60 [animation setDuration:kAnimationDuration];
61 [animation setAnimationBlockingMode:NSAnimationBlocking];
62 } else {
63 animation.reset([[ConstrainedWindowAnimationHide alloc]
64 initWithWindow:customWindow_]);
65 }
34 [animation startAnimation]; 66 [animation startAnimation];
35 } 67 }
36 68
37 [[customWindow_ parentWindow] removeChildWindow:customWindow_]; 69 [[customWindow_ parentWindow] removeChildWindow:customWindow_];
38 [customWindow_ close]; 70 [customWindow_ close];
39 } 71 }
40 72
41 - (void)hideSheet { 73 - (void)hideSheet {
42 // Hide the sheet window, and any of its direct child windows, by setting the 74 // 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 75 // 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
75 107
76 - (void)resizeWithNewSize:(NSSize)size { 108 - (void)resizeWithNewSize:(NSSize)size {
77 // NOOP 109 // NOOP
78 } 110 }
79 111
80 - (NSWindow*)sheetWindow { 112 - (NSWindow*)sheetWindow {
81 return customWindow_; 113 return customWindow_;
82 } 114 }
83 115
84 @end 116 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698