[iOS WK2] YouTube videos flash at the wrong place at the end of rotation
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Jun 2017 01:43:27 +0000 (01:43 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Jun 2017 01:43:27 +0000 (01:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173445
rdar://problem/31584852

Reviewed by Tim Horton.

In MobileSafari where WKWebView rotation uses _dynamicViewportUpdateModes, we could do a
visibleContentRect update at the end of rotation which computed a bad layoutViewportRect,
because it used a m_baseLayoutViewportSize from the old orientation.

We have actually sent a new m_baseLayoutViewportSize to the UI process by this point in
a layer tree commit, but _didCommitLayerTree: ignored it because we had a _dynamicViewportUpdateMode.

Fix is to always update the layout viewport data from the web process, since during dynamic
viewport updates, we still need these data to compute rectangles sent back to the web process via
visible content rect updates.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didCommitLayerTree:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::computeCustomFixedPositionRect):
(WebKit::WebPageProxy::updateLayoutViewportParameters): Cleanup.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm

index dd4d56b..2e388f8 100644 (file)
@@ -1,3 +1,28 @@
+2017-06-15  Simon Fraser  <simon.fraser@apple.com>
+
+        [iOS WK2] YouTube videos flash at the wrong place at the end of rotation
+        https://bugs.webkit.org/show_bug.cgi?id=173445
+        rdar://problem/31584852
+
+        Reviewed by Tim Horton.
+
+        In MobileSafari where WKWebView rotation uses _dynamicViewportUpdateModes, we could do a
+        visibleContentRect update at the end of rotation which computed a bad layoutViewportRect,
+        because it used a m_baseLayoutViewportSize from the old orientation.
+
+        We have actually sent a new m_baseLayoutViewportSize to the UI process by this point in 
+        a layer tree commit, but _didCommitLayerTree: ignored it because we had a _dynamicViewportUpdateMode.
+
+        Fix is to always update the layout viewport data from the web process, since during dynamic
+        viewport updates, we still need these data to compute rectangles sent back to the web process via
+        visible content rect updates.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _didCommitLayerTree:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::computeCustomFixedPositionRect):
+        (WebKit::WebPageProxy::updateLayoutViewportParameters): Cleanup.
+
 2017-06-15  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Using -[WebItemProviderPasteboard setItemProviders:] to swap out item providers before a drop breaks item provider loading
index 445609d..c0db733 100644 (file)
@@ -1478,6 +1478,8 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
 
     LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView _didCommitLayerTree:] transactionID " <<  layerTreeTransaction.transactionID() << " _dynamicViewportUpdateMode " << (int)_dynamicViewportUpdateMode);
 
+    BOOL needUpdateVisbleContentRects = _page->updateLayoutViewportParameters(layerTreeTransaction);
+
     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) {
         if (_resizeAnimationTransformTransactionID && layerTreeTransaction.transactionID() >= _resizeAnimationTransformTransactionID.value()) {
             _resizeAnimationTransformTransactionID = std::nullopt;
@@ -1514,8 +1516,6 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
         _stableStatePresentationUpdateCallbacks = nil;
     }
 
-    BOOL needUpdateVisbleContentRects = _page->updateLayoutViewportParameters(layerTreeTransaction);
-
     if (![_contentView _mayDisableDoubleTapGesturesDuringSingleTap])
         [_contentView _setDoubleTapGesturesEnabled:self._allowsDoubleTapGestures];
 
index a5c6fc4..43bb4f0 100644 (file)
@@ -259,7 +259,7 @@ WebCore::FloatRect WebPageProxy::computeCustomFixedPositionRect(const FloatRect&
         
     FloatSize constainedSize = isBelowMinimumScale ? constrainedUnobscuredRect.size() : unobscuredContentRect.size();
     FloatRect unobscuredContentRectForViewport = isBelowMinimumScale ? constrainedUnobscuredRect : unobscuredContentRectRespectingInputViewBounds;
-    
+
     FloatRect layoutViewportRect = FrameView::computeUpdatedLayoutViewportRect(LayoutRect(currentCustomFixedPositionRect), LayoutRect(documentRect), LayoutSize(constainedSize), LayoutRect(unobscuredContentRectForViewport), m_baseLayoutViewportSize, m_minStableLayoutViewportOrigin, m_maxStableLayoutViewportOrigin, constraint);
     
     if (layoutViewportRect != currentCustomFixedPositionRect)
@@ -404,15 +404,18 @@ void WebPageProxy::didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction&
 
 bool WebPageProxy::updateLayoutViewportParameters(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
 {
-    bool changed = m_baseLayoutViewportSize != layerTreeTransaction.baseLayoutViewportSize()
-        || m_minStableLayoutViewportOrigin != layerTreeTransaction.minStableLayoutViewportOrigin()
-        || m_maxStableLayoutViewportOrigin != layerTreeTransaction.maxStableLayoutViewportOrigin();
+    if (m_baseLayoutViewportSize == layerTreeTransaction.baseLayoutViewportSize()
+        && m_minStableLayoutViewportOrigin == layerTreeTransaction.minStableLayoutViewportOrigin()
+        && m_maxStableLayoutViewportOrigin == layerTreeTransaction.maxStableLayoutViewportOrigin())
+        return false;
 
     m_baseLayoutViewportSize = layerTreeTransaction.baseLayoutViewportSize();
     m_minStableLayoutViewportOrigin = layerTreeTransaction.minStableLayoutViewportOrigin();
     m_maxStableLayoutViewportOrigin = layerTreeTransaction.maxStableLayoutViewportOrigin();
-    
-    return changed;
+
+    LOG_WITH_STREAM(VisibleRects, stream << "WebPageProxy::updateLayoutViewportParameters: baseLayoutViewportSize: " << m_baseLayoutViewportSize << " minStableLayoutViewportOrigin: " << m_minStableLayoutViewportOrigin << " maxStableLayoutViewportOrigin: " << m_maxStableLayoutViewportOrigin);
+
+    return true;
 }
 
 void WebPageProxy::layerTreeCommitComplete()