Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_FULLSCREEN_TRANSITION_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_FULLSCREEN_TRANSITION_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_FULLSCREEN_TRANSITION_H_ | 6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_FULLSCREEN_TRANSITION_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 @class FramedBrowserWindow; | |
| 11 | |
| 10 // This class is responsible for managing the custom transition of a | 12 // This class is responsible for managing the custom transition of a |
| 11 // BrowserWindow from its normal state into an AppKit Fullscreen state. | 13 // BrowserWindow from its normal state into an AppKit Fullscreen state |
| 14 // and vice versa. | |
| 12 // | 15 // |
| 13 // By default, when AppKit Fullscreens a window, it creates a new virtual | 16 // By default, when AppKit Fullscreens a window, it creates a new virtual |
| 14 // desktop and slides it in from the right of the screen. At the same time, the | 17 // desktop and slides it in from the right of the screen. At the same time, the |
| 15 // old virtual desktop slides off to the left. This animation takes one second, | 18 // old virtual desktop slides off to the left. This animation takes one second, |
| 16 // and the time is not customizable without elevated privileges or a | 19 // and the time is not customizable without elevated privileges or a |
| 17 // self-modifying binary | 20 // self-modifying binary |
| 18 // (https://code.google.com/p/chromium/issues/detail?id=414527). During that | 21 // (https://code.google.com/p/chromium/issues/detail?id=414527). During that |
| 19 // second, no user interaction is possible. | 22 // second, no user interaction is possible. |
| 20 // | 23 // |
| 21 // The default implementation of the AppKit transition smoothly animates a | 24 // The default implementation of the AppKit transition smoothly animates a |
| 22 // window from its original size to the full size of the screen. At the | 25 // window from its original size to the expected size. At the |
| 23 // beginning of the animation, it takes a snapshot of the window's current | 26 // beginning of the animation, it takes a snapshot of the window's current |
| 24 // state. Then it resizes the window, calls drawRect: (theorized, not tested), | 27 // state. Then it resizes the window, calls drawRect: (theorized, not tested), |
| 25 // and takes a snapshot of the window's final state. The animation is a simple | 28 // and takes a snapshot of the window's final state. The animation is a simple |
| 26 // crossfade between the two snapshots. This has a flaw. Frequently, the | 29 // crossfade between the two snapshots. This has a flaw. Frequently, the |
| 27 // renderer has not yet drawn content for the resized window by the time | 30 // renderer has not yet drawn content for the resized window by the time |
| 28 // drawRect: is called. As a result, the animation is effectively a no-op. When | 31 // drawRect: is called. As a result, the animation is effectively a no-op. When |
| 29 // the animation is finished, the new web content flashes in. | 32 // the animation is finished, the new web content flashes in. |
| 30 // | 33 // |
| 31 // The window's delegate can override two methods to customize the transition. | 34 // The window's delegate can override four methods to customize the transition. |
| 32 // -customWindowsToEnterFullScreenForWindow: | 35 // -customWindowsToEnterFullScreenForWindow: |
| 33 // The return of this method is an array of NSWindows. Each window that is | 36 // The return of this method is an array of NSWindows. Each window that is |
| 34 // returned will be added to the new virtual desktop after the animation is | 37 // returned will be added to the new virtual desktop after the animation is |
| 35 // finished, but will not be a part of the animation itself. | 38 // finished, but will not be a part of the animation itself. |
| 36 // -window:startCustomAnimationToEnterFullScreenWithDuration: | 39 // -window:startCustomAnimationToEnterFullScreenWithDuration: |
| 37 // In this method, the window's delegate adds animations to the windows | 40 // In this method, the window's delegate adds animations to the windows |
| 38 // returned in the above method. | 41 // returned in the above method. |
| 42 // -customWindowsToExitFullScreenForWindow: | |
| 43 // This method is similar to customWindowsToEnterFullScreenForWindow, but | |
| 44 // will be used for exiting full screen | |
| 45 // -window:startCustomAnimationToExitFullScreenWithDuration: | |
| 46 // In this method, the window's delegate adds animations to the windows | |
| 47 // returned in the above method. | |
| 39 // | 48 // |
| 40 // The goal of this class is to mimic the default animation, but instead of | 49 // The goal of this class is to mimic the default animation, but instead of |
| 41 // taking a snapshot of the final web content, it uses the live web content | 50 // taking a snapshot of the final web content, it uses the live web content |
| 42 // during the animation. | 51 // during the animation. |
| 43 // | 52 // |
| 44 // See https://code.google.com/p/chromium/issues/detail?id=414527#c22 and its | 53 // See https://code.google.com/p/chromium/issues/detail?id=414527#c22 and its |
| 45 // preceding comments for a more detailed description of the implementation, | 54 // preceding comments for a more detailed description of the implementation, |
| 46 // and the reasoning behind the decisions made. | 55 // and the reasoning behind the decisions made. |
| 47 // | 56 // |
| 48 // Recommended usage: | 57 // Recommended usage for entering full screen: |
| 49 // (Override method on NSWindow's delegate) | 58 // (Override method on NSWindow's delegate): |
| 50 // - (NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow*)window { | 59 // - (NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow*)window { |
| 51 // self.transition = [[[BrowserWindowEnterFullscreenTransition alloc] | 60 // self.transition = [[[BrowserWindowEnterFullscreenTransition alloc] |
| 52 // initWithWindow:window] autorelease]; | 61 // initEnterWithWindow:window] autorelease]; |
| 53 // return [self.transition customWindowsToEnterFullScreen]; | 62 // return [self.transition customWindowsForFullScreen]; |
| 54 // } | 63 // } |
| 55 // | 64 // |
| 56 // (Override method on NSWindow's delegate) | 65 // (Override method on NSWindow's delegate) |
| 57 // - (void)window:(NSWindow*)window | 66 // - (void)window:(NSWindow*)window |
| 58 // startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { | 67 // startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { |
| 59 // [self.transition | 68 // [self.transition |
| 60 // startCustomAnimationToEnterFullScreenWithDuration:duration]; | 69 // startCustomFullScreenAnimationWithDuration:duration]; |
|
Andre
2015/08/13 23:03:18
nit: I think this will fit in a single line withou
spqchan1
2015/08/14 01:08:26
Done.
| |
| 61 // } | 70 // } |
| 62 // | 71 // |
| 63 // (Override method on NSWindow's delegate) | 72 // (Override method on NSWindow's delegate) |
| 64 // - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 73 // - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
| 65 // self.transition = nil; | 74 // self.transition = nil; |
| 66 // } | 75 // } |
| 67 // | 76 // |
| 68 // (Override method on NSWindow) | 77 // (Override method on NSWindow) |
| 69 // - (NSRect)constrainFrameRect:(NSRect)frame toScreen:(NSScreen*)screen { | 78 // - (NSRect)constrainFrameRect:(NSRect)frame toScreen:(NSScreen*)screen { |
| 70 // if (self.transition && ![self.transition shouldWindowBeConstrained]) | 79 // if (self.transition && ![self.transition shouldWindowBeConstrained]) |
| 71 // return frame; | 80 // return frame; |
| 72 // return [super constrainFrameRect:frame toScreen:screen]; | 81 // return [super constrainFrameRect:frame toScreen:screen]; |
| 73 // } | 82 // } |
| 83 // | |
| 84 // For exiting fullscreen, you should do the same as above, but you must | |
| 85 // override following methods instead. | |
| 86 // - customWindowsToExitFullScreenForWindow:, | |
| 87 // - startCustomAnimationToEnterFullScreenWithDuration: | |
| 88 // - windowDidExitFullScreen: | |
|
Andre
2015/08/13 23:03:19
nit: no spaces after '-'
spqchan1
2015/08/14 01:08:26
Done.
| |
| 89 // In addition, you should use initExitWithWindow:frame: instead of | |
| 90 // initEnterWithWindow:. For the frame parameter, you should pass the expected | |
| 91 // frame of the window at the end of the transition. If you want the window to | |
| 92 // resize and move to the frame it had before entering fullscreen, you will be | |
| 93 // responsible for saving the value of the frame and passing it to the | |
| 94 // parameter. | |
| 74 | 95 |
| 75 @interface BrowserWindowEnterFullscreenTransition : NSObject | 96 @interface BrowserWindowFullscreenTransition : NSObject |
| 76 | 97 |
| 77 // Designated initializer. |window| is the NSWindow that is going to be moved | 98 // Designated initializers. |window| is the NSWindow that is going to be moved |
| 78 // into a fullscreen Space (virtual desktop), and resized to have the same size | 99 // into a fullscreen Space (virtual desktop), and resized to have the same size |
| 79 // as the screen. |window|'s root view must be layer backed. | 100 // as the screen. |window|'s root view must be layer backed. |
| 80 - (instancetype)initWithWindow:(NSWindow*)window; | 101 // initEnterWithWindow will create a BrowserWindowFullscreenTransition that |
| 102 // enters fullscreen. initExitWithWindow will create one that exits fullscreen, | |
| 103 // using |frame| as the frame that |window| is going to transition into. | |
| 104 - (instancetype)initEnterWithWindow:(FramedBrowserWindow*)window; | |
| 105 - (instancetype)initExitWithWindow:(FramedBrowserWindow*)window | |
| 106 frame:(NSRect)frame; | |
| 81 | 107 |
| 82 // Returns the windows to be used in the custom transition. | 108 // Returns the windows to be used in the custom fullscreen transition. |
| 83 // - Takes a snapshot of the current window. | 109 - (NSArray*)customWindowsForFullScreenTransition; |
| 84 // - Makes a new snapshot window which shows the snapshot in the same | |
| 85 // location as the current window. | |
| 86 // - Adds the style mask NSFullScreenWindowMask to the current window. | |
| 87 // - Makes the current window transparent, and resizes the current window to | |
| 88 // be the same size as the screen. | |
| 89 - (NSArray*)customWindowsToEnterFullScreen; | |
| 90 | 110 |
| 91 // Begins the animations used for the custom fullscreen transition. | 111 // This method begins animation for exit or enter fullscreen transition. |
| 92 // - Animates the snapshot to the full size of the screen while fading it out. | 112 // In this method, the following happens: |
| 93 // - Animates the current window from it's original location to its final | 113 // - Animates the snapshot to the expected final size of the window while |
| 94 // location, while fading it in. | 114 // fading it out. |
| 115 // - Animates the current window from its original to final location and size | |
| 116 // while fading it in. | |
| 117 // If the transition is for exiting fullscreen, we would shrink the content view | |
| 118 // to the expected final size so that we can to avoid clipping from the | |
| 119 // window. | |
| 120 | |
|
Andre
2015/08/13 23:03:19
nit: this blank line makes the above comment not p
spqchan1
2015/08/14 01:08:26
Done.
| |
| 95 // Note: The two animations are added to different layers in different windows. | 121 // Note: The two animations are added to different layers in different windows. |
| 96 // There is no explicit logic to keep the two animations in sync. If this | 122 // There is no explicit logic to keep the two animations in sync. If this |
| 97 // proves to be a problem, the relevant layers should attempt to sync up their | 123 // proves to be a problem, the relevant layers should attempt to sync up their |
| 98 // time offsets with CACurrentMediaTime(). | 124 // time offsets with CACurrentMediaTime(). |
| 99 - (void)startCustomAnimationToEnterFullScreenWithDuration: | 125 - (void)startCustomFullScreenAnimationWithDuration:(NSTimeInterval)duration; |
| 100 (NSTimeInterval)duration; | |
| 101 | 126 |
| 102 // When this method returns true, the NSWindow method | 127 // When this method returns true, the NSWindow method |
| 103 // -constrainFrameRect:toScreen: must return the frame rect without | 128 // -constrainFrameRect:toScreen: must return the frame rect without |
| 104 // constraining it. The owner of the instance of this class is responsible for | 129 // constraining it. The owner of the instance of this class is responsible for |
| 105 // hooking up this logic. | 130 // hooking up this logic. |
| 106 - (BOOL)shouldWindowBeUnconstrained; | 131 - (BOOL)shouldWindowBeUnconstrained; |
| 107 | 132 |
| 133 // Returns the size of the window we expect the BrowserWindowLayout to have. | |
| 134 // During the exit fullscreen transition, the content size shrinks while the | |
| 135 // window frame stays the same. When that happens, we want to set the | |
| 136 // BrowserWindowLayout's window parameter to the content size instead of the | |
| 137 // actual window's size. | |
| 138 - (NSSize)getDesiredWindowLayoutSize; | |
|
Andre
2015/08/13 23:03:19
We don't usually use the 'get' prefix for Objectiv
spqchan1
2015/08/14 01:08:26
Done.
| |
| 139 | |
| 108 @end | 140 @end |
| 109 | 141 |
| 110 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_FULLSCREEN_TRANSITION_H_ | 142 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_FULLSCREEN_TRANSITION_H_ |
| OLD | NEW |