<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[181173] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/181173">181173</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-03-06 11:28:26 -0800 (Fri, 06 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Scroll to make the video element visible when exiting fullscreen.
https://bugs.webkit.org/show_bug.cgi?id=141439

Patch by Jeremy Jones &lt;jeremyj@apple.com&gt; 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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementh">trunk/Source/WebCore/dom/Element.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenControllerAVKitmm">trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith">trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm">trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingScrollBehaviorcpp">trunk/Source/WebCore/rendering/ScrollBehavior.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingScrollBehaviorh">trunk/Source/WebCore/rendering/ScrollBehavior.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxyh">trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxymessagesin">trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxymm">trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessiosWebVideoFullscreenManagerh">trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessiosWebVideoFullscreenManagermessagesin">trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessiosWebVideoFullscreenManagermm">trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/ChangeLog        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2015-03-06  Jeremy Jones  &lt;jeremyj@apple.com&gt;
+
+        Scroll to make the video element visible when exiting fullscreen.
+        https://bugs.webkit.org/show_bug.cgi?id=141439
+
+        Reviewed by Simon Fraser.
+
+        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:
+
</ins><span class="cx"> 2015-03-06  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Crash in -[WebCascadeList objectAtIndex:] + 195
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/dom/Element.cpp        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -611,6 +611,20 @@
</span><span class="cx">         renderer()-&gt;scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Element::scrollIntoViewIfNotVisible(bool centerIfNotVisible)
+{
+    document().updateLayoutIgnorePendingStylesheets();
+    
+    if (!renderer())
+        return;
+    
+    LayoutRect bounds = renderer()-&gt;anchorRect();
+    if (centerIfNotVisible)
+        renderer()-&gt;scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNotVisible, ScrollAlignment::alignCenterIfNotVisible);
+    else
+        renderer()-&gt;scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNotVisible, ScrollAlignment::alignToEdgeIfNotVisible);
+}
+    
</ins><span class="cx"> void Element::scrollByUnits(int units, ScrollGranularity granularity)
</span><span class="cx"> {
</span><span class="cx">     document().updateLayoutIgnorePendingStylesheets();
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.h (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.h        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/dom/Element.h        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -122,6 +122,7 @@
</span><span class="cx"> 
</span><span class="cx">     void scrollIntoView(bool alignToTop = true);
</span><span class="cx">     void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
</span><ins>+    WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
</ins><span class="cx"> 
</span><span class="cx">     void scrollByLines(int lines);
</span><span class="cx">     void scrollByPages(int pages);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenControllerAVKitmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -183,6 +183,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)fullscreenMayReturnToInline
</span><span class="cx"> {
</span><ins>+    _interface-&gt;preparedToReturnToInline(true, _videoElement-&gt;clientRect());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -84,24 +84,25 @@
</span><span class="cx">     WEBCORE_EXPORT virtual void setLegibleMediaSelectionOptions(const Vector&lt;WTF::String&gt;&amp; options, uint64_t selectedIndex) override;
</span><span class="cx">     WEBCORE_EXPORT virtual void setExternalPlayback(bool enabled, ExternalPlaybackTargetType, WTF::String localizedDeviceName) override;
</span><span class="cx">     
</span><del>-    WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&amp;, IntRect initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
</del><ins>+    WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&amp;, const IntRect&amp; initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
</ins><span class="cx">     WEBCORE_EXPORT virtual void enterFullscreen();
</span><del>-    WEBCORE_EXPORT virtual void exitFullscreen(IntRect finalRect);
</del><ins>+    WEBCORE_EXPORT virtual void exitFullscreen(const IntRect&amp; finalRect);
</ins><span class="cx">     WEBCORE_EXPORT virtual void cleanupFullscreen();
</span><span class="cx">     WEBCORE_EXPORT virtual void invalidate();
</span><span class="cx">     WEBCORE_EXPORT virtual void requestHideAndExitFullscreen();
</span><ins>+    WEBCORE_EXPORT virtual void preparedToReturnToInline(bool visible, const IntRect&amp; inlineRect);
</ins><span class="cx"> 
</span><span class="cx">     HTMLMediaElement::VideoFullscreenMode mode() const { return m_mode; }
</span><span class="cx">     void setIsOptimized(bool);
</span><span class="cx">     WEBCORE_EXPORT bool mayAutomaticallyShowVideoOptimized();
</span><del>-    bool fullscreenMayReturnToInline();
</del><ins>+    void fullscreenMayReturnToInline();
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     void beginSession();
</span><del>-    void setupFullscreenInternal(PlatformLayer&amp;, IntRect initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
</del><ins>+    void setupFullscreenInternal(PlatformLayer&amp;, const IntRect&amp; initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
</ins><span class="cx">     void enterFullscreenOptimized();
</span><span class="cx">     void enterFullscreenStandard();
</span><del>-    void exitFullscreenInternal(IntRect finalRect);
</del><ins>+    void exitFullscreenInternal(const IntRect&amp; finalRect);
</ins><span class="cx">     void cleanupFullscreenInternal();
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;WebAVPlayerController&gt; m_playerController;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -115,6 +115,8 @@
</span><span class="cx"> @property AVPlayerControllerExternalPlaybackType externalPlaybackType;
</span><span class="cx"> @property (retain) NSString *externalPlaybackAirPlayDeviceLocalizedName;
</span><span class="cx"> 
</span><ins>+@property (copy) void (^exitOptimizedCallback)(BOOL restored);
+
</ins><span class="cx"> - (BOOL)playerViewController:(AVPlayerViewController *)playerViewController shouldExitFullScreenWithReason:(AVPlayerViewControllerExitFullScreenReason)reason;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="lines">@@ -201,13 +203,15 @@
</span><span class="cx"> - (void)playerViewController:(AVPlayerViewController *)playerViewController restoreUserInterfaceForOptimizedFullscreenStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(playerViewController);
</span><del>-    completionHandler(self.fullscreenInterface-&gt;fullscreenMayReturnToInline());
</del><ins>+    self.exitOptimizedCallback = completionHandler;
+    self.fullscreenInterface-&gt;fullscreenMayReturnToInline();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)playerViewControllerWillCancelOptimizedFullscree:(AVPlayerViewController *)playerViewController
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(playerViewController);
</span><del>-    ASSERT(self.delegate);
</del><ins>+    if (!self.delegate)
+        return
</ins><span class="cx">     self.delegate-&gt;requestExitFullscreen();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -844,7 +848,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebVideoFullscreenInterfaceAVKit::setupFullscreen(PlatformLayer&amp; videoLayer, WebCore::IntRect initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
</del><ins>+void WebVideoFullscreenInterfaceAVKit::setupFullscreen(PlatformLayer&amp; videoLayer, const WebCore::IntRect&amp; initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
</ins><span class="cx"> {
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</span><span class="cx"> 
</span><span class="lines">@@ -858,7 +862,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal(PlatformLayer&amp; videoLayer, WebCore::IntRect initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
</del><ins>+void WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal(PlatformLayer&amp; videoLayer, const WebCore::IntRect&amp; initialRect, UIView* parentView, HTMLMediaElement::VideoFullscreenMode mode, bool allowOptimizedFullscreen)
</ins><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(videoLayer);
</span><span class="cx">     UNUSED_PARAM(mode);
</span><span class="lines">@@ -992,7 +996,7 @@
</span><span class="cx">     }];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebVideoFullscreenInterfaceAVKit::exitFullscreen(WebCore::IntRect finalRect)
</del><ins>+void WebVideoFullscreenInterfaceAVKit::exitFullscreen(const WebCore::IntRect&amp; finalRect)
</ins><span class="cx"> {
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</span><span class="cx"> 
</span><span class="lines">@@ -1012,7 +1016,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal(WebCore::IntRect finalRect)
</del><ins>+void WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal(const WebCore::IntRect&amp; finalRect)
</ins><span class="cx"> {
</span><span class="cx">     [m_playerViewController setShowsPlaybackControls:NO];
</span><span class="cx">     if (m_viewController)
</span><span class="lines">@@ -1143,6 +1147,22 @@
</span><span class="cx">         m_videoFullscreenModel-&gt;requestExitFullscreen();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline(bool visible, const IntRect&amp; inlineRect)
+{
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    dispatch_async(dispatch_get_main_queue(), [strongThis, visible, inlineRect] {
+        if (strongThis-&gt;m_playerController.get().exitOptimizedCallback) {
+            
+            if (strongThis-&gt;m_viewController)
+                [strongThis-&gt;m_playerViewController view].frame = [strongThis-&gt;m_parentView convertRect:inlineRect toView:nil];
+            else
+                [strongThis-&gt;m_playerViewController view].frame = inlineRect;
+            
+            strongThis-&gt;m_playerController.get().exitOptimizedCallback(visible);
+        }
+    });
+}
+
</ins><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setIsOptimized(bool active)
</span><span class="cx"> {
</span><span class="cx">     if (m_mode &amp; HTMLMediaElement::VideoFullscreenModeStandard) {
</span><span class="lines">@@ -1181,10 +1201,10 @@
</span><span class="cx">     return [m_playerController isPlaying] &amp;&amp; m_mode == HTMLMediaElement::VideoFullscreenModeStandard &amp;&amp; wkIsOptimizedFullscreenSupported();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool WebVideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline()
</del><ins>+void WebVideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline()
</ins><span class="cx"> {
</span><del>-    m_fullscreenChangeObserver-&gt;fullscreenMayReturnToInline();
-    return true;
</del><ins>+    if (m_fullscreenChangeObserver)
+        m_fullscreenChangeObserver-&gt;fullscreenMayReturnToInline();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingScrollBehaviorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/ScrollBehavior.cpp (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/ScrollBehavior.cpp        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/rendering/ScrollBehavior.cpp        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -46,6 +46,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+const ScrollAlignment ScrollAlignment::alignCenterIfNotVisible = { noScroll, alignCenter, noScroll };
+const ScrollAlignment ScrollAlignment::alignToEdgeIfNotVisible = { noScroll, alignToClosestEdge, noScroll };
</ins><span class="cx"> const ScrollAlignment ScrollAlignment::alignCenterIfNeeded = { noScroll, alignCenter, alignToClosestEdge };
</span><span class="cx"> WEBCORE_EXPORT const ScrollAlignment ScrollAlignment::alignToEdgeIfNeeded = { noScroll, alignToClosestEdge, alignToClosestEdge };
</span><span class="cx"> WEBCORE_EXPORT const ScrollAlignment ScrollAlignment::alignCenterAlways = { alignCenter, alignCenter, alignCenter };
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingScrollBehaviorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/ScrollBehavior.h (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/ScrollBehavior.h        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebCore/rendering/ScrollBehavior.h        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -61,6 +61,8 @@
</span><span class="cx">     static ScrollBehavior getPartialBehavior(const ScrollAlignment&amp; s) { return s.m_rectPartial; }
</span><span class="cx">     static ScrollBehavior getHiddenBehavior(const ScrollAlignment&amp; s) { return s.m_rectHidden; }
</span><span class="cx"> 
</span><ins>+    static const ScrollAlignment alignCenterIfNotVisible;
+    static const ScrollAlignment alignToEdgeIfNotVisible;
</ins><span class="cx">     static const ScrollAlignment alignCenterIfNeeded;
</span><span class="cx">     WEBCORE_EXPORT static const ScrollAlignment alignToEdgeIfNeeded;
</span><span class="cx">     WEBCORE_EXPORT static const ScrollAlignment alignCenterAlways;
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/ChangeLog        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2015-03-06  Jeremy Jones  &lt;jeremyj@apple.com&gt;
+
+        Scroll to make the video element visible when exiting fullscreen.
+        https://bugs.webkit.org/show_bug.cgi?id=141439
+
+        Reviewed by Simon Fraser.
+
+        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):
+
</ins><span class="cx"> 2015-03-06  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rename NetworkCacheStorageCocoa.mm to NetworkCacheStorage.cpp
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -55,11 +55,12 @@
</span><span class="cx">     virtual void didReceiveMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;) override;
</span><span class="cx"> 
</span><span class="cx">     // Translate to FullscreenInterface
</span><del>-    void setupFullscreenWithID(uint32_t, WebCore::IntRect initialRect, float hostingDeviceScaleFactor, WebCore::HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
</del><ins>+    void setupFullscreenWithID(uint32_t, const WebCore::IntRect&amp; initialRect, float hostingDeviceScaleFactor, WebCore::HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
</ins><span class="cx">     void setSeekableRangesVector(const Vector&lt;std::pair&lt;double, double&gt;&gt;&amp;);
</span><span class="cx">     void setExternalPlaybackProperties(bool enabled, uint32_t targetType, String localizedDeviceName);
</span><span class="cx">     void fullscreenModeChanged(WebCore::HTMLMediaElement::VideoFullscreenMode) override;
</span><del>-    
</del><ins>+    void preparedToReturnToInline(bool visible, const WebCore::IntRect&amp; inlineRect) override;
+
</ins><span class="cx">     // Fullscreen Observer
</span><span class="cx">     virtual void didSetupFullscreen() override;
</span><span class="cx">     virtual void didEnterFullscreen() override;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -36,5 +36,6 @@
</span><span class="cx">     EnterFullscreen()
</span><span class="cx">     ExitFullscreen(WebCore::IntRect finalRect)
</span><span class="cx">     CleanupFullscreen()
</span><ins>+    PreparedToReturnToInline(bool visible, WebCore::IntRect inlineRect)
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -75,7 +75,7 @@
</span><span class="cx">     m_layerHost.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebVideoFullscreenManagerProxy::setupFullscreenWithID(uint32_t videoLayerID, WebCore::IntRect initialRect, float hostingDeviceScaleFactor, HTMLMediaElement::VideoFullscreenMode videoFullscreenMode, bool allowOptimizedFullscreen)
</del><ins>+void WebVideoFullscreenManagerProxy::setupFullscreenWithID(uint32_t videoLayerID, const WebCore::IntRect&amp; initialRect, float hostingDeviceScaleFactor, HTMLMediaElement::VideoFullscreenMode videoFullscreenMode, bool allowOptimizedFullscreen)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(videoLayerID);
</span><span class="cx">     m_layerHost = WKMakeRenderLayer(videoLayerID);
</span><span class="lines">@@ -119,7 +119,14 @@
</span><span class="cx">     
</span><span class="cx"> void WebVideoFullscreenManagerProxy::fullscreenMayReturnToInline()
</span><span class="cx"> {
</span><ins>+    bool isViewVisible = m_page-&gt;isViewVisible();
+    m_page-&gt;send(Messages::WebVideoFullscreenManager::FullscreenMayReturnToInline(isViewVisible), m_page-&gt;pageID());
+}
+    
+void WebVideoFullscreenManagerProxy::preparedToReturnToInline(bool visible, const WebCore::IntRect&amp; inlineRect)
+{
</ins><span class="cx">     m_page-&gt;fullscreenMayReturnToInline();
</span><ins>+    WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline(visible, inlineRect);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenManagerProxy::requestExitFullscreen()
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessiosWebVideoFullscreenManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -86,6 +86,7 @@
</span><span class="cx">     virtual void didExitFullscreen();
</span><span class="cx">     virtual void didCleanupFullscreen();
</span><span class="cx">     virtual void setVideoLayerGravityEnum(unsigned);
</span><ins>+    virtual void fullscreenMayReturnToInline(bool isPageVisible);
</ins><span class="cx">     void setVideoLayerFrameFenced(WebCore::FloatRect bounds, IPC::Attachment fencePort);
</span><span class="cx">     
</span><span class="cx">     WebPage* m_page;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessiosWebVideoFullscreenManagermessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.messages.in (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.messages.in        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.messages.in        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -42,5 +42,6 @@
</span><span class="cx">     SelectAudioMediaOption(uint64_t index)
</span><span class="cx">     SelectLegibleMediaOption(uint64_t index)
</span><span class="cx">     fullscreenModeChanged(WebCore::HTMLMediaElement::VideoFullscreenMode videoFullscreenMode)
</span><ins>+    FullscreenMayReturnToInline(bool isPageVisible)
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessiosWebVideoFullscreenManagermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm (181172 => 181173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm        2015-03-06 19:08:55 UTC (rev 181172)
+++ trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm        2015-03-06 19:28:26 UTC (rev 181173)
</span><span class="lines">@@ -258,6 +258,13 @@
</span><span class="cx">     setVideoLayerGravity((WebVideoFullscreenModel::VideoGravity)gravity);
</span><span class="cx"> }
</span><span class="cx">     
</span><ins>+void WebVideoFullscreenManager::fullscreenMayReturnToInline(bool isPageVisible)
+{
+    if (!isPageVisible)
+        m_videoElement-&gt;scrollIntoViewIfNotVisible(false);
+    m_page-&gt;send(Messages::WebVideoFullscreenManagerProxy::PreparedToReturnToInline(true, clientRectForElement(m_videoElement.get())), m_page-&gt;pageID());
+}
+    
</ins><span class="cx"> void WebVideoFullscreenManager::setVideoLayerFrameFenced(WebCore::FloatRect bounds, IPC::Attachment fencePort)
</span><span class="cx"> {
</span><span class="cx">     if (m_layerHostingContext)
</span></span></pre>
</div>
</div>

</body>
</html>