Add new optimized fullscreen delegate methods
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Apr 2015 23:28:48 +0000 (23:28 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Apr 2015 23:28:48 +0000 (23:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144071

Reviewed by Eric Carlson.

AVPlayerViewController requires three new delegate methods to be implemented by WebKit which
notify the delegates exactly when the owning view will enter and leave fullscreen mode. One
of the delegate methods (-enterOptimizedFullScreenModeRedirectingVideoToLayer:) gives the
delegate an opportunity to move the video sublayer into a new CALayer. The matching delegate
(-leaveOptimizedFullScreenMode), allows us to return our sublayer back to its original parent.
The third delegate (-isOptimizedFullscreenPossible) is required so the AVPlayerViewController
knows whether to allow a standard -> optimized fullscreen transition.

Drive-by fix: initialize ivars at declaration time.

* platform/ios/WebVideoFullscreenInterfaceAVKit.h:
* platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
(-[WebAVPlayerController isOptimizedFullscreenPossible]):
(-[WebAVVideoLayer enterOptimizedFullScreenModeRedirectingVideoToLayer:]):
(-[WebAVVideoLayer leaveOptimizedFullScreenMode]):
(WebVideoFullscreenInterfaceAVKit::WebVideoFullscreenInterfaceAVKit):
(WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal):
(+[WebAVPlayerController keyPathsForValuesAffectingPlayingOnExternalScreen]): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h
Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm

index b09874b..831bcda 100644 (file)
@@ -1,3 +1,29 @@
+2015-04-22  Jer Noble  <jer.noble@apple.com>
+
+        Add new optimized fullscreen delegate methods
+        https://bugs.webkit.org/show_bug.cgi?id=144071
+
+        Reviewed by Eric Carlson.
+
+        AVPlayerViewController requires three new delegate methods to be implemented by WebKit which
+        notify the delegates exactly when the owning view will enter and leave fullscreen mode. One
+        of the delegate methods (-enterOptimizedFullScreenModeRedirectingVideoToLayer:) gives the
+        delegate an opportunity to move the video sublayer into a new CALayer. The matching delegate
+        (-leaveOptimizedFullScreenMode), allows us to return our sublayer back to its original parent.
+        The third delegate (-isOptimizedFullscreenPossible) is required so the AVPlayerViewController
+        knows whether to allow a standard -> optimized fullscreen transition.
+
+        Drive-by fix: initialize ivars at declaration time.
+
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
+        (-[WebAVPlayerController isOptimizedFullscreenPossible]):
+        (-[WebAVVideoLayer enterOptimizedFullScreenModeRedirectingVideoToLayer:]):
+        (-[WebAVVideoLayer leaveOptimizedFullScreenMode]):
+        (WebVideoFullscreenInterfaceAVKit::WebVideoFullscreenInterfaceAVKit):
+        (WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal):
+        (+[WebAVPlayerController keyPathsForValuesAffectingPlayingOnExternalScreen]): Deleted.
+
 2015-04-22  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [iOS] Caret does not line up with text when using the system font
index 3273148..b04bd10 100644 (file)
@@ -97,6 +97,7 @@ public:
     WEBCORE_EXPORT virtual void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
 
     HTMLMediaElement::VideoFullscreenMode mode() const { return m_mode; }
+    bool allowOptimizedFullscreen() const { return m_allowOptimizedFullscreen; }
     void setIsOptimized(bool);
     WEBCORE_EXPORT bool mayAutomaticallyShowVideoOptimized() const;
     void fullscreenMayReturnToInline(std::function<void(bool)> callback);
@@ -127,19 +128,20 @@ protected:
     RetainPtr<AVPlayerViewController> m_playerViewController;
     RetainPtr<CALayer> m_videoLayer;
     RetainPtr<WebAVVideoLayer> m_videoLayerContainer;
-    WebVideoFullscreenModel* m_videoFullscreenModel;
-    WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver;
+    WebVideoFullscreenModel* m_videoFullscreenModel { nullptr };
+    WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
 
     // These are only used when fullscreen is presented in a separate window.
     RetainPtr<UIWindow> m_window;
     RetainPtr<UIViewController> m_viewController;
     RetainPtr<UIView> m_parentView;
     RetainPtr<UIWindow> m_parentWindow;
-    HTMLMediaElement::VideoFullscreenMode m_mode;
+    HTMLMediaElement::VideoFullscreenMode m_mode { HTMLMediaElement::VideoFullscreenModeNone };
     std::function<void(bool)> m_prepareToInlineCallback;
-    bool m_exitRequested;
-    bool m_exitCompleted;
-    bool m_enterRequested;
+    bool m_allowOptimizedFullscreen { false };
+    bool m_exitRequested { false };
+    bool m_exitCompleted { false };
+    bool m_enterRequested { false };
 
     void doEnterFullscreen();
 };
index 809109a..1ae8fb9 100644 (file)
@@ -552,6 +552,11 @@ static const char* boolString(bool val)
 {
     return [NSSet setWithObjects:@"externalPlaybackActive", nil];
 }
+
+- (BOOL)isOptimizedFullscreenPossible
+{
+    return self.fullscreenInterface->allowOptimizedFullscreen();
+}
 @end
 
 @interface WebAVMediaSelectionOption : NSObject
@@ -691,16 +696,21 @@ static const char* boolString(bool val)
     return _videoLayerGravity;
 }
 
+- (void)enterOptimizedFullScreenModeRedirectingVideoToLayer:(CALayer *)layer
+{
+    [_videoSublayer removeFromSuperlayer];
+    [layer addSublayer:_videoSublayer.get()];
+}
+
+- (void)leaveOptimizedFullScreenMode
+{
+    [_videoSublayer removeFromSuperlayer];
+    [self addSublayer:_videoSublayer.get()];
+}
 @end
 
 WebVideoFullscreenInterfaceAVKit::WebVideoFullscreenInterfaceAVKit()
     : m_playerController(adoptNS([[WebAVPlayerController alloc] init]))
-    , m_videoFullscreenModel(nullptr)
-    , m_fullscreenChangeObserver(nullptr)
-    , m_mode(HTMLMediaElement::VideoFullscreenModeNone)
-    , m_exitRequested(false)
-    , m_exitCompleted(false)
-    , m_enterRequested(false)
 {
     [m_playerController setFullscreenInterface:this];
 }
@@ -904,6 +914,8 @@ void WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal(PlatformLayer& vi
     UNUSED_PARAM(videoLayer);
     UNUSED_PARAM(mode);
 
+    m_allowOptimizedFullscreen = allowOptimizedFullscreen;
+
     [CATransaction begin];
     [CATransaction setDisableActions:YES];
     m_parentView = parentView;
@@ -1323,5 +1335,4 @@ void WebVideoFullscreenInterfaceAVKit::clearMode(HTMLMediaElement::VideoFullscre
         m_videoFullscreenModel->fullscreenModeChanged(m_mode);
 }
 
-
 #endif