Changeset 135944 in webkit


Ignore:
Timestamp:
Nov 27, 2012, 4:40:26 PM (13 years ago)
Author:
jer.noble@apple.com
Message:

[WK2] [Mac] WebKit Full Screen API should use NSWindow full screen API.
https://bugs.webkit.org/show_bug.cgi?id=100025

Reviewed by Dan Bernstein.

Use the NSWindow full screen API when taking the WebView full screen. To facility the case where the browser window is already
in full screen mode, no longer hide the browser window when entering full screen. Instead, provide a placeholder view with
instructions to click the placeholder to exit full screen.

  • UIProcess/mac/WKFullScreenWindowController.h:
  • UIProcess/mac/WKFullScreenWindowController.mm:

(-[WKFullScreenWindowController init]): Set self as the window's delegate; enable window's full screen action.
(-[WKFullScreenWindowController dealloc]): Clear our window's delegate.
(-[WKFullScreenWindowController applicationDidChangeScreenParameters:]): Remove reference to _updateWindowAndDockForFullScreen.
(-[WKFullScreenWindowController enterFullScreen:]): Ditto. Create a WKFullScreenPlaceholderView instead of generic NSImageView.
(-[WKFullScreenWindowController beganEnterFullScreenWithInitialFrame:finalFrame:]): Ditto. Call NSWindow enterFullScreen: API.
(-[WKFullScreenWindowController finishedEnterFullScreenAnimation:]): Show the warning view.
(-[WKFullScreenWindowController exitFullScreen]): Hide the warning view.
(-[WKFullScreenWindowController beganExitFullScreenWithInitialFrame:finalFrame:]): Add special case where we are exiting

from full screen mode when the full screen window is not on screen.

(-[WKFullScreenWindowController finishedExitFullScreenAnimation:]): Remove reference to _updateMenuAndDockForFullScreen.
(-[WKFullScreenWindowController customWindowsToEnterFullScreenForWindow:]): Added. Return the background window and the full screen window.
(-[WKFullScreenWindowController customWindowsToExitFullScreenForWindow:]): Ditto.
(-[WKFullScreenWindowController window:startCustomAnimationToEnterFullScreenWithDuration:]): Added. Call through to _startEnterFullScreenAnimationWithDuration:
(-[WKFullScreenWindowController window:startCustomAnimationToExitFullScreenWithDuration:]): Added. Call through to _startExitFullScreenAnimationWithDuration:

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r135935 r135944  
     12012-10-22  Jer Noble  <jer.noble@apple.com>
     2
     3        [WK2] [Mac] WebKit Full Screen API should use NSWindow full screen API.
     4        https://bugs.webkit.org/show_bug.cgi?id=100025
     5
     6        Reviewed by Dan Bernstein.
     7
     8        Use the NSWindow full screen API when taking the WebView full screen. To facility the case where the browser window is already
     9        in full screen mode, no longer hide the browser window when entering full screen. Instead, provide a placeholder view with
     10        instructions to click the placeholder to exit full screen.
     11
     12        * UIProcess/mac/WKFullScreenWindowController.h:
     13        * UIProcess/mac/WKFullScreenWindowController.mm:
     14        (-[WKFullScreenWindowController init]): Set self as the window's delegate; enable window's full screen action.
     15        (-[WKFullScreenWindowController dealloc]): Clear our window's delegate.
     16        (-[WKFullScreenWindowController applicationDidChangeScreenParameters:]): Remove reference to _updateWindowAndDockForFullScreen.
     17        (-[WKFullScreenWindowController enterFullScreen:]):  Ditto. Create a WKFullScreenPlaceholderView instead of generic NSImageView.
     18        (-[WKFullScreenWindowController beganEnterFullScreenWithInitialFrame:finalFrame:]): Ditto. Call NSWindow enterFullScreen: API.
     19        (-[WKFullScreenWindowController finishedEnterFullScreenAnimation:]): Show the warning view.
     20        (-[WKFullScreenWindowController exitFullScreen]): Hide the warning view.
     21        (-[WKFullScreenWindowController beganExitFullScreenWithInitialFrame:finalFrame:]): Add special case where we are exiting
     22            from full screen mode when the full screen window is not on screen.
     23        (-[WKFullScreenWindowController finishedExitFullScreenAnimation:]): Remove reference to _updateMenuAndDockForFullScreen.
     24        (-[WKFullScreenWindowController customWindowsToEnterFullScreenForWindow:]): Added. Return the background window and the full screen window.
     25        (-[WKFullScreenWindowController customWindowsToExitFullScreenForWindow:]): Ditto.
     26        (-[WKFullScreenWindowController window:startCustomAnimationToEnterFullScreenWithDuration:]): Added. Call through to _startEnterFullScreenAnimationWithDuration:
     27        (-[WKFullScreenWindowController window:startCustomAnimationToExitFullScreenWithDuration:]): Added. Call through to _startExitFullScreenAnimationWithDuration:
     28
    1292012-11-27  Yael Aharon  <yael.aharon@intel.com>
    230
  • trunk/Source/WebKit2/UIProcess/mac/WKFullScreenWindowController.h

    r113238 r135944  
    3939
    4040@class WKView;
     41@class WebCoreFullScreenPlaceholderView;
    4142@class WebWindowScaleAnimation;
    4243@class WebWindowFadeAnimation;
    4344
    44 @interface WKFullScreenWindowController : NSWindowController {
     45@interface WKFullScreenWindowController : NSWindowController<NSWindowDelegate> {
    4546@private
    4647    WKView *_webView;
    47     RetainPtr<NSImageView> _webViewPlaceholder;
     48    RetainPtr<WebCoreFullScreenPlaceholderView> _webViewPlaceholder;
    4849    RetainPtr<WebWindowScaleAnimation> _scaleAnimation;
    4950    RetainPtr<WebWindowFadeAnimation> _fadeAnimation;
  • trunk/Source/WebKit2/UIProcess/mac/WKFullScreenWindowController.mm

    r132738 r135944  
    4040#import <WebCore/FloatRect.h>
    4141#import <WebCore/IntRect.h>
     42#import <WebCore/LocalizedStrings.h>
     43#import <WebCore/WebCoreFullScreenPlaceholderView.h>
    4244#import <WebCore/WebCoreFullScreenWindow.h>
    4345#import <WebCore/WebWindowAnimation.h>
     
    5456static const NSTimeInterval DefaultWatchdogTimerInterval = 1;
    5557
     58@interface NSWindow (WebNSWindowDetails)
     59- (void)exitFullScreenMode:(id)sender;
     60- (void)enterFullScreenMode:(id)sender;
     61@end
     62
    5663@interface WKFullScreenWindowController(Private)<NSAnimationDelegate>
    57 - (void)_updateMenuAndDockForFullScreen;
    5864- (void)_replaceView:(NSView*)view with:(NSView*)otherView;
    5965- (WebPageProxy*)_page;
     
    8894- (id)init
    8995{
    90     NSWindow *window = [[WebCoreFullScreenWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
    91     self = [super initWithWindow:window];
    92     [window release];
     96    RetainPtr<NSWindow> window = adoptNS([[WebCoreFullScreenWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
     97    self = [super initWithWindow:window.get()];
    9398    if (!self)
    9499        return nil;
     100    [window.get() setDelegate:self];
     101    [window.get() setCollectionBehavior:([window collectionBehavior] | NSWindowCollectionBehaviorFullScreenPrimary)];
    95102    [self windowDidLoad];
    96103   
     
    101108{
    102109    [self setWebView:nil];
     110    [[self window] setDelegate:nil];
    103111   
    104112    [NSObject cancelPreviousPerformRequestsWithTarget:self];
     
    175183    // Update our presentation parameters, and ensure that the full screen window occupies the
    176184    // entire screen:
    177     [self _updateMenuAndDockForFullScreen];
    178185    NSWindow* window = [self window];
    179186    NSRect screenFrame = [[window screen] frame];
     
    213220    _isFullScreen = YES;
    214221
    215     [self _updateMenuAndDockForFullScreen];   
    216 
    217222    if (!screen)
    218223        screen = [NSScreen mainScreen];
     
    247252    // Swap the webView placeholder into place.
    248253    if (!_webViewPlaceholder) {
    249         _webViewPlaceholder.adoptNS([[NSImageView alloc] init]);
    250         [_webViewPlaceholder.get() setLayer:[CALayer layer]];
    251         [_webViewPlaceholder.get() setWantsLayer:YES];
     254        _webViewPlaceholder.adoptNS([[WebCoreFullScreenPlaceholderView alloc] initWithFrame:[_webView frame]]);
     255        [_webViewPlaceholder.get() setTarget:self];
     256        [_webViewPlaceholder.get() setAction:@selector(cancelOperation:)];
    252257    }
    253     [[_webViewPlaceholder.get() layer] setContents:(id)webViewContents.get()];
     258    [_webViewPlaceholder.get() setContents:(id)webViewContents.get()];
    254259    [self _replaceView:_webView with:_webViewPlaceholder.get()];
    255260   
     
    274279    _finalFrame = finalFrame;
    275280
    276     [self _updateMenuAndDockForFullScreen];   
    277 
    278     [self _startEnterFullScreenAnimationWithDuration:defaultAnimationDuration];
     281    if (!_backgroundWindow)
     282        _backgroundWindow = createBackgroundFullscreenWindow(NSZeroRect);
     283
     284    [[self window] enterFullScreenMode:self];
    279285}
    280286
     
    294300        windowBounds.origin = NSZeroPoint;
    295301        WKWindowSetClipRect([self window], windowBounds);
    296 
    297         NSWindow *webWindow = [_webViewPlaceholder.get() window];
    298 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
    299         // In Lion, NSWindow will animate into and out of orderOut operations. Suppress that
    300         // behavior here, making sure to reset the animation behavior afterward.
    301         NSWindowAnimationBehavior animationBehavior = [webWindow animationBehavior];
    302         [webWindow setAnimationBehavior:NSWindowAnimationBehaviorNone];
    303 #endif
    304         [webWindow orderOut:self];
    305 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
    306         [webWindow setAnimationBehavior:animationBehavior];
    307 #endif
    308302
    309303        [_fadeAnimation.get() stopAnimation];
     
    313307        [_backgroundWindow.get() orderOut:self];
    314308        [_backgroundWindow.get() setFrame:NSZeroRect display:YES];
     309
     310        [_webViewPlaceholder.get() setExitWarningVisible:YES];
    315311        NSEnableScreenUpdates();
    316312    } else
     
    329325    _isFullScreen = NO;
    330326
    331     // Screen updates to be re-enabled in _startExitFullScreenAnimationWithDuration:
     327    [_webViewPlaceholder.get() setExitWarningVisible:NO];
     328
     329    // Screen updates to be re-enabled in _startExitFullScreenAnimationWithDuration: or beganExitFullScreenWithInitialFrame:finalFrame:
    332330    NSDisableScreenUpdates();
    333331    [[self window] setAutodisplay:NO];
     
    350348        [self finishedEnterFullScreenAnimation:NO];
    351349
    352     [self _updateMenuAndDockForFullScreen];
    353    
    354     NSWindow* webWindow = [_webViewPlaceholder.get() window];
    355 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
    356     // In Lion, NSWindow will animate into and out of orderOut operations. Suppress that
    357     // behavior here, making sure to reset the animation behavior afterward.
    358     NSWindowAnimationBehavior animationBehavior = [webWindow animationBehavior];
    359     [webWindow setAnimationBehavior:NSWindowAnimationBehaviorNone];
    360 #endif
    361     // If the user has moved the fullScreen window into a new space, temporarily change
    362     // the collectionBehavior of the webView's window so that it is pulled into the active space:
    363     if (!([webWindow respondsToSelector:@selector(isOnActiveSpace)] ? [webWindow isOnActiveSpace] : YES)) {
    364         NSWindowCollectionBehavior behavior = [webWindow collectionBehavior];
    365         [webWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
    366         [webWindow orderWindow:NSWindowBelow relativeTo:[[self window] windowNumber]];
    367         [webWindow setCollectionBehavior:behavior];
    368     } else
    369         [webWindow orderWindow:NSWindowBelow relativeTo:[[self window] windowNumber]];
    370    
    371 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
    372     [webWindow setAnimationBehavior:animationBehavior];
    373 #endif
    374 
    375     [self _startExitFullScreenAnimationWithDuration:defaultAnimationDuration];
     350    if (![[self window] isOnActiveSpace]) {
     351        // If the full screen window is not in the active space, the NSWindow full screen animation delegate methods
     352        // will never be called. So call finishedExitFullScreenAnimation explicitly.
     353        [self finishedExitFullScreenAnimation:YES];
     354
     355        // Because we are breaking the normal animation pattern, re-enable screen updates
     356        // as exitFullScreen has disabled them, but _startExitFullScreenAnimationWithDuration:
     357        // will never be called.
     358        NSEnableScreenUpdates();
     359    }
     360
     361    [[self window] exitFullScreenMode:self];
    376362}
    377363
     
    383369        return;
    384370    _isExitingFullScreen = NO;
    385 
    386     [self _updateMenuAndDockForFullScreen];
    387371
    388372    // Screen updates to be re-enabled in completeFinishExitFullScreenAnimationAfterRepaint.
     
    445429
    446430#pragma mark -
    447 #pragma mark NSAnimation delegate
    448 
    449 - (void)animationDidEnd:(NSAnimation*)animation
    450 {
    451     if (_isFullScreen)
    452         [self finishedEnterFullScreenAnimation:YES];
    453     else
    454         [self finishedExitFullScreenAnimation:YES];
     431#pragma mark Custom NSWindow Full Screen Animation
     432
     433- (NSArray *)customWindowsToEnterFullScreenForWindow:(NSWindow *)window
     434{
     435    return [NSArray arrayWithObjects:[self window], _backgroundWindow.get(), nil];
     436}
     437
     438- (NSArray *)customWindowsToExitFullScreenForWindow:(NSWindow *)window
     439{
     440    return [NSArray arrayWithObjects:[self window], _backgroundWindow.get(), nil];
     441}
     442
     443- (void)window:(NSWindow *)window startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration
     444{
     445    [self _startEnterFullScreenAnimationWithDuration:duration];
     446}
     447
     448- (void)window:(NSWindow *)window startCustomAnimationToExitFullScreenWithDuration:(NSTimeInterval)duration
     449{
     450    [self _startExitFullScreenAnimationWithDuration:duration];
     451}
     452
     453- (void)windowDidFailToEnterFullScreen:(NSWindow *)window
     454{
     455    [self finishedEnterFullScreenAnimation:NO];
     456}
     457
     458- (void)windowDidEnterFullScreen:(NSNotification*)notification
     459{
     460    [self finishedEnterFullScreenAnimation:YES];
     461}
     462
     463- (void)windowDidFailToExitFullScreen:(NSWindow *)window
     464{
     465    [self finishedExitFullScreenAnimation:NO];
     466}
     467
     468- (void)windowDidExitFullScreen:(NSNotification*)notification
     469{
     470    [self finishedExitFullScreenAnimation:YES];
    455471}
    456472
    457473#pragma mark -
    458474#pragma mark Internal Interface
    459 
    460 - (void)_updateMenuAndDockForFullScreen
    461 {
    462     // NSApplicationPresentationOptions is available on > 10.6 only:
    463 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
    464     NSApplicationPresentationOptions options = NSApplicationPresentationDefault;
    465     NSScreen* fullScreenScreen = [[self window] screen];
    466    
    467     if (_isFullScreen) {
    468         // Auto-hide the menu bar if the fullScreenScreen contains the menu bar:
    469         // NOTE: if the fullScreenScreen contains the menu bar but not the dock, we must still
    470         // auto-hide the dock, or an exception will be thrown.
    471         if ([[NSScreen screens] objectAtIndex:0] == fullScreenScreen)
    472             options |= (NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock);
    473         // Check if the current screen contains the dock by comparing the screen's frame to its
    474         // visibleFrame; if a dock is present, the visibleFrame will differ. If the current screen
    475         // contains the dock, hide it.
    476         else if (!NSEqualRects([fullScreenScreen frame], [fullScreenScreen visibleFrame]))
    477             options |= NSApplicationPresentationAutoHideDock;
    478     }
    479    
    480     if ([NSApp respondsToSelector:@selector(setPresentationOptions:)])
    481         [NSApp setPresentationOptions:options];
    482     else
    483 #endif
    484         SetSystemUIMode(_isFullScreen ? kUIModeAllHidden : kUIModeNormal, 0);
    485 }
    486475
    487476- (WebPageProxy*)_page
     
    544533   
    545534    [_scaleAnimation.get() setAnimationBlockingMode:NSAnimationNonblocking];
    546     [_scaleAnimation.get() setDelegate:self];
    547535    [_scaleAnimation.get() setCurrentProgress:0];
    548536    [_scaleAnimation.get() startAnimation];
     
    597585
    598586    [_scaleAnimation.get() setAnimationBlockingMode:NSAnimationNonblocking];
    599     [_scaleAnimation.get() setDelegate:self];
    600587    [_scaleAnimation.get() setCurrentProgress:0];
    601588    [_scaleAnimation.get() startAnimation];
Note: See TracChangeset for help on using the changeset viewer.