Fix layout issues occuring when entering full screen mode.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Apr 2019 16:25:30 +0000 (16:25 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Apr 2019 16:25:30 +0000 (16:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197086
<rdar://problem/47733671>.

Patch by Remy Demarest <rdemarest@apple.com> on 2019-04-23
Reviewed by Darin Adler.

This issue is the result of changing the style mask of the window after entering
full screen mode. Safari adds an invisible toolbar to display the URL of the page
which ends up breaking the layout. Having that window use a style that includes a
titlebar fixes the bug.

Source/WebCore:

* platform/mac/WebCoreFullScreenWindow.mm:
(-[WebCoreFullScreenWindow constrainFrameRect:toScreen:]): Ensure that the window
can fill the entire screen including the underlapping the menu bar, so that the
window does not resize when the animation is done.
(-[WebCoreFullScreenWindow canBecomeMainWindow]): Borderless windows cannot become
main by default, adding the titlebar allows it to become main, prevent this from
happening at all to preserve the existing behavior.

Source/WebKit:

* Platform/spi/mac/AppKitSPI.h:
Declare an SPI to be used in WKFullScreenWindowController.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::fullScreenWindow): Make the full screen window show a titlebar
and make the content view underlap the titlebar to match the current behavior.
Remove NSWindowStyleMaskBorderless which has no effects since it is equal to zero.

* UIProcess/mac/WKFullScreenWindowController.mm:
(-[WKFullScreenWindowController initWithWindow:webView:page:]): Hide the titlebar
before beginning the animation to full screen.
(-[WKFullScreenWindowController finishedEnterFullScreenAnimation:]): Show the title
bar when in full screen instead of a blank bar.
(-[WKFullScreenWindowController finishedExitFullScreenAnimation:]): Hide the title
bar to restore the initial setting.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244545 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/WebCoreFullScreenWindow.mm
Source/WebKit/ChangeLog
Source/WebKit/Platform/spi/mac/AppKitSPI.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm

index e6a127e..8e32ba9 100644 (file)
@@ -1,3 +1,24 @@
+2019-04-23  Remy Demarest  <rdemarest@apple.com>
+
+        Fix layout issues occuring when entering full screen mode.
+        https://bugs.webkit.org/show_bug.cgi?id=197086
+        <rdar://problem/47733671>.
+
+        Reviewed by Darin Adler.
+
+        This issue is the result of changing the style mask of the window after entering
+        full screen mode. Safari adds an invisible toolbar to display the URL of the page
+        which ends up breaking the layout. Having that window use a style that includes a
+        titlebar fixes the bug.
+
+        * platform/mac/WebCoreFullScreenWindow.mm:
+        (-[WebCoreFullScreenWindow constrainFrameRect:toScreen:]): Ensure that the window
+        can fill the entire screen including the underlapping the menu bar, so that the
+        window does not resize when the animation is done.
+        (-[WebCoreFullScreenWindow canBecomeMainWindow]): Borderless windows cannot become
+        main by default, adding the titlebar allows it to become main, prevent this from
+        happening at all to preserve the existing behavior.
+
 2019-04-23  Chris Dumez  <cdumez@apple.com>
 
         [Process-Swap-On-Navigation] WebKit hangs when going back to a form submission's page due to Process-Swap-On-Navigation on iOS 12.2 and higher
index aa4501c..aa68e01 100644 (file)
     return self;
 }
 
+- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
+{
+    UNUSED_PARAM(screen);
+    return frameRect;
+}
+
+- (BOOL)canBecomeMainWindow
+{
+    return NO;
+}
+
 - (BOOL)canBecomeKeyWindow
 {
     return YES;
index c4a0f56..d37d929 100644 (file)
@@ -1,3 +1,32 @@
+2019-04-23  Remy Demarest  <rdemarest@apple.com>
+
+        Fix layout issues occuring when entering full screen mode.
+        https://bugs.webkit.org/show_bug.cgi?id=197086
+        <rdar://problem/47733671>.
+
+        Reviewed by Darin Adler.
+
+        This issue is the result of changing the style mask of the window after entering
+        full screen mode. Safari adds an invisible toolbar to display the URL of the page
+        which ends up breaking the layout. Having that window use a style that includes a
+        titlebar fixes the bug.
+
+        * Platform/spi/mac/AppKitSPI.h:
+        Declare an SPI to be used in WKFullScreenWindowController.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::fullScreenWindow): Make the full screen window show a titlebar
+        and make the content view underlap the titlebar to match the current behavior.
+        Remove NSWindowStyleMaskBorderless which has no effects since it is equal to zero.
+
+        * UIProcess/mac/WKFullScreenWindowController.mm:
+        (-[WKFullScreenWindowController initWithWindow:webView:page:]): Hide the titlebar
+        before beginning the animation to full screen.
+        (-[WKFullScreenWindowController finishedEnterFullScreenAnimation:]): Show the title
+        bar when in full screen instead of a blank bar.
+        (-[WKFullScreenWindowController finishedExitFullScreenAnimation:]): Hide the title
+        bar to restore the initial setting.
+
 2019-04-23  John Wilander  <wilander@apple.com>
 
         Ad Click Attribution redirects to well-known location should not trigger a conversion if they are blocked by content blockers
index fa6ab31..a2f921e 100644 (file)
 - (void)setInspectorBar:(NSInspectorBar *)bar;
 @end
 
+@interface NSWindow (FullScreenSupport)
+@property CGFloat titlebarAlphaValue;
+@end
+
 #endif
 
 @interface NSInspectorBar (IPI)
index 4c9014a..b0e15eb 100644 (file)
@@ -2610,7 +2610,7 @@ NSView *WebViewImpl::fullScreenPlaceholderView()
 NSWindow *WebViewImpl::fullScreenWindow()
 {
 #if ENABLE(FULLSCREEN_API)
-    return [[[WebCoreFullScreenWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:(NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable) backing:NSBackingStoreBuffered defer:NO] autorelease];
+    return [[[WebCoreFullScreenWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskUnifiedTitleAndToolbar | NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskResizable) backing:NSBackingStoreBuffered defer:NO] autorelease];
 #else
     return nil;
 #endif
index e5d4119..68b6cf6 100644 (file)
@@ -29,6 +29,7 @@
 
 #import "WKFullScreenWindowController.h"
 
+#import "AppKitSPI.h"
 #import "LayerTreeContext.h"
 #import "VideoFullscreenManagerProxy.h"
 #import "WKAPICast.h"
@@ -126,6 +127,9 @@ static void makeResponderFirstResponderIfDescendantOfView(NSWindow *window, NSRe
     [window setDelegate:self];
     [window setCollectionBehavior:([window collectionBehavior] | NSWindowCollectionBehaviorFullScreenPrimary)];
 
+    // Hide the titlebar during the animation to full screen so that only the WKWebView content is visible.
+    window.titlebarAlphaValue = 0;
+
     NSView *contentView = [window contentView];
     contentView.hidden = YES;
     contentView.autoresizesSubviews = YES;
@@ -341,6 +345,9 @@ static const float minVideoWidth = 480 + 20 + 20; // Note: Keep in sync with med
         NSSize minContentSize = self.window.contentMinSize;
         minContentSize.width = minVideoWidth;
         self.window.contentMinSize = minContentSize;
+
+        // Always show the titlebar in full screen mode.
+        self.window.titlebarAlphaValue = 1;
     } else {
         // Transition to fullscreen failed. Clean up.
         _fullScreenState = NotInFullScreen;
@@ -475,6 +482,9 @@ static RetainPtr<CGImageRef> takeWindowSnapshot(CGSWindowID windowID, bool captu
         return;
     _fullScreenState = NotInFullScreen;
 
+    // Hide the titlebar at the end of the animation so that it can slide away without turning blank.
+    self.window.titlebarAlphaValue = 0;
+
     NSResponder *firstResponder = [[self window] firstResponder];
 
     [CATransaction begin];