<!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>[209535] 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/209535">209535</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2016-12-08 06:05:27 -0800 (Thu, 08 Dec 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Source/WebCore:
::after and ::before don't work on :host
https://bugs.webkit.org/show_bug.cgi?id=164675
&lt;rdar://problem/29231874&gt;

Reviewed by Andreas Kling.

We didn't allow combining :host with any other selectors. Pseudo elements should be allowed.

Test: fast/shadow-dom/shadow-host-with-before-after.html

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

    Allow pseudo element matching.

(WebCore::ElementRuleCollector::matchHostPseudoClassRules):

    Use the normal collectMatchingRulesForList path instead of a direct call to SelectorChecker::matchHostPseudoClass.
    This path supports pseudo elements.

    Pass the information that we are matching :host rules with m_isMatchingHostPseudoClass bit
    similarly to how this is done with slots.

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

    Collect :host rules similarly to other rules.

(WebCore::RuleSet::addRule):
* css/SelectorChecker.cpp:

    Rename didMoveToShadowHost-&gt;mayMatchHostPseudoClass for clarity.

(WebCore::SelectorChecker::match):

    Enable :host matching in the current context immediately if needed.

(WebCore::SelectorChecker::matchHostPseudoClass):

    The check for illegal combinations with :host is now done in checkOne().

(WebCore::localContextForParent):
(WebCore::SelectorChecker::checkOne):

    In context where :host matches nothing else can match, except pseudo elements.

* css/SelectorChecker.h:

LayoutTests:
:after and :before don't work on :host
https://bugs.webkit.org/show_bug.cgi?id=164675
&lt;rdar://problem/29231874&gt;

Reviewed by Andreas Kling.

* fast/shadow-dom/shadow-host-with-before-after-expected.html: Added.
* fast/shadow-dom/shadow-host-with-before-after.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCorecssElementRuleCollectorh">trunk/Source/WebCore/css/ElementRuleCollector.h</a></li>
<li><a href="#trunkSourceWebCorecssRuleSetcpp">trunk/Source/WebCore/css/RuleSet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssSelectorCheckercpp">trunk/Source/WebCore/css/SelectorChecker.cpp</a></li>
<li><a href="#trunkSourceWebCorecssSelectorCheckerh">trunk/Source/WebCore/css/SelectorChecker.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastshadowdomshadowhostwithbeforeafterexpectedhtml">trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastshadowdomshadowhostwithbeforeafterhtml">trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/LayoutTests/ChangeLog        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-12-08  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        :after and :before don't work on :host
+        https://bugs.webkit.org/show_bug.cgi?id=164675
+        &lt;rdar://problem/29231874&gt;
+
+        Reviewed by Andreas Kling.
+
+        * fast/shadow-dom/shadow-host-with-before-after-expected.html: Added.
+        * fast/shadow-dom/shadow-host-with-before-after.html: Added.
+
</ins><span class="cx"> 2016-12-08  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r209490): [ios-simulator] LayoutTest fast/shadow-dom/media-shadow-manipulation.html is failing
</span></span></pre></div>
<a id="trunkLayoutTestsfastshadowdomshadowhostwithbeforeafterexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after-expected.html (0 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after-expected.html        2016-12-08 14:05:27 UTC (rev 209535)
</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="trunkLayoutTestsfastshadowdomshadowhostwithbeforeafterhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after.html (0 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after.html                                (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/shadow-host-with-before-after.html        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -0,0 +1,88 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;style&gt;
+.test {
+    width: 100px;
+    height: 25px;
+    background: red;
+    color: red;
+}
+#host1, #host2  {
+    color: green;
+}
+#host3 div, #host4 div {
+    width: 50%;
+    height: 100%;
+    background: green;
+    display: inline-block;
+}
+&lt;/style&gt;
+&lt;/head&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 id=&quot;host1&quot; class=&quot;test&quot;&gt;&lt;/div&gt;
+&lt;div id=&quot;host2&quot; class=&quot;test&quot;&gt;&lt;/div&gt;
+&lt;div id=&quot;host3&quot; class=&quot;test&quot;&gt;&lt;div&gt;text&lt;/div&gt;&lt;/div&gt;
+&lt;div id=&quot;host4&quot; class=&quot;test&quot;&gt;&lt;div&gt;text&lt;/div&gt;&lt;/div&gt;
+&lt;script&gt;
+
+host1.attachShadow({mode: 'closed'}).innerHTML = `&lt;style&gt;
+    :host::before, :host::after {
+        background: green;
+        width: 50%;
+        height: 100%;
+        background: green;
+        display: inline-block;
+        content: &quot;test&quot;;
+    }
+    &lt;/style&gt;`;
+
+host2.attachShadow({mode: 'closed'}).innerHTML = `&lt;style&gt;
+    :host(.green)::before, :host(.green)::after {
+        background: green;
+        width: 50%;
+        height: 100%;
+        background: green;
+        display: inline-block;
+        content: &quot;test&quot;;
+    }
+    &lt;/style&gt;`;
+
+getComputedStyle(host2).backgroundColor;
+host2.classList.add('green');
+
+host3.attachShadow({mode: 'closed'}).innerHTML = `&lt;style&gt;
+    :host {
+        color: green !important;
+    }
+    :host::before {
+        background: green;
+        width: 50%;
+        height: 100%;
+        background: green;
+        display: inline-block;
+        content: &quot;test&quot;;
+    }
+    &lt;/style&gt;&lt;slot&gt;&lt;/slot&gt;`;
+
+host4.attachShadow({mode: 'closed'}).innerHTML = `&lt;style&gt;
+    :host(.green) {
+        color: green !important;
+    }
+    :host(.green)::after {
+        background: green;
+        width: 50%;
+        height: 100%;
+        background: green;
+        display: inline-block;
+        content: &quot;test&quot;;
+    }
+    &lt;/style&gt;&lt;slot&gt;&lt;/slot&gt;`;
+
+getComputedStyle(host4).backgroundColor;
+host4.classList.add('green');
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/Source/WebCore/ChangeLog        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -1,3 +1,54 @@
</span><ins>+2016-12-08  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        ::after and ::before don't work on :host
+        https://bugs.webkit.org/show_bug.cgi?id=164675
+        &lt;rdar://problem/29231874&gt;
+
+        Reviewed by Andreas Kling.
+
+        We didn't allow combining :host with any other selectors. Pseudo elements should be allowed.
+
+        Test: fast/shadow-dom/shadow-host-with-before-after.html
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::matchAuthorRules):
+
+            Allow pseudo element matching.
+
+        (WebCore::ElementRuleCollector::matchHostPseudoClassRules):
+
+            Use the normal collectMatchingRulesForList path instead of a direct call to SelectorChecker::matchHostPseudoClass.
+            This path supports pseudo elements.
+
+            Pass the information that we are matching :host rules with m_isMatchingHostPseudoClass bit
+            similarly to how this is done with slots.
+
+        (WebCore::ElementRuleCollector::ruleMatches):
+        * css/ElementRuleCollector.h:
+        * css/RuleSet.cpp:
+
+            Collect :host rules similarly to other rules.
+
+        (WebCore::RuleSet::addRule):
+        * css/SelectorChecker.cpp:
+
+            Rename didMoveToShadowHost-&gt;mayMatchHostPseudoClass for clarity.
+
+        (WebCore::SelectorChecker::match):
+
+            Enable :host matching in the current context immediately if needed.
+
+        (WebCore::SelectorChecker::matchHostPseudoClass):
+
+            The check for illegal combinations with :host is now done in checkOne().
+
+        (WebCore::localContextForParent):
+        (WebCore::SelectorChecker::checkOne):
+
+            In context where :host matches nothing else can match, except pseudo elements.
+
+        * css/SelectorChecker.h:
+
</ins><span class="cx"> 2016-12-08  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix CMake build.
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -214,7 +214,7 @@
</span><span class="cx">     if (parent &amp;&amp; parent-&gt;shadowRoot())
</span><span class="cx">         matchSlottedPseudoElementRules(includeEmptyRules, ruleRange);
</span><span class="cx"> 
</span><del>-    if (m_element.shadowRoot() &amp;&amp; m_pseudoStyleRequest.pseudoId == NOPSEUDO)
</del><ins>+    if (m_element.shadowRoot())
</ins><span class="cx">         matchHostPseudoClassRules(includeEmptyRules, ruleRange);
</span><span class="cx"> 
</span><span class="cx">     if (m_element.isInShadowTree())
</span><span class="lines">@@ -244,18 +244,10 @@
</span><span class="cx">     if (shadowHostRules.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    SelectorChecker::CheckingContext context(m_mode);
-    SelectorChecker selectorChecker(m_element.document());
</del><ins>+    SetForScope&lt;bool&gt; change(m_isMatchingHostPseudoClass, true);
</ins><span class="cx"> 
</span><del>-    for (auto&amp; ruleData : shadowHostRules) {
-        if (ruleData.rule()-&gt;properties().isEmpty() &amp;&amp; !includeEmptyRules)
-            continue;
-        auto&amp; selector = *ruleData.selector();
-        unsigned specificity = 0;
-        if (!selectorChecker.matchHostPseudoClass(selector, m_element, context, specificity))
-            continue;
-        addMatchedRule(ruleData, specificity, Style::ScopeOrdinal::Shadow, ruleRange);
-    }
</del><ins>+    MatchRequest hostMatchRequest { nullptr, includeEmptyRules, Style::ScopeOrdinal::Shadow };
+    collectMatchingRulesForList(&amp;shadowHostRules, hostMatchRequest, ruleRange);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ElementRuleCollector::matchSlottedPseudoElementRules(bool includeEmptyRules, StyleResolver::RuleRange&amp; ruleRange)
</span><span class="lines">@@ -438,6 +430,7 @@
</span><span class="cx">     context.pseudoId = m_pseudoStyleRequest.pseudoId;
</span><span class="cx">     context.scrollbar = m_pseudoStyleRequest.scrollbar;
</span><span class="cx">     context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart;
</span><ins>+    context.isMatchingHostPseudoClass = m_isMatchingHostPseudoClass;
</ins><span class="cx"> 
</span><span class="cx">     bool selectorMatches;
</span><span class="cx"> #if ENABLE(CSS_SELECTOR_JIT)
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.h        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -103,6 +103,7 @@
</span><span class="cx">     bool m_sameOriginOnly { false };
</span><span class="cx">     SelectorChecker::Mode m_mode { SelectorChecker::Mode::ResolvingStyle };
</span><span class="cx">     bool m_isMatchingSlottedPseudoElements { false };
</span><ins>+    bool m_isMatchingHostPseudoClass { false };
</ins><span class="cx">     Vector&lt;std::unique_ptr&lt;RuleSet::RuleDataVector&gt;&gt; m_keepAliveSlottedPseudoElementRules;
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;MatchedRule, 64&gt; m_matchedRules;
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.cpp (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.cpp        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/Source/WebCore/css/RuleSet.cpp        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -205,6 +205,7 @@
</span><span class="cx">     const CSSSelector* classSelector = nullptr;
</span><span class="cx">     const CSSSelector* linkSelector = nullptr;
</span><span class="cx">     const CSSSelector* focusSelector = nullptr;
</span><ins>+    const CSSSelector* hostPseudoClassSelector = nullptr;
</ins><span class="cx">     const CSSSelector* customPseudoElementSelector = nullptr;
</span><span class="cx">     const CSSSelector* slottedPseudoElementSelector = nullptr;
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="lines">@@ -265,8 +266,8 @@
</span><span class="cx">                 focusSelector = selector;
</span><span class="cx">                 break;
</span><span class="cx">             case CSSSelector::PseudoClassHost:
</span><del>-                m_hostPseudoClassRules.append(ruleData);
-                return;
</del><ins>+                hostPseudoClassSelector = selector;
+                break;
</ins><span class="cx">             default:
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="lines">@@ -308,6 +309,11 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (hostPseudoClassSelector) {
+        m_hostPseudoClassRules.append(ruleData);
+        return;
+    }
+
</ins><span class="cx">     if (idSelector) {
</span><span class="cx">         addToRuleSet(idSelector-&gt;value().impl(), m_idRules, ruleData);
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebCorecssSelectorCheckercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/SelectorChecker.cpp        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -74,7 +74,7 @@
</span><span class="cx">     bool pseudoElementEffective { true };
</span><span class="cx">     bool hasScrollbarPseudo { false };
</span><span class="cx">     bool hasSelectionPseudo { false };
</span><del>-    bool didMoveToShadowHost { false };
</del><ins>+    bool mayMatchHostPseudoClass { false };
</ins><span class="cx"> 
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -182,6 +182,12 @@
</span><span class="cx">     specificity = 0;
</span><span class="cx"> 
</span><span class="cx">     LocalContext context(selector, element, checkingContext.resolvingMode == SelectorChecker::Mode::QueryingRules ? VisitedMatchType::Disabled : VisitedMatchType::Enabled, checkingContext.pseudoId);
</span><ins>+
+    if (checkingContext.isMatchingHostPseudoClass) {
+        ASSERT(element.shadowRoot());
+        context.mayMatchHostPseudoClass = true;
+    }
+
</ins><span class="cx">     PseudoIdSet pseudoIdSet;
</span><span class="cx">     MatchResult result = matchRecursively(checkingContext, context, pseudoIdSet, specificity);
</span><span class="cx">     if (result.match != Match::SelectorMatches)
</span><span class="lines">@@ -208,10 +214,6 @@
</span><span class="cx"> 
</span><span class="cx">     specificity = selector.simpleSelectorSpecificity();
</span><span class="cx"> 
</span><del>-    // :host doesn't combine with any other selectors.
-    if (selector.tagHistory())
-        return false;
-    
</del><span class="cx">     if (auto* selectorList = selector.selectorList()) {
</span><span class="cx">         LocalContext context(*selectorList-&gt;first(), element, VisitedMatchType::Enabled, NOPSEUDO);
</span><span class="cx">         context.inFunctionalPseudoClass = true;
</span><span class="lines">@@ -245,7 +247,7 @@
</span><span class="cx"> 
</span><span class="cx">     updatedContext.isMatchElement = false;
</span><span class="cx"> 
</span><del>-    if (updatedContext.didMoveToShadowHost) {
</del><ins>+    if (updatedContext.mayMatchHostPseudoClass) {
</ins><span class="cx">         updatedContext.element = nullptr;
</span><span class="cx">         return updatedContext;
</span><span class="cx">     }
</span><span class="lines">@@ -253,7 +255,7 @@
</span><span class="cx">     // Move to the shadow host if matching :host and the parent is the shadow root.
</span><span class="cx">     if (context.selector-&gt;match() == CSSSelector::PseudoClass &amp;&amp; context.selector-&gt;pseudoClassType() == CSSSelector::PseudoClassHost &amp;&amp; is&lt;ShadowRoot&gt;(context.element-&gt;parentNode())) {
</span><span class="cx">         updatedContext.element = downcast&lt;ShadowRoot&gt;(*context.element-&gt;parentNode()).host();
</span><del>-        updatedContext.didMoveToShadowHost = true;
</del><ins>+        updatedContext.mayMatchHostPseudoClass = true;
</ins><span class="cx">         return updatedContext;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -655,6 +657,14 @@
</span><span class="cx"> 
</span><span class="cx">     specificity = CSSSelector::addSpecificities(specificity, selector.simpleSelectorSpecificity());
</span><span class="cx"> 
</span><ins>+    if (context.mayMatchHostPseudoClass) {
+        // :host doesn't combine with anything except pseudo elements.
+        bool isHostPseudoClass = selector.match() == CSSSelector::PseudoClass &amp;&amp; selector.pseudoClassType() == CSSSelector::PseudoClassHost;
+        bool isPseudoElement = selector.match() == CSSSelector::PseudoElement;
+        if (!isHostPseudoClass &amp;&amp; !isPseudoElement)
+            return false;
+    }
+
</ins><span class="cx">     if (selector.match() == CSSSelector::Tag)
</span><span class="cx">         return tagMatches(element, selector);
</span><span class="cx"> 
</span><span class="lines">@@ -1039,7 +1049,7 @@
</span><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">         case CSSSelector::PseudoClassHost: {
</span><del>-            if (!context.didMoveToShadowHost)
</del><ins>+            if (!context.mayMatchHostPseudoClass)
</ins><span class="cx">                 return false;
</span><span class="cx">             unsigned hostSpecificity;
</span><span class="cx">             if (!matchHostPseudoClass(selector, element, checkingContext, hostSpecificity))
</span></span></pre></div>
<a id="trunkSourceWebCorecssSelectorCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/SelectorChecker.h (209534 => 209535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/SelectorChecker.h        2016-12-08 13:39:46 UTC (rev 209534)
+++ trunk/Source/WebCore/css/SelectorChecker.h        2016-12-08 14:05:27 UTC (rev 209535)
</span><span class="lines">@@ -84,6 +84,7 @@
</span><span class="cx">         RenderScrollbar* scrollbar { nullptr };
</span><span class="cx">         ScrollbarPart scrollbarPart { NoPart };
</span><span class="cx">         const ContainerNode* scope { nullptr };
</span><ins>+        bool isMatchingHostPseudoClass { false };
</ins><span class="cx"> 
</span><span class="cx">         // FIXME: It would be nicer to have a separate object for return values. This requires some more work in the selector compiler.
</span><span class="cx">         Style::Relations styleRelations;
</span></span></pre>
</div>
</div>

</body>
</html>