<!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>[190256] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/190256">190256</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-09-25 15:06:09 -0700 (Fri, 25 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement scoped styling for shadow DOM
https://bugs.webkit.org/show_bug.cgi?id=149230

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::collectMatchingRules):

    Only use special path here for user agent shadow trees.

* dom/AuthorStyleSheets.cpp:
(WebCore::AuthorStyleSheets::AuthorStyleSheets):
(WebCore::AuthorStyleSheets::removePendingSheet):
(WebCore::AuthorStyleSheets::updateActiveStyleSheets):

    Basic support for ShadowRoot scoped stylesheets.

* dom/AuthorStyleSheets.h:
(WebCore::AuthorStyleSheets::activeStyleSheets):
* dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::~InlineStyleSheetOwner):
(WebCore::authorStyleSheetsForElement):
(WebCore::InlineStyleSheetOwner::insertedIntoDocument):
(WebCore::InlineStyleSheetOwner::removedFromDocument):
(WebCore::InlineStyleSheetOwner::clearDocumentData):
(WebCore::InlineStyleSheetOwner::childrenChanged):
(WebCore::InlineStyleSheetOwner::createSheet):
(WebCore::InlineStyleSheetOwner::isLoading):
(WebCore::InlineStyleSheetOwner::sheetLoaded):
(WebCore::InlineStyleSheetOwner::startLoadingDynamicSheet):

    Basic support for ShadowRoot scoped inline stylesheets.

* dom/InlineStyleSheetOwner.h:
(WebCore::InlineStyleSheetOwner::sheet):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::styleResolver):

    Create and initialize ShadowRoot scoped style resolver.

(WebCore::ShadowRoot::resetStyleResolver):
(WebCore::ShadowRoot::authorStyleSheets):

    Collection of author stylesheets in the shadow tree.

(WebCore::ShadowRoot::updateStyle):

    Trigger style recalc when stylesheets change.

(WebCore::ShadowRoot::cloneNode):
* dom/ShadowRoot.h:
(WebCore::ShadowRoot::resetStyleInheritance):
* html/HTMLStyleElement.h:
* svg/SVGStyleElement.h:

LayoutTests:

* fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html: Added.
* fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html: Added.

    Add a test that verifies that shadow DOM style doesn't affect normal DOM.

* platform/mac/TestExpectations:

    Enable fast/shadow-dom/css-scoping-shadow-with-rules.html</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacTestExpectations">trunk/LayoutTests/platform/mac/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorcpp">trunk/Source/WebCore/css/ElementRuleCollector.cpp</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="#trunkSourceWebCoredomInlineStyleSheetOwnercpp">trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp</a></li>
<li><a href="#trunkSourceWebCoredomInlineStyleSheetOwnerh">trunk/Source/WebCore/dom/InlineStyleSheetOwner.h</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="#trunkSourceWebCorehtmlHTMLStyleElementh">trunk/Source/WebCore/html/HTMLStyleElement.h</a></li>
<li><a href="#trunkSourceWebCoresvgSVGStyleElementh">trunk/Source/WebCore/svg/SVGStyleElement.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastshadowdomcssscopingshadowwithrulesnostyleleakexpectedhtml">trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastshadowdomcssscopingshadowwithrulesnostyleleakhtml">trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/LayoutTests/ChangeLog        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-09-25  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Implement scoped styling for shadow DOM
+        https://bugs.webkit.org/show_bug.cgi?id=149230
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html: Added.
+        * fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html: Added.
+
+            Add a test that verifies that shadow DOM style doesn't affect normal DOM.
+
+        * platform/mac/TestExpectations:
+
+            Enable fast/shadow-dom/css-scoping-shadow-with-rules.html
+
</ins><span class="cx"> 2015-09-25  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Scrolling a overflow: scroll region makes find overlay holes stick to the edge of the region
</span></span></pre></div>
<a id="trunkLayoutTestsfastshadowdomcssscopingshadowwithrulesnostyleleakexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html (0 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+    &lt;p&gt;Test passes if you see a single 100px by 100px green box below.&lt;/p&gt;
+    &lt;div style=&quot;width: 100px; height: 100px; background: green;&quot;&gt;&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastshadowdomcssscopingshadowwithrulesnostyleleakhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html (0 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html                                (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;title&gt;CSS Scoping - a style rule inside a shadow tree doesn't affect the normal dom&lt;/title&gt;
+    &lt;link rel=&quot;author&quot; title=&quot;Ryosuke Niwa&quot; href=&quot;mailto:rniwa@webkit.org&quot;/&gt;
+    &lt;link rel=&quot;help&quot; href=&quot;http://www.w3.org/TR/css-scoping-1/#selectors-data-model&quot;&gt;
+    &lt;link rel=&quot;match&quot; href=&quot;reference/green-box.html&quot;/&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;style&gt;
+    my-host {
+        display: block;
+    }
+    div {
+        width: 100px;
+        height: 100px;
+        background: green;
+        color:green;
+    }
+    &lt;/style&gt;
+    &lt;p&gt;Test passes if you see a single 100px by 100px green box below.&lt;/p&gt; 
+    &lt;my-host&gt;
+    &lt;/my-host&gt;
+    &lt;div&gt;FAIL&lt;/div&gt;
+    &lt;script&gt;
+
+    try {
+        var shadowHost = document.querySelector('my-host');
+        shadowRoot = shadowHost.attachShadow({mode: 'open'});
+        shadowRoot.innerHTML = '&lt;style&gt; div { background: red; } &lt;/style&gt;';
+    } catch (exception) {
+        document.body.appendChild(document.createTextNode(exception));
+    }
+
+    &lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -1308,8 +1308,6 @@
</span><span class="cx"> webkit.org/b/149128 fast/text/control-characters [ ImageOnlyFailure ]
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/148695 fast/shadow-dom [ Pass ]
</span><del>-
-webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-with-rules.html [ ImageOnlyFailure ]
</del><span class="cx"> webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-host-rule.html [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-host-functional-rule.html [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-slotted-rule.html [ ImageOnlyFailure ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/ChangeLog        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -1,3 +1,62 @@
</span><ins>+2015-09-25  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Implement scoped styling for shadow DOM
+        https://bugs.webkit.org/show_bug.cgi?id=149230
+
+        Reviewed by Ryosuke Niwa.
+
+        Test: fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::collectMatchingRules):
+
+            Only use special path here for user agent shadow trees.
+
+        * dom/AuthorStyleSheets.cpp:
+        (WebCore::AuthorStyleSheets::AuthorStyleSheets):
+        (WebCore::AuthorStyleSheets::removePendingSheet):
+        (WebCore::AuthorStyleSheets::updateActiveStyleSheets):
+
+            Basic support for ShadowRoot scoped stylesheets.
+
+        * dom/AuthorStyleSheets.h:
+        (WebCore::AuthorStyleSheets::activeStyleSheets):
+        * dom/InlineStyleSheetOwner.cpp:
+        (WebCore::InlineStyleSheetOwner::~InlineStyleSheetOwner):
+        (WebCore::authorStyleSheetsForElement):
+        (WebCore::InlineStyleSheetOwner::insertedIntoDocument):
+        (WebCore::InlineStyleSheetOwner::removedFromDocument):
+        (WebCore::InlineStyleSheetOwner::clearDocumentData):
+        (WebCore::InlineStyleSheetOwner::childrenChanged):
+        (WebCore::InlineStyleSheetOwner::createSheet):
+        (WebCore::InlineStyleSheetOwner::isLoading):
+        (WebCore::InlineStyleSheetOwner::sheetLoaded):
+        (WebCore::InlineStyleSheetOwner::startLoadingDynamicSheet):
+
+            Basic support for ShadowRoot scoped inline stylesheets.
+
+        * dom/InlineStyleSheetOwner.h:
+        (WebCore::InlineStyleSheetOwner::sheet):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::styleResolver):
+
+            Create and initialize ShadowRoot scoped style resolver.
+
+        (WebCore::ShadowRoot::resetStyleResolver):
+        (WebCore::ShadowRoot::authorStyleSheets):
+
+            Collection of author stylesheets in the shadow tree.
+
+        (WebCore::ShadowRoot::updateStyle):
+
+            Trigger style recalc when stylesheets change.
+
+        (WebCore::ShadowRoot::cloneNode):
+        * dom/ShadowRoot.h:
+        (WebCore::ShadowRoot::resetStyleInheritance):
+        * html/HTMLStyleElement.h:
+        * svg/SVGStyleElement.h:
+
</ins><span class="cx"> 2015-09-25  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Clean up CMake build on Mac
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> #include &quot;RenderRegion.h&quot;
</span><span class="cx"> #include &quot;SVGElement.h&quot;
</span><span class="cx"> #include &quot;SelectorCompiler.h&quot;
</span><ins>+#include &quot;ShadowRoot.h&quot;
</ins><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> #include &quot;StyledElement.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -152,7 +153,8 @@
</span><span class="cx">         collectMatchingRulesForList(matchRequest.ruleSet-&gt;cuePseudoRules(), matchRequest, ruleRange);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    if (m_element.isInShadowTree()) {
</del><ins>+    auto* shadowRoot = m_element.containingShadowRoot();
+    if (shadowRoot &amp;&amp; shadowRoot-&gt;type() == ShadowRoot::Type::UserAgent) {
</ins><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></span></pre></div>
<a id="trunkSourceWebCoredomAuthorStyleSheetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/AuthorStyleSheets.cpp (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/AuthorStyleSheets.cpp        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/dom/AuthorStyleSheets.cpp        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> #include &quot;SVGNames.h&quot;
</span><span class="cx"> #include &quot;SVGStyleElement.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><ins>+#include &quot;ShadowRoot.h&quot;
</ins><span class="cx"> #include &quot;StyleInvalidationAnalysis.h&quot;
</span><span class="cx"> #include &quot;StyleResolver.h&quot;
</span><span class="cx"> #include &quot;StyleSheetContents.h&quot;
</span><span class="lines">@@ -54,11 +55,17 @@
</span><span class="cx"> using namespace ContentExtensions;
</span><span class="cx"> using namespace HTMLNames;
</span><span class="cx"> 
</span><del>-AuthorStyleSheets::AuthorStyleSheets(TreeScope&amp; treeScope)
-    : m_document(treeScope.documentScope())
</del><ins>+AuthorStyleSheets::AuthorStyleSheets(Document&amp; document)
+    : m_document(document)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+AuthorStyleSheets::AuthorStyleSheets(ShadowRoot&amp; shadowRoot)
+    : m_document(shadowRoot.documentScope())
+    , m_shadowRoot(&amp;shadowRoot)
+{
+}
+
</ins><span class="cx"> // This method is called whenever a top-level stylesheet has finished loading.
</span><span class="cx"> void AuthorStyleSheets::removePendingSheet(RemovePendingSheetNotificationType notification)
</span><span class="cx"> {
</span><span class="lines">@@ -79,7 +86,12 @@
</span><span class="cx">         m_document.setNeedsNotifyRemoveAllPendingStylesheet();
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-    
</del><ins>+
+    if (m_shadowRoot) {
+        m_shadowRoot-&gt;updateStyle();
+        return;
+    }
+
</ins><span class="cx">     m_document.didRemoveAllPendingStylesheet();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -299,9 +311,12 @@
</span><span class="cx">     bool requiresFullStyleRecalc;
</span><span class="cx">     analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
</span><span class="cx"> 
</span><del>-    if (styleResolverUpdateType == Reconstruct)
-        m_document.clearStyleResolver();
-    else {
</del><ins>+    if (styleResolverUpdateType == Reconstruct) {
+        if (m_shadowRoot)
+            m_shadowRoot-&gt;resetStyleResolver();
+        else
+            m_document.clearStyleResolver();
+    } else {
</ins><span class="cx">         StyleResolver&amp; styleResolver = m_document.ensureStyleResolver();
</span><span class="cx">         if (styleResolverUpdateType == Reset) {
</span><span class="cx">             styleResolver.ruleSets().resetAuthorStyle();
</span></span></pre></div>
<a id="trunkSourceWebCoredomAuthorStyleSheetsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/AuthorStyleSheets.h (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/AuthorStyleSheets.h        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/dom/AuthorStyleSheets.h        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -45,12 +45,14 @@
</span><span class="cx"> class StyleSheet;
</span><span class="cx"> class StyleSheetContents;
</span><span class="cx"> class StyleSheetList;
</span><ins>+class ShadowRoot;
</ins><span class="cx"> class TreeScope;
</span><span class="cx"> 
</span><span class="cx"> class AuthorStyleSheets {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    explicit AuthorStyleSheets(TreeScope&amp;);
</del><ins>+    explicit AuthorStyleSheets(Document&amp;);
+    explicit AuthorStyleSheets(ShadowRoot&amp;);
</ins><span class="cx"> 
</span><span class="cx">     const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; activeStyleSheets() const { return m_activeStyleSheets; }
</span><span class="cx"> 
</span><span class="lines">@@ -107,6 +109,7 @@
</span><span class="cx">     void analyzeStyleSheetChange(UpdateFlag, const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; newStylesheets, StyleResolverUpdateType&amp;, bool&amp; requiresFullStyleRecalc);
</span><span class="cx"> 
</span><span class="cx">     Document&amp; m_document;
</span><ins>+    ShadowRoot* m_shadowRoot { nullptr };
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;RefPtr&lt;StyleSheet&gt;&gt; m_styleSheetsForStyleSheetList;
</span><span class="cx">     Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; m_activeStyleSheets;
</span></span></pre></div>
<a id="trunkSourceWebCoredomInlineStyleSheetOwnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include &quot;MediaList.h&quot;
</span><span class="cx"> #include &quot;MediaQueryEvaluator.h&quot;
</span><span class="cx"> #include &quot;ScriptableDocumentParser.h&quot;
</span><ins>+#include &quot;ShadowRoot.h&quot;
</ins><span class="cx"> #include &quot;StyleSheetContents.h&quot;
</span><span class="cx"> #include &quot;TextNodeTraversal.h&quot;
</span><span class="cx"> #include &lt;wtf/text/StringBuilder.h&gt;
</span><span class="lines">@@ -46,10 +47,16 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InlineStyleSheetOwner::insertedIntoDocument(Document&amp; document, Element&amp; element)
</del><ins>+static AuthorStyleSheets&amp; authorStyleSheetsForElement(Element&amp; element)
</ins><span class="cx"> {
</span><del>-    document.authorStyleSheets().addStyleSheetCandidateNode(element, m_isParsingChildren);
</del><ins>+    auto* shadowRoot = element.containingShadowRoot();
+    return shadowRoot ? shadowRoot-&gt;authorStyleSheets() : element.document().authorStyleSheets();
+}
</ins><span class="cx"> 
</span><ins>+void InlineStyleSheetOwner::insertedIntoDocument(Document&amp;, Element&amp; element)
+{
+    authorStyleSheetsForElement(element).addStyleSheetCandidateNode(element, m_isParsingChildren);
+
</ins><span class="cx">     if (m_isParsingChildren)
</span><span class="cx">         return;
</span><span class="cx">     createSheetFromTextContents(element);
</span><span class="lines">@@ -57,7 +64,7 @@
</span><span class="cx"> 
</span><span class="cx"> void InlineStyleSheetOwner::removedFromDocument(Document&amp; document, Element&amp; element)
</span><span class="cx"> {
</span><del>-    document.authorStyleSheets().removeStyleSheetCandidateNode(element);
</del><ins>+    authorStyleSheetsForElement(element).removeStyleSheetCandidateNode(element);
</ins><span class="cx"> 
</span><span class="cx">     if (m_sheet)
</span><span class="cx">         clearSheet();
</span><span class="lines">@@ -67,14 +74,14 @@
</span><span class="cx">         document.styleResolverChanged(DeferRecalcStyle);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InlineStyleSheetOwner::clearDocumentData(Document&amp; document, Element&amp; element)
</del><ins>+void InlineStyleSheetOwner::clearDocumentData(Document&amp;, Element&amp; element)
</ins><span class="cx"> {
</span><span class="cx">     if (m_sheet)
</span><span class="cx">         m_sheet-&gt;clearOwnerNode();
</span><span class="cx"> 
</span><span class="cx">     if (!element.inDocument())
</span><span class="cx">         return;
</span><del>-    document.authorStyleSheets().removeStyleSheetCandidateNode(element);
</del><ins>+    authorStyleSheetsForElement(element).removeStyleSheetCandidateNode(element);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InlineStyleSheetOwner::childrenChanged(Element&amp; element)
</span><span class="lines">@@ -138,7 +145,7 @@
</span><span class="cx">     if (!screenEval.eval(mediaQueries.get()) &amp;&amp; !printEval.eval(mediaQueries.get()))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    document.authorStyleSheets().addPendingSheet();
</del><ins>+    authorStyleSheetsForElement(element).addPendingSheet();
</ins><span class="cx"> 
</span><span class="cx">     m_loading = true;
</span><span class="cx"> 
</span><span class="lines">@@ -160,18 +167,18 @@
</span><span class="cx">     return m_sheet &amp;&amp; m_sheet-&gt;isLoading();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool InlineStyleSheetOwner::sheetLoaded(Document&amp; document)
</del><ins>+bool InlineStyleSheetOwner::sheetLoaded(Element&amp; element)
</ins><span class="cx"> {
</span><span class="cx">     if (isLoading())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    document.authorStyleSheets().removePendingSheet();
</del><ins>+    authorStyleSheetsForElement(element).removePendingSheet();
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InlineStyleSheetOwner::startLoadingDynamicSheet(Document&amp; document)
</del><ins>+void InlineStyleSheetOwner::startLoadingDynamicSheet(Element&amp; element)
</ins><span class="cx"> {
</span><del>-    document.authorStyleSheets().addPendingSheet();
</del><ins>+    authorStyleSheetsForElement(element).addPendingSheet();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomInlineStyleSheetOwnerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/InlineStyleSheetOwner.h (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/InlineStyleSheetOwner.h        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/dom/InlineStyleSheetOwner.h        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -41,8 +41,8 @@
</span><span class="cx">     CSSStyleSheet* sheet() const { return m_sheet.get(); }
</span><span class="cx"> 
</span><span class="cx">     bool isLoading() const;
</span><del>-    bool sheetLoaded(Document&amp;);
-    void startLoadingDynamicSheet(Document&amp;);
</del><ins>+    bool sheetLoaded(Element&amp;);
+    void startLoadingDynamicSheet(Element&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void insertedIntoDocument(Document&amp;, Element&amp;);
</span><span class="cx">     void removedFromDocument(Document&amp;, Element&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoredomShadowRootcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ShadowRoot.cpp        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -27,6 +27,8 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;ShadowRoot.h&quot;
</span><span class="cx"> 
</span><ins>+#include &quot;AuthorStyleSheets.h&quot;
+#include &quot;CSSStyleSheet.h&quot;
</ins><span class="cx"> #include &quot;ElementTraversal.h&quot;
</span><span class="cx"> #include &quot;InsertionPoint.h&quot;
</span><span class="cx"> #include &quot;RenderElement.h&quot;
</span><span class="lines">@@ -40,6 +42,7 @@
</span><span class="cx"> struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope {
</span><span class="cx">     unsigned countersAndFlags[1];
</span><span class="cx">     void* styleResolver;
</span><ins>+    void* authorStyleSheets;
</ins><span class="cx">     void* host;
</span><span class="cx"> #if ENABLE(SHADOW_DOM)
</span><span class="cx">     void* slotAssignment;
</span><span class="lines">@@ -73,12 +76,44 @@
</span><span class="cx"> 
</span><span class="cx"> StyleResolver&amp; ShadowRoot::styleResolver()
</span><span class="cx"> {
</span><del>-    if (m_styleResolver)
-        return *m_styleResolver;
</del><ins>+    // FIXME: Use isolated style resolver for user agent shadow roots.
+    if (m_type == Type::UserAgent)
+        return document().ensureStyleResolver();
</ins><span class="cx"> 
</span><del>-    return document().ensureStyleResolver();
</del><ins>+    if (!m_styleResolver) {
+        // FIXME: We could share style resolver with shadow roots that have identical style.
+        m_styleResolver = std::make_unique&lt;StyleResolver&gt;(document(), true);
+        if (m_authorStyleSheets)
+            m_styleResolver-&gt;appendAuthorStyleSheets(0, m_authorStyleSheets-&gt;activeStyleSheets());
+    }
+    return *m_styleResolver;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ShadowRoot::resetStyleResolver()
+{
+    m_styleResolver = nullptr;
+}
+
+AuthorStyleSheets&amp; ShadowRoot::authorStyleSheets()
+{
+    if (!m_authorStyleSheets)
+        m_authorStyleSheets = std::make_unique&lt;AuthorStyleSheets&gt;(*this);
+    return *m_authorStyleSheets;
+}
+
+void ShadowRoot::updateStyle()
+{
+    bool shouldRecalcStyle = false;
+
+    if (m_authorStyleSheets) {
+        // FIXME: Make optimized updated work.
+        shouldRecalcStyle = m_authorStyleSheets-&gt;updateActiveStyleSheets(AuthorStyleSheets::FullUpdate);
+    }
+
+    if (shouldRecalcStyle)
+        setNeedsStyleRecalc();
+}
+
</ins><span class="cx"> PassRefPtr&lt;Node&gt; ShadowRoot::cloneNode(bool, ExceptionCode&amp; ec)
</span><span class="cx"> {
</span><span class="cx">     ec = DATA_CLONE_ERR;
</span></span></pre></div>
<a id="trunkSourceWebCoredomShadowRooth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ShadowRoot.h (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ShadowRoot.h        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/dom/ShadowRoot.h        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class AuthorStyleSheets;
</ins><span class="cx"> class ContentDistributor;
</span><span class="cx"> class HTMLSlotElement;
</span><span class="cx"> class SlotAssignment;
</span><span class="lines">@@ -56,6 +57,10 @@
</span><span class="cx">     virtual ~ShadowRoot();
</span><span class="cx"> 
</span><span class="cx">     StyleResolver&amp; styleResolver();
</span><ins>+    AuthorStyleSheets&amp; authorStyleSheets();
+    
+    void updateStyle();
+    void resetStyleResolver();
</ins><span class="cx"> 
</span><span class="cx">     bool resetStyleInheritance() const { return m_resetStyleInheritance; }
</span><span class="cx">     void setResetStyleInheritance(bool);
</span><span class="lines">@@ -102,10 +107,11 @@
</span><span class="cx">     bool m_resetStyleInheritance;
</span><span class="cx">     Type m_type;
</span><span class="cx"> 
</span><ins>+    Element* m_host;
+
</ins><span class="cx">     std::unique_ptr&lt;StyleResolver&gt; m_styleResolver;
</span><ins>+    std::unique_ptr&lt;AuthorStyleSheets&gt; m_authorStyleSheets;
</ins><span class="cx"> 
</span><del>-    Element* m_host;
-
</del><span class="cx"> #if ENABLE(SHADOW_DOM)
</span><span class="cx">     std::unique_ptr&lt;SlotAssignment&gt; m_slotAssignments;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLStyleElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLStyleElement.h (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLStyleElement.h        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/html/HTMLStyleElement.h        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -59,9 +59,9 @@
</span><span class="cx">     virtual void finishParsingChildren() override;
</span><span class="cx"> 
</span><span class="cx">     bool isLoading() const { return m_styleSheetOwner.isLoading(); }
</span><del>-    virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(document()); }
</del><ins>+    virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(*this); }
</ins><span class="cx">     virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) override;
</span><del>-    virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(document()); }
</del><ins>+    virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(*this); }
</ins><span class="cx"> 
</span><span class="cx">     virtual void addSubresourceAttributeURLs(ListHashSet&lt;URL&gt;&amp;) const override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGStyleElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGStyleElement.h (190255 => 190256)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGStyleElement.h        2015-09-25 22:04:32 UTC (rev 190255)
+++ trunk/Source/WebCore/svg/SVGStyleElement.h        2015-09-25 22:06:09 UTC (rev 190256)
</span><span class="lines">@@ -59,8 +59,8 @@
</span><span class="cx">     virtual void finishParsingChildren() override;
</span><span class="cx"> 
</span><span class="cx">     virtual bool isLoading() const { return m_styleSheetOwner.isLoading(); }
</span><del>-    virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(document()); }
-    virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(document()); }
</del><ins>+    virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(*this); }
+    virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(*this); }
</ins><span class="cx">     virtual Timer* svgLoadEventTimer() override { return &amp;m_svgLoadEventTimer; }
</span><span class="cx"> 
</span><span class="cx">     InlineStyleSheetOwner m_styleSheetOwner;
</span></span></pre>
</div>
</div>

</body>
</html>