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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_fullscreen_transition.mm

Issue 1813693003: Fixed a fullscreen race condition on OSX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser_window_fullscreen_transition.h" 5 #import "chrome/browser/ui/cocoa/browser_window_fullscreen_transition.h"
6 6
7 #include <QuartzCore/QuartzCore.h> 7 #include <QuartzCore/QuartzCore.h>
8 8
9 #include "base/mac/bind_objc_block.h" 9 #include "base/mac/bind_objc_block.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/mac/mac_util.h" 11 #include "base/mac/mac_util.h"
12 #import "base/mac/sdk_forward_declarations.h" 12 #import "base/mac/sdk_forward_declarations.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 15 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
16 #import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h" 16 #import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h"
17 17
18 namespace { 18 namespace {
19 19
20 NSString* const kPrimaryWindowAnimationID = @"PrimaryWindowAnimationID"; 20 NSString* const kPrimaryWindowAnimationID = @"PrimaryWindowAnimationID";
21 NSString* const kSnapshotWindowAnimationID = @"SnapshotWindowAnimationID"; 21 NSString* const kSnapshotWindowAnimationID = @"SnapshotWindowAnimationID";
22 NSString* const kAnimationIDKey = @"AnimationIDKey"; 22 NSString* const kAnimationIDKey = @"AnimationIDKey";
23 23
24 // The fraction of the duration from AppKit's startCustomAnimation methods 24 // The fraction of the duration from AppKit's startCustomAnimation methods
25 // that we want our animation to run in. 25 // that we want our animation to run in. Yosemite's fraction is smaller
26 // since its fullscreen transition is significantly slower.
26 CGFloat const kAnimationDurationFraction = 0.5; 27 CGFloat const kAnimationDurationFraction = 0.5;
28 CGFloat const kAnimationDurationFractionYosemite = 0.3;
27 29
28 // This class has two simultaneous animations to resize and reposition layers. 30 // This class has two simultaneous animations to resize and reposition layers.
29 // These animations must use the same timing function, otherwise there will be 31 // These animations must use the same timing function, otherwise there will be
30 // visual discordance. 32 // visual discordance.
31 NSString* TransformAnimationTimingFunction() { 33 NSString* TransformAnimationTimingFunction() {
32 return kCAMediaTimingFunctionEaseInEaseOut; 34 return kCAMediaTimingFunctionEaseInEaseOut;
33 } 35 }
34 36
35 // This class locks and unlocks the FrameBrowserWindow. Its destructor ensures 37 // This class locks and unlocks the FrameBrowserWindow. Its destructor ensures
36 // that the lock gets released. 38 // that the lock gets released.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // The frame that |primaryWindow_| is expected to have after the transition 126 // The frame that |primaryWindow_| is expected to have after the transition
125 // is finished. 127 // is finished.
126 NSRect finalFrame_; 128 NSRect finalFrame_;
127 129
128 // This view draws the tabstrip background during the exit animation. 130 // This view draws the tabstrip background during the exit animation.
129 base::scoped_nsobject<FullscreenTabStripBackgroundView> 131 base::scoped_nsobject<FullscreenTabStripBackgroundView>
130 fullscreenTabStripBackgroundView_; 132 fullscreenTabStripBackgroundView_;
131 133
132 // Locks and unlocks the FullSizeContentWindow. 134 // Locks and unlocks the FullSizeContentWindow.
133 scoped_ptr<FrameAndStyleLock> lock_; 135 scoped_ptr<FrameAndStyleLock> lock_;
136
137 // Flag that indicates if the animation was completed. Sets to true at the
138 // end of the animation.
139 BOOL completedTransition_;
140
141 // Delegate that informs the state of the transition.
142 id<BrowserWindowFullscreenTransitionDelegate> delegate_; // weak
134 } 143 }
135 144
136 // Takes a snapshot of |primaryWindow_| and puts it in |snapshotLayer_|. 145 // Takes a snapshot of |primaryWindow_| and puts it in |snapshotLayer_|.
137 - (void)takeSnapshot; 146 - (void)takeSnapshot;
138 147
139 // Creates |snapshotWindow_| and adds |snapshotLayer_| to it. 148 // Creates |snapshotWindow_| and adds |snapshotLayer_| to it.
140 - (void)makeAndPrepareSnapshotWindow; 149 - (void)makeAndPrepareSnapshotWindow;
141 150
142 // This method has several effects on |primaryWindow_|: 151 // This method has several effects on |primaryWindow_|:
143 // - Saves current state. 152 // - Saves current state.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if ((self = [super init])) { 195 if ((self = [super init])) {
187 primaryWindow_.reset([window retain]); 196 primaryWindow_.reset([window retain]);
188 197
189 isEnteringFullscreen_ = YES; 198 isEnteringFullscreen_ = YES;
190 initialFrame_ = [primaryWindow_ frame]; 199 initialFrame_ = [primaryWindow_ frame];
191 finalFrame_ = [[primaryWindow_ screen] frame]; 200 finalFrame_ = [[primaryWindow_ screen] frame];
192 } 201 }
193 return self; 202 return self;
194 } 203 }
195 204
196 - (instancetype)initExitWithWindow:(FramedBrowserWindow*)window 205 - (instancetype)
197 frame:(NSRect)frame 206 initExitWithWindow:(FramedBrowserWindow*)window
198 tabStripBackgroundView:(NSView*)view { 207 delegate:(id<BrowserWindowFullscreenTransitionDelegate>)delegate
208 frame:(NSRect)frame
209 tabStripBackgroundView:(NSView*)view {
199 DCHECK(window); 210 DCHECK(window);
200 DCHECK([self rootLayerOfWindow:window]); 211 DCHECK([self rootLayerOfWindow:window]);
201 if ((self = [super init])) { 212 if ((self = [super init])) {
202 primaryWindow_.reset([window retain]); 213 primaryWindow_.reset([window retain]);
203 tabStripBackgroundView_.reset([view retain]); 214 tabStripBackgroundView_.reset([view retain]);
204 isEnteringFullscreen_ = NO; 215 isEnteringFullscreen_ = NO;
205 finalFrame_ = frame; 216 finalFrame_ = frame;
206 initialFrame_ = [[primaryWindow_ screen] frame]; 217 initialFrame_ = [[primaryWindow_ screen] frame];
218 delegate_ = delegate;
207 219
208 lock_.reset(new FrameAndStyleLock(window)); 220 lock_.reset(new FrameAndStyleLock(window));
209 } 221 }
210 return self; 222 return self;
211 } 223 }
212 224
213 - (NSArray*)customWindowsForFullScreenTransition { 225 - (NSArray*)customWindowsForFullScreenTransition {
214 [self takeSnapshot]; 226 [self takeSnapshot];
215 [self makeAndPrepareSnapshotWindow]; 227 [self makeAndPrepareSnapshotWindow];
216 return @[ primaryWindow_.get(), snapshotWindow_.get() ]; 228 return @[ primaryWindow_.get(), snapshotWindow_.get() ];
217 } 229 }
218 230
231 - (BOOL)isTransitionCompleted {
232 return completedTransition_;
233 }
234
219 - (void)startCustomFullScreenAnimationWithDuration:(NSTimeInterval)duration { 235 - (void)startCustomFullScreenAnimationWithDuration:(NSTimeInterval)duration {
220 CGFloat animationDuration = duration * kAnimationDurationFraction; 236 CGFloat durationFraction = base::mac::IsOSYosemite()
237 ? kAnimationDurationFractionYosemite
238 : kAnimationDurationFraction;
239 CGFloat animationDuration = duration * durationFraction;
221 [self preparePrimaryWindowForAnimation]; 240 [self preparePrimaryWindowForAnimation];
222 [self animatePrimaryWindowWithDuration:animationDuration]; 241 [self animatePrimaryWindowWithDuration:animationDuration];
223 [self animateSnapshotWindowWithDuration:animationDuration]; 242 [self animateSnapshotWindowWithDuration:animationDuration];
224 } 243 }
225 244
226 - (BOOL)shouldWindowBeUnconstrained { 245 - (BOOL)shouldWindowBeUnconstrained {
227 return changingPrimaryWindowSize_; 246 return changingPrimaryWindowSize_;
228 } 247 }
229 248
230 - (NSSize)desiredWindowLayoutSize { 249 - (NSSize)desiredWindowLayoutSize {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 DCHECK_EQ(NSWidth(content.frame), expectedSize.width); 514 DCHECK_EQ(NSWidth(content.frame), expectedSize.width);
496 515
497 // Restore the state of the primary window and make it visible again. 516 // Restore the state of the primary window and make it visible again.
498 [primaryWindow_ setOpaque:primaryWindowInitialOpaque_]; 517 [primaryWindow_ setOpaque:primaryWindowInitialOpaque_];
499 [primaryWindow_ setBackgroundColor:primaryWindowInitialBackgroundColor_]; 518 [primaryWindow_ setBackgroundColor:primaryWindowInitialBackgroundColor_];
500 519
501 CALayer* root = [self rootLayerOfWindow:primaryWindow_]; 520 CALayer* root = [self rootLayerOfWindow:primaryWindow_];
502 [root removeAnimationForKey:kPrimaryWindowAnimationID]; 521 [root removeAnimationForKey:kPrimaryWindowAnimationID];
503 root.opacity = 1; 522 root.opacity = 1;
504 } 523 }
524
525 completedTransition_ = YES;
526
527 if (!isEnteringFullscreen_)
528 [delegate_ finishedExitingFullscreen];
505 } 529 }
506 530
507 - (CALayer*)rootLayerOfWindow:(NSWindow*)window { 531 - (CALayer*)rootLayerOfWindow:(NSWindow*)window {
508 return [[[window contentView] superview] layer]; 532 return [[[window contentView] superview] layer];
509 } 533 }
510 534
511 - (NSPoint)pointRelativeToCurrentScreen:(NSPoint)point { 535 - (NSPoint)pointRelativeToCurrentScreen:(NSPoint)point {
512 NSRect screenFrame = [[primaryWindow_ screen] frame]; 536 NSRect screenFrame = [[primaryWindow_ screen] frame];
513 return NSMakePoint(point.x - screenFrame.origin.x, 537 return NSMakePoint(point.x - screenFrame.origin.x,
514 point.y - screenFrame.origin.y); 538 point.y - screenFrame.origin.y);
515 } 539 }
516 540
517 @end 541 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698