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