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

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

Issue 1850313002: Fix Fullscreen Animation Crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_fullscreen_transition.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // - Set the size to the screen's size. 157 // - Set the size to the screen's size.
158 - (void)preparePrimaryWindowForAnimation; 158 - (void)preparePrimaryWindowForAnimation;
159 159
160 // Applies the fullscreen animation to |snapshotLayer_|. 160 // Applies the fullscreen animation to |snapshotLayer_|.
161 - (void)animateSnapshotWindowWithDuration:(CGFloat)duration; 161 - (void)animateSnapshotWindowWithDuration:(CGFloat)duration;
162 162
163 // Sets |primaryWindow_|'s frame to the expected frame. 163 // Sets |primaryWindow_|'s frame to the expected frame.
164 - (void)changePrimaryWindowToFinalFrame; 164 - (void)changePrimaryWindowToFinalFrame;
165 165
166 // Override of CAAnimation delegate method. 166 // Override of CAAnimation delegate method.
167 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag; 167 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished;
168 168
169 // Returns the layer of the root view of |window|. 169 // Returns the layer of the root view of |window|.
170 - (CALayer*)rootLayerOfWindow:(NSWindow*)window; 170 - (CALayer*)rootLayerOfWindow:(NSWindow*)window;
171 171
172 // Convert the point to be relative to the screen the primary window is on. 172 // Convert the point to be relative to the screen the primary window is on.
173 // This is important because if we're using multiple screens, the coordinate 173 // This is important because if we're using multiple screens, the coordinate
174 // system extends to the second screen. 174 // system extends to the second screen.
175 // 175 //
176 // For example, if the screen width is 1440, the second screen's frame origin 176 // For example, if the screen width is 1440, the second screen's frame origin
177 // is located at (1440, 0) and any x coordinate on the second screen will be 177 // is located at (1440, 0) and any x coordinate on the second screen will be
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 - (BOOL)shouldWindowBeUnconstrained { 248 - (BOOL)shouldWindowBeUnconstrained {
249 return changingPrimaryWindowSize_; 249 return changingPrimaryWindowSize_;
250 } 250 }
251 251
252 - (NSSize)desiredWindowLayoutSize { 252 - (NSSize)desiredWindowLayoutSize {
253 return isEnteringFullscreen_ ? [primaryWindow_ frame].size 253 return isEnteringFullscreen_ ? [primaryWindow_ frame].size
254 : [[primaryWindow_ contentView] bounds].size; 254 : [[primaryWindow_ contentView] bounds].size;
255 } 255 }
256 256
257 - (void)browserWillBeDestroyed {
258 CALayer* root = [self rootLayerOfWindow:primaryWindow_];
259 [root removeAllAnimations];
260 [snapshotLayer_ removeAllAnimations];
261
262 controller_ = nullptr;
Robert Sesek 2016/04/04 18:13:50 nullptr -> nil
spqchan 2016/04/04 18:40:35 Done.
263 }
264
257 // -------------------------Private Methods---------------------------- 265 // -------------------------Private Methods----------------------------
258 266
259 - (void)takeSnapshot { 267 - (void)takeSnapshot {
260 base::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( 268 base::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage(
261 CGRectNull, kCGWindowListOptionIncludingWindow, 269 CGRectNull, kCGWindowListOptionIncludingWindow,
262 [primaryWindow_ windowNumber], kCGWindowImageBoundsIgnoreFraming)); 270 [primaryWindow_ windowNumber], kCGWindowImageBoundsIgnoreFraming));
263 snapshotLayer_.reset([[CALayer alloc] init]); 271 snapshotLayer_.reset([[CALayer alloc] init]);
264 [snapshotLayer_ setFrame:NSRectToCGRect([primaryWindow_ frame])]; 272 [snapshotLayer_ setFrame:NSRectToCGRect([primaryWindow_ frame])];
265 [snapshotLayer_ setContents:static_cast<id>(windowSnapshot.get())]; 273 [snapshotLayer_ setContents:static_cast<id>(windowSnapshot.get())];
266 [snapshotLayer_ setAnchorPoint:CGPointMake(0, 0)]; 274 [snapshotLayer_ setAnchorPoint:CGPointMake(0, 0)];
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 CALayer* root = [self rootLayerOfWindow:primaryWindow_]; 474 CALayer* root = [self rootLayerOfWindow:primaryWindow_];
467 [root addAnimation:group forKey:kPrimaryWindowAnimationID]; 475 [root addAnimation:group forKey:kPrimaryWindowAnimationID];
468 } 476 }
469 477
470 - (void)changePrimaryWindowToFinalFrame { 478 - (void)changePrimaryWindowToFinalFrame {
471 changingPrimaryWindowSize_ = YES; 479 changingPrimaryWindowSize_ = YES;
472 [primaryWindow_ setFrame:finalFrame_ display:NO]; 480 [primaryWindow_ setFrame:finalFrame_ display:NO];
473 changingPrimaryWindowSize_ = NO; 481 changingPrimaryWindowSize_ = NO;
474 } 482 }
475 483
476 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag { 484 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished {
477 NSString* animationID = [theAnimation valueForKey:kAnimationIDKey]; 485 NSString* animationID = [theAnimation valueForKey:kAnimationIDKey];
478 486
479 // Remove the snapshot window. 487 // Remove the snapshot window.
480 if ([animationID isEqual:kSnapshotWindowAnimationID]) { 488 if ([animationID isEqual:kSnapshotWindowAnimationID]) {
481 [snapshotWindow_ orderOut:nil]; 489 [snapshotWindow_ orderOut:nil];
482 snapshotWindow_.reset(); 490 snapshotWindow_.reset();
483 snapshotLayer_.reset(); 491 snapshotLayer_.reset();
484 return; 492 return;
485 } 493 }
486 494
(...skipping 30 matching lines...) Expand all
517 DCHECK_EQ(NSWidth(content.frame), expectedSize.width); 525 DCHECK_EQ(NSWidth(content.frame), expectedSize.width);
518 526
519 // Restore the state of the primary window and make it visible again. 527 // Restore the state of the primary window and make it visible again.
520 [primaryWindow_ setOpaque:primaryWindowInitialOpaque_]; 528 [primaryWindow_ setOpaque:primaryWindowInitialOpaque_];
521 [primaryWindow_ setBackgroundColor:primaryWindowInitialBackgroundColor_]; 529 [primaryWindow_ setBackgroundColor:primaryWindowInitialBackgroundColor_];
522 530
523 CALayer* root = [self rootLayerOfWindow:primaryWindow_]; 531 CALayer* root = [self rootLayerOfWindow:primaryWindow_];
524 [root removeAnimationForKey:kPrimaryWindowAnimationID]; 532 [root removeAnimationForKey:kPrimaryWindowAnimationID];
525 root.opacity = 1; 533 root.opacity = 1;
526 534
527 if (!isEnteringFullscreen_) 535 completedTransition_ = YES;
536
537 if (!isEnteringFullscreen_ && controller_)
Robert Sesek 2016/04/04 18:13:50 Don't need the && controller_ since it's an ObjC o
spqchan 2016/04/04 18:40:35 Done.
528 [controller_ exitFullscreenAnimationFinished]; 538 [controller_ exitFullscreenAnimationFinished];
529 } 539 }
530
531 completedTransition_ = YES;
532 } 540 }
533 541
534 - (CALayer*)rootLayerOfWindow:(NSWindow*)window { 542 - (CALayer*)rootLayerOfWindow:(NSWindow*)window {
535 return [[[window contentView] superview] layer]; 543 return [[[window contentView] superview] layer];
536 } 544 }
537 545
538 - (NSPoint)pointRelativeToCurrentScreen:(NSPoint)point { 546 - (NSPoint)pointRelativeToCurrentScreen:(NSPoint)point {
539 NSRect screenFrame = [[primaryWindow_ screen] frame]; 547 NSRect screenFrame = [[primaryWindow_ screen] frame];
540 return NSMakePoint(point.x - screenFrame.origin.x, 548 return NSMakePoint(point.x - screenFrame.origin.x,
541 point.y - screenFrame.origin.y); 549 point.y - screenFrame.origin.y);
542 } 550 }
543 551
544 @end 552 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_fullscreen_transition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698