<!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>[247952] branches/safari-608-branch/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/247952">247952</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2019-07-29 20:54:06 -0700 (Mon, 29 Jul 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/247667">r247667</a>. rdar://problem/53647463

    [Text autosizing] Do not nuke the style on dynamicViewportSizeUpdate
    https://bugs.webkit.org/show_bug.cgi?id=199718
    <rdar://problem/53344961>

    Reviewed by Simon Fraser.

    Source/WebCore:

    When the page scale changes (e.g. as the result of shink to fit mode) we need to visit all the text content on the page and check whether they need to be boosted.
    Currently we call setNeedsRecalcStyleInAllFrames() to accomplish it. Unfortunatelly setNeedsRecalcStyleInAllFrames destroys all the style information which means that the
    subsequent styleResolve() needs to start from scratch.
    This patch addresses this issue by directly adjusting the computed style information when text boosting is required and schedules layout accordingly. We also trigger this style adjusting
    on a timer so that rapid dynamicViewportSizeUpdate() calls won't trigger redundant layouts.

    * css/StyleResolver.cpp:
    (WebCore::hasTextChild):
    (WebCore::StyleResolver::adjustRenderStyleForTextAutosizing):
    (WebCore::hasTextChildren): Deleted.
    * css/StyleResolver.h:
    * page/FrameView.h:
    * page/Page.cpp:
    (WebCore::Page::invalidateTextAutoSizeInAllFrames):
    * page/Page.h:

    Source/WebKit:

    * WebProcess/WebPage/WebPage.cpp:
    (WebKit::m_textAutoSizingAdjustmentTimer):
    (WebKit::WebPage::close):
    (WebKit::WebPage::didCommitLoad):
    (WebKit::WebPage::textAutoSizingAdjustmentTimerFired):
    (WebKit::m_shrinkToFitContentTimer): Deleted.
    * WebProcess/WebPage/WebPage.h:
    * WebProcess/WebPage/ios/WebPageIOS.mm:
    (WebKit::WebPage::dynamicViewportSizeUpdate):
    (WebKit::WebPage::resetIdempotentTextAutosizingIfNeeded):
    (WebKit::WebPage::resetTextAutosizing):
    (WebKit::WebPage::viewportConfigurationChanged):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247667 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari608branchSourceWebCoreChangeLog">branches/safari-608-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari608branchSourceWebCorecssStyleResolvercpp">branches/safari-608-branch/Source/WebCore/css/StyleResolver.cpp</a></li>
<li><a href="#branchessafari608branchSourceWebCorecssStyleResolverh">branches/safari-608-branch/Source/WebCore/css/StyleResolver.h</a></li>
<li><a href="#branchessafari608branchSourceWebCorepageFrameViewh">branches/safari-608-branch/Source/WebCore/page/FrameView.h</a></li>
<li><a href="#branchessafari608branchSourceWebCorepagePagecpp">branches/safari-608-branch/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#branchessafari608branchSourceWebCorepagePageh">branches/safari-608-branch/Source/WebCore/page/Page.h</a></li>
<li><a href="#branchessafari608branchSourceWebKitChangeLog">branches/safari-608-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari608branchSourceWebKitWebProcessWebPageWebPagecpp">branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#branchessafari608branchSourceWebKitWebProcessWebPageWebPageh">branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#branchessafari608branchSourceWebKitWebProcessWebPageiosWebPageIOSmm">branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari608branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebCore/ChangeLog (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebCore/ChangeLog      2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebCore/ChangeLog 2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -1,5 +1,75 @@
</span><span class="cx"> 2019-07-29  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r247667. rdar://problem/53647463
+
+    [Text autosizing] Do not nuke the style on dynamicViewportSizeUpdate
+    https://bugs.webkit.org/show_bug.cgi?id=199718
+    <rdar://problem/53344961>
+    
+    Reviewed by Simon Fraser.
+    
+    Source/WebCore:
+    
+    When the page scale changes (e.g. as the result of shink to fit mode) we need to visit all the text content on the page and check whether they need to be boosted.
+    Currently we call setNeedsRecalcStyleInAllFrames() to accomplish it. Unfortunatelly setNeedsRecalcStyleInAllFrames destroys all the style information which means that the
+    subsequent styleResolve() needs to start from scratch.
+    This patch addresses this issue by directly adjusting the computed style information when text boosting is required and schedules layout accordingly. We also trigger this style adjusting
+    on a timer so that rapid dynamicViewportSizeUpdate() calls won't trigger redundant layouts.
+    
+    * css/StyleResolver.cpp:
+    (WebCore::hasTextChild):
+    (WebCore::StyleResolver::adjustRenderStyleForTextAutosizing):
+    (WebCore::hasTextChildren): Deleted.
+    * css/StyleResolver.h:
+    * page/FrameView.h:
+    * page/Page.cpp:
+    (WebCore::Page::invalidateTextAutoSizeInAllFrames):
+    * page/Page.h:
+    
+    Source/WebKit:
+    
+    * WebProcess/WebPage/WebPage.cpp:
+    (WebKit::m_textAutoSizingAdjustmentTimer):
+    (WebKit::WebPage::close):
+    (WebKit::WebPage::didCommitLoad):
+    (WebKit::WebPage::textAutoSizingAdjustmentTimerFired):
+    (WebKit::m_shrinkToFitContentTimer): Deleted.
+    * WebProcess/WebPage/WebPage.h:
+    * WebProcess/WebPage/ios/WebPageIOS.mm:
+    (WebKit::WebPage::dynamicViewportSizeUpdate):
+    (WebKit::WebPage::resetIdempotentTextAutosizingIfNeeded):
+    (WebKit::WebPage::resetTextAutosizing):
+    (WebKit::WebPage::viewportConfigurationChanged):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-07-20  Zalan Bujtas  <zalan@apple.com>
+
+            [Text autosizing] Do not nuke the style on dynamicViewportSizeUpdate
+            https://bugs.webkit.org/show_bug.cgi?id=199718
+            <rdar://problem/53344961>
+
+            Reviewed by Simon Fraser.
+
+            When the page scale changes (e.g. as the result of shink to fit mode) we need to visit all the text content on the page and check whether they need to be boosted.
+            Currently we call setNeedsRecalcStyleInAllFrames() to accomplish it. Unfortunatelly setNeedsRecalcStyleInAllFrames destroys all the style information which means that the
+            subsequent styleResolve() needs to start from scratch.
+            This patch addresses this issue by directly adjusting the computed style information when text boosting is required and schedules layout accordingly. We also trigger this style adjusting
+            on a timer so that rapid dynamicViewportSizeUpdate() calls won't trigger redundant layouts.
+
+            * css/StyleResolver.cpp:
+            (WebCore::hasTextChild):
+            (WebCore::StyleResolver::adjustRenderStyleForTextAutosizing):
+            (WebCore::hasTextChildren): Deleted.
+            * css/StyleResolver.h:
+            * page/FrameView.h:
+            * page/Page.cpp:
+            (WebCore::Page::invalidateTextAutoSizeInAllFrames):
+            * page/Page.h:
+
+2019-07-29  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r247662. rdar://problem/53648208
</span><span class="cx"> 
</span><span class="cx">     Remote WebInspector should enable mock capture devices in UIProcess if doing it in WebProcess
</span></span></pre></div>
<a id="branchessafari608branchSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebCore/css/StyleResolver.cpp (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebCore/css/StyleResolver.cpp  2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebCore/css/StyleResolver.cpp     2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -871,7 +871,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><del>-static bool hasTextChildren(const Element& element)
</del><ins>+static bool hasTextChild(const Element& element)
</ins><span class="cx"> {
</span><span class="cx">     for (auto* child = element.firstChild(); child; child = child->nextSibling()) {
</span><span class="cx">         if (is<Text>(child))
</span><span class="lines">@@ -880,17 +880,14 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void StyleResolver::adjustRenderStyleForTextAutosizing(RenderStyle& style, const Element& element)
</del><ins>+bool StyleResolver::adjustRenderStyleForTextAutosizing(RenderStyle& style, const Element& element)
</ins><span class="cx"> {
</span><span class="cx">     if (!settings().textAutosizingEnabled() || !settings().textAutosizingUsesIdempotentMode())
</span><del>-        return;
</del><ins>+        return false;
</ins><span class="cx"> 
</span><span class="cx">     AutosizeStatus::updateStatus(style);
</span><del>-    if (!hasTextChildren(element))
-        return;
-
</del><span class="cx">     if (style.textSizeAdjust().isNone())
</span><del>-        return;
</del><ins>+        return false;
</ins><span class="cx"> 
</span><span class="cx">     float initialScale = document().page() ? document().page()->initialScale() : 1;
</span><span class="cx">     auto adjustLineHeightIfNeeded = [&](auto computedFontSize) {
</span><span class="lines">@@ -912,16 +909,20 @@
</span><span class="cx">     auto specifiedFontSize = fontDescription.specifiedSize();
</span><span class="cx">     bool isCandidate = style.isIdempotentTextAutosizingCandidate();
</span><span class="cx">     if (!isCandidate && WTF::areEssentiallyEqual(initialComputedFontSize, specifiedFontSize))
</span><del>-        return;
</del><ins>+        return false;
</ins><span class="cx"> 
</span><span class="cx">     auto adjustedFontSize = AutosizeStatus::idempotentTextSize(fontDescription.specifiedSize(), initialScale);
</span><span class="cx">     if (isCandidate && WTF::areEssentiallyEqual(initialComputedFontSize, adjustedFontSize))
</span><del>-        return;
</del><ins>+        return false;
</ins><span class="cx"> 
</span><ins>+    if (!hasTextChild(element))
+        return false;
+
</ins><span class="cx">     fontDescription.setComputedSize(isCandidate ? adjustedFontSize : specifiedFontSize);
</span><span class="cx">     style.setFontDescription(WTFMove(fontDescription));
</span><span class="cx">     style.fontCascade().update(&document().fontSelector());
</span><span class="cx">     adjustLineHeightIfNeeded(adjustedFontSize);
</span><ins>+    return true;
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari608branchSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebCore/css/StyleResolver.h (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebCore/css/StyleResolver.h    2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebCore/css/StyleResolver.h       2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -469,6 +469,8 @@
</span><span class="cx"> 
</span><span class="cx">     RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSValue&, ApplyCascadedPropertyState&) const;
</span><span class="cx"> 
</span><ins>+    bool adjustRenderStyleForTextAutosizing(RenderStyle&, const Element&);
+
</ins><span class="cx"> private:
</span><span class="cx">     void cacheBorderAndBackground();
</span><span class="cx"> 
</span><span class="lines">@@ -500,8 +502,6 @@
</span><span class="cx">     // the last reference to a style declaration are garbage collected.
</span><span class="cx">     void sweepMatchedPropertiesCache();
</span><span class="cx"> 
</span><del>-    void adjustRenderStyleForTextAutosizing(RenderStyle&, const Element&);
-
</del><span class="cx">     typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
</span><span class="cx">     MatchedPropertiesCache m_matchedPropertiesCache;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari608branchSourceWebCorepageFrameViewh"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebCore/page/FrameView.h (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebCore/page/FrameView.h       2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebCore/page/FrameView.h  2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -402,6 +402,8 @@
</span><span class="cx">     void updateIsVisuallyNonEmpty();
</span><span class="cx">     void updateSignificantRenderedTextMilestoneIfNeeded();
</span><span class="cx">     bool isVisuallyNonEmpty() const { return m_isVisuallyNonEmpty; }
</span><ins>+    WEBCORE_EXPORT bool qualifiesAsVisuallyNonEmpty() const;
+
</ins><span class="cx">     WEBCORE_EXPORT void enableAutoSizeMode(bool enable, const IntSize& minSize);
</span><span class="cx">     WEBCORE_EXPORT void setAutoSizeFixedMinimumHeight(int);
</span><span class="cx">     bool isAutoSizeEnabled() const { return m_shouldAutoSize; }
</span><span class="lines">@@ -791,7 +793,6 @@
</span><span class="cx"> 
</span><span class="cx">     void markRootOrBodyRendererDirty() const;
</span><span class="cx"> 
</span><del>-    bool qualifiesAsVisuallyNonEmpty() const;
</del><span class="cx">     bool qualifiesAsSignificantRenderedText() const;
</span><span class="cx">     void updateHasReachedSignificantRenderedTextThreshold();
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari608branchSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebCore/page/Page.cpp (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebCore/page/Page.cpp  2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebCore/page/Page.cpp     2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx"> #include "PointerCaptureController.h"
</span><span class="cx"> #include "PointerLockController.h"
</span><span class="cx"> #include "ProgressTracker.h"
</span><ins>+#include "RenderDescendantIterator.h"
</ins><span class="cx"> #include "RenderLayerCompositor.h"
</span><span class="cx"> #include "RenderTheme.h"
</span><span class="cx"> #include "RenderView.h"
</span><span class="lines">@@ -3004,4 +3005,27 @@
</span><span class="cx">     chrome().client().didFinishLoadingImageForElement(element);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+void Page::recomputeTextAutoSizingInAllFrames()
+{
+    ASSERT(settings().textAutosizingEnabled() && settings().textAutosizingUsesIdempotentMode());
+    for (auto* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
+        if (!frame->document())
+            continue;
+        auto& document = *frame->document();
+        if (!document.renderView() || !document.styleScope().resolverIfExists())
+            continue;
+
+        auto& styleResolver = document.styleScope().resolver();
+        for (auto& renderer : descendantsOfType<RenderElement>(*document.renderView())) {
+            if (auto* element = renderer.element()) {
+                auto needsLayout = styleResolver.adjustRenderStyleForTextAutosizing(renderer.mutableStyle(), *element);
+                if (needsLayout)
+                    renderer.setNeedsLayout();
+            }
+        }
+    }
+}
+#endif
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari608branchSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebCore/page/Page.h (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebCore/page/Page.h    2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebCore/page/Page.h       2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -388,6 +388,7 @@
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><span class="cx">     float textAutosizingWidth() const { return m_textAutosizingWidth; }
</span><span class="cx">     void setTextAutosizingWidth(float textAutosizingWidth) { m_textAutosizingWidth = textAutosizingWidth; }
</span><ins>+    WEBCORE_EXPORT void recomputeTextAutoSizingInAllFrames();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     const FloatBoxExtent& fullscreenInsets() const { return m_fullscreenInsets; }
</span></span></pre></div>
<a id="branchessafari608branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebKit/ChangeLog (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebKit/ChangeLog       2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebKit/ChangeLog  2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -1,5 +1,72 @@
</span><span class="cx"> 2019-07-29  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r247667. rdar://problem/53647463
+
+    [Text autosizing] Do not nuke the style on dynamicViewportSizeUpdate
+    https://bugs.webkit.org/show_bug.cgi?id=199718
+    <rdar://problem/53344961>
+    
+    Reviewed by Simon Fraser.
+    
+    Source/WebCore:
+    
+    When the page scale changes (e.g. as the result of shink to fit mode) we need to visit all the text content on the page and check whether they need to be boosted.
+    Currently we call setNeedsRecalcStyleInAllFrames() to accomplish it. Unfortunatelly setNeedsRecalcStyleInAllFrames destroys all the style information which means that the
+    subsequent styleResolve() needs to start from scratch.
+    This patch addresses this issue by directly adjusting the computed style information when text boosting is required and schedules layout accordingly. We also trigger this style adjusting
+    on a timer so that rapid dynamicViewportSizeUpdate() calls won't trigger redundant layouts.
+    
+    * css/StyleResolver.cpp:
+    (WebCore::hasTextChild):
+    (WebCore::StyleResolver::adjustRenderStyleForTextAutosizing):
+    (WebCore::hasTextChildren): Deleted.
+    * css/StyleResolver.h:
+    * page/FrameView.h:
+    * page/Page.cpp:
+    (WebCore::Page::invalidateTextAutoSizeInAllFrames):
+    * page/Page.h:
+    
+    Source/WebKit:
+    
+    * WebProcess/WebPage/WebPage.cpp:
+    (WebKit::m_textAutoSizingAdjustmentTimer):
+    (WebKit::WebPage::close):
+    (WebKit::WebPage::didCommitLoad):
+    (WebKit::WebPage::textAutoSizingAdjustmentTimerFired):
+    (WebKit::m_shrinkToFitContentTimer): Deleted.
+    * WebProcess/WebPage/WebPage.h:
+    * WebProcess/WebPage/ios/WebPageIOS.mm:
+    (WebKit::WebPage::dynamicViewportSizeUpdate):
+    (WebKit::WebPage::resetIdempotentTextAutosizingIfNeeded):
+    (WebKit::WebPage::resetTextAutosizing):
+    (WebKit::WebPage::viewportConfigurationChanged):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-07-20  Zalan Bujtas  <zalan@apple.com>
+
+            [Text autosizing] Do not nuke the style on dynamicViewportSizeUpdate
+            https://bugs.webkit.org/show_bug.cgi?id=199718
+            <rdar://problem/53344961>
+
+            Reviewed by Simon Fraser.
+
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::m_textAutoSizingAdjustmentTimer):
+            (WebKit::WebPage::close):
+            (WebKit::WebPage::didCommitLoad):
+            (WebKit::WebPage::textAutoSizingAdjustmentTimerFired):
+            (WebKit::m_shrinkToFitContentTimer): Deleted.
+            * WebProcess/WebPage/WebPage.h:
+            * WebProcess/WebPage/ios/WebPageIOS.mm:
+            (WebKit::WebPage::dynamicViewportSizeUpdate):
+            (WebKit::WebPage::resetIdempotentTextAutosizingIfNeeded):
+            (WebKit::WebPage::resetTextAutosizing):
+            (WebKit::WebPage::viewportConfigurationChanged):
+
+2019-07-29  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r247662. rdar://problem/53648208
</span><span class="cx"> 
</span><span class="cx">     Remote WebInspector should enable mock capture devices in UIProcess if doing it in WebProcess
</span></span></pre></div>
<a id="branchessafari608branchSourceWebKitWebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp  2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp     2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -431,6 +431,9 @@
</span><span class="cx"> #if ENABLE(VIEWPORT_RESIZING)
</span><span class="cx">     , m_shrinkToFitContentTimer(*this, &WebPage::shrinkToFitContentTimerFired, 0_s)
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    , m_textAutoSizingAdjustmentTimer(*this, &WebPage::textAutoSizingAdjustmentTimerFired)
+#endif
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_pageID);
</span><span class="cx"> 
</span><span class="lines">@@ -1402,6 +1405,10 @@
</span><span class="cx">     m_shrinkToFitContentTimer.stop();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    m_textAutoSizingAdjustmentTimer.stop();
+#endif
+
</ins><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><span class="cx">     m_contextMenuClient = std::make_unique<API::InjectedBundle::PageContextMenuClient>();
</span><span class="cx"> #endif
</span><span class="lines">@@ -5793,6 +5800,10 @@
</span><span class="cx">     m_shrinkToFitContentTimer.stop();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    m_textAutoSizingAdjustmentTimer.stop();
+#endif
+
</ins><span class="cx"> #if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
</span><span class="cx">     resetPrimarySnapshottedPlugIn();
</span><span class="cx"> #endif
</span><span class="lines">@@ -6796,6 +6807,13 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+void WebPage::textAutoSizingAdjustmentTimerFired()
+{
+    m_page->recomputeTextAutoSizingInAllFrames();
+}
+#endif
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #undef RELEASE_LOG_IF_ALLOWED
</span></span></pre></div>
<a id="branchessafari608branchSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.h (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.h    2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/WebPage.h       2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -1251,8 +1251,6 @@
</span><span class="cx">     void handleSyntheticClick(WebCore::Node& nodeRespondingToClick, const WebCore::FloatPoint& location, OptionSet<WebKit::WebEvent::Modifier>, WebCore::PointerID = WebCore::mousePointerID);
</span><span class="cx">     void completeSyntheticClick(WebCore::Node& nodeRespondingToClick, const WebCore::FloatPoint& location, OptionSet<WebKit::WebEvent::Modifier>, WebCore::SyntheticClickType, WebCore::PointerID = WebCore::mousePointerID);
</span><span class="cx">     void sendTapHighlightForNodeIfNecessary(uint64_t requestID, WebCore::Node*);
</span><del>-    void resetTextAutosizing();
-    void resetIdempotentTextAutosizingIfNeeded(double previousInitialScale);
</del><span class="cx">     WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithFocusedElement);
</span><span class="cx">     RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithFocusedElement);
</span><span class="cx">     void setFocusedFrameBeforeSelectingTextAtLocation(const WebCore::IntPoint&);
</span><span class="lines">@@ -1265,6 +1263,11 @@
</span><span class="cx">     bool applyAutocorrectionInternal(const String& correction, const String& originalText);
</span><span class="cx">     bool shouldIgnoreMetaViewport() const;
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    void textAutoSizingAdjustmentTimerFired();
+    void resetTextAutosizing();
+    void resetIdempotentTextAutosizingIfNeeded(double previousInitialScale);
+#endif
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIEWPORT_RESIZING)
</span><span class="cx">     void scheduleShrinkToFitContent();
</span><span class="lines">@@ -1956,6 +1959,9 @@
</span><span class="cx"> #if HAVE(VISIBILITY_PROPAGATION_VIEW)
</span><span class="cx">     std::unique_ptr<LayerHostingContext> m_contextForVisibilityPropagation;
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    WebCore::Timer m_textAutoSizingAdjustmentTimer;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS_FAMILY)
</span></span></pre></div>
<a id="branchessafari608branchSourceWebKitWebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (247951 => 247952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm    2019-07-30 03:54:02 UTC (rev 247951)
+++ branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm       2019-07-30 03:54:06 UTC (rev 247952)
</span><span class="lines">@@ -3110,16 +3110,6 @@
</span><span class="cx">     m_page->setOverrideViewportArguments(arguments);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::resetTextAutosizing()
-{
-    for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        Document* document = frame->document();
-        if (!document || !document->renderView())
-            continue;
-        document->renderView()->resetTextAutosizing();
-    }
-}
-
</del><span class="cx"> void WebPage::dynamicViewportSizeUpdate(const FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, DynamicViewportSizeUpdateID dynamicViewportSizeUpdateID)
</span><span class="cx"> {
</span><span class="cx">     SetForScope<bool> dynamicSizeUpdateGuard(m_inDynamicSizeUpdate, true);
</span><span class="lines">@@ -3165,9 +3155,10 @@
</span><span class="cx"> 
</span><span class="cx">     IntSize newLayoutSize = m_viewportConfiguration.layoutSize();
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
</ins><span class="cx">     if (setFixedLayoutSize(newLayoutSize))
</span><span class="cx">         resetTextAutosizing();
</span><del>-
</del><ins>+#endif
</ins><span class="cx">     setMaximumUnobscuredSize(maximumUnobscuredSize);
</span><span class="cx">     m_page->setUnobscuredSafeAreaInsets(targetUnobscuredSafeAreaInsets);
</span><span class="cx"> 
</span><span class="lines">@@ -3338,6 +3329,55 @@
</span><span class="cx">         m_viewportConfiguration.setDefaultConfiguration(parametersForStandardFrame());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+void WebPage::resetIdempotentTextAutosizingIfNeeded(double previousInitialScale)
+{
+    if (!m_page->settings().textAutosizingUsesIdempotentMode())
+        return;
+
+    const float minimumScaleChangeBeforeRecomputingTextAutosizing = 0.01;
+    if (std::abs(previousInitialScale - m_page->initialScale()) < minimumScaleChangeBeforeRecomputingTextAutosizing)
+        return;
+
+    if (m_page->initialScale() >= 1 && previousInitialScale >= 1)
+        return;
+
+    if (!m_page->mainFrame().view())
+        return;
+
+    auto textAutoSizingDelay = [&] {
+        auto& frameView = *m_page->mainFrame().view();
+        auto isVisaullyNonEmpty = frameView.isVisuallyNonEmpty();
+        auto willBeVisuallyNonEmptySoon = !isVisaullyNonEmpty && frameView.qualifiesAsVisuallyNonEmpty();
+        if (willBeVisuallyNonEmptySoon) {
+            // Be a bit more agressive on the first display.
+            const Seconds shortTextAutoSizingDelayOnViewportChange = 20_ms;
+            return shortTextAutoSizingDelayOnViewportChange;
+        } 
+        if (!isVisaullyNonEmpty) {
+            // We don't anticipate any paining after the next upcoming layout.
+            const Seconds longTextAutoSizingDelayOnViewportChange = 100_ms;
+            return longTextAutoSizingDelayOnViewportChange;
+        }
+        const Seconds defaultTextAutoSizingDelayOnViewportChange = 80_ms;
+        return defaultTextAutoSizingDelayOnViewportChange;
+    };
+
+    // We don't need to update text sizing eagerly. There might be multiple incoming dynamic viewport changes.
+    m_textAutoSizingAdjustmentTimer.startOneShot(textAutoSizingDelay());
+}
+
+void WebPage::resetTextAutosizing()
+{
+    for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+        Document* document = frame->document();
+        if (!document || !document->renderView())
+            continue;
+        document->renderView()->resetTextAutosizing();
+    }
+}
+#endif
+
</ins><span class="cx"> #if ENABLE(VIEWPORT_RESIZING)
</span><span class="cx"> 
</span><span class="cx"> void WebPage::scheduleShrinkToFitContent()
</span><span class="lines">@@ -3432,31 +3472,17 @@
</span><span class="cx">     return m_page->settings().shouldIgnoreMetaViewport();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::resetIdempotentTextAutosizingIfNeeded(double previousInitialScale)
-{
-    if (!m_page->settings().textAutosizingUsesIdempotentMode())
-        return;
-
-    const float minimumScaleChangeBeforeRecomputingTextAutosizing = 0.01;
-    if (std::abs(previousInitialScale - m_page->initialScale()) < minimumScaleChangeBeforeRecomputingTextAutosizing)
-        return;
-
-    if (m_page->initialScale() >= 1 && previousInitialScale >= 1)
-        return;
-
-    m_page->setNeedsRecalcStyleInAllFrames();
-}
-
</del><span class="cx"> void WebPage::viewportConfigurationChanged(ZoomToInitialScale zoomToInitialScale)
</span><span class="cx"> {
</span><ins>+    double initialScale = m_viewportConfiguration.initialScale();
+#if ENABLE(TEXT_AUTOSIZING)
</ins><span class="cx">     double previousInitialScale = m_page->initialScale();
</span><del>-    double initialScale = m_viewportConfiguration.initialScale();
</del><span class="cx">     m_page->setInitialScale(initialScale);
</span><span class="cx">     resetIdempotentTextAutosizingIfNeeded(previousInitialScale);
</span><span class="cx"> 
</span><span class="cx">     if (setFixedLayoutSize(m_viewportConfiguration.layoutSize()))
</span><span class="cx">         resetTextAutosizing();
</span><del>-
</del><ins>+#endif
</ins><span class="cx">     double scale;
</span><span class="cx">     if (m_userHasChangedPageScaleFactor && zoomToInitialScale == ZoomToInitialScale::No)
</span><span class="cx">         scale = std::max(std::min(pageScaleFactor(), m_viewportConfiguration.maximumScale()), m_viewportConfiguration.minimumScale());
</span></span></pre>
</div>
</div>

</body>
</html>