<!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>[190347] trunk/Source/WebCore</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/190347">190347</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-09-30 08:39:15 -0700 (Wed, 30 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use separate style resolver for user agent shadow trees
https://bugs.webkit.org/show_bug.cgi?id=149626

Reviewed by Andreas Kling.

We now support separate style resolvers for shadow trees. Use this mechanism to have a separate
per-document style resolver for user agent shadow trees. This isolates user agent shadow trees
from author style better and simplifies the style resolver. It can also avoid some unnecessary style recalcs.

* css/DocumentRuleSets.cpp:
(WebCore::DocumentRuleSets::resetAuthorStyle):
(WebCore::DocumentRuleSets::appendAuthorStyleSheets):

    Change interface so that only the new rules are provided.

* css/DocumentRuleSets.h:
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::addElementStyleProperties):
(WebCore::ElementRuleCollector::collectMatchingRules):

    We can remove special bailout as shadow tree style resolver won't have other author style

(WebCore::ElementRuleCollector::sortAndTransferMatchedRules):

    Remove the exception that disables property whitelists for UA stylesheets. We don't seem to use the feature.

(WebCore::ElementRuleCollector::matchUARules):
(WebCore::MatchingUARulesScope::MatchingUARulesScope): Deleted.
(WebCore::MatchingUARulesScope::~MatchingUARulesScope): Deleted.
(WebCore::MatchingUARulesScope::isMatchingUARules): Deleted.

    Remove this unnecessary hack.

* css/ElementRuleCollector.h:
(WebCore::ElementRuleCollector::ElementRuleCollector):
* css/RuleSet.cpp:
(WebCore::RuleSet::addStyleRule):
(WebCore::RuleSet::copyShadowPseudoElementRulesFrom):

    Also copy WebVTT rules. They are currently a sort of mixture of UA and author shadow tree.

(WebCore::shrinkMapVectorsToFit):
* css/RuleSet.h:
(WebCore::RuleData::containsUncommonAttributeSelector):
(WebCore::RuleData::linkMatchType):
(WebCore::RuleData::hasDocumentSecurityOrigin):
(WebCore::RuleData::propertyWhitelistType):
(WebCore::RuleData::descendantSelectorIdentifierHashes):
(WebCore::RuleSet::ruleCount):
(WebCore::RuleSet::hasShadowPseudoElementRules):
* css/StyleInvalidationAnalysis.cpp:
(WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
(WebCore::StyleInvalidationAnalysis::invalidateIfNeeded):

    Don't invalidate the whole tree when author shadow pseudo element rules change. Just invalidate the shadow trees.

(WebCore::StyleInvalidationAnalysis::invalidateStyleForTree):
(WebCore::StyleInvalidationAnalysis::invalidateStyle):
(WebCore::invalidateIfNeeded): Deleted.
(WebCore::invalidateStyleForTree): Deleted.
* css/StyleInvalidationAnalysis.h:
(WebCore::StyleInvalidationAnalysis::dirtiesAllStyle):
(WebCore::StyleInvalidationAnalysis::hasShadowPseudoElementRulesInAuthorSheet):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::MatchResult::addMatchedProperties):
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::appendAuthorStyleSheets):

    Simpler interface.

* css/StyleResolver.h:
(WebCore::StyleResolver::document):
(WebCore::StyleResolver::documentSettings):
(WebCore::StyleResolver::ruleSets):
* dom/AuthorStyleSheets.cpp:
(WebCore::AuthorStyleSheets::collectActiveStyleSheets):
(WebCore::AuthorStyleSheets::analyzeStyleSheetChange):

    Cleanups.

(WebCore::filterEnabledNonemptyCSSStyleSheets):
(WebCore::AuthorStyleSheets::updateActiveStyleSheets):
(WebCore::AuthorStyleSheets::updateStyleResolver):

    Factor to a function.
    Copy any author shadow pseudo elements to user agent shadow tree resolver.

(WebCore::AuthorStyleSheets::activeStyleSheetsForInspector):
* dom/AuthorStyleSheets.h:
* dom/Document.cpp:
(WebCore::Document::createStyleResolver):
(WebCore::Document::userAgentShadowTreeStyleResolver):

    Use separate resolver.

(WebCore::Document::fontsNeedUpdate):
(WebCore::Document::clearStyleResolver):
* dom/Document.h:
(WebCore::Document::ensureStyleResolver):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::styleResolver):

    Return document-global shadow tree resolver for ua trees.

* style/StyleResolveTree.cpp:
(WebCore::Style::resolveShadowTree):

    Take styleChange of shadow root into account.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssDocumentRuleSetscpp">trunk/Source/WebCore/css/DocumentRuleSets.cpp</a></li>
<li><a href="#trunkSourceWebCorecssDocumentRuleSetsh">trunk/Source/WebCore/css/DocumentRuleSets.h</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorcpp">trunk/Source/WebCore/css/ElementRuleCollector.cpp</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorh">trunk/Source/WebCore/css/ElementRuleCollector.h</a></li>
<li><a href="#trunkSourceWebCorecssRuleSetcpp">trunk/Source/WebCore/css/RuleSet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssRuleSeth">trunk/Source/WebCore/css/RuleSet.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleInvalidationAnalysiscpp">trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleInvalidationAnalysish">trunk/Source/WebCore/css/StyleInvalidationAnalysis.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolverh">trunk/Source/WebCore/css/StyleResolver.h</a></li>
<li><a href="#trunkSourceWebCoredomAuthorStyleSheetscpp">trunk/Source/WebCore/dom/AuthorStyleSheets.cpp</a></li>
<li><a href="#trunkSourceWebCoredomAuthorStyleSheetsh">trunk/Source/WebCore/dom/AuthorStyleSheets.h</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="#trunkSourceWebCoredomShadowRootcpp">trunk/Source/WebCore/dom/ShadowRoot.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleResolveTreecpp">trunk/Source/WebCore/style/StyleResolveTree.cpp</a></li>
<li><a href="#trunkSourceWebCoresvgSVGElementcpp">trunk/Source/WebCore/svg/SVGElement.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/ChangeLog        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -1,3 +1,114 @@
</span><ins>+2015-09-29  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Use separate style resolver for user agent shadow trees
+        https://bugs.webkit.org/show_bug.cgi?id=149626
+
+        Reviewed by Andreas Kling.
+
+        We now support separate style resolvers for shadow trees. Use this mechanism to have a separate
+        per-document style resolver for user agent shadow trees. This isolates user agent shadow trees
+        from author style better and simplifies the style resolver. It can also avoid some unnecessary style recalcs.
+
+        * css/DocumentRuleSets.cpp:
+        (WebCore::DocumentRuleSets::resetAuthorStyle):
+        (WebCore::DocumentRuleSets::appendAuthorStyleSheets):
+
+            Change interface so that only the new rules are provided.
+
+        * css/DocumentRuleSets.h:
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::addElementStyleProperties):
+        (WebCore::ElementRuleCollector::collectMatchingRules):
+
+            We can remove special bailout as shadow tree style resolver won't have other author style
+
+        (WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
+
+            Remove the exception that disables property whitelists for UA stylesheets. We don't seem to use the feature.
+
+        (WebCore::ElementRuleCollector::matchUARules):
+        (WebCore::MatchingUARulesScope::MatchingUARulesScope): Deleted.
+        (WebCore::MatchingUARulesScope::~MatchingUARulesScope): Deleted.
+        (WebCore::MatchingUARulesScope::isMatchingUARules): Deleted.
+
+            Remove this unnecessary hack.
+
+        * css/ElementRuleCollector.h:
+        (WebCore::ElementRuleCollector::ElementRuleCollector):
+        * css/RuleSet.cpp:
+        (WebCore::RuleSet::addStyleRule):
+        (WebCore::RuleSet::copyShadowPseudoElementRulesFrom):
+
+            Also copy WebVTT rules. They are currently a sort of mixture of UA and author shadow tree.
+
+        (WebCore::shrinkMapVectorsToFit):
+        * css/RuleSet.h:
+        (WebCore::RuleData::containsUncommonAttributeSelector):
+        (WebCore::RuleData::linkMatchType):
+        (WebCore::RuleData::hasDocumentSecurityOrigin):
+        (WebCore::RuleData::propertyWhitelistType):
+        (WebCore::RuleData::descendantSelectorIdentifierHashes):
+        (WebCore::RuleSet::ruleCount):
+        (WebCore::RuleSet::hasShadowPseudoElementRules):
+        * css/StyleInvalidationAnalysis.cpp:
+        (WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
+        (WebCore::StyleInvalidationAnalysis::invalidateIfNeeded):
+
+            Don't invalidate the whole tree when author shadow pseudo element rules change. Just invalidate the shadow trees.
+
+        (WebCore::StyleInvalidationAnalysis::invalidateStyleForTree):
+        (WebCore::StyleInvalidationAnalysis::invalidateStyle):
+        (WebCore::invalidateIfNeeded): Deleted.
+        (WebCore::invalidateStyleForTree): Deleted.
+        * css/StyleInvalidationAnalysis.h:
+        (WebCore::StyleInvalidationAnalysis::dirtiesAllStyle):
+        (WebCore::StyleInvalidationAnalysis::hasShadowPseudoElementRulesInAuthorSheet):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::MatchResult::addMatchedProperties):
+        (WebCore::StyleResolver::StyleResolver):
+        (WebCore::StyleResolver::appendAuthorStyleSheets):
+
+            Simpler interface.
+
+        * css/StyleResolver.h:
+        (WebCore::StyleResolver::document):
+        (WebCore::StyleResolver::documentSettings):
+        (WebCore::StyleResolver::ruleSets):
+        * dom/AuthorStyleSheets.cpp:
+        (WebCore::AuthorStyleSheets::collectActiveStyleSheets):
+        (WebCore::AuthorStyleSheets::analyzeStyleSheetChange):
+
+            Cleanups.
+
+        (WebCore::filterEnabledNonemptyCSSStyleSheets):
+        (WebCore::AuthorStyleSheets::updateActiveStyleSheets):
+        (WebCore::AuthorStyleSheets::updateStyleResolver):
+
+            Factor to a function.
+            Copy any author shadow pseudo elements to user agent shadow tree resolver.
+
+        (WebCore::AuthorStyleSheets::activeStyleSheetsForInspector):
+        * dom/AuthorStyleSheets.h:
+        * dom/Document.cpp:
+        (WebCore::Document::createStyleResolver):
+        (WebCore::Document::userAgentShadowTreeStyleResolver):
+
+            Use separate resolver.
+
+        (WebCore::Document::fontsNeedUpdate):
+        (WebCore::Document::clearStyleResolver):
+        * dom/Document.h:
+        (WebCore::Document::ensureStyleResolver):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::styleResolver):
+
+            Return document-global shadow tree resolver for ua trees.
+
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::resolveShadowTree):
+
+            Take styleChange of shadow root into account.
+
</ins><span class="cx"> 2015-09-30  Gwang Yoon Hwang  &lt;yoon@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Support HiDPI Properly in WebKitGtk+ with the TextureMapper
</span></span></pre></div>
<a id="trunkSourceWebCorecssDocumentRuleSetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/DocumentRuleSets.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/DocumentRuleSets.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/DocumentRuleSets.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -83,18 +83,16 @@
</span><span class="cx">     m_authorStyle-&gt;disableAutoShrinkToFit();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void DocumentRuleSets::appendAuthorStyleSheets(unsigned firstNew, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; styleSheets, MediaQueryEvaluator* medium, InspectorCSSOMWrappers&amp; inspectorCSSOMWrappers, StyleResolver* resolver)
</del><ins>+void DocumentRuleSets::appendAuthorStyleSheets(const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; styleSheets, MediaQueryEvaluator* medium, InspectorCSSOMWrappers&amp; inspectorCSSOMWrappers, StyleResolver* resolver)
</ins><span class="cx"> {
</span><span class="cx">     // This handles sheets added to the end of the stylesheet list only. In other cases the style resolver
</span><span class="cx">     // needs to be reconstructed. To handle insertions too the rule order numbers would need to be updated.
</span><del>-    unsigned size = styleSheets.size();
-    for (unsigned i = firstNew; i &lt; size; ++i) {
-        CSSStyleSheet* cssSheet = styleSheets[i].get();
</del><ins>+    for (auto&amp; cssSheet : styleSheets) {
</ins><span class="cx">         ASSERT(!cssSheet-&gt;disabled());
</span><span class="cx">         if (cssSheet-&gt;mediaQueries() &amp;&amp; !medium-&gt;eval(cssSheet-&gt;mediaQueries(), resolver))
</span><span class="cx">             continue;
</span><span class="cx">         m_authorStyle-&gt;addRulesFromSheet(&amp;cssSheet-&gt;contents(), *medium, resolver);
</span><del>-        inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet);
</del><ins>+        inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet.get());
</ins><span class="cx">     }
</span><span class="cx">     m_authorStyle-&gt;shrinkToFit();
</span><span class="cx">     collectFeatures();
</span></span></pre></div>
<a id="trunkSourceWebCorecssDocumentRuleSetsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/DocumentRuleSets.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/DocumentRuleSets.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/DocumentRuleSets.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx"> 
</span><span class="cx">     void initUserStyle(ExtensionStyleSheets&amp;, const MediaQueryEvaluator&amp;, StyleResolver&amp;);
</span><span class="cx">     void resetAuthorStyle();
</span><del>-    void appendAuthorStyleSheets(unsigned firstNew, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp;, MediaQueryEvaluator*, InspectorCSSOMWrappers&amp;, StyleResolver*);
</del><ins>+    void appendAuthorStyleSheets(const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp;, MediaQueryEvaluator*, InspectorCSSOMWrappers&amp;, StyleResolver*);
</ins><span class="cx"> 
</span><span class="cx">     void collectFeatures();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -113,35 +113,6 @@
</span><span class="cx">         m_result.isCacheable = false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-class MatchingUARulesScope {
-public:
-    MatchingUARulesScope();
-    ~MatchingUARulesScope();
-
-    static bool isMatchingUARules();
-
-private:
-    static bool m_matchingUARules;
-};
-
-MatchingUARulesScope::MatchingUARulesScope()
-{
-    ASSERT(!m_matchingUARules);
-    m_matchingUARules = true;
-}
-
-MatchingUARulesScope::~MatchingUARulesScope()
-{
-    m_matchingUARules = false;
-}
-
-inline bool MatchingUARulesScope::isMatchingUARules()
-{
-    return m_matchingUARules;
-}
-
-bool MatchingUARulesScope::m_matchingUARules = false;
-
</del><span class="cx"> void ElementRuleCollector::collectMatchingRules(const MatchRequest&amp; matchRequest, StyleResolver::RuleRange&amp; ruleRange)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(matchRequest.ruleSet);
</span><span class="lines">@@ -158,10 +129,6 @@
</span><span class="cx">         const AtomicString&amp; pseudoId = m_element.shadowPseudoId();
</span><span class="cx">         if (!pseudoId.isEmpty())
</span><span class="cx">             collectMatchingRulesForList(matchRequest.ruleSet-&gt;shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
</span><del>-
-        // Only match UA rules in shadow tree.
-        if (!MatchingUARulesScope::isMatchingUARules())
-            return;
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // We need to collect the rules for id, class, tag, and everything else into a buffer and
</span><span class="lines">@@ -215,7 +182,7 @@
</span><span class="cx">     for (const MatchedRule&amp; matchedRule : matchedRules) {
</span><span class="cx">         if (m_style &amp;&amp; matchedRule.ruleData-&gt;containsUncommonAttributeSelector())
</span><span class="cx">             m_style-&gt;setUnique();
</span><del>-        m_result.addMatchedProperties(matchedRule.ruleData-&gt;rule()-&gt;properties(), matchedRule.ruleData-&gt;rule(), matchedRule.ruleData-&gt;linkMatchType(), matchedRule.ruleData-&gt;propertyWhitelistType(MatchingUARulesScope::isMatchingUARules()));
</del><ins>+        m_result.addMatchedProperties(matchedRule.ruleData-&gt;rule()-&gt;properties(), matchedRule.ruleData-&gt;rule(), matchedRule.ruleData-&gt;linkMatchType(), matchedRule.ruleData-&gt;propertyWhitelistType());
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -251,8 +218,6 @@
</span><span class="cx"> 
</span><span class="cx"> void ElementRuleCollector::matchUARules()
</span><span class="cx"> {
</span><del>-    MatchingUARulesScope scope;
-
</del><span class="cx">     // First we match rules from the user agent sheet.
</span><span class="cx">     if (CSSDefaultStyleSheets::simpleDefaultStyleSheet)
</span><span class="cx">         m_result.isCacheable = false;
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -50,11 +50,6 @@
</span><span class="cx">         , m_style(style)
</span><span class="cx">         , m_ruleSets(ruleSets)
</span><span class="cx">         , m_selectorFilter(selectorFilter)
</span><del>-        , m_isPrintStyle(false)
-        , m_regionForStyling(nullptr)
-        , m_pseudoStyleRequest(NOPSEUDO)
-        , m_sameOriginOnly(false)
-        , m_mode(SelectorChecker::Mode::ResolvingStyle)
</del><span class="cx">         , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(element.parentNode()))
</span><span class="cx">     {
</span><span class="cx">     }
</span><span class="lines">@@ -98,11 +93,11 @@
</span><span class="cx">     const DocumentRuleSets&amp; m_ruleSets;
</span><span class="cx">     const SelectorFilter&amp; m_selectorFilter;
</span><span class="cx"> 
</span><del>-    bool m_isPrintStyle;
-    const RenderRegion* m_regionForStyling;
-    PseudoStyleRequest m_pseudoStyleRequest;
-    bool m_sameOriginOnly;
-    SelectorChecker::Mode m_mode;
</del><ins>+    bool m_isPrintStyle { false };
+    const RenderRegion* m_regionForStyling { nullptr };
+    PseudoStyleRequest m_pseudoStyleRequest { NOPSEUDO };
+    bool m_sameOriginOnly { false };
+    SelectorChecker::Mode m_mode { SelectorChecker::Mode::ResolvingStyle };
</ins><span class="cx">     bool m_canUseFastReject;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;Vector&lt;MatchedRule, 32&gt;&gt; m_matchedRules;
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/RuleSet.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -377,6 +377,29 @@
</span><span class="cx">         addRule(rule, selectorIndex, addRuleFlags);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool RuleSet::hasShadowPseudoElementRules() const
+{
+    if (!m_shadowPseudoElementRules.isEmpty())
+        return true;
+#if ENABLE(VIDEO_TRACK)
+    if (!m_cuePseudoRules.isEmpty())
+        return true;
+#endif
+    return false;
+}
+
+void RuleSet::copyShadowPseudoElementRulesFrom(const RuleSet&amp; other)
+{
+    for (auto&amp; keyValuePair : other.m_shadowPseudoElementRules)
+        m_shadowPseudoElementRules.add(keyValuePair.key, std::make_unique&lt;RuleDataVector&gt;(*keyValuePair.value));
+
+#if ENABLE(VIDEO_TRACK)
+    // FIXME: We probably shouldn't treat WebVTT as author stylable user agent shadow tree.
+    for (auto&amp; cue : other.m_cuePseudoRules)
+        m_cuePseudoRules.append(cue);
+#endif
+}
+
</ins><span class="cx"> static inline void shrinkMapVectorsToFit(RuleSet::AtomRuleMap&amp; map)
</span><span class="cx"> {
</span><span class="cx">     for (auto&amp; vector : map.values())
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/RuleSet.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">     bool containsUncommonAttributeSelector() const { return m_containsUncommonAttributeSelector; }
</span><span class="cx">     unsigned linkMatchType() const { return m_linkMatchType; }
</span><span class="cx">     bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
</span><del>-    PropertyWhitelistType propertyWhitelistType(bool isMatchingUARules = false) const { return isMatchingUARules ? PropertyWhitelistNone : static_cast&lt;PropertyWhitelistType&gt;(m_propertyWhitelistType); }
</del><ins>+    PropertyWhitelistType propertyWhitelistType() const { return static_cast&lt;PropertyWhitelistType&gt;(m_propertyWhitelistType); }
</ins><span class="cx">     // Try to balance between memory usage (there can be lots of RuleData objects) and good filtering performance.
</span><span class="cx">     static const unsigned maximumIdentifierCount = 4;
</span><span class="cx">     const unsigned* descendantSelectorIdentifierHashes() const { return m_descendantSelectorIdentifierHashes; }
</span><span class="lines">@@ -187,7 +187,8 @@
</span><span class="cx"> 
</span><span class="cx">     unsigned ruleCount() const { return m_ruleCount; }
</span><span class="cx"> 
</span><del>-    bool hasShadowPseudoElementRules() const { return !m_shadowPseudoElementRules.isEmpty(); }
</del><ins>+    bool hasShadowPseudoElementRules() const;
+    void copyShadowPseudoElementRulesFrom(const RuleSet&amp;);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     void addChildRules(const Vector&lt;RefPtr&lt;StyleRuleBase&gt;&gt;&amp;, const MediaQueryEvaluator&amp; medium, StyleResolver*, bool hasDocumentSecurityOrigin, bool isInitiatingElementInUserAgentShadowTree, AddRuleFlags);
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleInvalidationAnalysiscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;ElementIterator.h&quot;
</span><span class="cx"> #include &quot;ElementRuleCollector.h&quot;
</span><span class="cx"> #include &quot;SelectorFilter.h&quot;
</span><ins>+#include &quot;ShadowRoot.h&quot;
</ins><span class="cx"> #include &quot;StyleRuleImport.h&quot;
</span><span class="cx"> #include &quot;StyleSheetContents.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -83,17 +84,20 @@
</span><span class="cx">     for (auto&amp; sheet : sheets)
</span><span class="cx">         m_ruleSets.authorStyle()-&gt;addRulesFromSheet(sheet, mediaQueryEvaluator);
</span><span class="cx"> 
</span><del>-    // FIXME: We don't descent into shadow trees or otherwise handle shadow pseudo elements.
-    if (m_ruleSets.authorStyle()-&gt;hasShadowPseudoElementRules())
-        m_dirtiesAllStyle = true;
</del><ins>+    m_hasShadowPseudoElementRulesInAuthorSheet = m_ruleSets.authorStyle()-&gt;hasShadowPseudoElementRules();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-enum class CheckDescendants { Yes, No };
-static CheckDescendants invalidateIfNeeded(Element&amp; element, SelectorFilter&amp; filter, const DocumentRuleSets&amp; ruleSets)
</del><ins>+StyleInvalidationAnalysis::CheckDescendants StyleInvalidationAnalysis::invalidateIfNeeded(Element&amp; element, SelectorFilter&amp; filter)
</ins><span class="cx"> {
</span><ins>+    if (m_hasShadowPseudoElementRulesInAuthorSheet) {
+        // FIXME: This could do actual rule matching too.
+        if (auto* shadowRoot = element.shadowRoot())
+            shadowRoot-&gt;setNeedsStyleRecalc();
+    }
+
</ins><span class="cx">     switch (element.styleChangeType()) {
</span><span class="cx">     case NoStyleChange: {
</span><del>-        ElementRuleCollector ruleCollector(element, nullptr, ruleSets, filter);
</del><ins>+        ElementRuleCollector ruleCollector(element, nullptr, m_ruleSets, filter);
</ins><span class="cx">         ruleCollector.setMode(SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements);
</span><span class="cx">         ruleCollector.matchAuthorRules(false);
</span><span class="cx"> 
</span><span class="lines">@@ -112,9 +116,9 @@
</span><span class="cx">     return CheckDescendants::Yes;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void invalidateStyleForTree(Element&amp; root, SelectorFilter&amp; filter, const DocumentRuleSets&amp; ruleSets)
</del><ins>+void StyleInvalidationAnalysis::invalidateStyleForTree(Element&amp; root, SelectorFilter&amp; filter)
</ins><span class="cx"> {
</span><del>-    if (invalidateIfNeeded(root, filter, ruleSets) == CheckDescendants::No)
</del><ins>+    if (invalidateIfNeeded(root, filter) == CheckDescendants::No)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;Element*, 20&gt; parentStack;
</span><span class="lines">@@ -136,7 +140,7 @@
</span><span class="cx">         }
</span><span class="cx">         previousElement = &amp;descendant;
</span><span class="cx"> 
</span><del>-        if (invalidateIfNeeded(descendant, filter, ruleSets) == CheckDescendants::Yes)
</del><ins>+        if (invalidateIfNeeded(descendant, filter) == CheckDescendants::Yes)
</ins><span class="cx">             it.traverseNext();
</span><span class="cx">         else
</span><span class="cx">             it.traverseNextSkippingChildren();
</span><span class="lines">@@ -160,7 +164,7 @@
</span><span class="cx"> 
</span><span class="cx">     SelectorFilter filter;
</span><span class="cx">     filter.setupParentStack(documentElement);
</span><del>-    invalidateStyleForTree(*documentElement, filter, m_ruleSets);
</del><ins>+    invalidateStyleForTree(*documentElement, filter);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleInvalidationAnalysish"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleInvalidationAnalysis.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleInvalidationAnalysis.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/StyleInvalidationAnalysis.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class Document;
</span><ins>+class SelectorFilter;
</ins><span class="cx"> class StyleSheetContents;
</span><span class="cx"> 
</span><span class="cx"> class StyleInvalidationAnalysis {
</span><span class="lines">@@ -40,10 +41,16 @@
</span><span class="cx">     StyleInvalidationAnalysis(const Vector&lt;StyleSheetContents*&gt;&amp;, const MediaQueryEvaluator&amp;);
</span><span class="cx"> 
</span><span class="cx">     bool dirtiesAllStyle() const { return m_dirtiesAllStyle; }
</span><ins>+    bool hasShadowPseudoElementRulesInAuthorSheet() const { return m_hasShadowPseudoElementRulesInAuthorSheet; }
</ins><span class="cx">     void invalidateStyle(Document&amp;);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    bool m_dirtiesAllStyle;
</del><ins>+    enum class CheckDescendants { Yes, No };
+    CheckDescendants invalidateIfNeeded(Element&amp;, SelectorFilter&amp;);
+    void invalidateStyleForTree(Element&amp;, SelectorFilter&amp;);
+
+    bool m_dirtiesAllStyle { false };
+    bool m_hasShadowPseudoElementRulesInAuthorSheet { false };
</ins><span class="cx">     DocumentRuleSets m_ruleSets;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/StyleResolver.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -271,11 +271,11 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-StyleResolver::StyleResolver(Document&amp; document, bool matchAuthorAndUserStyles)
</del><ins>+StyleResolver::StyleResolver(Document&amp; document)
</ins><span class="cx">     : m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
</span><span class="cx">     , m_matchedPropertiesCacheSweepTimer(*this, &amp;StyleResolver::sweepMatchedPropertiesCache)
</span><span class="cx">     , m_document(document)
</span><del>-    , m_matchAuthorAndUserStyles(matchAuthorAndUserStyles)
</del><ins>+    , m_matchAuthorAndUserStyles(m_document.settings() ? m_document.settings()-&gt;authorAndUserStylesEnabled() : true)
</ins><span class="cx"> #if ENABLE(CSS_DEVICE_ADAPTATION)
</span><span class="cx">     , m_viewportStyleResolver(ViewportStyleResolver::create(&amp;document))
</span><span class="cx"> #endif
</span><span class="lines">@@ -316,9 +316,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; styleSheets)
</del><ins>+void StyleResolver::appendAuthorStyleSheets(const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; styleSheets)
</ins><span class="cx"> {
</span><del>-    m_ruleSets.appendAuthorStyleSheets(firstNew, styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, this);
</del><ins>+    m_ruleSets.appendAuthorStyleSheets(styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, this);
</ins><span class="cx">     if (auto renderView = document().renderView())
</span><span class="cx">         renderView-&gt;style().fontCascade().update(&amp;document().fontSelector());
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/css/StyleResolver.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -138,7 +138,7 @@
</span><span class="cx"> class StyleResolver {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(StyleResolver); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    StyleResolver(Document&amp;, bool matchAuthorAndUserStyles);
</del><ins>+    StyleResolver(Document&amp;);
</ins><span class="cx">     ~StyleResolver();
</span><span class="cx"> 
</span><span class="cx">     // Using these during tree walk will allow style selector to optimize child and descendant selector lookups.
</span><span class="lines">@@ -162,9 +162,7 @@
</span><span class="cx">     Document&amp; document() { return m_document; }
</span><span class="cx">     Settings* documentSettings() { return m_document.settings(); }
</span><span class="cx"> 
</span><del>-    // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() directly after we factor StyleRsolver further.
-    // https://bugs.webkit.org/show_bug.cgi?id=108890
-    void appendAuthorStyleSheets(unsigned firstNew, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp;);
</del><ins>+    void appendAuthorStyleSheets(const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp;);
</ins><span class="cx"> 
</span><span class="cx">     DocumentRuleSets&amp; ruleSets() { return m_ruleSets; }
</span><span class="cx">     const DocumentRuleSets&amp; ruleSets() const { return m_ruleSets; }
</span></span></pre></div>
<a id="trunkSourceWebCoredomAuthorStyleSheetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/AuthorStyleSheets.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/AuthorStyleSheets.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/dom/AuthorStyleSheets.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -211,9 +211,8 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AuthorStyleSheets::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; newStylesheets, StyleResolverUpdateType&amp; styleResolverUpdateType, bool&amp; requiresFullStyleRecalc)
</del><ins>+AuthorStyleSheets::StyleResolverUpdateType AuthorStyleSheets::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; newStylesheets, bool&amp; requiresFullStyleRecalc)
</ins><span class="cx"> {
</span><del>-    styleResolverUpdateType = Reconstruct;
</del><span class="cx">     requiresFullStyleRecalc = true;
</span><span class="cx">     
</span><span class="cx">     // Stylesheets of &lt;style&gt; elements that @import stylesheets are active but loading. We need to trigger a full recalc when such loads are done.
</span><span class="lines">@@ -225,30 +224,32 @@
</span><span class="cx">     }
</span><span class="cx">     if (m_hadActiveLoadingStylesheet &amp;&amp; !hasActiveLoadingStylesheet) {
</span><span class="cx">         m_hadActiveLoadingStylesheet = false;
</span><del>-        return;
</del><ins>+        return Reconstruct;
</ins><span class="cx">     }
</span><span class="cx">     m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet;
</span><span class="cx"> 
</span><span class="cx">     if (updateFlag != OptimizedUpdate)
</span><del>-        return;
</del><ins>+        return Reconstruct;
</ins><span class="cx">     if (!m_document.styleResolverIfExists())
</span><del>-        return;
</del><ins>+        return Reconstruct;
+
</ins><span class="cx">     StyleResolver&amp; styleResolver = *m_document.styleResolverIfExists();
</span><span class="cx"> 
</span><span class="cx">     // Find out which stylesheets are new.
</span><span class="cx">     unsigned oldStylesheetCount = m_activeStyleSheets.size();
</span><span class="cx">     if (newStylesheetCount &lt; oldStylesheetCount)
</span><del>-        return;
</del><ins>+        return Reconstruct;
+
</ins><span class="cx">     Vector&lt;StyleSheetContents*&gt; addedSheets;
</span><span class="cx">     unsigned newIndex = 0;
</span><span class="cx">     for (unsigned oldIndex = 0; oldIndex &lt; oldStylesheetCount; ++oldIndex) {
</span><span class="cx">         if (newIndex &gt;= newStylesheetCount)
</span><del>-            return;
</del><ins>+            return Reconstruct;
</ins><span class="cx">         while (m_activeStyleSheets[oldIndex] != newStylesheets[newIndex]) {
</span><span class="cx">             addedSheets.append(&amp;newStylesheets[newIndex]-&gt;contents());
</span><span class="cx">             ++newIndex;
</span><span class="cx">             if (newIndex == newStylesheetCount)
</span><del>-                return;
</del><ins>+                return Reconstruct;
</ins><span class="cx">         }
</span><span class="cx">         ++newIndex;
</span><span class="cx">     }
</span><span class="lines">@@ -259,16 +260,19 @@
</span><span class="cx">     }
</span><span class="cx">     // If all new sheets were added at the end of the list we can just add them to existing StyleResolver.
</span><span class="cx">     // If there were insertions we need to re-add all the stylesheets so rules are ordered correctly.
</span><del>-    styleResolverUpdateType = hasInsertions ? Reset : Additive;
</del><ins>+    auto styleResolverUpdateType = hasInsertions ? Reset : Additive;
</ins><span class="cx"> 
</span><span class="cx">     // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs.
</span><span class="cx">     if (!m_document.bodyOrFrameset() || m_document.hasNodesWithPlaceholderStyle())
</span><del>-        return;
</del><ins>+        return styleResolverUpdateType;
+
</ins><span class="cx">     StyleInvalidationAnalysis invalidationAnalysis(addedSheets, styleResolver.mediaQueryEvaluator());
</span><span class="cx">     if (invalidationAnalysis.dirtiesAllStyle())
</span><del>-        return;
</del><ins>+        return styleResolverUpdateType;
</ins><span class="cx">     invalidationAnalysis.invalidateStyle(m_document);
</span><span class="cx">     requiresFullStyleRecalc = false;
</span><ins>+
+    return styleResolverUpdateType;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void filterEnabledNonemptyCSSStyleSheets(Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; result, const Vector&lt;RefPtr&lt;StyleSheet&gt;&gt;&amp; sheets)
</span><span class="lines">@@ -307,25 +311,10 @@
</span><span class="cx">     activeCSSStyleSheets.appendVector(m_document.extensionStyleSheets().authorStyleSheetsForTesting());
</span><span class="cx">     filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
</span><span class="cx"> 
</span><del>-    StyleResolverUpdateType styleResolverUpdateType;
</del><span class="cx">     bool requiresFullStyleRecalc;
</span><del>-    analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
</del><ins>+    auto styleResolverUpdateType = analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, requiresFullStyleRecalc);
</ins><span class="cx"> 
</span><del>-    if (styleResolverUpdateType == Reconstruct) {
-        if (m_shadowRoot)
-            m_shadowRoot-&gt;resetStyleResolver();
-        else
-            m_document.clearStyleResolver();
-    } else {
-        StyleResolver&amp; styleResolver = m_document.ensureStyleResolver();
-        if (styleResolverUpdateType == Reset) {
-            styleResolver.ruleSets().resetAuthorStyle();
-            styleResolver.appendAuthorStyleSheets(0, activeCSSStyleSheets);
-        } else {
-            ASSERT(styleResolverUpdateType == Additive);
-            styleResolver.appendAuthorStyleSheets(m_activeStyleSheets.size(), activeCSSStyleSheets);
-        }
-    }
</del><ins>+    updateStyleResolver(activeCSSStyleSheets, styleResolverUpdateType);
</ins><span class="cx"> 
</span><span class="cx">     m_weakCopyOfActiveStyleSheetListForFastLookup = nullptr;
</span><span class="cx">     m_activeStyleSheets.swap(activeCSSStyleSheets);
</span><span class="lines">@@ -344,6 +333,35 @@
</span><span class="cx">     return requiresFullStyleRecalc;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AuthorStyleSheets::updateStyleResolver(Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; activeStyleSheets, StyleResolverUpdateType updateType)
+{
+    if (updateType == Reconstruct) {
+        if (m_shadowRoot)
+            m_shadowRoot-&gt;resetStyleResolver();
+        else
+            m_document.clearStyleResolver();
+        return;
+    }
+    auto&amp; styleResolver = m_document.ensureStyleResolver();
+    auto&amp; userAgentShadowTreeStyleResolver = m_document.userAgentShadowTreeStyleResolver();
+
+    if (updateType == Reset) {
+        styleResolver.ruleSets().resetAuthorStyle();
+        styleResolver.appendAuthorStyleSheets(activeStyleSheets);
+    } else {
+        ASSERT(updateType == Additive);
+        unsigned firstNewIndex = m_activeStyleSheets.size();
+        Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; newStyleSheets;
+        newStyleSheets.appendRange(activeStyleSheets.begin() + firstNewIndex, activeStyleSheets.end());
+        styleResolver.appendAuthorStyleSheets(newStyleSheets);
+    }
+
+    userAgentShadowTreeStyleResolver.ruleSets().resetAuthorStyle();
+    auto&amp; authorRuleSet = *styleResolver.ruleSets().authorStyle();
+    if (authorRuleSet.hasShadowPseudoElementRules())
+        userAgentShadowTreeStyleResolver.ruleSets().authorStyle()-&gt;copyShadowPseudoElementRulesFrom(authorRuleSet);
+}
+
</ins><span class="cx"> const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; AuthorStyleSheets::activeStyleSheetsForInspector() const
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; result;
</span></span></pre></div>
<a id="trunkSourceWebCoredomAuthorStyleSheetsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/AuthorStyleSheets.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/AuthorStyleSheets.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/dom/AuthorStyleSheets.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -106,7 +106,8 @@
</span><span class="cx">         Reset,
</span><span class="cx">         Additive
</span><span class="cx">     };
</span><del>-    void analyzeStyleSheetChange(UpdateFlag, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; newStylesheets, StyleResolverUpdateType&amp;, bool&amp; requiresFullStyleRecalc);
</del><ins>+    StyleResolverUpdateType analyzeStyleSheetChange(UpdateFlag, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; newStylesheets, bool&amp; requiresFullStyleRecalc);
+    void updateStyleResolver(Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp;, StyleResolverUpdateType);
</ins><span class="cx"> 
</span><span class="cx">     Document&amp; m_document;
</span><span class="cx">     ShadowRoot* m_shadowRoot { nullptr };
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/dom/Document.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -2111,13 +2111,24 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::createStyleResolver()
</span><span class="cx"> {
</span><del>-    bool matchAuthorAndUserStyles = true;
-    if (Settings* settings = this-&gt;settings())
-        matchAuthorAndUserStyles = settings-&gt;authorAndUserStylesEnabled();
-    m_styleResolver = std::make_unique&lt;StyleResolver&gt;(*this, matchAuthorAndUserStyles);
-    m_styleResolver-&gt;appendAuthorStyleSheets(0, authorStyleSheets().activeStyleSheets());
</del><ins>+    m_styleResolver = std::make_unique&lt;StyleResolver&gt;(*this);
+    m_styleResolver-&gt;appendAuthorStyleSheets(authorStyleSheets().activeStyleSheets());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+StyleResolver&amp; Document::userAgentShadowTreeStyleResolver()
+{
+    if (!m_userAgentShadowTreeStyleResolver) {
+        m_userAgentShadowTreeStyleResolver = std::make_unique&lt;StyleResolver&gt;(*this);
+
+        // FIXME: Filter out shadow pseudo elements we don't want to expose to authors.
+        auto&amp; documentAuthorStyle = *ensureStyleResolver().ruleSets().authorStyle();
+        if (documentAuthorStyle.hasShadowPseudoElementRules())
+            m_userAgentShadowTreeStyleResolver-&gt;ruleSets().authorStyle()-&gt;copyShadowPseudoElementRulesFrom(documentAuthorStyle);
+    }
+
+    return *m_userAgentShadowTreeStyleResolver;
+}
+
</ins><span class="cx"> void Document::fontsNeedUpdate(FontSelector&amp;)
</span><span class="cx"> {
</span><span class="cx">     if (m_styleResolver)
</span><span class="lines">@@ -2139,6 +2150,7 @@
</span><span class="cx"> void Document::clearStyleResolver()
</span><span class="cx"> {
</span><span class="cx">     m_styleResolver = nullptr;
</span><ins>+    m_userAgentShadowTreeStyleResolver = nullptr;
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: It would be better if the FontSelector could survive this operation.
</span><span class="cx">     if (m_fontSelector) {
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/dom/Document.h        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -495,6 +495,7 @@
</span><span class="cx">             createStyleResolver();
</span><span class="cx">         return *m_styleResolver;
</span><span class="cx">     }
</span><ins>+    StyleResolver&amp; userAgentShadowTreeStyleResolver();
</ins><span class="cx"> 
</span><span class="cx">     CSSFontSelector&amp; fontSelector();
</span><span class="cx"> 
</span><span class="lines">@@ -1394,6 +1395,7 @@
</span><span class="cx">     unsigned m_referencingNodeCount;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;StyleResolver&gt; m_styleResolver;
</span><ins>+    std::unique_ptr&lt;StyleResolver&gt; m_userAgentShadowTreeStyleResolver;
</ins><span class="cx">     bool m_didCalculateStyleResolver;
</span><span class="cx">     bool m_hasNodesWithPlaceholderStyle;
</span><span class="cx">     bool m_needsNotifyRemoveAllPendingStylesheet;
</span></span></pre></div>
<a id="trunkSourceWebCoredomShadowRootcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ShadowRoot.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -77,15 +77,14 @@
</span><span class="cx"> 
</span><span class="cx"> StyleResolver&amp; ShadowRoot::styleResolver()
</span><span class="cx"> {
</span><del>-    // FIXME: Use isolated style resolver for user agent shadow roots.
</del><span class="cx">     if (m_type == Type::UserAgent)
</span><del>-        return document().ensureStyleResolver();
</del><ins>+        return document().userAgentShadowTreeStyleResolver();
</ins><span class="cx"> 
</span><span class="cx">     if (!m_styleResolver) {
</span><span class="cx">         // FIXME: We could share style resolver with shadow roots that have identical style.
</span><del>-        m_styleResolver = std::make_unique&lt;StyleResolver&gt;(document(), true);
</del><ins>+        m_styleResolver = std::make_unique&lt;StyleResolver&gt;(document());
</ins><span class="cx">         if (m_authorStyleSheets)
</span><del>-            m_styleResolver-&gt;appendAuthorStyleSheets(0, m_authorStyleSheets-&gt;activeStyleSheets());
</del><ins>+            m_styleResolver-&gt;appendAuthorStyleSheets(m_authorStyleSheets-&gt;activeStyleSheets());
</ins><span class="cx">     }
</span><span class="cx">     return *m_styleResolver;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleResolveTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleResolveTree.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleResolveTree.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/style/StyleResolveTree.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -725,6 +725,8 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(shadowRoot.host() == &amp;host);
</span><span class="cx">     ASSERT(host.renderer());
</span><ins>+    if (shadowRoot.styleChangeType() &gt;= FullStyleChange)
+        change = Force;
</ins><span class="cx">     RenderTreePosition renderTreePosition(*host.renderer());
</span><span class="cx">     for (Node* child = shadowRoot.firstChild(); child; child = child-&gt;nextSibling()) {
</span><span class="cx">         if (child-&gt;renderer())
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGElement.cpp (190346 => 190347)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGElement.cpp        2015-09-30 14:07:42 UTC (rev 190346)
+++ trunk/Source/WebCore/svg/SVGElement.cpp        2015-09-30 15:39:15 UTC (rev 190347)
</span><span class="lines">@@ -791,10 +791,11 @@
</span><span class="cx"> 
</span><span class="cx"> RefPtr&lt;RenderStyle&gt; SVGElement::customStyleForRenderer(RenderStyle&amp; parentStyle)
</span><span class="cx"> {
</span><del>-    if (!correspondingElement())
-        return resolveStyle(&amp;parentStyle);
</del><ins>+    // If the element is in a &lt;use&gt; tree we get the style from the definition tree.
+    if (auto* styleElement = this-&gt;correspondingElement())
+        return styleElement-&gt;styleResolver().styleForElement(styleElement, &amp;parentStyle, DisallowStyleSharing);
</ins><span class="cx"> 
</span><del>-    return styleResolver().styleForElement(correspondingElement(), &amp;parentStyle, DisallowStyleSharing);
</del><ins>+    return resolveStyle(&amp;parentStyle);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> MutableStyleProperties* SVGElement::animatedSMILStyleProperties() const
</span></span></pre>
</div>
</div>

</body>
</html>