Changeset 181173 in webkit


Ignore:
Timestamp:
Mar 6, 2015 11:28:26 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Scroll to make the video element visible when exiting fullscreen.
https://bugs.webkit.org/show_bug.cgi?id=141439

Patch by Jeremy Jones <jeremyj@apple.com> on 2015-03-06
Reviewed by Simon Fraser.

Source/WebCore:

This patch will scroll the element so it is visible when exiting fullscreen,
but only if the element is completely scrolled off screen.
Also update the element screen rect so exit animation goes to the correct location.

  • dom/Element.cpp:

(WebCore::Element::scrollIntoViewIfNotVisible): Added.

  • dom/Element.h: Add declaration for scrollIntoViewIfNotVisible.
  • platform/ios/WebVideoFullscreenControllerAVKit.mm:

(-[WebVideoFullscreenController fullscreenMayReturnToInline]):

  • platform/ios/WebVideoFullscreenInterfaceAVKit.h:
  • platform/ios/WebVideoFullscreenInterfaceAVKit.mm:

(-[WebAVPlayerController playerViewController:restoreUserInterfaceForOptimizedFullscreenStopWithCompletionHandler:]):
(-[WebAVPlayerController playerViewControllerWillCancelOptimizedFullscree:]):
(WebVideoFullscreenInterfaceAVKit::setupFullscreen):
(WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal):
(WebVideoFullscreenInterfaceAVKit::exitFullscreen):
(WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal):
(WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline):
(WebVideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline):

  • rendering/ScrollBehavior.cpp:
  • rendering/ScrollBehavior.h:

Source/WebKit2:

This patch will restore interface state when exiting fullscreen.
Adds preparedToReturnToInline to continue exiting once the interface is updated.

  • UIProcess/ios/WebVideoFullscreenManagerProxy.h:
  • UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
  • UIProcess/ios/WebVideoFullscreenManagerProxy.mm:

(WebKit::WebVideoFullscreenManagerProxy::setupFullscreenWithID):
(WebKit::WebVideoFullscreenManagerProxy::fullscreenMayReturnToInline):
(WebKit::WebVideoFullscreenManagerProxy::preparedToReturnToInline): added.

  • WebProcess/ios/WebVideoFullscreenManager.h:
  • WebProcess/ios/WebVideoFullscreenManager.messages.in:
  • WebProcess/ios/WebVideoFullscreenManager.mm:

(WebKit::WebVideoFullscreenManager::fullscreenMayReturnToInline):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181172 r181173  
     12015-03-06  Jeremy Jones  <jeremyj@apple.com>
     2
     3        Scroll to make the video element visible when exiting fullscreen.
     4        https://bugs.webkit.org/show_bug.cgi?id=141439
     5
     6        Reviewed by Simon Fraser.
     7
     8        This patch will scroll the element so it is visible when exiting fullscreen,
     9        but only if the element is completely scrolled off screen.
     10        Also update the element screen rect so exit animation goes to the correct location.
     11
     12        * dom/Element.cpp:
     13        (WebCore::Element::scrollIntoViewIfNotVisible): Added.
     14        * dom/Element.h: Add declaration for scrollIntoViewIfNotVisible.
     15        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
     16        (-[WebVideoFullscreenController fullscreenMayReturnToInline]):
     17        * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
     18        * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
     19        (-[WebAVPlayerController playerViewController:restoreUserInterfaceForOptimizedFullscreenStopWithCompletionHandler:]):
     20        (-[WebAVPlayerController playerViewControllerWillCancelOptimizedFullscree:]):
     21        (WebVideoFullscreenInterfaceAVKit::setupFullscreen):
     22        (WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal):
     23        (WebVideoFullscreenInterfaceAVKit::exitFullscreen):
     24        (WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal):
     25        (WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline):
     26        (WebVideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline):
     27        * rendering/ScrollBehavior.cpp:
     28        * rendering/ScrollBehavior.h:
     29
    1302015-03-06  Myles C. Maxfield  <mmaxfield@apple.com>
    231
  • trunk/Source/WebCore/dom/Element.cpp

    r181169 r181173  
    612612}
    613613
     614void Element::scrollIntoViewIfNotVisible(bool centerIfNotVisible)
     615{
     616    document().updateLayoutIgnorePendingStylesheets();
     617   
     618    if (!renderer())
     619        return;
     620   
     621    LayoutRect bounds = renderer()->anchorRect();
     622    if (centerIfNotVisible)
     623        renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNotVisible, ScrollAlignment::alignCenterIfNotVisible);
     624    else
     625        renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNotVisible, ScrollAlignment::alignToEdgeIfNotVisible);
     626}
     627   
    614628void Element::scrollByUnits(int units, ScrollGranularity granularity)
    615629{
  • trunk/Source/WebCore/dom/Element.h

    r181169 r181173  
    123123    void scrollIntoView(bool alignToTop = true);
    124124    void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
     125    WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
    125126
    126127    void scrollByLines(int lines);
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm

    r177399 r181173  
    184184- (void)fullscreenMayReturnToInline
    185185{
     186    _interface->preparedToReturnToInline(true, _videoElement->clientRect());
    186187}
    187188
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h

    r179941 r181173  
    8585    WEBCORE_EXPORT virtual void setExternalPlayback(bool enabled, ExternalPlaybackTargetType, WTF::String localizedDeviceName) override;
    8686   
    87     WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&, IntRect initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
     87    WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&, const IntRect& initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
    8888    WEBCORE_EXPORT virtual void enterFullscreen();
    89     WEBCORE_EXPORT virtual void exitFullscreen(IntRect finalRect);
     89    WEBCORE_EXPORT virtual void exitFullscreen(const IntRect& finalRect);
    9090    WEBCORE_EXPORT virtual void cleanupFullscreen();
    9191    WEBCORE_EXPORT virtual void invalidate();
    9292    WEBCORE_EXPORT virtual void requestHideAndExitFullscreen();
     93    WEBCORE_EXPORT virtual void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
    9394
    9495    HTMLMediaElement::VideoFullscreenMode mode() const { return m_mode; }
    9596    void setIsOptimized(bool);
    9697    WEBCORE_EXPORT bool mayAutomaticallyShowVideoOptimized();
    97     bool fullscreenMayReturnToInline();
     98    void fullscreenMayReturnToInline();
    9899
    99100protected:
    100101    void beginSession();
    101     void setupFullscreenInternal(PlatformLayer&, IntRect initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
     102    void setupFullscreenInternal(PlatformLayer&, const IntRect& initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
    102103    void enterFullscreenOptimized();
    103104    void enterFullscreenStandard();
    104     void exitFullscreenInternal(IntRect finalRect);
     105    void exitFullscreenInternal(const IntRect& finalRect);
    105106    void cleanupFullscreenInternal();
    106107
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm

    r181049 r181173  
    116116@property (retain) NSString *externalPlaybackAirPlayDeviceLocalizedName;
    117117
     118@property (copy) void (^exitOptimizedCallback)(BOOL restored);
     119
    118120- (BOOL)playerViewController:(AVPlayerViewController *)playerViewController shouldExitFullScreenWithReason:(AVPlayerViewControllerExitFullScreenReason)reason;
    119121@end
     
    202204{
    203205    UNUSED_PARAM(playerViewController);
    204     completionHandler(self.fullscreenInterface->fullscreenMayReturnToInline());
     206    self.exitOptimizedCallback = completionHandler;
     207    self.fullscreenInterface->fullscreenMayReturnToInline();
    205208}
    206209
     
    208211{
    209212    UNUSED_PARAM(playerViewController);
    210     ASSERT(self.delegate);
     213    if (!self.delegate)
     214        return
    211215    self.delegate->requestExitFullscreen();
    212216}
     
    845849}
    846850
    847 void WebVideoFullscreenInterfaceAVKit::setupFullscreen(PlatformLayer& videoLayer, WebCore::IntRect initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
     851void WebVideoFullscreenInterfaceAVKit::setupFullscreen(PlatformLayer& videoLayer, const WebCore::IntRect& initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
    848852{
    849853    RefPtr<WebVideoFullscreenInterfaceAVKit> strongThis(this);
     
    859863}
    860864
    861 void WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal(PlatformLayer& videoLayer, WebCore::IntRect initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
     865void WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal(PlatformLayer& videoLayer, const WebCore::IntRect& initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
    862866{
    863867    UNUSED_PARAM(videoLayer);
     
    993997}
    994998
    995 void WebVideoFullscreenInterfaceAVKit::exitFullscreen(WebCore::IntRect finalRect)
     999void WebVideoFullscreenInterfaceAVKit::exitFullscreen(const WebCore::IntRect& finalRect)
    9961000{
    9971001    RefPtr<WebVideoFullscreenInterfaceAVKit> strongThis(this);
     
    10131017}
    10141018
    1015 void WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal(WebCore::IntRect finalRect)
     1019void WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal(const WebCore::IntRect& finalRect)
    10161020{
    10171021    [m_playerViewController setShowsPlaybackControls:NO];
     
    11441148}
    11451149
     1150void WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline(bool visible, const IntRect& inlineRect)
     1151{
     1152    RefPtr<WebVideoFullscreenInterfaceAVKit> strongThis(this);
     1153    dispatch_async(dispatch_get_main_queue(), [strongThis, visible, inlineRect] {
     1154        if (strongThis->m_playerController.get().exitOptimizedCallback) {
     1155           
     1156            if (strongThis->m_viewController)
     1157                [strongThis->m_playerViewController view].frame = [strongThis->m_parentView convertRect:inlineRect toView:nil];
     1158            else
     1159                [strongThis->m_playerViewController view].frame = inlineRect;
     1160           
     1161            strongThis->m_playerController.get().exitOptimizedCallback(visible);
     1162        }
     1163    });
     1164}
     1165
    11461166void WebVideoFullscreenInterfaceAVKit::setIsOptimized(bool active)
    11471167{
     
    11821202}
    11831203
    1184 bool WebVideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline()
    1185 {
    1186     m_fullscreenChangeObserver->fullscreenMayReturnToInline();
    1187     return true;
     1204void WebVideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline()
     1205{
     1206    if (m_fullscreenChangeObserver)
     1207        m_fullscreenChangeObserver->fullscreenMayReturnToInline();
    11881208}
    11891209
  • trunk/Source/WebCore/rendering/ScrollBehavior.cpp

    r177050 r181173  
    4747namespace WebCore {
    4848
     49const ScrollAlignment ScrollAlignment::alignCenterIfNotVisible = { noScroll, alignCenter, noScroll };
     50const ScrollAlignment ScrollAlignment::alignToEdgeIfNotVisible = { noScroll, alignToClosestEdge, noScroll };
    4951const ScrollAlignment ScrollAlignment::alignCenterIfNeeded = { noScroll, alignCenter, alignToClosestEdge };
    5052WEBCORE_EXPORT const ScrollAlignment ScrollAlignment::alignToEdgeIfNeeded = { noScroll, alignToClosestEdge, alignToClosestEdge };
  • trunk/Source/WebCore/rendering/ScrollBehavior.h

    r180301 r181173  
    6262    static ScrollBehavior getHiddenBehavior(const ScrollAlignment& s) { return s.m_rectHidden; }
    6363
     64    static const ScrollAlignment alignCenterIfNotVisible;
     65    static const ScrollAlignment alignToEdgeIfNotVisible;
    6466    static const ScrollAlignment alignCenterIfNeeded;
    6567    WEBCORE_EXPORT static const ScrollAlignment alignToEdgeIfNeeded;
  • trunk/Source/WebKit2/ChangeLog

    r181162 r181173  
     12015-03-06  Jeremy Jones  <jeremyj@apple.com>
     2
     3        Scroll to make the video element visible when exiting fullscreen.
     4        https://bugs.webkit.org/show_bug.cgi?id=141439
     5
     6        Reviewed by Simon Fraser.
     7
     8        This patch will restore interface state when exiting fullscreen.
     9        Adds preparedToReturnToInline to continue exiting once the interface is updated.
     10
     11        * UIProcess/ios/WebVideoFullscreenManagerProxy.h:
     12        * UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
     13        * UIProcess/ios/WebVideoFullscreenManagerProxy.mm:
     14        (WebKit::WebVideoFullscreenManagerProxy::setupFullscreenWithID):
     15        (WebKit::WebVideoFullscreenManagerProxy::fullscreenMayReturnToInline):
     16        (WebKit::WebVideoFullscreenManagerProxy::preparedToReturnToInline): added.
     17        * WebProcess/ios/WebVideoFullscreenManager.h:
     18        * WebProcess/ios/WebVideoFullscreenManager.messages.in:
     19        * WebProcess/ios/WebVideoFullscreenManager.mm:
     20        (WebKit::WebVideoFullscreenManager::fullscreenMayReturnToInline):
     21
    1222015-03-06  Antti Koivisto  <antti@apple.com>
    223
  • trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h

    r178660 r181173  
    5656
    5757    // Translate to FullscreenInterface
    58     void setupFullscreenWithID(uint32_t, WebCore::IntRect initialRect, float hostingDeviceScaleFactor, WebCore::HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
     58    void setupFullscreenWithID(uint32_t, const WebCore::IntRect& initialRect, float hostingDeviceScaleFactor, WebCore::HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
    5959    void setSeekableRangesVector(const Vector<std::pair<double, double>>&);
    6060    void setExternalPlaybackProperties(bool enabled, uint32_t targetType, String localizedDeviceName);
    6161    void fullscreenModeChanged(WebCore::HTMLMediaElement::VideoFullscreenMode) override;
    62    
     62    void preparedToReturnToInline(bool visible, const WebCore::IntRect& inlineRect) override;
     63
    6364    // Fullscreen Observer
    6465    virtual void didSetupFullscreen() override;
  • trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in

    r179480 r181173  
    3737    ExitFullscreen(WebCore::IntRect finalRect)
    3838    CleanupFullscreen()
     39    PreparedToReturnToInline(bool visible, WebCore::IntRect inlineRect)
    3940}
    4041#endif
  • trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm

    r179574 r181173  
    7676}
    7777
    78 void WebVideoFullscreenManagerProxy::setupFullscreenWithID(uint32_t videoLayerID, WebCore::IntRect initialRect, float hostingDeviceScaleFactor, HTMLMediaElement::VideoFullscreenMode videoFullscreenMode, bool allowOptimizedFullscreen)
     78void WebVideoFullscreenManagerProxy::setupFullscreenWithID(uint32_t videoLayerID, const WebCore::IntRect& initialRect, float hostingDeviceScaleFactor, HTMLMediaElement::VideoFullscreenMode videoFullscreenMode, bool allowOptimizedFullscreen)
    7979{
    8080    ASSERT(videoLayerID);
     
    120120void WebVideoFullscreenManagerProxy::fullscreenMayReturnToInline()
    121121{
     122    bool isViewVisible = m_page->isViewVisible();
     123    m_page->send(Messages::WebVideoFullscreenManager::FullscreenMayReturnToInline(isViewVisible), m_page->pageID());
     124}
     125   
     126void WebVideoFullscreenManagerProxy::preparedToReturnToInline(bool visible, const WebCore::IntRect& inlineRect)
     127{
    122128    m_page->fullscreenMayReturnToInline();
     129    WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline(visible, inlineRect);
    123130}
    124131
  • trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h

    r179480 r181173  
    8787    virtual void didCleanupFullscreen();
    8888    virtual void setVideoLayerGravityEnum(unsigned);
     89    virtual void fullscreenMayReturnToInline(bool isPageVisible);
    8990    void setVideoLayerFrameFenced(WebCore::FloatRect bounds, IPC::Attachment fencePort);
    9091   
  • trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.messages.in

    r177012 r181173  
    4343    SelectLegibleMediaOption(uint64_t index)
    4444    fullscreenModeChanged(WebCore::HTMLMediaElement::VideoFullscreenMode videoFullscreenMode)
     45    FullscreenMayReturnToInline(bool isPageVisible)
    4546}
    4647#endif
  • trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm

    r179480 r181173  
    259259}
    260260   
     261void WebVideoFullscreenManager::fullscreenMayReturnToInline(bool isPageVisible)
     262{
     263    if (!isPageVisible)
     264        m_videoElement->scrollIntoViewIfNotVisible(false);
     265    m_page->send(Messages::WebVideoFullscreenManagerProxy::PreparedToReturnToInline(true, clientRectForElement(m_videoElement.get())), m_page->pageID());
     266}
     267   
    261268void WebVideoFullscreenManager::setVideoLayerFrameFenced(WebCore::FloatRect bounds, IPC::Attachment fencePort)
    262269{
Note: See TracChangeset for help on using the changeset viewer.