Page using safe area constant properties jumps to correct layout after resize
https://bugs.webkit.org/show_bug.cgi?id=174598
<rdar://problem/33364275>
Reviewed by Simon Fraser.
Source/WebKit:
Test: fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _beginAnimatedResizeWithUpdates:]):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::dynamicViewportSizeUpdate):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::dynamicViewportSizeUpdate):
Plumb unobscured safe area insets through in the dynamicViewportSizeUpdate,
like we do in VisibleContentRectUpdate (once again sad that these aren't
more similar), so that it will be correct in the during-rotation snapshot,
instead of only becoming correct in the first visible content rect update
post-rotation.
LayoutTests:
* fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation-expected.txt: Added.
* fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html: Added.
Add a test making sure that dynamic-viewport-update-based rotation
updates safe area insets when needed.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@219594 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 40e509c..095aa25 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2017-07-17 Timothy Horton <timothy_horton@apple.com>
+
+ Page using safe area constant properties jumps to correct layout after resize
+ https://bugs.webkit.org/show_bug.cgi?id=174598
+ <rdar://problem/33364275>
+
+ Reviewed by Simon Fraser.
+
+ * fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation-expected.txt: Added.
+ * fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html: Added.
+ Add a test making sure that dynamic-viewport-update-based rotation
+ updates safe area insets when needed.
+
2017-07-17 Matt Lewis <jlewis3@apple.com>
Fixed test expectations after r219518.
diff --git a/LayoutTests/fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation-expected.txt b/LayoutTests/fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation-expected.txt
new file mode 100644
index 0000000..8a19d8e
--- /dev/null
+++ b/LayoutTests/fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation-expected.txt
@@ -0,0 +1,15 @@
+Before rotation
+layoutViewport: 0, 0 - 320 x 548
+visualViewport: 0, 0 - 320 x 548
+client rect of fixed object:0, 0 - 320 x 548
+
+In resize event handler:
+layoutViewport: 0, 0 - 568 x 320
+visualViewport: 0, 0 - 568 x 320
+client rect of fixed object:100, 50 - 443 x 195
+
+After rotation
+layoutViewport: 0, 0 - 568 x 320
+visualViewport: 0, 0 - 568 x 320
+client rect of fixed object:100, 50 - 443 x 195
+
diff --git a/LayoutTests/fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html b/LayoutTests/fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html
new file mode 100644
index 0000000..1ccc8d7
--- /dev/null
+++ b/LayoutTests/fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+ <meta name="viewport" content="initial-scale=1, viewport-fit=cover">
+ <style>
+ body {
+ height: 2000px;
+ }
+
+ #extent {
+ position: fixed;
+ border: 10px solid rgba(0, 0, 128, 0.5);
+ left: constant(safe-area-inset-left);
+ top: constant(safe-area-inset-top);
+ right: constant(safe-area-inset-right);
+ bottom: constant(safe-area-inset-bottom);
+ }
+ </style>
+ <script src="../../../../resources/js-test-pre.js"></script>
+ <script src="resources/rotation-utils.js"></script>
+ <script>
+ if (window.internals) {
+ internals.settings.setConstantPropertiesEnabled(true);
+ internals.settings.setViewportFitEnabled(true);
+ }
+
+ function getRotationUIScript()
+ {
+ return `
+ (function() {
+ uiController.setSafeAreaInsets(50, 25, 75, 100);
+ uiController.simulateRotationLikeSafari('landscape-right', function() {
+ uiController.uiScriptComplete();
+ });
+ })();`
+ }
+
+ window.addEventListener('resize', function() {
+ accumulateLog('');
+ accumulateLog('In resize event handler:');
+ logFixedAndViewports();
+ }, false);
+
+ window.addEventListener('load', doTest, false);
+ </script>
+</head>
+<body>
+ <div id="extent"></div>
+<script src="../../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index d52f82a..1018bf6 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,28 @@
+2017-07-17 Timothy Horton <timothy_horton@apple.com>
+
+ Page using safe area constant properties jumps to correct layout after resize
+ https://bugs.webkit.org/show_bug.cgi?id=174598
+ <rdar://problem/33364275>
+
+ Reviewed by Simon Fraser.
+
+ Test: fast/events/ios/rotation/safe-area-insets-during-safari-type-rotation.html
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _beginAnimatedResizeWithUpdates:]):
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/ios/WebPageProxyIOS.mm:
+ (WebKit::WebPageProxy::dynamicViewportSizeUpdate):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::dynamicViewportSizeUpdate):
+ Plumb unobscured safe area insets through in the dynamicViewportSizeUpdate,
+ like we do in VisibleContentRectUpdate (once again sad that these aren't
+ more similar), so that it will be correct in the during-rotation snapshot,
+ instead of only becoming correct in the first visible content rect update
+ post-rotation.
+
2017-07-17 Chris Dumez <cdumez@apple.com>
UserMediaPermissionRequestManagerProxy should not use WebCore::Timer
diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
index 3be40d7..7da4d60 100644
--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
@@ -4859,7 +4859,10 @@
CGRect visibleRectInContentCoordinates = [self convertRect:newBounds toView:_contentView.get()];
CGRect unobscuredRectInContentCoordinates = [self convertRect:futureUnobscuredRectInSelfCoordinates toView:_contentView.get()];
- _page->dynamicViewportSizeUpdate(newMinimumLayoutSize, newMaximumUnobscuredSize, visibleRectInContentCoordinates, unobscuredRectInContentCoordinates, futureUnobscuredRectInSelfCoordinates, targetScale, newOrientation);
+ UIEdgeInsets unobscuredSafeAreaInsets = [self _computedUnobscuredSafeAreaInset];
+ WebCore::FloatBoxExtent unobscuredSafeAreaInsetsExtent(unobscuredSafeAreaInsets.top, unobscuredSafeAreaInsets.right, unobscuredSafeAreaInsets.bottom, unobscuredSafeAreaInsets.left);
+
+ _page->dynamicViewportSizeUpdate(newMinimumLayoutSize, newMaximumUnobscuredSize, visibleRectInContentCoordinates, unobscuredRectInContentCoordinates, futureUnobscuredRectInSelfCoordinates, unobscuredSafeAreaInsetsExtent, targetScale, newOrientation);
if (WebKit::DrawingAreaProxy* drawingArea = _page->drawingArea())
drawingArea->setSize(WebCore::IntSize(newBounds.size), WebCore::IntSize(), WebCore::IntSize());
}
diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h
index a908803..52cd36f 100644
--- a/Source/WebKit/UIProcess/WebPageProxy.h
+++ b/Source/WebKit/UIProcess/WebPageProxy.h
@@ -499,7 +499,7 @@
void overflowScrollWillStartScroll();
void overflowScrollDidEndScroll();
- void dynamicViewportSizeUpdate(const WebCore::FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, double targetScale, int32_t deviceOrientation);
+ void dynamicViewportSizeUpdate(const WebCore::FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation);
void synchronizeDynamicViewportUpdate();
void setViewportConfigurationMinimumLayoutSize(const WebCore::FloatSize&);
diff --git a/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm b/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
index c1ba764..c43c765 100644
--- a/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
+++ b/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
@@ -287,7 +287,7 @@
m_pageClient.overflowScrollDidEndScroll();
}
-void WebPageProxy::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const FloatRect& targetUnobscuredRectInScrollViewCoordinates, double targetScale, int32_t deviceOrientation)
+void WebPageProxy::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation)
{
if (!isValid())
return;
@@ -296,7 +296,7 @@
m_dynamicViewportSizeUpdateWaitingForTarget = true;
m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = true;
- m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(minimumLayoutSize, maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect, targetUnobscuredRectInScrollViewCoordinates, targetScale, deviceOrientation, ++m_currentDynamicViewportSizeUpdateID), m_pageID);
+ m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(minimumLayoutSize, maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect, targetUnobscuredRectInScrollViewCoordinates, unobscuredSafeAreaInsets, targetScale, deviceOrientation, ++m_currentDynamicViewportSizeUpdateID), m_pageID);
}
void WebPageProxy::synchronizeDynamicViewportUpdate()
diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h
index 142f57d..77245d5 100644
--- a/Source/WebKit/WebProcess/WebPage/WebPage.h
+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h
@@ -825,7 +825,7 @@
void setViewportConfigurationMinimumLayoutSize(const WebCore::FloatSize&);
void setMaximumUnobscuredSize(const WebCore::FloatSize&);
void setDeviceOrientation(int32_t);
- void dynamicViewportSizeUpdate(const WebCore::FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, double scale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID);
+ void dynamicViewportSizeUpdate(const WebCore::FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double scale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID);
void synchronizeDynamicViewportUpdate(double& newTargetScale, WebCore::FloatPoint& newScrollPosition, uint64_t& nextValidLayerTreeTransactionID);
std::optional<float> scaleFromUIProcess(const VisibleContentRectUpdateInfo&) const;
void updateVisibleContentRects(const VisibleContentRectUpdateInfo&, MonotonicTime oldestTimestamp);
diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
index 9e32133..1aaa1dd 100644
--- a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
+++ b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
@@ -43,7 +43,7 @@
SetViewportConfigurationMinimumLayoutSize(WebCore::FloatSize size)
SetMaximumUnobscuredSize(WebCore::FloatSize size)
SetDeviceOrientation(int32_t deviceOrientation)
- DynamicViewportSizeUpdate(WebCore::FloatSize minimumLayoutSize, WebCore::FloatSize maximumUnobscuredSize, WebCore::FloatRect targetExposedContentRect, WebCore::FloatRect targetUnobscuredRect, WebCore::FloatRect targetUnobscuredRectInScrollViewCoordinates, double scale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID)
+ DynamicViewportSizeUpdate(WebCore::FloatSize minimumLayoutSize, WebCore::FloatSize maximumUnobscuredSize, WebCore::FloatRect targetExposedContentRect, WebCore::FloatRect targetUnobscuredRect, WebCore::FloatRect targetUnobscuredRectInScrollViewCoordinates, WebCore::BoxExtent<float> targetUnobscuredSafeAreaInsets, double scale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID)
SynchronizeDynamicViewportUpdate() -> (double newTargetScale, WebCore::FloatPoint newScrollPosition, uint64_t nextValidLayerTreeTransactionID)
HandleTap(WebCore::IntPoint point, uint64_t lastLayerTreeTransactionId)
diff --git a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
index 475ac86..af08af8 100644
--- a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
+++ b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
@@ -2856,7 +2856,7 @@
}
}
-void WebPage::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, double targetScale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID)
+void WebPage::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID)
{
SetForScope<bool> dynamicSizeUpdateGuard(m_inDynamicSizeUpdate, true);
// FIXME: this does not handle the cases where the content would change the content size or scroll position from JavaScript.
@@ -2900,6 +2900,7 @@
resetTextAutosizing();
setMaximumUnobscuredSize(maximumUnobscuredSize);
+ m_page->setUnobscuredSafeAreaInsets(targetUnobscuredSafeAreaInsets);
frameView.updateLayoutAndStyleIfNeededRecursive();