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: Comments from tapted. 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 currentContext] setDuration:kAnimationDuration];
tapted 2016/03/15 00:39:40 I think we need a [NSAnimationContext beginGroupi
erikchen 2016/03/15 00:52:25 Done.
41 [[customWindow_ animator] setAlphaValue:1.0];
42 } else {
43 [animation startAnimation];
44 }
28 } 45 }
29 46
30 - (void)closeSheetWithAnimation:(BOOL)withAnimation { 47 - (void)closeSheetWithAnimation:(BOOL)withAnimation {
31 if (withAnimation) { 48 if (withAnimation) {
32 base::scoped_nsobject<NSAnimation> animation( 49 base::scoped_nsobject<NSAnimation> animation;
33 [[ConstrainedWindowAnimationHide alloc] initWithWindow:customWindow_]); 50 if (useSimpleAnimations_) {
51 // Use a blocking animation, rather than -[NSWindow animator].
52 NSArray* animationArray = @[ @{
53 NSViewAnimationTargetKey : customWindow_,
54 NSViewAnimationEffectKey : NSViewAnimationFadeOutEffect,
55 } ];
56 animation.reset(
57 [[NSViewAnimation alloc] initWithViewAnimations:animationArray]);
58 [animation setDuration:kAnimationDuration];
59 [animation setAnimationBlockingMode:NSAnimationBlocking];
60 } else {
61 animation.reset([[ConstrainedWindowAnimationHide alloc]
62 initWithWindow:customWindow_]);
63 }
34 [animation startAnimation]; 64 [animation startAnimation];
35 } 65 }
36 66
37 [[customWindow_ parentWindow] removeChildWindow:customWindow_]; 67 [[customWindow_ parentWindow] removeChildWindow:customWindow_];
38 [customWindow_ close]; 68 [customWindow_ close];
39 } 69 }
40 70
41 - (void)hideSheet { 71 - (void)hideSheet {
42 // Hide the sheet window, and any of its direct child windows, by setting the 72 // 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 73 // 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 105
76 - (void)resizeWithNewSize:(NSSize)size { 106 - (void)resizeWithNewSize:(NSSize)size {
77 // NOOP 107 // NOOP
78 } 108 }
79 109
80 - (NSWindow*)sheetWindow { 110 - (NSWindow*)sheetWindow {
81 return customWindow_; 111 return customWindow_;
82 } 112 }
83 113
84 @end 114 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698