<!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>[207669] trunk/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/207669">207669</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2016-10-21 06:36:45 -0700 (Fri, 21 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Style resolver should be updated lazily
https://bugs.webkit.org/show_bug.cgi?id=163721

Reviewed by Andreas Kling.

Currently when stylesheets change in some way we generally update style resolvers and
invalidate style immediately. We should do this lazily to avoid unnecessary work.

Also improve naming of the stylesheet invalidation functions and use more optimal functions in some places.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::updateStyleIfNeededForNode):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::didMutateRules):
(WebCore::CSSStyleSheet::didMutate):
(WebCore::CSSStyleSheet::setDisabled):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):

    Initialize root style font with null font selector.
    This avoids hitting a CSSFontSelector assert in fast/media/mq-relative-constraints-08.html where
    media query evaluation requires font information before it is ready.
    Exposed by increased laziness in this patch.

* dom/Document.cpp:
(WebCore::Document::setContentLanguage):
(WebCore::Document::updateLayoutIgnorePendingStylesheets):
(WebCore::Document::isPageBoxVisible):
(WebCore::Document::pageSizeAndMarginsInPixels):
(WebCore::Document::processHttpEquiv):
(WebCore::Document::setSelectedStylesheetSet):
(WebCore::Document::didInsertInDocumentShadowRoot):
(WebCore::Document::didRemoveInDocumentShadowRoot):
* dom/Document.h:
(WebCore::Document::inDocumentShadowRoots):

    Track all shadow roots in the document. This allows us to find and flush style scopes cheaply.

* dom/Element.cpp:
(WebCore::Element::computedStyle):
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::ExtensionStyleSheets):
(WebCore::ExtensionStyleSheets::clearPageUserSheet):
(WebCore::ExtensionStyleSheets::updatePageUserSheet):
(WebCore::ExtensionStyleSheets::invalidateInjectedStyleSheetCache):
(WebCore::ExtensionStyleSheets::addUserStyleSheet):
(WebCore::ExtensionStyleSheets::addAuthorStyleSheetForTesting):
(WebCore::ExtensionStyleSheets::addDisplayNoneSelector):
(WebCore::ExtensionStyleSheets::maybeAddContentExtensionSheet):
(WebCore::ExtensionStyleSheets::styleResolverChangedTimerFired): Deleted.

    Since updates are now done lazily we don't need a special timer for extension stylesheets.

* dom/ExtensionStyleSheets.h:
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::checkStyleSheet):
(WebCore::ProcessingInstruction::sheetLoaded):
(WebCore::ProcessingInstruction::removedFrom):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::ShadowRoot):
(WebCore::ShadowRoot::insertedInto):
(WebCore::ShadowRoot::removedFrom):
(WebCore::ShadowRoot::styleScope):
* dom/ShadowRoot.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::setDisabledState):
(WebCore::HTMLLinkElement::parseAttribute):
(WebCore::HTMLLinkElement::process):
(WebCore::HTMLLinkElement::removePendingSheet):
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::parseAttribute):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::createInspectorStyleSheetForDocument):
(WebCore::InspectorCSSAgent::forcePseudoState):
(WebCore::InspectorCSSAgent::resetPseudoStates):
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::setEmulatedMedia):
* page/Frame.cpp:
(WebCore::Frame::setPrinting):
* page/FrameView.cpp:
(WebCore::FrameView::layout):
(WebCore::FrameView::setPagination):
(WebCore::FrameView::setViewportSizeForCSSViewportUnits):
* page/Page.cpp:
(WebCore::Page::setViewMode):
(WebCore::Page::setNeedsRecalcStyleInAllFrames):
(WebCore::Page::invalidateInjectedStyleSheetCacheInAllFrames):
* style/StyleScope.cpp:
(WebCore::Style::Scope::setPreferredStylesheetSetName):
(WebCore::Style::Scope::setSelectedStylesheetSetName):
(WebCore::Style::Scope::removePendingSheet):
(WebCore::Style::Scope::removeStyleSheetCandidateNode):
(WebCore::Style::Scope::activeStyleSheetsForInspector):
(WebCore::Style::Scope::flushPendingUpdate):

    Also flush descendant shadow roots.

(WebCore::Style::Scope::scheduleUpdate):
(WebCore::Style::Scope::didChangeActiveStyleSheetCandidates):

    Make lazy.

(WebCore::Style::Scope::didChangeStyleSheetContents):

    Make lazy.

(WebCore::Style::Scope::didChangeStyleSheetEnvironment):

    Environment changes also affect author shadow roots.

(WebCore::Style::Scope::styleSheetsForStyleSheetList):
(WebCore::Style::Scope::scheduleActiveSetUpdate): Deleted.
(WebCore::Style::Scope::didChangeCandidatesForActiveSet): Deleted.
(WebCore::Style::Scope::didChangeContentsOrInterpretation): Deleted.

    Improved naming of these and split didChangeContentsOrInterpretation into two separate functions.

* style/StyleScope.h:
(WebCore::Style::Scope::styleSheetsForStyleSheetList): Deleted.
(WebCore::Style::Scope::setPreferredStylesheetSetName): Deleted.
(WebCore::Style::Scope::setSelectedStylesheetSetName): Deleted.
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::rebuildFontFace):
(WebCore::SVGFontFaceElement::removedFrom):
* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState):

    Ensure that cationsStyleSheetOverride really becomes empty. Some tests rely on not having suprise
    inserted stylesheets. Previously this was racy and the patch affected order of things.

(WebCore::Internals::styleChangeType):
* xml/XMLTreeViewer.cpp:
(WebCore::XMLTreeViewer::transformDocumentToTreeView):
* xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::end):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::doEnd):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSComputedStyleDeclarationcpp">trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontSelectorcpp">trunk/Source/WebCore/css/CSSFontSelector.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontSelectorh">trunk/Source/WebCore/css/CSSFontSelector.h</a></li>
<li><a href="#trunkSourceWebCorecssCSSStyleSheetcpp">trunk/Source/WebCore/css/CSSStyleSheet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</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="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomExtensionStyleSheetscpp">trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp</a></li>
<li><a href="#trunkSourceWebCoredomExtensionStyleSheetsh">trunk/Source/WebCore/dom/ExtensionStyleSheets.h</a></li>
<li><a href="#trunkSourceWebCoredomProcessingInstructioncpp">trunk/Source/WebCore/dom/ProcessingInstruction.cpp</a></li>
<li><a href="#trunkSourceWebCoredomShadowRootcpp">trunk/Source/WebCore/dom/ShadowRoot.cpp</a></li>
<li><a href="#trunkSourceWebCoredomShadowRooth">trunk/Source/WebCore/dom/ShadowRoot.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementcpp">trunk/Source/WebCore/html/HTMLLinkElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLStyleElementcpp">trunk/Source/WebCore/html/HTMLStyleElement.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorCSSAgentcpp">trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorPageAgentcpp">trunk/Source/WebCore/inspector/InspectorPageAgent.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFramecpp">trunk/Source/WebCore/page/Frame.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.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="#trunkSourceWebCoresvgSVGFontFaceElementcpp">trunk/Source/WebCore/svg/SVGFontFaceElement.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCorexmlXMLTreeViewercpp">trunk/Source/WebCore/xml/XMLTreeViewer.cpp</a></li>
<li><a href="#trunkSourceWebCorexmlparserXMLDocumentParsercpp">trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCorexmlparserXMLDocumentParserLibxml2cpp">trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebHTMLViewmm">trunk/Source/WebKit/mac/WebView/WebHTMLView.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/ChangeLog        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -1,3 +1,143 @@
</span><ins>+2016-10-21  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Style resolver should be updated lazily
+        https://bugs.webkit.org/show_bug.cgi?id=163721
+
+        Reviewed by Andreas Kling.
+
+        Currently when stylesheets change in some way we generally update style resolvers and
+        invalidate style immediately. We should do this lazily to avoid unnecessary work.
+
+        Also improve naming of the stylesheet invalidation functions and use more optimal functions in some places.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::updateStyleIfNeededForNode):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::didMutateRules):
+        (WebCore::CSSStyleSheet::didMutate):
+        (WebCore::CSSStyleSheet::setDisabled):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::StyleResolver):
+
+            Initialize root style font with null font selector.
+            This avoids hitting a CSSFontSelector assert in fast/media/mq-relative-constraints-08.html where
+            media query evaluation requires font information before it is ready.
+            Exposed by increased laziness in this patch.
+
+        * dom/Document.cpp:
+        (WebCore::Document::setContentLanguage):
+        (WebCore::Document::updateLayoutIgnorePendingStylesheets):
+        (WebCore::Document::isPageBoxVisible):
+        (WebCore::Document::pageSizeAndMarginsInPixels):
+        (WebCore::Document::processHttpEquiv):
+        (WebCore::Document::setSelectedStylesheetSet):
+        (WebCore::Document::didInsertInDocumentShadowRoot):
+        (WebCore::Document::didRemoveInDocumentShadowRoot):
+        * dom/Document.h:
+        (WebCore::Document::inDocumentShadowRoots):
+
+            Track all shadow roots in the document. This allows us to find and flush style scopes cheaply.
+
+        * dom/Element.cpp:
+        (WebCore::Element::computedStyle):
+        * dom/ExtensionStyleSheets.cpp:
+        (WebCore::ExtensionStyleSheets::ExtensionStyleSheets):
+        (WebCore::ExtensionStyleSheets::clearPageUserSheet):
+        (WebCore::ExtensionStyleSheets::updatePageUserSheet):
+        (WebCore::ExtensionStyleSheets::invalidateInjectedStyleSheetCache):
+        (WebCore::ExtensionStyleSheets::addUserStyleSheet):
+        (WebCore::ExtensionStyleSheets::addAuthorStyleSheetForTesting):
+        (WebCore::ExtensionStyleSheets::addDisplayNoneSelector):
+        (WebCore::ExtensionStyleSheets::maybeAddContentExtensionSheet):
+        (WebCore::ExtensionStyleSheets::styleResolverChangedTimerFired): Deleted.
+
+            Since updates are now done lazily we don't need a special timer for extension stylesheets.
+
+        * dom/ExtensionStyleSheets.h:
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::checkStyleSheet):
+        (WebCore::ProcessingInstruction::sheetLoaded):
+        (WebCore::ProcessingInstruction::removedFrom):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::ShadowRoot):
+        (WebCore::ShadowRoot::insertedInto):
+        (WebCore::ShadowRoot::removedFrom):
+        (WebCore::ShadowRoot::styleScope):
+        * dom/ShadowRoot.h:
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::setDisabledState):
+        (WebCore::HTMLLinkElement::parseAttribute):
+        (WebCore::HTMLLinkElement::process):
+        (WebCore::HTMLLinkElement::removePendingSheet):
+        * html/HTMLStyleElement.cpp:
+        (WebCore::HTMLStyleElement::parseAttribute):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::createInspectorStyleSheetForDocument):
+        (WebCore::InspectorCSSAgent::forcePseudoState):
+        (WebCore::InspectorCSSAgent::resetPseudoStates):
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::setEmulatedMedia):
+        * page/Frame.cpp:
+        (WebCore::Frame::setPrinting):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::layout):
+        (WebCore::FrameView::setPagination):
+        (WebCore::FrameView::setViewportSizeForCSSViewportUnits):
+        * page/Page.cpp:
+        (WebCore::Page::setViewMode):
+        (WebCore::Page::setNeedsRecalcStyleInAllFrames):
+        (WebCore::Page::invalidateInjectedStyleSheetCacheInAllFrames):
+        * style/StyleScope.cpp:
+        (WebCore::Style::Scope::setPreferredStylesheetSetName):
+        (WebCore::Style::Scope::setSelectedStylesheetSetName):
+        (WebCore::Style::Scope::removePendingSheet):
+        (WebCore::Style::Scope::removeStyleSheetCandidateNode):
+        (WebCore::Style::Scope::activeStyleSheetsForInspector):
+        (WebCore::Style::Scope::flushPendingUpdate):
+
+            Also flush descendant shadow roots.
+
+        (WebCore::Style::Scope::scheduleUpdate):
+        (WebCore::Style::Scope::didChangeActiveStyleSheetCandidates):
+
+            Make lazy.
+
+        (WebCore::Style::Scope::didChangeStyleSheetContents):
+
+            Make lazy.
+
+        (WebCore::Style::Scope::didChangeStyleSheetEnvironment):
+
+            Environment changes also affect author shadow roots.
+
+        (WebCore::Style::Scope::styleSheetsForStyleSheetList):
+        (WebCore::Style::Scope::scheduleActiveSetUpdate): Deleted.
+        (WebCore::Style::Scope::didChangeCandidatesForActiveSet): Deleted.
+        (WebCore::Style::Scope::didChangeContentsOrInterpretation): Deleted.
+
+            Improved naming of these and split didChangeContentsOrInterpretation into two separate functions.
+
+        * style/StyleScope.h:
+        (WebCore::Style::Scope::styleSheetsForStyleSheetList): Deleted.
+        (WebCore::Style::Scope::setPreferredStylesheetSetName): Deleted.
+        (WebCore::Style::Scope::setSelectedStylesheetSetName): Deleted.
+        * svg/SVGFontFaceElement.cpp:
+        (WebCore::SVGFontFaceElement::rebuildFontFace):
+        (WebCore::SVGFontFaceElement::removedFrom):
+        * testing/Internals.cpp:
+        (WebCore::Internals::resetToConsistentState):
+
+            Ensure that cationsStyleSheetOverride really becomes empty. Some tests rely on not having suprise
+            inserted stylesheets. Previously this was racy and the patch affected order of things.
+
+        (WebCore::Internals::styleChangeType):
+        * xml/XMLTreeViewer.cpp:
+        (WebCore::XMLTreeViewer::transformDocumentToTreeView):
+        * xml/parser/XMLDocumentParser.cpp:
+        (WebCore::XMLDocumentParser::end):
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::doEnd):
+
</ins><span class="cx"> 2016-10-21  Xabier Rodriguez Calvar  &lt;calvaris@igalia.com&gt; and Adam Bergkvist  &lt;adam.bergkvist@ericsson.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WebRTC: [OpenWebRTC] Move SDPProcessorScriptResource(Gtk) to openwebrtc directory
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSComputedStyleDeclarationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -2354,9 +2354,12 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline bool updateStyleIfNeededForNode(const Node&amp; node)
</del><ins>+static bool updateStyleIfNeededForNode(const Node&amp; node)
</ins><span class="cx"> {
</span><span class="cx">     Document&amp; document = node.document();
</span><ins>+
+    document.styleScope().flushPendingUpdate();
+
</ins><span class="cx">     if (!document.hasPendingForcedStyleRecalc() &amp;&amp; !(document.childNeedsStyleRecalc() &amp;&amp; nodeOrItsAncestorNeedsStyleRecalc(node)))
</span><span class="cx">         return false;
</span><span class="cx">     document.updateStyleIfNeeded();
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontSelectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontSelector.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -280,7 +280,8 @@
</span><span class="cx"> 
</span><span class="cx"> FontRanges CSSFontSelector::fontRangesForFamily(const FontDescription&amp; fontDescription, const AtomicString&amp; familyName)
</span><span class="cx"> {
</span><del>-    ASSERT(!m_buildIsUnderway); // If this ASSERT() fires, it usually means you forgot a document.updateStyleIfNeeded() somewhere.
</del><ins>+    // If this ASSERT() fires, it usually means you forgot a document.updateStyleIfNeeded() somewhere.
+    ASSERT(!m_buildIsUnderway || m_isComputingRootStyleFont);
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too.
</span><span class="cx">     bool resolveGenericFamilyFirst = familyName == standardFamily;
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontSelectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontSelector.h (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontSelector.h        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/css/CSSFontSelector.h        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -83,6 +83,8 @@
</span><span class="cx"> 
</span><span class="cx">     FontFaceSet&amp; fontFaceSet();
</span><span class="cx"> 
</span><ins>+    void setIsComputingRootStyleFont(bool value) { m_isComputingRootStyleFont = value; }
+
</ins><span class="cx"> private:
</span><span class="cx">     explicit CSSFontSelector(Document&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -112,6 +114,7 @@
</span><span class="cx">     unsigned m_version;
</span><span class="cx">     bool m_creatingFont { false };
</span><span class="cx">     bool m_buildIsUnderway { false };
</span><ins>+    bool m_isComputingRootStyleFont { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSStyleSheetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSStyleSheet.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -180,11 +180,11 @@
</span><span class="cx">                 resolver-&gt;addKeyframeStyle(*insertedKeyframesRule);
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        scope-&gt;scheduleActiveSetUpdate();
</del><ins>+        scope-&gt;didChangeActiveStyleSheetCandidates();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    scope-&gt;didChangeContentsOrInterpretation();
</del><ins>+    scope-&gt;didChangeStyleSheetContents();
</ins><span class="cx"> 
</span><span class="cx">     m_mutatedRules = true;
</span><span class="cx"> }
</span><span class="lines">@@ -194,7 +194,7 @@
</span><span class="cx">     auto* scope = styleScope();
</span><span class="cx">     if (!scope)
</span><span class="cx">         return;
</span><del>-    scope-&gt;didChangeContentsOrInterpretation();
</del><ins>+    scope-&gt;didChangeStyleSheetContents();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CSSStyleSheet::clearOwnerNode()
</span><span class="lines">@@ -217,7 +217,8 @@
</span><span class="cx">         return;
</span><span class="cx">     m_isDisabled = disabled;
</span><span class="cx"> 
</span><del>-    didMutate();
</del><ins>+    if (auto* scope = styleScope())
+        scope-&gt;didChangeActiveStyleSheetCandidates();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CSSStyleSheet::setMediaQueries(Ref&lt;MediaQuerySet&gt;&amp;&amp; mediaQueries)
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/css/StyleResolver.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -268,8 +268,14 @@
</span><span class="cx">     else
</span><span class="cx">         m_mediaQueryEvaluator = MediaQueryEvaluator { &quot;all&quot; };
</span><span class="cx"> 
</span><del>-    if (root)
</del><ins>+    if (root) {
</ins><span class="cx">         m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), MatchOnlyUserAgentRules).renderStyle;
</span><ins>+        // Turn off assertion against font lookups during style resolver initialization. We may need root style font for media queries.
+        m_document.fontSelector().setIsComputingRootStyleFont(true);
+        m_rootDefaultStyle-&gt;fontCascade().update(&amp;m_document.fontSelector());
+        m_rootDefaultStyle-&gt;fontCascade().primaryFont();
+        m_document.fontSelector().setIsComputingRootStyleFont(false);
+    }
</ins><span class="cx"> 
</span><span class="cx">     if (m_rootDefaultStyle &amp;&amp; view)
</span><span class="cx">         m_mediaQueryEvaluator = MediaQueryEvaluator { view-&gt;mediaType(), m_document, m_rootDefaultStyle.get() };
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/Document.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -1356,7 +1356,7 @@
</span><span class="cx">     m_contentLanguage = language;
</span><span class="cx"> 
</span><span class="cx">     // Recalculate style so language is used when selecting the initial font.
</span><del>-    m_styleScope-&gt;didChangeContentsOrInterpretation();
</del><ins>+    m_styleScope-&gt;didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Document::setXMLVersion(const String&amp; version, ExceptionCode&amp; ec)
</span><span class="lines">@@ -1965,7 +1965,7 @@
</span><span class="cx">         HTMLElement* bodyElement = bodyOrFrameset();
</span><span class="cx">         if (bodyElement &amp;&amp; !bodyElement-&gt;renderer() &amp;&amp; m_pendingSheetLayout == NoLayoutWithPendingSheets) {
</span><span class="cx">             m_pendingSheetLayout = DidLayoutWithPendingSheets;
</span><del>-            styleScope().didChangeContentsOrInterpretation();
</del><ins>+            styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx">             recalcStyle(Style::Force);
</span><span class="cx">         } else if (m_hasNodesWithPlaceholderStyle)
</span><span class="cx">             // If new nodes have been added or style recalc has been done with style sheets still pending, some nodes 
</span><span class="lines">@@ -2102,6 +2102,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool Document::isPageBoxVisible(int pageIndex)
</span><span class="cx"> {
</span><ins>+    updateStyleIfNeeded();
</ins><span class="cx">     std::unique_ptr&lt;RenderStyle&gt; pageStyle(styleScope().resolver().styleForPage(pageIndex));
</span><span class="cx">     return pageStyle-&gt;visibility() != HIDDEN; // display property doesn't apply to @page.
</span><span class="cx"> }
</span><span class="lines">@@ -2108,6 +2109,7 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::pageSizeAndMarginsInPixels(int pageIndex, IntSize&amp; pageSize, int&amp; marginTop, int&amp; marginRight, int&amp; marginBottom, int&amp; marginLeft)
</span><span class="cx"> {
</span><ins>+    updateStyleIfNeeded();
</ins><span class="cx">     std::unique_ptr&lt;RenderStyle&gt; style = styleScope().resolver().styleForPage(pageIndex);
</span><span class="cx"> 
</span><span class="cx">     int width = pageSize.width();
</span><span class="lines">@@ -3161,7 +3163,6 @@
</span><span class="cx">         // -dwh
</span><span class="cx">         styleScope().setSelectedStylesheetSetName(content);
</span><span class="cx">         styleScope().setPreferredStylesheetSetName(content);
</span><del>-        styleScope().didChangeContentsOrInterpretation();
</del><span class="cx">         break;
</span><span class="cx"> 
</span><span class="cx">     case HTTPHeaderName::Refresh: {
</span><span class="lines">@@ -3471,7 +3472,6 @@
</span><span class="cx"> void Document::setSelectedStylesheetSet(const String&amp; aString)
</span><span class="cx"> {
</span><span class="cx">     styleScope().setSelectedStylesheetSetName(aString);
</span><del>-    styleScope().didChangeContentsOrInterpretation();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Document::evaluateMediaQueryList()
</span><span class="lines">@@ -7043,4 +7043,16 @@
</span><span class="cx">     return m_domWindow ? m_domWindow-&gt;getSelection() : nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Document::didInsertInDocumentShadowRoot(ShadowRoot&amp; shadowRoot)
+{
+    ASSERT(shadowRoot.inDocument());
+    m_inDocumentShadowRoots.add(&amp;shadowRoot);
+}
+
+void Document::didRemoveInDocumentShadowRoot(ShadowRoot&amp; shadowRoot)
+{
+    ASSERT(m_inDocumentShadowRoots.contains(&amp;shadowRoot));
+    m_inDocumentShadowRoots.remove(&amp;shadowRoot);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/Document.h        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -1296,6 +1296,10 @@
</span><span class="cx"> 
</span><span class="cx">     DOMSelection* getSelection();
</span><span class="cx"> 
</span><ins>+    void didInsertInDocumentShadowRoot(ShadowRoot&amp;);
+    void didRemoveInDocumentShadowRoot(ShadowRoot&amp;);
+    const HashSet&lt;ShadowRoot*&gt;&amp; inDocumentShadowRoots() const { return m_inDocumentShadowRoots; }
+
</ins><span class="cx"> protected:
</span><span class="cx">     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 &lt;&lt; 1 };
</span><span class="cx">     Document(Frame*, const URL&amp;, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
</span><span class="lines">@@ -1737,6 +1741,8 @@
</span><span class="cx">     HashSet&lt;MediaProducer*&gt; m_audioProducers;
</span><span class="cx">     MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
</span><span class="cx"> 
</span><ins>+    HashSet&lt;ShadowRoot*&gt; m_inDocumentShadowRoots;
+
</ins><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">     typedef HashMap&lt;uint64_t, WebCore::MediaPlaybackTargetClient*&gt; TargetIdToClientMap;
</span><span class="cx">     TargetIdToClientMap m_idToClientMap;
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/Element.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -2702,15 +2702,15 @@
</span><span class="cx"> 
</span><span class="cx"> const RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier)
</span><span class="cx"> {
</span><ins>+    if (!inDocument())
+        return nullptr;
+
</ins><span class="cx">     if (PseudoElement* pseudoElement = beforeOrAfterPseudoElement(*this, pseudoElementSpecifier))
</span><span class="cx">         return pseudoElement-&gt;computedStyle();
</span><span class="cx"> 
</span><span class="cx">     auto* style = existingComputedStyle();
</span><del>-    if (!style) {
-        if (!inDocument())
-            return nullptr;
</del><ins>+    if (!style)
</ins><span class="cx">         style = &amp;resolveComputedStyle();
</span><del>-    }
</del><span class="cx"> 
</span><span class="cx">     if (pseudoElementSpecifier) {
</span><span class="cx">         if (auto* cachedPseudoStyle = style-&gt;getCachedPseudoStyle(pseudoElementSpecifier))
</span></span></pre></div>
<a id="trunkSourceWebCoredomExtensionStyleSheetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -55,7 +55,6 @@
</span><span class="cx"> 
</span><span class="cx"> ExtensionStyleSheets::ExtensionStyleSheets(Document&amp; document)
</span><span class="cx">     : m_document(document)
</span><del>-    , m_styleResolverChangedTimer(*this, &amp;ExtensionStyleSheets::styleResolverChangedTimerFired)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -92,7 +91,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_pageUserSheet) {
</span><span class="cx">         m_pageUserSheet = nullptr;
</span><del>-        m_document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+        m_document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -100,7 +99,7 @@
</span><span class="cx"> {
</span><span class="cx">     clearPageUserSheet();
</span><span class="cx">     if (pageUserSheet())
</span><del>-        m_document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+        m_document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; ExtensionStyleSheets::injectedUserStyleSheets() const
</span><span class="lines">@@ -154,12 +153,8 @@
</span><span class="cx"> 
</span><span class="cx"> void ExtensionStyleSheets::invalidateInjectedStyleSheetCache()
</span><span class="cx"> {
</span><del>-    if (!m_injectedStyleSheetCacheValid)
-        return;
</del><span class="cx">     m_injectedStyleSheetCacheValid = false;
</span><del>-    if (m_injectedUserStyleSheets.isEmpty() &amp;&amp; m_injectedAuthorStyleSheets.isEmpty())
-        return;
-    m_document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+    m_document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ExtensionStyleSheets::addUserStyleSheet(Ref&lt;StyleSheetContents&gt;&amp;&amp; userSheet)
</span><span class="lines">@@ -166,7 +161,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(userSheet.get().isUserStyleSheet());
</span><span class="cx">     m_userStyleSheets.append(CSSStyleSheet::create(WTFMove(userSheet), m_document));
</span><del>-    m_document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+    m_document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ExtensionStyleSheets::addAuthorStyleSheetForTesting(Ref&lt;StyleSheetContents&gt;&amp;&amp; authorSheet)
</span><span class="lines">@@ -173,7 +168,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!authorSheet.get().isUserStyleSheet());
</span><span class="cx">     m_authorStyleSheetsForTesting.append(CSSStyleSheet::create(WTFMove(authorSheet), m_document));
</span><del>-    m_document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+    m_document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="lines">@@ -186,7 +181,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (result.iterator-&gt;value-&gt;addDisplayNoneSelector(selector, selectorID))
</span><del>-        m_styleResolverChangedTimer.startOneShot(0);
</del><ins>+        m_document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ExtensionStyleSheets::maybeAddContentExtensionSheet(const String&amp; identifier, StyleSheetContents&amp; sheet)
</span><span class="lines">@@ -199,15 +194,11 @@
</span><span class="cx">     Ref&lt;CSSStyleSheet&gt; cssSheet = CSSStyleSheet::create(sheet, m_document);
</span><span class="cx">     m_contentExtensionSheets.set(identifier, &amp;cssSheet.get());
</span><span class="cx">     m_userStyleSheets.append(adoptRef(cssSheet.leakRef()));
</span><del>-    m_styleResolverChangedTimer.startOneShot(0);
</del><ins>+    m_document.styleScope().didChangeStyleSheetEnvironment();
+
</ins><span class="cx"> }
</span><span class="cx"> #endif // ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx"> 
</span><del>-void ExtensionStyleSheets::styleResolverChangedTimerFired()
-{
-    m_document.styleScope().didChangeContentsOrInterpretation();
-}
-
</del><span class="cx"> void ExtensionStyleSheets::detachFromDocument()
</span><span class="cx"> {
</span><span class="cx">     if (m_pageUserSheet)
</span></span></pre></div>
<a id="trunkSourceWebCoredomExtensionStyleSheetsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.h (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ExtensionStyleSheets.h        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.h        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -77,8 +77,6 @@
</span><span class="cx">     void detachFromDocument();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void styleResolverChangedTimerFired();
-
</del><span class="cx">     Document&amp; m_document;
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;CSSStyleSheet&gt; m_pageUserSheet;
</span><span class="lines">@@ -94,8 +92,6 @@
</span><span class="cx">     HashMap&lt;String, RefPtr&lt;CSSStyleSheet&gt;&gt; m_contentExtensionSheets;
</span><span class="cx">     HashMap&lt;String, RefPtr&lt;ContentExtensions::ContentExtensionStyleSheet&gt;&gt; m_contentExtensionSelectorSheets;
</span><span class="cx"> #endif
</span><del>-
-    Timer m_styleResolverChangedTimer;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomProcessingInstructioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ProcessingInstruction.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ProcessingInstruction.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/ProcessingInstruction.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -156,6 +156,10 @@
</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><span class="cx">                 document().styleScope().removePendingSheet();
</span><ins>+#if ENABLE(XSLT)
+                if (m_isXSL)
+                    document().styleScope().flushPendingUpdate();
+#endif
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="lines">@@ -174,6 +178,10 @@
</span><span class="cx"> {
</span><span class="cx">     if (!isLoading()) {
</span><span class="cx">         document().styleScope().removePendingSheet();
</span><ins>+#if ENABLE(XSLT)
+        if (m_isXSL)
+            document().styleScope().flushPendingUpdate();
+#endif
</ins><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx">     return false;
</span><span class="lines">@@ -272,9 +280,7 @@
</span><span class="cx">         document().styleScope().removePendingSheet();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // If we're in document teardown, then we don't need to do any notification of our sheet's removal.
-    if (document().hasLivingRenderTree())
-        document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+    document().styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ProcessingInstruction::finishParsingChildren()
</span></span></pre></div>
<a id="trunkSourceWebCoredomShadowRootcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ShadowRoot.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx">     : DocumentFragment(document, CreateShadowRoot)
</span><span class="cx">     , TreeScope(*this, document)
</span><span class="cx">     , m_type(type)
</span><ins>+    , m_styleScope(std::make_unique&lt;Style::Scope&gt;(*this))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -60,6 +61,7 @@
</span><span class="cx">     : DocumentFragment(document, CreateShadowRoot)
</span><span class="cx">     , TreeScope(*this, document)
</span><span class="cx">     , m_type(Mode::UserAgent)
</span><ins>+    , m_styleScope(std::make_unique&lt;Style::Scope&gt;(*this))
</ins><span class="cx">     , m_slotAssignment(WTFMove(slotAssignment))
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -79,10 +81,23 @@
</span><span class="cx">     removeDetachedChildren();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Node::InsertionNotificationRequest ShadowRoot::insertedInto(ContainerNode&amp; insertionPoint)
+{
+    auto result = DocumentFragment::insertedInto(insertionPoint);
+    if (inDocument())
+        document().didInsertInDocumentShadowRoot(*this);
+    return result;
+}
+
+void ShadowRoot::removedFrom(ContainerNode&amp; insertionPoint)
+{
+    if (inDocument())
+        document().didRemoveInDocumentShadowRoot(*this);
+    DocumentFragment::removedFrom(insertionPoint);
+}
+
</ins><span class="cx"> Style::Scope&amp; ShadowRoot::styleScope()
</span><span class="cx"> {
</span><del>-    if (!m_styleScope)
-        m_styleScope = std::make_unique&lt;Style::Scope&gt;(*this);
</del><span class="cx">     return *m_styleScope;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomShadowRooth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ShadowRoot.h (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ShadowRoot.h        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/dom/ShadowRoot.h        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -104,6 +104,9 @@
</span><span class="cx"> 
</span><span class="cx">     Ref&lt;Node&gt; cloneNodeInternal(Document&amp;, CloningOperation) override;
</span><span class="cx"> 
</span><ins>+    Node::InsertionNotificationRequest insertedInto(ContainerNode&amp; insertionPoint) override;
+    void removedFrom(ContainerNode&amp; insertionPoint) override;
+
</ins><span class="cx">     bool m_resetStyleInheritance { false };
</span><span class="cx">     Mode m_type { Mode::UserAgent };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -140,7 +140,7 @@
</span><span class="cx">         if (!m_sheet &amp;&amp; m_disabledState == EnabledViaScript)
</span><span class="cx">             process();
</span><span class="cx">         else
</span><del>-            document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+            document().styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -176,7 +176,7 @@
</span><span class="cx">         m_media = value.string().convertToASCIILowercase();
</span><span class="cx">         process();
</span><span class="cx">         if (m_sheet &amp;&amp; !isDisabled())
</span><del>-            document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+            document().styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     if (name == disabledAttr) {
</span><span class="lines">@@ -283,7 +283,7 @@
</span><span class="cx">     } else if (m_sheet) {
</span><span class="cx">         // we no longer contain a stylesheet, e.g. perhaps rel or type was changed
</span><span class="cx">         clearSheet();
</span><del>-        document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+        document().styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -557,7 +557,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (type == InactiveSheet) {
</span><span class="cx">         // Document just needs to know about the sheet for exposure through document.styleSheets
</span><del>-        document().styleScope().didChangeCandidatesForActiveSet();
</del><ins>+        document().styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLStyleElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLStyleElement.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLStyleElement.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/html/HTMLStyleElement.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -77,7 +77,7 @@
</span><span class="cx">         if (sheet()) {
</span><span class="cx">             sheet()-&gt;setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(value));
</span><span class="cx">             if (auto* scope = m_styleSheetOwner.styleScope())
</span><del>-                scope-&gt;didChangeContentsOrInterpretation();
</del><ins>+                scope-&gt;didChangeStyleSheetContents();
</ins><span class="cx">         } else
</span><span class="cx">             m_styleSheetOwner.childrenChanged(*this);
</span><span class="cx">     } else if (name == typeAttr)
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorCSSAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -797,6 +797,7 @@
</span><span class="cx">     InlineStyleOverrideScope overrideScope(document);
</span><span class="cx">     ExceptionCode ec = 0;
</span><span class="cx">     targetNode-&gt;appendChild(styleElement, ec);
</span><ins>+    document.styleScope().flushPendingUpdate();
</ins><span class="cx">     m_creatingViaInspectorStyleSheet = false;
</span><span class="cx">     if (ec)
</span><span class="cx">         return nullptr;
</span><span class="lines">@@ -889,7 +890,7 @@
</span><span class="cx">         m_nodeIdToForcedPseudoState.set(nodeId, forcedPseudoState);
</span><span class="cx">     else
</span><span class="cx">         m_nodeIdToForcedPseudoState.remove(nodeId);
</span><del>-    element-&gt;document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+    element-&gt;document().styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorCSSAgent::getNamedFlowCollection(ErrorString&amp; errorString, int documentNodeId, RefPtr&lt;Inspector::Protocol::Array&lt;Inspector::Protocol::CSS::NamedFlow&gt;&gt;&amp; result)
</span><span class="lines">@@ -1189,7 +1190,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_nodeIdToForcedPseudoState.clear();
</span><span class="cx">     for (auto&amp; document : documentsToChange)
</span><del>-        document-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+        document-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorPageAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -1002,7 +1002,7 @@
</span><span class="cx">     m_emulatedMedia = media;
</span><span class="cx">     Document* document = m_page.mainFrame().document();
</span><span class="cx">     if (document) {
</span><del>-        document-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+        document-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">         document-&gt;updateLayout();
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorepageFramecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Frame.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Frame.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/page/Frame.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -644,7 +644,7 @@
</span><span class="cx">     m_doc-&gt;setPrinting(printing);
</span><span class="cx">     view()-&gt;adjustMediaTypeForPrinting(printing);
</span><span class="cx"> 
</span><del>-    m_doc-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+    m_doc-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">     if (shouldUsePrintingLayout()) {
</span><span class="cx">         view()-&gt;forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
</span><span class="cx">     } else {
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/page/FrameView.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -1335,7 +1335,7 @@
</span><span class="cx">         auto* styleResolver = document.styleScope().resolverIfExists();
</span><span class="cx">         if (!styleResolver || styleResolver-&gt;hasMediaQueriesAffectedByViewportChange()) {
</span><span class="cx">             LOG(Layout, &quot;  hasMediaQueriesAffectedByViewportChange, enqueueing style recalc&quot;);
</span><del>-            document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+            document.styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">             // FIXME: This instrumentation event is not strictly accurate since cached media query results do not persist across StyleResolver rebuilds.
</span><span class="cx">             InspectorInstrumentation::mediaQueryResultChanged(document);
</span><span class="cx">         } else
</span><span class="lines">@@ -3532,7 +3532,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_pagination = pagination;
</span><span class="cx"> 
</span><del>-    frame().document()-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+    frame().document()-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IntRect FrameView::windowClipRect() const
</span><span class="lines">@@ -4998,11 +4998,8 @@
</span><span class="cx">     m_overrideViewportSize = size;
</span><span class="cx">     m_hasOverrideViewportSize = true;
</span><span class="cx">     
</span><del>-    if (Document* document = frame().document()) {
-        // FIXME: this should probably be updateViewportUnitsOnResize(), but synchronously
-        // dirtying style here causes assertions on iOS (rdar://problem/19998166).
-        document-&gt;styleScope().didChangeContentsOrInterpretation();
-    }
</del><ins>+    if (Document* document = frame().document())
+        document-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> IntSize FrameView::viewportSizeForCSSViewportUnits() const
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/page/Page.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -424,7 +424,7 @@
</span><span class="cx">         m_mainFrame-&gt;view()-&gt;forceLayout();
</span><span class="cx"> 
</span><span class="cx">     if (m_mainFrame-&gt;document())
</span><del>-        m_mainFrame-&gt;document()-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+        m_mainFrame-&gt;document()-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
</span><span class="cx"> 
</span><span class="lines">@@ -500,9 +500,10 @@
</span><span class="cx"> 
</span><span class="cx"> void Page::setNeedsRecalcStyleInAllFrames()
</span><span class="cx"> {
</span><ins>+    // FIXME: Figure out what this function is actually trying to add in different call sites.
</ins><span class="cx">     for (Frame* frame = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext()) {
</span><span class="cx">         if (Document* document = frame-&gt;document())
</span><del>-            document-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+            document-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1159,7 +1160,6 @@
</span><span class="cx">         if (!document)
</span><span class="cx">             continue;
</span><span class="cx">         document-&gt;extensionStyleSheets().invalidateInjectedStyleSheetCache();
</span><del>-        document-&gt;styleScope().didChangeContentsOrInterpretation();
</del><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/style/StyleScope.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -71,6 +71,10 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Scope::~Scope()
+{
+}
+
</ins><span class="cx"> bool Scope::shouldUseSharedUserAgentShadowTreeStyleResolver() const
</span><span class="cx"> {
</span><span class="cx">     if (!m_shadowRoot)
</span><span class="lines">@@ -120,6 +124,22 @@
</span><span class="cx">     return node.document().styleScope();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Scope::setPreferredStylesheetSetName(const String&amp; name)
+{
+    if (m_preferredStylesheetSetName == name)
+        return;
+    m_preferredStylesheetSetName = name;
+    didChangeActiveStyleSheetCandidates();
+}
+
+void Scope::setSelectedStylesheetSetName(const String&amp; name)
+{
+    if (m_selectedStylesheetSetName == name)
+        return;
+    m_selectedStylesheetSetName = name;
+    didChangeActiveStyleSheetCandidates();
+}
+
</ins><span class="cx"> // This method is called whenever a top-level stylesheet has finished loading.
</span><span class="cx"> void Scope::removePendingSheet(RemovePendingSheetNotificationType notification)
</span><span class="cx"> {
</span><span class="lines">@@ -141,7 +161,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    didChangeCandidatesForActiveSet();
</del><ins>+    didChangeActiveStyleSheetCandidates();
</ins><span class="cx"> 
</span><span class="cx">     if (!m_shadowRoot)
</span><span class="cx">         m_document.didRemoveAllPendingStylesheet();
</span><span class="lines">@@ -183,7 +203,7 @@
</span><span class="cx"> void Scope::removeStyleSheetCandidateNode(Node&amp; node)
</span><span class="cx"> {
</span><span class="cx">     if (m_styleSheetCandidateNodes.remove(&amp;node))
</span><del>-        scheduleActiveSetUpdate();
</del><ins>+        didChangeActiveStyleSheetCandidates();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Scope::collectActiveStyleSheets(Vector&lt;RefPtr&lt;StyleSheet&gt;&gt;&amp; sheets)
</span><span class="lines">@@ -338,22 +358,20 @@
</span><span class="cx"> 
</span><span class="cx"> void Scope::updateActiveStyleSheets(UpdateType updateType)
</span><span class="cx"> {
</span><del>-    ASSERT(!m_pendingUpdateType);
</del><ins>+    ASSERT(!m_pendingUpdate);
</ins><span class="cx"> 
</span><ins>+    if (!m_document.hasLivingRenderTree())
+        return;
+
</ins><span class="cx">     if (m_document.inStyleRecalc() || m_document.inRenderTreeUpdate()) {
</span><span class="cx">         // Protect against deleting style resolver in the middle of a style resolution.
</span><span class="cx">         // Crash stacks indicate we can get here when a resource load fails synchronously (for example due to content blocking).
</span><span class="cx">         // FIXME: These kind of cases should be eliminated and this path replaced by an assert.
</span><del>-        m_pendingUpdateType = UpdateType::ContentsOrInterpretation;
</del><ins>+        m_pendingUpdate = UpdateType::ContentsOrInterpretation;
</ins><span class="cx">         m_document.scheduleForcedStyleRecalc();
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!m_document.hasLivingRenderTree()) {
-        clearResolver();
-        return;
-    }
-
</del><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><span class="cx">     if (!m_shadowRoot &amp;&amp; !m_didUpdateActiveStyleSheets &amp;&amp; m_pendingStyleSheetCount) {
</span><span class="lines">@@ -418,7 +436,7 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; Scope::activeStyleSheetsForInspector() const
</del><ins>+const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; Scope::activeStyleSheetsForInspector()
</ins><span class="cx"> {
</span><span class="cx">     Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; result;
</span><span class="cx"> 
</span><span class="lines">@@ -451,9 +469,13 @@
</span><span class="cx"> 
</span><span class="cx"> void Scope::flushPendingUpdate()
</span><span class="cx"> {
</span><del>-    if (!m_pendingUpdateType)
</del><ins>+    if (!m_shadowRoot) {
+        for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots())
+            descendantShadowRoot-&gt;styleScope().flushPendingUpdate();
+    }
+    if (!m_pendingUpdate)
</ins><span class="cx">         return;
</span><del>-    auto updateType = *m_pendingUpdateType;
</del><ins>+    auto updateType = *m_pendingUpdate;
</ins><span class="cx"> 
</span><span class="cx">     clearPendingUpdate();
</span><span class="cx"> 
</span><span class="lines">@@ -463,40 +485,52 @@
</span><span class="cx"> void Scope::clearPendingUpdate()
</span><span class="cx"> {
</span><span class="cx">     m_pendingUpdateTimer.stop();
</span><del>-    m_pendingUpdateType = { };
</del><ins>+    m_pendingUpdate = { };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Scope::scheduleActiveSetUpdate()
</del><ins>+void Scope::scheduleUpdate(UpdateType update)
</ins><span class="cx"> {
</span><del>-    if (m_shadowRoot) {
-        // FIXME: We need to flush updates recursively to support asynchronous updates in shadow trees.
-        didChangeCandidatesForActiveSet();
-        return;
-    }
</del><ins>+    if (!m_pendingUpdate || *m_pendingUpdate &lt; update)
+        m_pendingUpdate = update;
+
</ins><span class="cx">     if (m_pendingUpdateTimer.isActive())
</span><span class="cx">         return;
</span><del>-    if (!m_pendingUpdateType)
-        m_pendingUpdateType = UpdateType::ActiveSet;
</del><span class="cx">     m_pendingUpdateTimer.startOneShot(0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Scope::didChangeCandidatesForActiveSet()
</del><ins>+void Scope::didChangeActiveStyleSheetCandidates()
</ins><span class="cx"> {
</span><del>-    auto updateType = m_pendingUpdateType.valueOr(UpdateType::ActiveSet);
-    clearPendingUpdate();
-    updateActiveStyleSheets(updateType);
</del><ins>+    scheduleUpdate(UpdateType::ActiveSet);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Scope::didChangeContentsOrInterpretation()
</del><ins>+void Scope::didChangeStyleSheetContents()
</ins><span class="cx"> {
</span><del>-    clearPendingUpdate();
-    updateActiveStyleSheets(UpdateType::ContentsOrInterpretation);
</del><ins>+    scheduleUpdate(UpdateType::ContentsOrInterpretation);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Scope::didChangeStyleSheetEnvironment()
+{
+    if (!m_shadowRoot) {
+        for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots()) {
+            // Stylesheets is author shadow roots are are potentially affected.
+            if (descendantShadowRoot-&gt;mode() != ShadowRoot::Mode::UserAgent)
+                descendantShadowRoot-&gt;styleScope().scheduleUpdate(UpdateType::ContentsOrInterpretation);
+        }
+    }
+    scheduleUpdate(UpdateType::ContentsOrInterpretation);
+}
+
</ins><span class="cx"> void Scope::pendingUpdateTimerFired()
</span><span class="cx"> {
</span><span class="cx">     flushPendingUpdate();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+const Vector&lt;RefPtr&lt;StyleSheet&gt;&gt;&amp; Scope::styleSheetsForStyleSheetList()
+{
+    // FIXME: StyleSheetList content should be updated separately from style resolver updates.
+    flushPendingUpdate();
+    return m_styleSheetsForStyleSheetList;
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><ins>+}
</ins></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.h (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.h        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/style/StyleScope.h        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -56,10 +56,12 @@
</span><span class="cx">     explicit Scope(Document&amp;);
</span><span class="cx">     explicit Scope(ShadowRoot&amp;);
</span><span class="cx"> 
</span><ins>+    ~Scope();
+
</ins><span class="cx">     const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; activeStyleSheets() const { return m_activeStyleSheets; }
</span><span class="cx"> 
</span><del>-    const Vector&lt;RefPtr&lt;StyleSheet&gt;&gt;&amp; styleSheetsForStyleSheetList() const { return m_styleSheetsForStyleSheetList; }
-    const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; activeStyleSheetsForInspector() const;
</del><ins>+    const Vector&lt;RefPtr&lt;StyleSheet&gt;&gt;&amp; styleSheetsForStyleSheetList();
+    const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; activeStyleSheetsForInspector();
</ins><span class="cx"> 
</span><span class="cx">     void addStyleSheetCandidateNode(Node&amp;, bool createdByParser);
</span><span class="cx">     void removeStyleSheetCandidateNode(Node&amp;);
</span><span class="lines">@@ -66,8 +68,8 @@
</span><span class="cx"> 
</span><span class="cx">     String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; }
</span><span class="cx">     String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; }
</span><del>-    void setPreferredStylesheetSetName(const String&amp; name) { m_preferredStylesheetSetName = name; }
-    void setSelectedStylesheetSetName(const String&amp; name) { m_selectedStylesheetSetName = name; }
</del><ins>+    void setPreferredStylesheetSetName(const String&amp;);
+    void setSelectedStylesheetSetName(const String&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void addPendingSheet() { m_pendingStyleSheetCount++; }
</span><span class="cx">     enum RemovePendingSheetNotificationType {
</span><span class="lines">@@ -82,12 +84,16 @@
</span><span class="cx"> 
</span><span class="cx">     bool activeStyleSheetsContains(const CSSStyleSheet*) const;
</span><span class="cx"> 
</span><del>-    void didChangeCandidatesForActiveSet();
-    void scheduleActiveSetUpdate();
-    WEBCORE_EXPORT void didChangeContentsOrInterpretation();
</del><ins>+    // This is called when some stylesheet becomes newly enabled or disabled.
+    void didChangeActiveStyleSheetCandidates();
+    // This is called when contents of a stylesheet is mutated.
+    void didChangeStyleSheetContents();
+    // This is called when the environment where we intrepret the stylesheets changes (for example switching to printing).
+    // The change is assumed to potentially affect all author and user stylesheets including shadow roots.
+    WEBCORE_EXPORT void didChangeStyleSheetEnvironment();
</ins><span class="cx"> 
</span><del>-    bool hasPendingUpdate() const { return !!m_pendingUpdateType; }
-    void flushPendingUpdate();
</del><ins>+    bool hasPendingUpdate() const { return !!m_pendingUpdate; }
+    WEBCORE_EXPORT void flushPendingUpdate();
</ins><span class="cx"> 
</span><span class="cx">     StyleResolver&amp; resolver();
</span><span class="cx">     StyleResolver* resolverIfExists();
</span><span class="lines">@@ -100,6 +106,7 @@
</span><span class="cx"> 
</span><span class="cx">     enum class UpdateType { ActiveSet, ContentsOrInterpretation };
</span><span class="cx">     void updateActiveStyleSheets(UpdateType);
</span><ins>+    void scheduleUpdate(UpdateType);
</ins><span class="cx"> 
</span><span class="cx">     void collectActiveStyleSheets(Vector&lt;RefPtr&lt;StyleSheet&gt;&gt;&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -133,7 +140,7 @@
</span><span class="cx">     int m_pendingStyleSheetCount { 0 };
</span><span class="cx">     bool m_didUpdateActiveStyleSheets { false };
</span><span class="cx"> 
</span><del>-    Optional&lt;UpdateType&gt; m_pendingUpdateType;
</del><ins>+    Optional&lt;UpdateType&gt; m_pendingUpdate;
</ins><span class="cx"> 
</span><span class="cx">     ListHashSet&lt;Node*&gt; m_styleSheetCandidateNodes;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGFontFaceElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGFontFaceElement.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGFontFaceElement.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/svg/SVGFontFaceElement.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -267,7 +267,7 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+    document().styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Node::InsertionNotificationRequest SVGFontFaceElement::insertedInto(ContainerNode&amp; rootParent)
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx">         document().accessSVGExtensions().unregisterSVGFontFaceElement(this);
</span><span class="cx">         m_fontFaceRule-&gt;mutableProperties().clear();
</span><span class="cx"> 
</span><del>-        document().styleScope().didChangeContentsOrInterpretation();
</del><ins>+        document().styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">     } else
</span><span class="cx">         ASSERT(!m_fontElement);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/testing/Internals.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -118,6 +118,7 @@
</span><span class="cx"> #include &quot;SourceBuffer.h&quot;
</span><span class="cx"> #include &quot;SpellChecker.h&quot;
</span><span class="cx"> #include &quot;StaticNodeList.h&quot;
</span><ins>+#include &quot;StyleScope.h&quot;
</ins><span class="cx"> #include &quot;StyleSheetContents.h&quot;
</span><span class="cx"> #include &quot;TextIterator.h&quot;
</span><span class="cx"> #include &quot;TreeScope.h&quot;
</span><span class="lines">@@ -381,6 +382,7 @@
</span><span class="cx">     WebCore::Settings::setUsesOverlayScrollbars(false);
</span><span class="cx">     WebCore::Settings::setUsesMockScrollAnimator(false);
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><ins>+    page.group().captionPreferences().setTestingMode(true);
</ins><span class="cx">     page.group().captionPreferences().setCaptionsStyleSheetOverride(emptyString());
</span><span class="cx">     page.group().captionPreferences().setTestingMode(false);
</span><span class="cx"> #endif
</span><span class="lines">@@ -501,6 +503,8 @@
</span><span class="cx"> 
</span><span class="cx"> String Internals::styleChangeType(Node&amp; node)
</span><span class="cx"> {
</span><ins>+    node.document().styleScope().flushPendingUpdate();
+
</ins><span class="cx">     return styleValidityToToString(node.styleValidity());
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorexmlXMLTreeViewercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/XMLTreeViewer.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/XMLTreeViewer.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/xml/XMLTreeViewer.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx">     String cssString = StringImpl::createWithoutCopying(XMLViewer_css, sizeof(XMLViewer_css));
</span><span class="cx">     auto text = m_document.createTextNode(cssString);
</span><span class="cx">     m_document.getElementById(String(ASCIILiteral(&quot;xml-viewer-style&quot;)))-&gt;appendChild(text, IGNORE_EXCEPTION);
</span><del>-    m_document.styleScope().didChangeContentsOrInterpretation();
</del><ins>+    m_document.styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorexmlparserXMLDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -200,7 +200,7 @@
</span><span class="cx">         insertErrorMessageBlock();
</span><span class="cx">     else {
</span><span class="cx">         updateLeafTextNode();
</span><del>-        document()-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+        document()-&gt;styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (isParsing())
</span></span></pre></div>
<a id="trunkSourceWebCorexmlparserXMLDocumentParserLibxml2cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -1387,7 +1387,7 @@
</span><span class="cx">         document()-&gt;setTransformSource(std::make_unique&lt;TransformSource&gt;(doc));
</span><span class="cx"> 
</span><span class="cx">         document()-&gt;setParsing(false); // Make the document think it's done, so it will apply XSL stylesheets.
</span><del>-        document()-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+        document()-&gt;styleScope().didChangeActiveStyleSheetCandidates();
</ins><span class="cx"> 
</span><span class="cx">         // styleResolverChanged() call can detach the parser and null out its document.
</span><span class="cx">         // In that case, we just bail out.
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebHTMLViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (207668 => 207669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm        2016-10-21 13:27:10 UTC (rev 207668)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm        2016-10-21 13:36:45 UTC (rev 207669)
</span><span class="lines">@@ -3612,7 +3612,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     if (Frame* coreFrame = core([self _frame])) {
</span><del>-        coreFrame-&gt;document()-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+        coreFrame-&gt;document()-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">         coreFrame-&gt;document()-&gt;updateStyleIfNeeded();
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -5024,7 +5024,7 @@
</span><span class="cx"> 
</span><span class="cx">             document-&gt;setPaginatedForScreen(_private-&gt;paginateScreenContent);
</span><span class="cx">             document-&gt;setPrinting(_private-&gt;printing);
</span><del>-            document-&gt;styleScope().didChangeContentsOrInterpretation();
</del><ins>+            document-&gt;styleScope().didChangeStyleSheetEnvironment();
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>