<!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>[213446] 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/213446">213446</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2017-03-06 04:19:43 -0800 (Mon, 06 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow render tree building before loading stylesheet elements
https://bugs.webkit.org/show_bug.cgi?id=169079
Source/WebCore:

&lt;rdar://problem/30865709&gt;

Reviewed by Andreas Kling.

Currently we don't resolve style or construct renderers if there are any pending
stylesheet loads. This patch enables style and renderer constuction up to the
first encountered loading style element.

This is a step toward allowing incremental rendering for in-body stylesheets.

* dom/Document.cpp:
(WebCore::Document::needsStyleRecalc):

    Ensure scrolling to anchor eventually happens.

* dom/Document.h:
(WebCore::Document::isIgnoringPendingStylesheets):
* dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::createSheet):
(WebCore::InlineStyleSheetOwner::sheetLoaded):
(WebCore::InlineStyleSheetOwner::startLoadingDynamicSheet):
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::checkStyleSheet):
(WebCore::ProcessingInstruction::sheetLoaded):
(WebCore::ProcessingInstruction::removedFrom):
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::addPendingSheet):
(WebCore::HTMLLinkElement::removePendingSheet):
* style/StyleScope.cpp:
(WebCore::Style::Scope::addPendingSheet):
(WebCore::Style::Scope::removePendingSheet):

    Track pending sheet nodes in a map so we can test if a given node has a pending sheet.
    This is also more robust in general.

(WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet):
(WebCore::Style::Scope::updateActiveStyleSheets):
* style/StyleScope.h:
(WebCore::Style::Scope::hasPendingSheet):
(WebCore::Style::Scope::hasPendingSheets):
(WebCore::Style::Scope::addPendingSheet): Deleted.
* style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::styleForElement):

    Instead of global test for placeholder construction check the status of the pending sheet flag.

(WebCore::Style::hasLoadingStylesheet):
(WebCore::Style::TreeResolver::resolveComposedTree):

    Set a flag when encountering a pending top level sheet during DOM traversal.

(WebCore::Style::TreeResolver::resolve):
* style/StyleTreeResolver.h:
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::dataChanged):

    Ensure SVG images have layout before getting the size.

LayoutTests:

Reviewed by Andreas Kling.

Ensure that style is synchronized after adding a stylesheet dynamically by doing an additional test.
Otherwise the class/attr invalidation test may as we don't know about the new stylesheet yet.
This is functionally fine (future synchronization would invalidate the style) but messes up the test
trying to verify class/attr change invalidation specifically.

* fast/css/style-invalidation-attribute-change-descendants-expected.txt:
* fast/css/style-invalidation-attribute-change-descendants.html:
* fast/css/style-invalidation-class-change-descendants-expected.txt:
* fast/css/style-invalidation-class-change-descendants.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastcssstyleinvalidationattributechangedescendantsexpectedtxt">trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcssstyleinvalidationattributechangedescendantshtml">trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants.html</a></li>
<li><a href="#trunkLayoutTestsfastcssstyleinvalidationclasschangedescendantsexpectedtxt">trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcssstyleinvalidationclasschangedescendantshtml">trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCoredomInlineStyleSheetOwnercpp">trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp</a></li>
<li><a href="#trunkSourceWebCoredomProcessingInstructioncpp">trunk/Source/WebCore/dom/ProcessingInstruction.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementcpp">trunk/Source/WebCore/html/HTMLLinkElement.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleScopecpp">trunk/Source/WebCore/style/StyleScope.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleScopeh">trunk/Source/WebCore/style/StyleScope.h</a></li>
<li><a href="#trunkSourceWebCorestyleStyleTreeResolvercpp">trunk/Source/WebCore/style/StyleTreeResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleTreeResolverh">trunk/Source/WebCore/style/StyleTreeResolver.h</a></li>
<li><a href="#trunkSourceWebCoresvggraphicsSVGImagecpp">trunk/Source/WebCore/svg/graphics/SVGImage.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/LayoutTests/ChangeLog        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-03-06  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Allow render tree building before loading stylesheet elements
+        https://bugs.webkit.org/show_bug.cgi?id=169079
+
+        Reviewed by Andreas Kling.
+
+        Ensure that style is synchronized after adding a stylesheet dynamically by doing an additional test.
+        Otherwise the class/attr invalidation test may as we don't know about the new stylesheet yet.
+        This is functionally fine (future synchronization would invalidate the style) but messes up the test
+        trying to verify class/attr change invalidation specifically.
+
+        * fast/css/style-invalidation-attribute-change-descendants-expected.txt:
+        * fast/css/style-invalidation-attribute-change-descendants.html:
+        * fast/css/style-invalidation-class-change-descendants-expected.txt:
+        * fast/css/style-invalidation-class-change-descendants.html:
+
</ins><span class="cx"> 2017-03-05  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed GTK+ gardening. Rebaseline fast/css/css2-system-fonts.html after r213267.
</span></span></pre></div>
<a id="trunkLayoutTestsfastcssstyleinvalidationattributechangedescendantsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants-expected.txt (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants-expected.txt        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants-expected.txt        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -170,6 +170,10 @@
</span><span class="cx"> PASS testStyleChangeType(&quot;inert&quot;, &quot;NoStyleChange&quot;) is true
</span><span class="cx"> PASS hasExpectedStyle is true
</span><span class="cx"> Inserting stylesheet '[myattr3] target { color:rgb(12, 0, 0); }'
</span><ins>+PASS testStyleChangeType(&quot;root&quot;, &quot;NoStyleChange&quot;) || testStyleChangeType(&quot;root&quot;, &quot;InlineStyleChange&quot;) is true
+PASS testStyleChangeType(&quot;target&quot;, &quot;NoStyleChange&quot;) is true
+PASS testStyleChangeType(&quot;inert&quot;, &quot;NoStyleChange&quot;) is true
+PASS hasExpectedStyle is true
</ins><span class="cx"> Setting attribute 'myattr3' value ''
</span><span class="cx"> PASS testStyleChangeType(&quot;root&quot;, &quot;NoStyleChange&quot;) || testStyleChangeType(&quot;root&quot;, &quot;InlineStyleChange&quot;) is true
</span><span class="cx"> PASS testStyleChangeType(&quot;target&quot;, &quot;InlineStyleChange&quot;) is true
</span></span></pre></div>
<a id="trunkLayoutTestsfastcssstyleinvalidationattributechangedescendantshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants.html (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants.html        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants.html        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -276,6 +276,9 @@
</span><span class="cx"> debug(&quot;Inserting stylesheet '&quot; + dynamicSheet.innerHTML + &quot;'&quot;);
</span><span class="cx"> document.head.appendChild(dynamicSheet);
</span><span class="cx"> 
</span><ins>+testStyleInvalidation(&quot;NoStyleChange&quot;);
+checkStyle(11);
+
</ins><span class="cx"> setAttribute('myattr3', '');
</span><span class="cx"> testStyleInvalidation(&quot;InlineStyleChange&quot;);
</span><span class="cx"> checkStyle(12);
</span></span></pre></div>
<a id="trunkLayoutTestsfastcssstyleinvalidationclasschangedescendantsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants-expected.txt (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants-expected.txt        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants-expected.txt        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -73,6 +73,10 @@
</span><span class="cx"> PASS testStyleChangeType(&quot;inert&quot;, &quot;NoStyleChange&quot;) is true
</span><span class="cx"> PASS hasExpectedStyle is true
</span><span class="cx"> Inserting stylesheet 'root.dynamicStyle target { color:rgb(6, 6, 6); }'
</span><ins>+PASS testStyleChangeType(&quot;root&quot;, &quot;NoStyleChange&quot;) || testStyleChangeType(&quot;root&quot;, &quot;InlineStyleChange&quot;) is true
+PASS testStyleChangeType(&quot;target&quot;, &quot;NoStyleChange&quot;) is true
+PASS testStyleChangeType(&quot;inert&quot;, &quot;NoStyleChange&quot;) is true
+PASS hasExpectedStyle is true
</ins><span class="cx"> Adding class dynamicStyle
</span><span class="cx"> PASS testStyleChangeType(&quot;root&quot;, &quot;NoStyleChange&quot;) || testStyleChangeType(&quot;root&quot;, &quot;InlineStyleChange&quot;) is true
</span><span class="cx"> PASS testStyleChangeType(&quot;target&quot;, &quot;InlineStyleChange&quot;) is true
</span></span></pre></div>
<a id="trunkLayoutTestsfastcssstyleinvalidationclasschangedescendantshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants.html (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants.html        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/LayoutTests/fast/css/style-invalidation-class-change-descendants.html        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -167,7 +167,7 @@
</span><span class="cx"> 
</span><span class="cx"> removeClass('dynamicStyle');
</span><span class="cx"> testStyleInvalidation(&quot;NoStyleChange&quot;);
</span><del>-checkStyle(0)
</del><ins>+checkStyle(0);
</ins><span class="cx"> 
</span><span class="cx"> var dynamicSheet = document.createElement(&quot;style&quot;);
</span><span class="cx"> dynamicSheet.innerHTML = &quot;root.dynamicStyle target { color:rgb(6, 6, 6); }&quot;
</span><span class="lines">@@ -174,6 +174,9 @@
</span><span class="cx"> debug(&quot;Inserting stylesheet '&quot; + dynamicSheet.innerHTML + &quot;'&quot;);
</span><span class="cx"> document.head.appendChild(dynamicSheet);
</span><span class="cx"> 
</span><ins>+testStyleInvalidation(&quot;NoStyleChange&quot;);
+checkStyle(0);
+
</ins><span class="cx"> addClass('dynamicStyle');
</span><span class="cx"> testStyleInvalidation(&quot;InlineStyleChange&quot;);
</span><span class="cx"> checkStyle(6);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/ChangeLog        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -1,3 +1,65 @@
</span><ins>+2017-03-06  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Allow render tree building before loading stylesheet elements
+        https://bugs.webkit.org/show_bug.cgi?id=169079
+        &lt;rdar://problem/30865709&gt;
+
+        Reviewed by Andreas Kling.
+
+        Currently we don't resolve style or construct renderers if there are any pending
+        stylesheet loads. This patch enables style and renderer constuction up to the
+        first encountered loading style element.
+
+        This is a step toward allowing incremental rendering for in-body stylesheets.
+
+        * dom/Document.cpp:
+        (WebCore::Document::needsStyleRecalc):
+
+            Ensure scrolling to anchor eventually happens.
+
+        * dom/Document.h:
+        (WebCore::Document::isIgnoringPendingStylesheets):
+        * dom/InlineStyleSheetOwner.cpp:
+        (WebCore::InlineStyleSheetOwner::createSheet):
+        (WebCore::InlineStyleSheetOwner::sheetLoaded):
+        (WebCore::InlineStyleSheetOwner::startLoadingDynamicSheet):
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::checkStyleSheet):
+        (WebCore::ProcessingInstruction::sheetLoaded):
+        (WebCore::ProcessingInstruction::removedFrom):
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::addPendingSheet):
+        (WebCore::HTMLLinkElement::removePendingSheet):
+        * style/StyleScope.cpp:
+        (WebCore::Style::Scope::addPendingSheet):
+        (WebCore::Style::Scope::removePendingSheet):
+
+            Track pending sheet nodes in a map so we can test if a given node has a pending sheet.
+            This is also more robust in general.
+
+        (WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet):
+        (WebCore::Style::Scope::updateActiveStyleSheets):
+        * style/StyleScope.h:
+        (WebCore::Style::Scope::hasPendingSheet):
+        (WebCore::Style::Scope::hasPendingSheets):
+        (WebCore::Style::Scope::addPendingSheet): Deleted.
+        * style/StyleTreeResolver.cpp:
+        (WebCore::Style::TreeResolver::styleForElement):
+
+            Instead of global test for placeholder construction check the status of the pending sheet flag.
+
+        (WebCore::Style::hasLoadingStylesheet):
+        (WebCore::Style::TreeResolver::resolveComposedTree):
+
+            Set a flag when encountering a pending top level sheet during DOM traversal.
+
+        (WebCore::Style::TreeResolver::resolve):
+        * style/StyleTreeResolver.h:
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::dataChanged):
+
+            Ensure SVG images have layout before getting the size.
+
</ins><span class="cx"> 2017-03-06  Vanessa Chipirrás Navalón  &lt;vchipirras@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GStreamer] Adopt nullptr
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/dom/Document.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -1854,7 +1854,20 @@
</span><span class="cx">     if (pageCacheState() != NotInPageCache)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    return m_pendingStyleRecalcShouldForce || childNeedsStyleRecalc() || styleScope().hasPendingUpdate();
</del><ins>+    if (m_pendingStyleRecalcShouldForce)
+        return true;
+
+    if (childNeedsStyleRecalc())
+        return true;
+
+    if (styleScope().hasPendingUpdate())
+        return true;
+
+    // Ensure this happens eventually as it is currently in resolveStyle. This can be removed if the code moves.
+    if (m_gotoAnchorNeededAfterStylesheetsLoad &amp;&amp; !styleScope().hasPendingSheets())
+        return true;
+
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Document::updateStyleIfNeeded()
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/dom/Document.h        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -484,6 +484,7 @@
</span><span class="cx">     CSSFontSelector&amp; fontSelector() { return m_fontSelector; }
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT bool haveStylesheetsLoaded() const;
</span><ins>+    bool isIgnoringPendingStylesheets() const { return m_ignorePendingStylesheets; }
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT StyleSheetList&amp; styleSheets();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomInlineStyleSheetOwnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -157,7 +157,7 @@
</span><span class="cx">     Document&amp; document = element.document();
</span><span class="cx">     if (m_sheet) {
</span><span class="cx">         if (m_sheet-&gt;isLoading() &amp;&amp; m_styleScope)
</span><del>-            m_styleScope-&gt;removePendingSheet();
</del><ins>+            m_styleScope-&gt;removePendingSheet(element);
</ins><span class="cx">         clearSheet();
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -178,7 +178,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (m_styleScope)
</span><del>-        m_styleScope-&gt;addPendingSheet();
</del><ins>+        m_styleScope-&gt;addPendingSheet(element);
</ins><span class="cx"> 
</span><span class="cx">     auto cacheKey = makeInlineStyleSheetCacheKey(text, element);
</span><span class="cx">     if (cacheKey) {
</span><span class="lines">@@ -228,21 +228,21 @@
</span><span class="cx">     return m_sheet &amp;&amp; m_sheet-&gt;isLoading();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool InlineStyleSheetOwner::sheetLoaded(Element&amp;)
</del><ins>+bool InlineStyleSheetOwner::sheetLoaded(Element&amp; element)
</ins><span class="cx"> {
</span><span class="cx">     if (isLoading())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     if (m_styleScope)
</span><del>-        m_styleScope-&gt;removePendingSheet();
</del><ins>+        m_styleScope-&gt;removePendingSheet(element);
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InlineStyleSheetOwner::startLoadingDynamicSheet(Element&amp;)
</del><ins>+void InlineStyleSheetOwner::startLoadingDynamicSheet(Element&amp; element)
</ins><span class="cx"> {
</span><span class="cx">     if (m_styleScope)
</span><del>-        m_styleScope-&gt;addPendingSheet();
</del><ins>+        m_styleScope-&gt;addPendingSheet(element);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InlineStyleSheetOwner::clearCache()
</span></span></pre></div>
<a id="trunkSourceWebCoredomProcessingInstructioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ProcessingInstruction.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ProcessingInstruction.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/dom/ProcessingInstruction.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -129,12 +129,17 @@
</span><span class="cx">                 m_cachedSheet = nullptr;
</span><span class="cx">             }
</span><span class="cx"> 
</span><ins>+            if (m_loading) {
+                m_loading = false;
+                document().styleScope().removePendingSheet(*this);
+            }
+
</ins><span class="cx">             String url = document().completeURL(href).string();
</span><span class="cx">             if (!dispatchBeforeLoadEvent(url))
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">             m_loading = true;
</span><del>-            document().styleScope().addPendingSheet();
</del><ins>+            document().styleScope().addPendingSheet(*this);
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(XSLT)
</span><span class="cx">             if (m_isXSL) {
</span><span class="lines">@@ -154,7 +159,7 @@
</span><span class="cx">             else {
</span><span class="cx">                 // The request may have been denied if (for example) the stylesheet is local and the document is remote.
</span><span class="cx">                 m_loading = false;
</span><del>-                document().styleScope().removePendingSheet();
</del><ins>+                document().styleScope().removePendingSheet(*this);
</ins><span class="cx"> #if ENABLE(XSLT)
</span><span class="cx">                 if (m_isXSL)
</span><span class="cx">                     document().styleScope().flushPendingUpdate();
</span><span class="lines">@@ -176,7 +181,7 @@
</span><span class="cx"> bool ProcessingInstruction::sheetLoaded()
</span><span class="cx"> {
</span><span class="cx">     if (!isLoading()) {
</span><del>-        document().styleScope().removePendingSheet();
</del><ins>+        document().styleScope().removePendingSheet(*this);
</ins><span class="cx"> #if ENABLE(XSLT)
</span><span class="cx">         if (m_isXSL)
</span><span class="cx">             document().styleScope().flushPendingUpdate();
</span><span class="lines">@@ -276,7 +281,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_loading) {
</span><span class="cx">         m_loading = false;
</span><del>-        document().styleScope().removePendingSheet();
</del><ins>+        document().styleScope().removePendingSheet(*this);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     document().styleScope().didChangeActiveStyleSheetCandidates();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -551,7 +551,7 @@
</span><span class="cx">     if (m_pendingSheetType == InactiveSheet)
</span><span class="cx">         return;
</span><span class="cx">     ASSERT(m_styleScope);
</span><del>-    m_styleScope-&gt;addPendingSheet();
</del><ins>+    m_styleScope-&gt;addPendingSheet(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLLinkElement::removePendingSheet()
</span><span class="lines">@@ -569,7 +569,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_styleScope-&gt;removePendingSheet();
</del><ins>+    m_styleScope-&gt;removePendingSheet(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/style/StyleScope.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -72,6 +72,7 @@
</span><span class="cx"> 
</span><span class="cx"> Scope::~Scope()
</span><span class="cx"> {
</span><ins>+    ASSERT(m_nodesWithPendingSheets.isEmpty());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Scope::shouldUseSharedUserAgentShadowTreeStyleResolver() const
</span><span class="lines">@@ -171,14 +172,20 @@
</span><span class="cx">     didChangeActiveStyleSheetCandidates();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Scope::addPendingSheet(const Node&amp; node)
+{
+    ASSERT(!m_nodesWithPendingSheets.contains(&amp;node));
+
+    m_nodesWithPendingSheets.add(&amp;node);
+}
+
</ins><span class="cx"> // This method is called whenever a top-level stylesheet has finished loading.
</span><del>-void Scope::removePendingSheet()
</del><ins>+void Scope::removePendingSheet(const Node&amp; node)
</ins><span class="cx"> {
</span><del>-    // Make sure we knew this sheet was pending, and that our count isn't out of sync.
-    ASSERT(m_pendingStyleSheetCount &gt; 0);
</del><ins>+    ASSERT(m_nodesWithPendingSheets.contains(&amp;node));
</ins><span class="cx"> 
</span><del>-    m_pendingStyleSheetCount--;
-    if (m_pendingStyleSheetCount)
</del><ins>+    m_nodesWithPendingSheets.remove(&amp;node);
+    if (!m_nodesWithPendingSheets.isEmpty())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     didChangeActiveStyleSheetCandidates();
</span><span class="lines">@@ -187,6 +194,21 @@
</span><span class="cx">         m_document.didRemoveAllPendingStylesheet();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Scope::hasProcessingInstructionWithPendingSheet()
+{
+    ASSERT(!m_shadowRoot);
+
+    for (auto* child = m_document.firstChild(); child; child = child-&gt;nextSibling()) {
+        if (is&lt;Element&gt;(*child))
+            return false;
+        if (m_nodesWithPendingSheets.contains(child)) {
+            ASSERT(is&lt;ProcessingInstruction&gt;(*child));
+            return true;
+        }
+    }
+    return false;
+}
+
</ins><span class="cx"> void Scope::addStyleSheetCandidateNode(Node&amp; node, bool createdByParser)
</span><span class="cx"> {
</span><span class="cx">     if (!node.isConnected())
</span><span class="lines">@@ -394,7 +416,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Don't bother updating, since we haven't loaded all our style info yet
</span><span class="cx">     // and haven't calculated the style resolver for the first time.
</span><del>-    if (!m_shadowRoot &amp;&amp; !m_didUpdateActiveStyleSheets &amp;&amp; m_pendingStyleSheetCount) {
</del><ins>+    if (!m_shadowRoot &amp;&amp; !m_didUpdateActiveStyleSheets &amp;&amp; hasPendingSheets()) {
</ins><span class="cx">         clearResolver();
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.h (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.h        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/style/StyleScope.h        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &lt;memory&gt;
</span><span class="cx"> #include &lt;wtf/FastMalloc.h&gt;
</span><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><ins>+#include &lt;wtf/HashSet.h&gt;
</ins><span class="cx"> #include &lt;wtf/ListHashSet.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="lines">@@ -81,11 +82,12 @@
</span><span class="cx">     void setPreferredStylesheetSetName(const String&amp;);
</span><span class="cx">     void setSelectedStylesheetSetName(const String&amp;);
</span><span class="cx"> 
</span><del>-    void addPendingSheet() { m_pendingStyleSheetCount++; }
-    void removePendingSheet();
</del><ins>+    void addPendingSheet(const Node&amp;);
+    void removePendingSheet(const Node&amp;);
+    bool hasPendingSheet(const Node&amp; node) const { return m_nodesWithPendingSheets.contains(&amp;node); }
+    bool hasProcessingInstructionWithPendingSheet();
+    bool hasPendingSheets() const { return !m_nodesWithPendingSheets.isEmpty(); }
</ins><span class="cx"> 
</span><del>-    bool hasPendingSheets() const { return m_pendingStyleSheetCount &gt; 0; }
-
</del><span class="cx">     bool usesStyleBasedEditability() { return m_usesStyleBasedEditability; }
</span><span class="cx"> 
</span><span class="cx">     bool activeStyleSheetsContains(const CSSStyleSheet*) const;
</span><span class="lines">@@ -141,15 +143,17 @@
</span><span class="cx">     Vector&lt;RefPtr&lt;StyleSheet&gt;&gt; m_styleSheetsForStyleSheetList;
</span><span class="cx">     Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; m_activeStyleSheets;
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     Timer m_pendingUpdateTimer;
</span><span class="cx"> 
</span><span class="cx">     mutable std::unique_ptr&lt;HashSet&lt;const CSSStyleSheet*&gt;&gt; m_weakCopyOfActiveStyleSheetListForFastLookup;
</span><span class="cx"> 
</span><del>-    // Track the number of currently loading top-level stylesheets needed for rendering.
</del><ins>+    // Track the currently loading top-level stylesheets needed for rendering.
</ins><span class="cx">     // Sheets loaded using the @import directive are not included in this count.
</span><span class="cx">     // We use this count of pending sheets to detect when we can begin attaching
</span><span class="cx">     // elements and when it is safe to execute scripts.
</span><del>-    int m_pendingStyleSheetCount { 0 };
</del><ins>+    HashSet&lt;const Node*&gt; m_nodesWithPendingSheets;
+
</ins><span class="cx">     bool m_didUpdateActiveStyleSheets { false };
</span><span class="cx"> 
</span><span class="cx">     std::optional&lt;UpdateType&gt; m_pendingUpdate;
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleTreeResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleTreeResolver.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -126,7 +126,7 @@
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;RenderStyle&gt; TreeResolver::styleForElement(Element&amp; element, const RenderStyle&amp; inheritedStyle)
</span><span class="cx"> {
</span><del>-    if (!m_document.haveStylesheetsLoaded() &amp;&amp; !element.renderer()) {
</del><ins>+    if (m_didSeePendingStylesheet &amp;&amp; !element.renderer() &amp;&amp; !m_document.isIgnoringPendingStylesheets()) {
</ins><span class="cx">         m_document.setHasNodesWithPlaceholderStyle();
</span><span class="cx">         return makePlaceholderStyle(m_document);
</span><span class="cx">     }
</span><span class="lines">@@ -359,6 +359,21 @@
</span><span class="cx">         after-&gt;setHasValidStyle();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool hasLoadingStylesheet(const Style::Scope&amp; styleScope, const Element&amp; element, bool checkDescendants)
+{
+    if (!styleScope.hasPendingSheets())
+        return false;
+    if (styleScope.hasPendingSheet(element))
+        return true;
+    if (!checkDescendants)
+        return false;
+    for (auto&amp; descendant : descendantsOfType&lt;Element&gt;(element)) {
+        if (styleScope.hasPendingSheet(descendant))
+            return true;
+    };
+    return false;
+}
+
</ins><span class="cx"> void TreeResolver::resolveComposedTree()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_parentStack.size() == 1);
</span><span class="lines">@@ -438,6 +453,10 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         bool shouldIterateChildren = style &amp;&amp; (element.childNeedsStyleRecalc() || change != NoChange);
</span><ins>+
+        if (!m_didSeePendingStylesheet)
+            m_didSeePendingStylesheet = hasLoadingStylesheet(m_document.styleScope(), element, !shouldIterateChildren);
+
</ins><span class="cx">         if (!shouldIterateChildren) {
</span><span class="cx">             it.traverseNextSkippingChildren();
</span><span class="cx">             continue;
</span><span class="lines">@@ -463,6 +482,8 @@
</span><span class="cx">     if (!documentElement-&gt;childNeedsStyleRecalc() &amp;&amp; !documentElement-&gt;needsStyleRecalc())
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><ins>+    m_didSeePendingStylesheet = m_document.styleScope().hasProcessingInstructionWithPendingSheet();
+
</ins><span class="cx">     m_update = std::make_unique&lt;Update&gt;(m_document);
</span><span class="cx">     m_scopeStack.append(adoptRef(*new Scope(m_document)));
</span><span class="cx">     m_parentStack.append(Parent(m_document));
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleTreeResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleTreeResolver.h (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleTreeResolver.h        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/style/StyleTreeResolver.h        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -102,6 +102,7 @@
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;Ref&lt;Scope&gt;, 4&gt; m_scopeStack;
</span><span class="cx">     Vector&lt;Parent, 32&gt; m_parentStack;
</span><ins>+    bool m_didSeePendingStylesheet { false };
</ins><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;Update&gt; m_update;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoresvggraphicsSVGImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (213445 => 213446)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp        2017-03-06 10:32:57 UTC (rev 213445)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp        2017-03-06 12:19:43 UTC (rev 213446)
</span><span class="lines">@@ -451,6 +451,8 @@
</span><span class="cx">         loader.activeDocumentLoader()-&gt;writer().addData(data()-&gt;data(), data()-&gt;size());
</span><span class="cx">         loader.activeDocumentLoader()-&gt;writer().end();
</span><span class="cx"> 
</span><ins>+        frame.document()-&gt;updateLayoutIgnorePendingStylesheets();
+
</ins><span class="cx">         // Set the intrinsic size before a container size is available.
</span><span class="cx">         m_intrinsicSize = containerSize();
</span><span class="cx">         reportApproximateMemoryCost();
</span></span></pre>
</div>
</div>

</body>
</html>