Improve WebKitLegacy video fullscreen animation begin and end rects.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 01:58:33 +0000 (01:58 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 01:58:33 +0000 (01:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175152
rdar://problem/32840576

Patch by Jeremy Jones <jeremyj@apple.com> on 2017-08-03
Reviewed by Eric Carlson.

No new tests, becuase this change has no effect on the DOM.

This change uses different rects for fullscreen animation to prevent the animation
from failing, and to improve the aesthetics of the animation.

* platform/mac/WebVideoFullscreenController.mm:
(frameExpandedToRatioOfFrame):
(-[WebVideoFullscreenController enterFullscreen:]):
(-[WebVideoFullscreenController exitFullscreen]):
(-[WebVideoFullscreenWindow animateFromRect:toRect:withSubAnimation:controllerAction:]):
(constrainFrameToRatioOfFrame): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/WebVideoFullscreenController.mm

index 057c94516d6090e8f9573aaee256d26a37928d2e..72273c7aba9c6d547f0ff398534f181ac63956b7 100644 (file)
@@ -1,3 +1,23 @@
+2017-08-03  Jeremy Jones  <jeremyj@apple.com>
+
+        Improve WebKitLegacy video fullscreen animation begin and end rects.
+        https://bugs.webkit.org/show_bug.cgi?id=175152
+        rdar://problem/32840576
+
+        Reviewed by Eric Carlson.
+
+        No new tests, becuase this change has no effect on the DOM.
+
+        This change uses different rects for fullscreen animation to prevent the animation
+        from failing, and to improve the aesthetics of the animation.
+
+        * platform/mac/WebVideoFullscreenController.mm:
+        (frameExpandedToRatioOfFrame):
+        (-[WebVideoFullscreenController enterFullscreen:]):
+        (-[WebVideoFullscreenController exitFullscreen]):
+        (-[WebVideoFullscreenWindow animateFromRect:toRect:withSubAnimation:controllerAction:]):
+        (constrainFrameToRatioOfFrame): Deleted.
+
 2017-08-03  Jer Noble  <jer.noble@apple.com>
 
         [EME][Mac] SecureStop left on disk in Private Browsing mode.
index 152b6747150a3ff2af1cfe31cf0f5808a3cee10c..6587a291be2bfeda7b031541a545a89008098dd5 100644 (file)
@@ -233,22 +233,24 @@ SOFT_LINK_CLASS(AVFoundation, AVPlayerLayer)
 // MARK: -
 // MARK: Exposed Interface
 
-static void constrainFrameToRatioOfFrame(NSRect *frameToConstrain, const NSRect *frame)
+static NSRect frameExpandedToRatioOfFrame(NSRect frameToExpand, NSRect frame)
 {
     // Keep a constrained aspect ratio for the destination window
-    CGFloat originalRatio = frame->size.width / frame->size.height;
-    CGFloat newRatio = frameToConstrain->size.width / frameToConstrain->size.height;
+    NSRect result = frameToExpand;
+    CGFloat newRatio = frame.size.width / frame.size.height;
+    CGFloat originalRatio = frameToExpand.size.width / frameToExpand.size.height;
     if (newRatio > originalRatio) {
-        CGFloat newWidth = originalRatio * frameToConstrain->size.height;
-        CGFloat diff = frameToConstrain->size.width - newWidth;
-        frameToConstrain->size.width = newWidth;
-        frameToConstrain->origin.x += diff / 2;
+        CGFloat newWidth = newRatio * frameToExpand.size.height;
+        CGFloat diff = newWidth - frameToExpand.size.width;
+        result.size.width = newWidth;
+        result.origin.x -= diff / 2;
     } else {
-        CGFloat newHeight = frameToConstrain->size.width / originalRatio;
-        CGFloat diff = frameToConstrain->size.height - newHeight;
-        frameToConstrain->size.height = newHeight;
-        frameToConstrain->origin.y += diff / 2;
-    }    
+        CGFloat newHeight = frameToExpand.size.width / newRatio;
+        CGFloat diff = newHeight - frameToExpand.size.height;
+        result.size.height = newHeight;
+        result.origin.y -= diff / 2;
+    }
+    return result;
 }
 
 static NSWindow *createBackgroundFullscreenWindow(NSRect frame, int level)
@@ -277,9 +279,8 @@ static NSWindow *createBackgroundFullscreenWindow(NSRect frame, int level)
     if (!screen)
         screen = [NSScreen mainScreen];
 
-    NSRect frame = [self videoElementRect];
     NSRect endFrame = [screen frame];
-    constrainFrameToRatioOfFrame(&endFrame, &frame);
+    NSRect frame = frameExpandedToRatioOfFrame([self videoElementRect], endFrame);
 
     // Create a black window if needed
     if (!_backgroundFullscreenWindow)
@@ -316,8 +317,11 @@ static NSWindow *createBackgroundFullscreenWindow(NSRect frame, int level)
     // If our owner releases us we could crash if this is not the case.
     // Balanced in windowDidExitFullscreen
     [self retain];    
-    
-    [[self fullscreenWindow] animateFromRect:[[self window] frame] toRect:endFrame withSubAnimation:_fadeAnimation controllerAction:@selector(windowDidExitFullscreen)];
+
+    NSRect startFrame = [[self window] frame];
+    endFrame = frameExpandedToRatioOfFrame(endFrame, startFrame);
+
+    [[self fullscreenWindow] animateFromRect:startFrame toRect:endFrame withSubAnimation:_fadeAnimation controllerAction:@selector(windowDidExitFullscreen)];
 }
 
 - (void)applicationDidChangeScreenParameters:(NSNotification*)notification
@@ -504,7 +508,7 @@ static NSWindow *createBackgroundFullscreenWindow(NSRect frame, int level)
     if (!wasAnimating) {
         // We'll downscale the window during the animation based on the higher resolution rect
         BOOL higherResolutionIsEndRect = startRect.size.width < endRect.size.width && startRect.size.height < endRect.size.height;
-        [self setFrame:higherResolutionIsEndRect ? endRect : startRect display:NO];        
+        [self setFrame:higherResolutionIsEndRect ? endRect : startRect display:NO];
     }
     
     ASSERT(!_fullscreenAnimation);