<!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>[185661] trunk</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/185661">185661</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2015-06-17 12:23:08 -0700 (Wed, 17 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Safari tabs still have shrunken content after coming out of fullscreen
https://bugs.webkit.org/show_bug.cgi?id=146037
&lt;rdar://problem/21105960&gt;

Reviewed by Simon Fraser and Darin Adler.

* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::useFixedLayoutDidChange):
(WebKit::WebPageProxy::fixedLayoutSizeDidChange):
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setUseFixedLayout):
(WebKit::WebPage::setFixedLayoutSize):
Keep the UI process up-to-date when fixed layout is enabled or the size changes.
This is important because these things can change from the Web process side too,
and the UI process uses its (potentially stale) version to do some short-circuiting.
This was causing us to fail to turn off fixed layout when it was turned
on from the Web process side (by TiledCoreAnimationDrawingArea).

* UIProcess/mac/WKViewLayoutStrategy.mm:
(-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy willChangeLayoutStrategy]):
Reset the view scale, which WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy
makes heavy use of, just like the others.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm: Added.
(-[ShrinkToFitNavigationDelegate webView:didFinishNavigation:]):
(TEST):
Add a test that ensures that disabling scale-to-fit mode correctly updates
the page's layout.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWKViewLayoutStrategymm">trunk/Source/WebKit2/UIProcess/mac/WKViewLayoutStrategy.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaShrinkToFitmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Source/WebKit2/ChangeLog        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2015-06-17  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        Safari tabs still have shrunken content after coming out of fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=146037
+        &lt;rdar://problem/21105960&gt;
+
+        Reviewed by Simon Fraser and Darin Adler.
+
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::useFixedLayoutDidChange):
+        (WebKit::WebPageProxy::fixedLayoutSizeDidChange):
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setUseFixedLayout):
+        (WebKit::WebPage::setFixedLayoutSize):
+        Keep the UI process up-to-date when fixed layout is enabled or the size changes.
+        This is important because these things can change from the Web process side too,
+        and the UI process uses its (potentially stale) version to do some short-circuiting.
+        This was causing us to fail to turn off fixed layout when it was turned
+        on from the Web process side (by TiledCoreAnimationDrawingArea).
+
+        * UIProcess/mac/WKViewLayoutStrategy.mm:
+        (-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy willChangeLayoutStrategy]):
+        Reset the view scale, which WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy
+        makes heavy use of, just like the others.
+
</ins><span class="cx"> 2015-06-17  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Expose UIDelegate::UIClient::close via WKUIDelegate
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -1447,6 +1447,9 @@
</span><span class="cx">     void didPerformImmediateActionHitTest(const WebHitTestResult::Data&amp;, bool contentPreventsDefault, const UserData&amp;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    void useFixedLayoutDidChange(bool useFixedLayout) { m_useFixedLayout = useFixedLayout; }
+    void fixedLayoutSizeDidChange(WebCore::IntSize fixedLayoutSize) { m_fixedLayoutSize = fixedLayoutSize; }
+
</ins><span class="cx">     void handleAutoFillButtonClick(const UserData&amp;);
</span><span class="cx"> 
</span><span class="cx">     void handleMessage(IPC::Connection&amp;, const String&amp; messageName, const UserData&amp; messageBody);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -439,4 +439,6 @@
</span><span class="cx">     PlaybackTargetPickerClientStateDidChange(uint64_t contextId, unsigned mediaState)
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    UseFixedLayoutDidChange(bool useFixedLayout)
+    FixedLayoutSizeDidChange(WebCore::IntSize fixedLayoutSize)
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWKViewLayoutStrategymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WKViewLayoutStrategy.mm (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WKViewLayoutStrategy.mm        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Source/WebKit2/UIProcess/mac/WKViewLayoutStrategy.mm        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -401,6 +401,7 @@
</span><span class="cx"> - (void)willChangeLayoutStrategy
</span><span class="cx"> {
</span><span class="cx">     _page-&gt;setShouldScaleViewToFitDocument(false);
</span><ins>+    _page-&gt;scaleView(1);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -1537,6 +1537,8 @@
</span><span class="cx">     view-&gt;setUseFixedLayout(fixed);
</span><span class="cx">     if (!fixed)
</span><span class="cx">         setFixedLayoutSize(IntSize());
</span><ins>+
+    send(Messages::WebPageProxy::UseFixedLayoutDidChange(fixed));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPage::setFixedLayoutSize(const IntSize&amp; size)
</span><span class="lines">@@ -1546,6 +1548,8 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     view-&gt;setFixedLayoutSize(size);
</span><ins>+
+    send(Messages::WebPageProxy::FixedLayoutSizeDidChange(size));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IntSize WebPage::fixedLayoutSize() const
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Tools/ChangeLog        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-06-17  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        Safari tabs still have shrunken content after coming out of fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=146037
+        &lt;rdar://problem/21105960&gt;
+
+        Reviewed by Simon Fraser and Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm: Added.
+        (-[ShrinkToFitNavigationDelegate webView:didFinishNavigation:]):
+        (TEST):
+        Add a test that ensures that disabling scale-to-fit mode correctly updates
+        the page's layout.
+
</ins><span class="cx"> 2015-06-17  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Expose UIDelegate::UIClient::close via WKUIDelegate
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (185660 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-06-17 19:18:30 UTC (rev 185660)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx">                 290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; };
</span><span class="cx">                 297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
</span><span class="cx">                 2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */; };
</span><ins>+                2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */; };
</ins><span class="cx">                 2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
</span><span class="cx">                 2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
</span><span class="cx">                 2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
</span><span class="lines">@@ -468,6 +469,7 @@
</span><span class="cx">                 29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollPinningBehaviors.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShrinkToFit.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2DD7D3A9178205D00026E1E3 /* ResizeReversePaginatedWebView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeReversePaginatedWebView.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = &quot;lots-of-text-vertical-lr.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -842,6 +844,7 @@
</span><span class="cx">                                 CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
</span><span class="cx">                                 C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
</span><span class="cx">                                 37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */,
</span><ins>+                                2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
</ins><span class="cx">                                 7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
</span><span class="cx">                                 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
</span><span class="cx">                         );
</span><span class="lines">@@ -1602,6 +1605,7 @@
</span><span class="cx">                         isa = PBXSourcesBuildPhase;
</span><span class="cx">                         buildActionMask = 2147483647;
</span><span class="cx">                         files = (
</span><ins>+                                2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */,
</ins><span class="cx">                                 7AA021BB1AB09EA70052953F /* DateMath.cpp in Sources */,
</span><span class="cx">                                 2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */,
</span><span class="cx">                                 1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaShrinkToFitmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm (0 => 185661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm        2015-06-17 19:23:08 UTC (rev 185661)
</span><span class="lines">@@ -0,0 +1,84 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+
+#import &quot;PlatformUtilities.h&quot;
+#import &lt;WebKit/WKWebViewPrivate.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+#if WK_API_ENABLED &amp;&amp; !PLATFORM(IOS)
+
+static bool shrinkToFitDone;
+static bool shrinkToFitAfterNavigationDone;
+static bool shrinkToFitDisabledDone;
+
+@interface ShrinkToFitNavigationDelegate : NSObject &lt;WKNavigationDelegate&gt;
+@end
+
+@implementation ShrinkToFitNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    // After loading a wide page, the view should be scaled to fit the width of the document.
+    [webView evaluateJavaScript:@&quot;document.body.clientWidth&quot; completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(808, [result integerValue]);
+        shrinkToFitAfterNavigationDone = true;
+    }];
+}
+
+@end
+
+TEST(WebKit2, ShrinkToFit)
+{
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+
+    ShrinkToFitNavigationDelegate *delegate = [[ShrinkToFitNavigationDelegate alloc] init];
+    [webView setNavigationDelegate:delegate];
+
+    [webView evaluateJavaScript:@&quot;document.body.clientWidth&quot; completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(100, [result integerValue]);
+
+        [webView _setLayoutMode:_WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize];
+        shrinkToFitDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;shrinkToFitDone);
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;lots-of-text&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&amp;shrinkToFitAfterNavigationDone);
+
+    [webView _setLayoutMode:_WKLayoutModeViewSize];
+    [webView evaluateJavaScript:@&quot;document.body.clientWidth&quot; completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(100, [result integerValue]);
+        shrinkToFitDisabledDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;shrinkToFitDisabledDone);
+}
+
+#endif
</ins></span></pre>
</div>
</div>

</body>
</html>