Commit 42df3182 authored by jer.noble@apple.com's avatar jer.noble@apple.com

2011-03-11 Jer Noble <jer.noble@apple.com>

        Reviewed by Anders Carlsson.

        Add full screen animation code to WebFullScreenManager.
        https://bugs.webkit.org/show_bug.cgi?id=56220

        * WebProcess/FullScreen/WebFullScreenManager.cpp: .
        (WebKit::WebFullScreenManager::~WebFullScreenManager): Added.
        (WebKit::WebFullScreenManager::exitFullScreenForElement): Remove ASSERTs.
        (WebKit::WebFullScreenManager::willEnterFullScreen): Set the full screen renderer's background color.
        (WebKit::WebFullScreenManager::didEnterFullScreen): Ditto.
        (WebKit::WebFullScreenManager::willExitFullScreen): Ditto.
        (WebKit::WebFullScreenManager::didExitFullScreen): Ditto.
        * WebProcess/FullScreen/WebFullScreenManager.h: Make a few functions pure virtual to be implemented in a
            concrete subclass.
        * WebProcess/FullScreen/mac/WebFullScreenManagerMac.h: Added.
        * WebProcess/FullScreen/mac/WebFullScreenManagerMac.mm: Added.
        (-[WebFullScreenManagerAnimationListener initWithManager:WebKit::began:finished:]): Listener for CAAnimations.
        (-[WebFullScreenManagerAnimationListener animationDidStart:]): Added.
        (-[WebFullScreenManagerAnimationListener animationDidStop:finished:]): Added.
        (-[WebFullScreenManagerAnimationListener invalidate]): Added.
        (WebKit::WebFullScreenManager::create): Now creates a WebFullScreenManagerMac.
        (WebKit::WebFullScreenManagerMac::create): Added.
        (WebKit::WebFullScreenManagerMac::WebFullScreenManagerMac): Added.
        (WebKit::WebFullScreenManagerMac::~WebFullScreenManagerMac): Added.
        (WebKit::WebFullScreenManagerMac::setRootFullScreenLayer): Set up the remote layer host.
        (WebKit::WebFullScreenManagerMac::beginEnterFullScreenAnimation): Create a CATransform3D
            which will animate the full screen renderer from its initial position to its final one.
        (WebKit::WebFullScreenManagerMac::beginExitFullScreenAnimation): Ditto.

git-svn-id: svn://svn.chromium.org/blink/trunk@80923 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 15c749a0
/* /*
* Copyright (C) 2010 Apple Inc. All rights reserved. * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
......
/* /*
* Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved. * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
......
2011-03-11 Jer Noble <jer.noble@apple.com>
Reviewed by Anders Carlsson.
Add the WKFullScreenWindowController, mostly cribbed from WebKit's WebFullScreenController.
[WebKit2] Implement a full screen window controller
https://bugs.webkit.org/show_bug.cgi?id=56210
* UIProcess/mac/WKFullScreenWindowController.h: Added.
* UIProcess/mac/WKFullScreenWindowController.mm: Added.
(-[WKFullScreenWindowController init]): Remove the _mediaEventListener.
(-[WKFullScreenWindowController dealloc]): Make sure to cancel previous async requests.
(-[WKFullScreenWindowController windowDidLoad]): Remove the Tiger protection.
(-[WKFullScreenWindowController webView]): Type change.
(-[WKFullScreenWindowController setWebView:]): Type change.
(-[WKFullScreenWindowController applicationDidResignActive:]): Case changes.
(-[WKFullScreenWindowController applicationDidChangeScreenParameters:]): Case changes.
(-[WKFullScreenWindowController enterFullScreen:]): Removed most of the animation code
which will reappear in WebFullScreenManager.
(-[WKFullScreenWindowController beganEnterFullScreenAnimation]): Added.
(-[WKFullScreenWindowController finishedEnterFullScreenAnimation:]): Added.
(-[WKFullScreenWindowController exitFullScreen]): Ditto to enterFullScreen.
(-[WKFullScreenWindowController beganExitFullScreenAnimation]): Added.
(-[WKFullScreenWindowController finishedExitFullScreenAnimation:]): Added.
(-[WKFullScreenWindowController enterAcceleratedCompositingMode:WebKit::]): Set up the
layer tree host.
(-[WKFullScreenWindowController exitAcceleratedCompositingMode]): Tear down same.
(-[WKFullScreenWindowController getFullScreenRect:WebCore::]): Added.
(-[WKFullScreenWindowController _updateMenuAndDockForFullScreen]): Case changes.
(-[WKFullScreenWindowController _disableIdleDisplaySleep]): Ditto.
(-[WKFullScreenWindowController _enableIdleDisplaySleep]): Ditto.
(-[WKFullScreenWindowController _disableIdleSystemSleep]): Ditto.
(-[WKFullScreenWindowController _enableIdleSystemSleep]): Ditto.
(-[WKFullScreenWindowController _enableTickleTimer]): Ditto.
(-[WKFullScreenWindowController _disableTickleTimer]): Ditto.
(-[WKFullScreenWindowController _tickleTimerFired]): Ditto.
(-[WKFullScreenWindowController _updatePowerAssertions]): Use _isPlaying ivar.
(-[WKFullScreenWindowController _manager]): Added.
(-[WKFullScreenWindowController _requestExit]): Case changes.
(-[WKFullScreenWindowController _requestExitFullScreenWithAnimation:]): Ditto.
(-[WKFullScreenWindowController _swapView:with:]): Added.
(-[WKFullScreenWindowController _fullScreenWindow]): Case changes.
(-[WKFullScreenWindow initWithContentRect:styleMask:backing:defer:]): Geometry no
longer needs to be flipped.
(-[WKFullScreenWindow cancelOperation:]): Case changes.
2011-03-11 Jer Noble <jer.noble@apple.com> 2011-03-11 Jer Noble <jer.noble@apple.com>
Reviewed by Anders Carlsson. Reviewed by Anders Carlsson.
......
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#if ENABLE(FULLSCREEN_API)
#import <Cocoa/Cocoa.h>
#import <wtf/RetainPtr.h>
namespace WebKit {
class LayerTreeContext;
}
namespace WebCore {
class IntRect;
}
@class WKView;
@interface WKFullScreenWindowController : NSWindowController {
@private
WKView *_webView;
RetainPtr<NSView> _webViewPlaceholder;
RetainPtr<NSView> _layerViewPlaceholder;
RetainPtr<NSView> _layerHostingView;
BOOL _isAnimating;
BOOL _isFullScreen;
BOOL _isWindowLoaded;
BOOL _forceDisableAnimation;
BOOL _isPlaying;
CGRect _initialFrame;
uint32_t _idleDisplaySleepAssertion;
uint32_t _idleSystemSleepAssertion;
NSTimer *_tickleTimer;
}
- (WKView*)webView;
- (void)setWebView:(WKView*)webView;
- (void)enterFullScreen:(NSScreen *)screen;
- (void)exitFullScreen;
- (void)beganEnterFullScreenAnimation;
- (void)beganExitFullScreenAnimation;
- (void)finishedEnterFullScreenAnimation:(bool)completed;
- (void)finishedExitFullScreenAnimation:(bool)completed;
- (void)enterAcceleratedCompositingMode:(const WebKit::LayerTreeContext&)context;
- (void)exitAcceleratedCompositingMode;
- (WebCore::IntRect)getFullScreenRect;
@end
#endif
/*
* Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#if ENABLE(FULLSCREEN_API)
#import "WKFullScreenWindowController.h"
#import "LayerTreeContext.h"
#import "WebPageProxy.h"
#import "WebFullScreenManagerProxy.h"
#import "WKAPICast.h"
#import "WKViewInternal.h"
#import <IOKit/pwr_mgt/IOPMLib.h> // For IOPMAssertionCreate()
#import <HIToolbox/MacApplication.h> // For SetSystemUIMode()
#import <QuartzCore/QuartzCore.h>
#import <WebCore/IntRect.h>
#import <WebCore/FloatRect.h>
#import <WebKitSystemInterface.h>
static const NSTimeInterval tickleTimerInterval = 1.0;
using namespace WebKit;
using namespace WebCore;
#if defined(BUILDING_ON_LEOPARD)
@interface CATransaction(SnowLeopardConvenienceFunctions)
+ (void)setDisableActions:(BOOL)flag;
+ (void)setAnimationDuration:(CFTimeInterval)dur;
@end
@implementation CATransaction(SnowLeopardConvenienceFunctions)
+ (void)setDisableActions:(BOOL)flag
{
[self setValue:[NSNumber numberWithBool:flag] forKey:kCATransactionDisableActions];
}
+ (void)setAnimationDuration:(CFTimeInterval)dur
{
[self setValue:[NSNumber numberWithDouble:dur] forKey:kCATransactionAnimationDuration];
}
@end
#endif
@interface WKFullScreenWindow : NSWindow
{
NSView* _animationView;
CALayer* _backgroundLayer;
}
- (CALayer*)backgroundLayer;
- (NSView*)animationView;
@end
@interface WKFullScreenWindowController(Private)
- (void)_requestExitFullScreenWithAnimation:(BOOL)animation;
- (void)_updateMenuAndDockForFullScreen;
- (void)_updatePowerAssertions;
- (WKFullScreenWindow *)_fullScreenWindow;
- (CFTimeInterval)_animationDuration;
- (void)_swapView:(NSView*)view with:(NSView*)otherView;
- (WebFullScreenManagerProxy*)_manager;
@end
@interface NSWindow(IsOnActiveSpaceAdditionForTigerAndLeopard)
- (BOOL)isOnActiveSpace;
@end
@implementation WKFullScreenWindowController
#pragma mark -
#pragma mark Initialization
- (id)init
{
NSWindow *window = [[WKFullScreenWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
self = [super initWithWindow:window];
[window release];
if (!self)
return nil;
[self windowDidLoad];
return self;
}
- (void)dealloc
{
[self setWebView:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidResignActive:) name:NSApplicationDidResignActiveNotification object:NSApp];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeScreenParameters:) name:NSApplicationDidChangeScreenParametersNotification object:NSApp];
}
#pragma mark -
#pragma mark Accessors
- (WKView*)webView
{
return _webView;
}
- (void)setWebView:(WKView *)webView
{
[webView retain];
[_webView release];
_webView = webView;
}
#pragma mark -
#pragma mark Notifications
- (void)applicationDidResignActive:(NSNotification*)notification
{
// Check to see if the fullScreenWindow is on the active space; this function is available
// on 10.6 and later, so default to YES if the function is not available:
NSWindow* fullScreenWindow = [self _fullScreenWindow];
BOOL isOnActiveSpace = ([fullScreenWindow respondsToSelector:@selector(isOnActiveSpace)] ? [fullScreenWindow isOnActiveSpace] : YES);
// Replicate the QuickTime Player (X) behavior when losing active application status:
// Is the fullScreen screen the main screen? (Note: this covers the case where only a
// single screen is available.) Is the fullScreen screen on the current space? IFF so,
// then exit fullScreen mode.
if ([fullScreenWindow screen] == [[NSScreen screens] objectAtIndex:0] && isOnActiveSpace)
[self _requestExitFullScreenWithAnimation:NO];
}
- (void)applicationDidChangeScreenParameters:(NSNotification*)notification
{
// The user may have changed the main screen by moving the menu bar, or they may have changed
// the Dock's size or location, or they may have changed the fullScreen screen's dimensions.
// Update our presentation parameters, and ensure that the full screen window occupies the
// entire screen:
[self _updateMenuAndDockForFullScreen];
NSWindow* window = [self window];
[window setFrame:[[window screen] frame] display:YES];
}
#pragma mark -
#pragma mark Exposed Interface
- (void)enterFullScreen:(NSScreen *)screen
{
if (_isFullScreen)
return;
_isFullScreen = YES;
_isAnimating = YES;
NSDisableScreenUpdates();
if (!screen)
screen = [NSScreen mainScreen];
NSRect screenFrame = [screen frame];
NSRect webViewFrame = [_webView convertRectToBase:[_webView frame]];
webViewFrame.origin = [[_webView window] convertBaseToScreen:webViewFrame.origin];
// In the case of a multi-monitor setup where the webView straddles two
// monitors, we must create a window large enough to contain the destination
// frame and the initial frame.
NSRect windowFrame = NSUnionRect(screenFrame, webViewFrame);
[[self window] setFrame:windowFrame display:YES];
CALayer* backgroundLayer = [[self _fullScreenWindow] backgroundLayer];
NSRect backgroundFrame = {[[self window] convertScreenToBase:screenFrame.origin], screenFrame.size};
backgroundFrame = [[[self window] contentView] convertRectFromBase:backgroundFrame];
[CATransaction begin];
[CATransaction setDisableActions:YES];
[backgroundLayer setFrame:backgroundFrame];
[CATransaction commit];
CFTimeInterval duration = [self _animationDuration];
[self _manager]->willEnterFullScreen();
[self _manager]->beginEnterFullScreenAnimation(duration);
}
- (void)beganEnterFullScreenAnimation
{
[self _updateMenuAndDockForFullScreen];
[self _updatePowerAssertions];
// In a previous incarnation, the NSWindow attached to this controller may have
// been on a different screen. Temporarily change the collectionBehavior of the window:
NSWindow* fullScreenWindow = [self window];
NSWindowCollectionBehavior behavior = [fullScreenWindow collectionBehavior];
[fullScreenWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
[fullScreenWindow makeKeyAndOrderFront:self];
[fullScreenWindow setCollectionBehavior:behavior];
// Start the opacity animation. We can use implicit animations here because we don't care when
// the animation finishes.
[CATransaction begin];
[CATransaction setAnimationDuration:[self _animationDuration]];
[[[self _fullScreenWindow] backgroundLayer] setOpacity:1];
[CATransaction commit];
NSEnableScreenUpdates();
_isAnimating = YES;
}
- (void)finishedEnterFullScreenAnimation:(bool)completed
{
NSDisableScreenUpdates();
if (completed) {
// Swap the webView placeholder into place.
if (!_webViewPlaceholder)
_webViewPlaceholder.adoptNS([[NSView alloc] init]);
[self _swapView:_webView with:_webViewPlaceholder.get()];
// Then insert the WebView into the full screen window
NSView* animationView = [[self _fullScreenWindow] animationView];
[animationView addSubview:_webView positioned:NSWindowBelow relativeTo:_layerHostingView.get()];
[_webView setFrame:[animationView bounds]];
// FIXME: In Barolo, orderIn will animate, which is not what we want. Find a way
// to work around this behavior.
//[[_webViewPlaceholder.get() window] orderOut:self];
[[self window] makeKeyAndOrderFront:self];
}
[self _manager]->didEnterFullScreen();
NSEnableScreenUpdates();
_isAnimating = NO;
}
- (void)exitFullScreen
{
if (!_isFullScreen)
return;
_isFullScreen = NO;
_isAnimating = YES;
NSDisableScreenUpdates();
[self _manager]->willExitFullScreen();
[self _manager]->beginExitFullScreenAnimation([self _animationDuration]);
}
- (void)beganExitFullScreenAnimation
{
[self _updateMenuAndDockForFullScreen];
[self _updatePowerAssertions];
// The user may have moved the fullScreen window in Spaces, so temporarily change
// the collectionBehavior of the webView's window:
NSWindow* webWindow = [[self webView] window];
NSWindowCollectionBehavior behavior = [webWindow collectionBehavior];
[webWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
[webWindow orderWindow:NSWindowBelow relativeTo:[[self window] windowNumber]];
[webWindow setCollectionBehavior:behavior];
// Swap the webView back into its original position:
[self _swapView:_webViewPlaceholder.get() with:_webView];
[CATransaction begin];
[CATransaction setAnimationDuration:[self _animationDuration]];
[[[self _fullScreenWindow] backgroundLayer] setOpacity:0];
[CATransaction commit];
NSEnableScreenUpdates();
_isAnimating = YES;
}
- (void)finishedExitFullScreenAnimation:(bool)completed
{
NSDisableScreenUpdates();
if (completed) {
[self _updateMenuAndDockForFullScreen];
[self _updatePowerAssertions];
[NSCursor setHiddenUntilMouseMoves:YES];
[[self window] orderOut:self];
[[_webView window] makeKeyAndOrderFront:self];
}
[self _manager]->didExitFullScreen();
NSEnableScreenUpdates();
_isAnimating = NO;
}
- (void)enterAcceleratedCompositingMode:(const WebKit::LayerTreeContext&)layerTreeContext
{
if (_layerHostingView)
return;
ASSERT(!layerTreeContext.isEmpty());
// Create an NSView that will host our layer tree.
_layerHostingView.adoptNS([[NSView alloc] initWithFrame:[[self window] frame]]);
[_layerHostingView.get() setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[CATransaction begin];
[CATransaction setDisableActions:YES];
[[[self window] contentView] addSubview:_layerHostingView.get()];
// Create a root layer that will back the NSView.
RetainPtr<CALayer> rootLayer(AdoptNS, [[CALayer alloc] init]);
#ifndef NDEBUG
[rootLayer.get() setName:@"Hosting root layer"];
#endif
CALayer *renderLayer = WKMakeRenderLayer(layerTreeContext.contextID);
[rootLayer.get() addSublayer:renderLayer];
[_layerHostingView.get() setLayer:rootLayer.get()];
[_layerHostingView.get() setWantsLayer:YES];
[CATransaction commit];
}
- (void)exitAcceleratedCompositingMode
{
if (!_layerHostingView)
return;
[_layerHostingView.get() removeFromSuperview];
[_layerHostingView.get() setLayer:nil];
[_layerHostingView.get() setWantsLayer:NO];
_layerHostingView = 0;
}
- (WebCore::IntRect)getFullScreenRect
{
return enclosingIntRect([[self window] frame]);
}
#pragma mark -
#pragma mark Internal Interface
- (void)_updateMenuAndDockForFullScreen
{
// NSApplicationPresentationOptions is available on > 10.6 only:
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
NSApplicationPresentationOptions options = NSApplicationPresentationDefault;
NSScreen* fullScreenScreen = [[self window] screen];
if (_isFullScreen) {
// Auto-hide the menu bar if the fullScreenScreen contains the menu bar:
// NOTE: if the fullScreenScreen contains the menu bar but not the dock, we must still
// auto-hide the dock, or an exception will be thrown.
if ([[NSScreen screens] objectAtIndex:0] == fullScreenScreen)
options |= (NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock);
// Check if the current screen contains the dock by comparing the screen's frame to its
// visibleFrame; if a dock is present, the visibleFrame will differ. If the current screen
// contains the dock, hide it.
else if (!NSEqualRects([fullScreenScreen frame], [fullScreenScreen visibleFrame]))
options |= NSApplicationPresentationAutoHideDock;
}
if ([NSApp respondsToSelector:@selector(setPresentationOptions:)])
[NSApp setPresentationOptions:options];
else
#endif
SetSystemUIMode(_isFullScreen ? kUIModeNormal : kUIModeAllHidden, 0);
}
#if !defined(BUILDING_ON_TIGER) // IOPMAssertionCreateWithName not defined on < 10.5
- (void)_disableIdleDisplaySleep
{
if (_idleDisplaySleepAssertion == kIOPMNullAssertionID)
#if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &_idleDisplaySleepAssertion);
#else // IOPMAssertionCreate is depreciated in > 10.5
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullScreen."), &_idleDisplaySleepAssertion);
#endif
}
- (void)_enableIdleDisplaySleep
{
if (_idleDisplaySleepAssertion != kIOPMNullAssertionID) {
IOPMAssertionRelease(_idleDisplaySleepAssertion);
_idleDisplaySleepAssertion = kIOPMNullAssertionID;
}
}
- (void)_disableIdleSystemSleep
{
if (_idleSystemSleepAssertion == kIOPMNullAssertionID)
#if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &_idleSystemSleepAssertion);
#else // IOPMAssertionCreate is depreciated in > 10.5
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullScreen."), &_idleSystemSleepAssertion);
#endif
}
- (void)_enableIdleSystemSleep
{
if (_idleSystemSleepAssertion != kIOPMNullAssertionID) {
IOPMAssertionRelease(_idleSystemSleepAssertion);
_idleSystemSleepAssertion = kIOPMNullAssertionID;
}
}
- (void)_enableTickleTimer
{
[_tickleTimer invalidate];
[_tickleTimer release];
_tickleTimer = [[NSTimer scheduledTimerWithTimeInterval:tickleTimerInterval target:self selector:@selector(_tickleTimerFired) userInfo:nil repeats:YES] retain];
}
- (void)_disableTickleTimer
{
[_tickleTimer invalidate];
[_tickleTimer release];
_tickleTimer = nil;
}
- (void)_tickleTimerFired
{
UpdateSystemActivity(OverallAct);
}
#endif
- (void)_updatePowerAssertions
{
#if !defined(BUILDING_ON_TIGER)
if (_isPlaying && _isFullScreen) {
[self _disableIdleSystemSleep];
[self _disableIdleDisplaySleep];
[self _enableTickleTimer];
} else {
[self _enableIdleSystemSleep];
[self _enableIdleDisplaySleep];
[self _disableTickleTimer];
}
#endif
}
- (WebFullScreenManagerProxy*)_manager
{
WebPageProxy* webPage = toImpl([_webView pageRef]);
if (!webPage)
return 0;
return webPage->fullScreenManager();
}
- (void)_requestExit
{
[self exitFullScreen];
_forceDisableAnimation = NO;
}
- (void)_requestExitFullScreenWithAnimation:(BOOL)animation
{
_forceDisableAnimation = !animation;
[self performSelector:@selector(_requestExit) withObject:nil afterDelay:0];
}
- (void)_swapView:(NSView*)view with:(NSView*)otherView
{
[otherView setFrame:[view frame]];
[otherView setAutoresizingMask:[view autoresizingMask]];
[otherView removeFromSuperview];
[[view superview] replaceSubview:view with:otherView];
}
#pragma mark -
#pragma mark Utility Functions
- (WKFullScreenWindow *)_fullScreenWindow
{
ASSERT([[self window] isKindOfClass:[WKFullScreenWindow class]]);
return (WKFullScreenWindow *)[self window];
}
- (CFTimeInterval)_animationDuration
{
static const CFTimeInterval defaultDuration = 0.5;
CFTimeInterval duration = defaultDuration;
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
NSUInteger modifierFlags = [NSEvent modifierFlags];
#else
NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags];
#endif
if ((modifierFlags & NSControlKeyMask) == NSControlKeyMask)
duration *= 2;
if ((modifierFlags & NSShiftKeyMask) == NSShiftKeyMask)
duration *= 10;
if (_forceDisableAnimation) {
// This will disable scale animation
duration = 0;
}
return duration;
}
@end
#pragma mark -
@implementation WKFullScreenWindow
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
UNUSED_PARAM(aStyle);
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag];
if (!self)
return nil;
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
[self setIgnoresMouseEvents:NO];
[self setAcceptsMouseMovedEvents:YES];
[self setReleasedWhenClosed:NO];
[self setHasShadow:YES];
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
[self setMovable:NO];
#else
[self setMovableByWindowBackground:NO];
#endif
NSView* contentView = [self contentView];
_animationView = [[NSView alloc] initWithFrame:[contentView bounds]];
CALayer* contentLayer = [[CALayer alloc] init];
[_animationView setLayer:contentLayer];
[_animationView setWantsLayer:YES];
[_animationView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[contentView addSubview:_animationView];
_backgroundLayer = [[CALayer alloc] init];
[contentLayer addSublayer:_backgroundLayer];
[_backgroundLayer setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
[_backgroundLayer setOpacity:0];
return self;
}
- (void)dealloc
{
[_animationView release];
[_backgroundLayer release];
[super dealloc];
}
- (BOOL)canBecomeKeyWindow
{
return YES;
}
- (void)keyDown:(NSEvent *)theEvent
{
if ([[theEvent charactersIgnoringModifiers] isEqual:@"\e"]) // Esacpe key-code
[self cancelOperation:self];
else [super keyDown:theEvent];
}
- (void)cancelOperation:(id)sender
{
UNUSED_PARAM(sender);
[[self windowController] _requestExitFullScreenWithAnimation:YES];
}
- (CALayer*)backgroundLayer
{
return _backgroundLayer;
}
- (NSView*)animationView
{
return _animationView;
}
@end
#endif
...@@ -741,6 +741,9 @@ ...@@ -741,6 +741,9 @@
CD73BA47131ACC9A00EEDED2 /* WebFullScreenManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD73BA45131ACC8800EEDED2 /* WebFullScreenManagerProxyMessageReceiver.cpp */; }; CD73BA47131ACC9A00EEDED2 /* WebFullScreenManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD73BA45131ACC8800EEDED2 /* WebFullScreenManagerProxyMessageReceiver.cpp */; };
CD73BA4E131ACDB700EEDED2 /* WebFullScreenManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD73BA48131ACD8E00EEDED2 /* WebFullScreenManagerMessageReceiver.cpp */; }; CD73BA4E131ACDB700EEDED2 /* WebFullScreenManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD73BA48131ACD8E00EEDED2 /* WebFullScreenManagerMessageReceiver.cpp */; };
CD73BA53131B645B00EEDED2 /* WebFullScreenManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD73BA37131A29FE00EEDED2 /* WebFullScreenManager.cpp */; }; CD73BA53131B645B00EEDED2 /* WebFullScreenManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD73BA37131A29FE00EEDED2 /* WebFullScreenManager.cpp */; };
CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */; };
CDCA85C9132ABA4E00E961DF /* WKFullScreenWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */; };
CDCA85D5132AC2B300E961DF /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDCA85D4132AC2B300E961DF /* IOKit.framework */; };
D3B9484611FF4B6500032B39 /* WebPopupMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3B9484211FF4B6500032B39 /* WebPopupMenu.cpp */; }; D3B9484611FF4B6500032B39 /* WebPopupMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3B9484211FF4B6500032B39 /* WebPopupMenu.cpp */; };
D3B9484711FF4B6500032B39 /* WebPopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B9484311FF4B6500032B39 /* WebPopupMenu.h */; }; D3B9484711FF4B6500032B39 /* WebPopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B9484311FF4B6500032B39 /* WebPopupMenu.h */; };
D3B9484811FF4B6500032B39 /* WebSearchPopupMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3B9484411FF4B6500032B39 /* WebSearchPopupMenu.cpp */; }; D3B9484811FF4B6500032B39 /* WebSearchPopupMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3B9484411FF4B6500032B39 /* WebSearchPopupMenu.cpp */; };
...@@ -1615,6 +1618,9 @@ ...@@ -1615,6 +1618,9 @@
CD73BA48131ACD8E00EEDED2 /* WebFullScreenManagerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebFullScreenManagerMessageReceiver.cpp; sourceTree = "<group>"; }; CD73BA48131ACD8E00EEDED2 /* WebFullScreenManagerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebFullScreenManagerMessageReceiver.cpp; sourceTree = "<group>"; };
CD73BA49131ACD8E00EEDED2 /* WebFullScreenManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFullScreenManagerMessages.h; sourceTree = "<group>"; }; CD73BA49131ACD8E00EEDED2 /* WebFullScreenManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFullScreenManagerMessages.h; sourceTree = "<group>"; };
CD73BA4A131ACD8F00EEDED2 /* WebFullScreenManagerProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFullScreenManagerProxyMessages.h; sourceTree = "<group>"; }; CD73BA4A131ACD8F00EEDED2 /* WebFullScreenManagerProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFullScreenManagerProxyMessages.h; sourceTree = "<group>"; };
CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKFullScreenWindowController.mm; sourceTree = "<group>"; };
CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFullScreenWindowController.h; sourceTree = "<group>"; };
CDCA85D4132AC2B300E961DF /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
D3B9484211FF4B6500032B39 /* WebPopupMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPopupMenu.cpp; sourceTree = "<group>"; }; D3B9484211FF4B6500032B39 /* WebPopupMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPopupMenu.cpp; sourceTree = "<group>"; };
D3B9484311FF4B6500032B39 /* WebPopupMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPopupMenu.h; sourceTree = "<group>"; }; D3B9484311FF4B6500032B39 /* WebPopupMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPopupMenu.h; sourceTree = "<group>"; };
D3B9484411FF4B6500032B39 /* WebSearchPopupMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSearchPopupMenu.cpp; sourceTree = "<group>"; }; D3B9484411FF4B6500032B39 /* WebSearchPopupMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSearchPopupMenu.cpp; sourceTree = "<group>"; };
...@@ -1672,6 +1678,7 @@ ...@@ -1672,6 +1678,7 @@
1AA1CC5D100FA1A10078DEBC /* QuartzCore.framework in Frameworks */, 1AA1CC5D100FA1A10078DEBC /* QuartzCore.framework in Frameworks */,
1A1C4EC810D06099005E67E7 /* WebCore.framework in Frameworks */, 1A1C4EC810D06099005E67E7 /* WebCore.framework in Frameworks */,
BCF5068512431861005955AE /* Security.framework in Frameworks */, BCF5068512431861005955AE /* Security.framework in Frameworks */,
CDCA85D5132AC2B300E961DF /* IOKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -1745,6 +1752,7 @@ ...@@ -1745,6 +1752,7 @@
1AA1CD06100FA1BA0078DEBC /* Carbon.framework */, 1AA1CD06100FA1BA0078DEBC /* Carbon.framework */,
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */, 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */,
BCD0042C110C1E27003B8A67 /* CoreServices.framework */, BCD0042C110C1E27003B8A67 /* CoreServices.framework */,
CDCA85D4132AC2B300E961DF /* IOKit.framework */,
1AA1C7DE100E846E0078DEBC /* JavaScriptCore.framework */, 1AA1C7DE100E846E0078DEBC /* JavaScriptCore.framework */,
BC87DFA91018101400564216 /* libicucore.dylib */, BC87DFA91018101400564216 /* libicucore.dylib */,
1AA1CC5C100FA1A10078DEBC /* QuartzCore.framework */, 1AA1CC5C100FA1A10078DEBC /* QuartzCore.framework */,
...@@ -2868,6 +2876,8 @@ ...@@ -2868,6 +2876,8 @@
BCCF085C113F3B7500C650C5 /* mac */ = { BCCF085C113F3B7500C650C5 /* mac */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */,
CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */,
1A64292C12DE5F9800CAAE2C /* BackingStoreMac.mm */, 1A64292C12DE5F9800CAAE2C /* BackingStoreMac.mm */,
BC2651F511825EF800243E12 /* ChunkedUpdateDrawingAreaProxyMac.mm */, BC2651F511825EF800243E12 /* ChunkedUpdateDrawingAreaProxyMac.mm */,
1AA417ED12C00D87002BE67B /* TextCheckerMac.mm */, 1AA417ED12C00D87002BE67B /* TextCheckerMac.mm */,
...@@ -3455,6 +3465,7 @@ ...@@ -3455,6 +3465,7 @@
37C4E9F6131C6E7E0029BD5A /* config.h in Headers */, 37C4E9F6131C6E7E0029BD5A /* config.h in Headers */,
E1BB16A413201B9B00F49431 /* FullKeyboardAccessWatcher.h in Headers */, E1BB16A413201B9B00F49431 /* FullKeyboardAccessWatcher.h in Headers */,
33AA1067131F060000D4A575 /* WebCookieManagerProxyClient.h in Headers */, 33AA1067131F060000D4A575 /* WebCookieManagerProxyClient.h in Headers */,
CDCA85C9132ABA4E00E961DF /* WKFullScreenWindowController.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -4059,6 +4070,7 @@ ...@@ -4059,6 +4070,7 @@
CD73BA4E131ACDB700EEDED2 /* WebFullScreenManagerMessageReceiver.cpp in Sources */, CD73BA4E131ACDB700EEDED2 /* WebFullScreenManagerMessageReceiver.cpp in Sources */,
CD73BA53131B645B00EEDED2 /* WebFullScreenManager.cpp in Sources */, CD73BA53131B645B00EEDED2 /* WebFullScreenManager.cpp in Sources */,
CD6F75F4131B66D000D6B21E /* WebFullScreenManagerProxy.cpp in Sources */, CD6F75F4131B66D000D6B21E /* WebFullScreenManagerProxy.cpp in Sources */,
CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment