<!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>[175758] 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/175758">175758</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2014-11-07 12:29:49 -0800 (Fri, 07 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Pseudo element matchedCSSRules do not include matching selector info
https://bugs.webkit.org/show_bug.cgi?id=138438

Reviewed by Benjamin Poulain.

Source/WebCore:

Test: inspector/css/psuedo-element-matches.html

Element::matches is not the correct API to use to check selectors with pseudo-elements.
Instead we should use the CSS Selector checking machinary which understands them.

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getSupportedCSSProperties):
(WebCore::InspectorCSSAgent::buildArrayForRuleList):
(WebCore::InspectorCSSAgent::buildArrayForRegions):
(WebCore::InspectorCSSAgent::buildObjectForNamedFlow):
Some RefPtr release improvements.

(WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):
Use a SelectorChecker to check each Selector against the element.
This matches the SelectorChecker used when we collected the rules
for this element.

Source/WebInspectorUI:

* UserInterface/Base/Test.js:
(WebInspector.loaded):
Include a global setting for shadow dom used by DOM model classes.
Give it a &quot;test&quot; specific name to not override non-test setting values.

LayoutTests:

* inspector/css/pseudo-element-matches-expected.txt: Added.
* inspector/css/pseudo-element-matches.html: Added.
Add a test to ensure we get correct selector matches for a pseudo element
inside of an &lt;audio&gt; element. The test is heavily coupled to our UserAgent
stylesheet and Shadow DOM layout, so check for possible failures if
WebCore changes things.</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="#trunkSourceWebCoreinspectorInspectorCSSAgentcpp">trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceBaseTestjs">trunk/Source/WebInspectorUI/UserInterface/Base/Test.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsinspectorcsspseudoelementmatchesexpectedtxt">trunk/LayoutTests/inspector/css/pseudo-element-matches-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorcsspseudoelementmatcheshtml">trunk/LayoutTests/inspector/css/pseudo-element-matches.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (175757 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-11-07 20:25:17 UTC (rev 175757)
+++ trunk/LayoutTests/ChangeLog        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-11-07  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Pseudo element matchedCSSRules do not include matching selector info
+        https://bugs.webkit.org/show_bug.cgi?id=138438
+
+        Reviewed by Benjamin Poulain.
+
+        * inspector/css/pseudo-element-matches-expected.txt: Added.
+        * inspector/css/pseudo-element-matches.html: Added.
+        Add a test to ensure we get correct selector matches for a pseudo element
+        inside of an &lt;audio&gt; element. The test is heavily coupled to our UserAgent
+        stylesheet and Shadow DOM layout, so check for possible failures if
+        WebCore changes things.
+
</ins><span class="cx"> 2014-11-07  Bem Jones-Bey  &lt;bjonesbe@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Shapes] the sandbag JS utility code isn't producing the correct expected result in the shape-image gradient tests
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorcsspseudoelementmatchesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/css/pseudo-element-matches-expected.txt (0 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/css/pseudo-element-matches-expected.txt                                (rev 0)
+++ trunk/LayoutTests/inspector/css/pseudo-element-matches-expected.txt        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+Testing that psuedo element selectors correctly show matching selector information.
+
+
+video::-webkit-media-text-track-container
+audio::-webkit-media-text-track-container MATCHES
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcsspseudoelementmatcheshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/css/pseudo-element-matches.html (0 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/css/pseudo-element-matches.html                                (rev 0)
+++ trunk/LayoutTests/inspector/css/pseudo-element-matches.html        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -0,0 +1,83 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script type=&quot;text/javascript&quot; src=&quot;../../http/tests/inspector/inspector-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function test() {
+    var nodeStyles;
+
+    function validateMatchedSelectors()
+    {
+        var found = false;
+
+        for (var i = 0; i &lt; nodeStyles.matchedRules.length; ++i) {
+            var rule = nodeStyles.matchedRules[i];
+            if (rule.type !== WebInspector.CSSRule.Type.UserAgent)
+                continue;
+            if (rule.selectorText.indexOf(&quot;::-webkit-media-text-track-container&quot;) === -1)
+                continue;
+
+            found = true;
+            var index = 0;
+            for (var selector of rule.selectors) {
+                var matches = rule.matchedSelectorIndices.contains(index);
+                InspectorTest.log(selector.text + (matches ? &quot; MATCHES&quot; : &quot;&quot;));
+                index++;
+            }
+            break;
+        }
+
+        if (!found)
+            InspectorTest.log(&quot;Failed to find a ::-webkit-media-text-track-container UserAgent style. Test may need to change.&quot;);
+
+        InspectorTest.completeTest();
+    }
+
+    function onStylesRefreshed()
+    {
+        nodeStyles.removeEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, onStylesRefreshed, this);
+        validateMatchedSelectors();
+    }
+
+    WebInspector.domTreeManager.requestDocument(function(documentNode) {
+        WebInspector.domTreeManager.querySelector(documentNode.id, &quot;#node1&quot;, function(contentNodeId) {
+            try { 
+                if (contentNodeId) {
+                    var domNode = WebInspector.domTreeManager.nodeForId(contentNodeId);
+                    domNode.getSubtree(1, function() {
+                        var shadowRootDocument = domNode.children[0];
+                        shadowRootDocument.getSubtree(2, function() {
+                            var shadowRoot = shadowRootDocument.children[0];
+                            for (var i = 0; i &lt; shadowRoot.children.length; ++i) {
+                                var shadowNode = shadowRoot.children[i];
+                                if (shadowNode.getAttribute(&quot;pseudo&quot;) === &quot;-webkit-media-text-track-container&quot;) {
+                                    nodeStyles = WebInspector.cssStyleManager.stylesForNode(shadowNode);
+                                    if (nodeStyles.needsRefresh)
+                                        nodeStyles.addEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, onStylesRefreshed, this);
+                                    else
+                                        validateMatchedSelectors();
+                                    return;
+                                }
+                            }
+                        });
+                    });
+                } else {
+                    InspectorTest.log(&quot;DOM node not found.&quot;);
+                    InspectorTest.completeTest();
+                }
+            } catch (e) {
+                InspectorTest.log(&quot;Exception: &quot; + e.message);
+                InspectorTest.log(&quot;Failed to find a ::-webkit-media-text-track-container shadow element under an &lt;audio&gt;. Test may need to change.&quot;);
+                InspectorTest.completeTest();
+            }
+        });
+    });
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    &lt;p&gt;Testing that psuedo element selectors correctly show matching selector information.&lt;/p&gt;
+
+    &lt;audio id=&quot;node1&quot; controls&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (175757 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-07 20:25:17 UTC (rev 175757)
+++ trunk/Source/WebCore/ChangeLog        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-11-07  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Pseudo element matchedCSSRules do not include matching selector info
+        https://bugs.webkit.org/show_bug.cgi?id=138438
+
+        Reviewed by Benjamin Poulain.
+
+        Test: inspector/css/psuedo-element-matches.html
+
+        Element::matches is not the correct API to use to check selectors with pseudo-elements.
+        Instead we should use the CSS Selector checking machinary which understands them.
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getSupportedCSSProperties):
+        (WebCore::InspectorCSSAgent::buildArrayForRuleList):
+        (WebCore::InspectorCSSAgent::buildArrayForRegions):
+        (WebCore::InspectorCSSAgent::buildObjectForNamedFlow):
+        Some RefPtr release improvements.
+
+        (WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):
+        Use a SelectorChecker to check each Selector against the element.
+        This matches the SelectorChecker used when we collected the rules
+        for this element.
+
</ins><span class="cx"> 2014-11-07  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Drop useless HTMLElement::isURLAttribute() override
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorCSSAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (175757 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp        2014-11-07 20:25:17 UTC (rev 175757)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx"> #include &quot;NodeList.h&quot;
</span><span class="cx"> #include &quot;RenderNamedFlowFragment.h&quot;
</span><span class="cx"> #include &quot;SVGStyleElement.h&quot;
</span><ins>+#include &quot;SelectorChecker.h&quot;
</ins><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> #include &quot;StylePropertyShorthand.h&quot;
</span><span class="cx"> #include &quot;StyleResolver.h&quot;
</span><span class="lines">@@ -826,7 +827,7 @@
</span><span class="cx">             CSSPropertyID longhandID = shorthand.properties()[j];
</span><span class="cx">             longhands-&gt;addItem(getPropertyNameString(longhandID));
</span><span class="cx">         }
</span><del>-        property-&gt;setLonghands(longhands);
</del><ins>+        property-&gt;setLonghands(longhands.release());
</ins><span class="cx">         properties-&gt;addItem(property.release());
</span><span class="cx">     }
</span><span class="cx">     cssProperties = properties.release();
</span><span class="lines">@@ -1047,7 +1048,7 @@
</span><span class="cx">         RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt; ruleObject = buildObjectForRule(rule);
</span><span class="cx">         if (!ruleObject)
</span><span class="cx">             continue;
</span><del>-        result-&gt;addItem(ruleObject);
</del><ins>+        result-&gt;addItem(ruleObject.release());
</ins><span class="cx">     }
</span><span class="cx">     return result.release();
</span><span class="cx"> }
</span><span class="lines">@@ -1056,26 +1057,32 @@
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;Inspector::Protocol::Array&lt;Inspector::Protocol::CSS::RuleMatch&gt;&gt; result = Inspector::Protocol::Array&lt;Inspector::Protocol::CSS::RuleMatch&gt;::create();
</span><span class="cx"> 
</span><ins>+    SelectorChecker::CheckingContext context(SelectorChecker::Mode::CollectingRules);
+    SelectorChecker selectorChecker(element-&gt;document());
+
</ins><span class="cx">     for (unsigned i = 0; i &lt; matchedRules.size(); ++i) {
</span><span class="cx">         if (!matchedRules[i]-&gt;isStyleRule())
</span><span class="cx">             continue;
</span><ins>+
</ins><span class="cx">         StyleRule* matchedStyleRule = static_cast&lt;StyleRule*&gt;(matchedRules[i].get());
</span><span class="cx">         RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt; ruleObject = buildObjectForRule(matchedStyleRule, styleResolver);
</span><span class="cx">         if (!ruleObject)
</span><span class="cx">             continue;
</span><ins>+
</ins><span class="cx">         RefPtr&lt;Inspector::Protocol::Array&lt;int&gt;&gt; matchingSelectors = Inspector::Protocol::Array&lt;int&gt;::create();
</span><span class="cx">         const CSSSelectorList&amp; selectorList = matchedStyleRule-&gt;selectorList();
</span><span class="cx">         long index = 0;
</span><span class="cx">         for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector)) {
</span><del>-            bool matched = element-&gt;matches(selector-&gt;selectorText(), IGNORE_EXCEPTION);
</del><ins>+            bool matched = selectorChecker.match(selector, element, context);
</ins><span class="cx">             if (matched)
</span><span class="cx">                 matchingSelectors-&gt;addItem(index);
</span><span class="cx">             ++index;
</span><span class="cx">         }
</span><ins>+
</ins><span class="cx">         RefPtr&lt;Inspector::Protocol::CSS::RuleMatch&gt; match = Inspector::Protocol::CSS::RuleMatch::create()
</span><del>-            .setRule(ruleObject)
-            .setMatchingSelectors(matchingSelectors);
-        result-&gt;addItem(match);
</del><ins>+            .setRule(ruleObject.release())
+            .setMatchingSelectors(matchingSelectors.release());
+        result-&gt;addItem(match.release());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return result.release();
</span><span class="lines">@@ -1128,7 +1135,7 @@
</span><span class="cx">             // documentNodeId was previously asserted
</span><span class="cx">             .setNodeId(m_domAgent-&gt;pushNodeToFrontend(errorString, documentNodeId, regionList-&gt;item(i)));
</span><span class="cx"> 
</span><del>-        regions-&gt;addItem(region);
</del><ins>+        regions-&gt;addItem(region.release());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return regions.release();
</span><span class="lines">@@ -1144,14 +1151,13 @@
</span><span class="cx">         content-&gt;addItem(m_domAgent-&gt;pushNodeToFrontend(errorString, documentNodeId, contentList-&gt;item(i)));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    RefPtr&lt;Inspector::Protocol::CSS::NamedFlow&gt; namedFlow = Inspector::Protocol::CSS::NamedFlow::create()
</del><ins>+    return Inspector::Protocol::CSS::NamedFlow::create()
</ins><span class="cx">         .setDocumentNodeId(documentNodeId)
</span><span class="cx">         .setName(webkitNamedFlow-&gt;name().string())
</span><span class="cx">         .setOverset(webkitNamedFlow-&gt;overset())
</span><del>-        .setContent(content)
-        .setRegions(buildArrayForRegions(errorString, webkitNamedFlow-&gt;getRegions(), documentNodeId));
-
-    return namedFlow.release();
</del><ins>+        .setContent(content.release())
+        .setRegions(buildArrayForRegions(errorString, webkitNamedFlow-&gt;getRegions(), documentNodeId))
+        .release();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorCSSAgent::didRemoveDocument(Document* document)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (175757 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2014-11-07 20:25:17 UTC (rev 175757)
+++ trunk/Source/WebInspectorUI/ChangeLog        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-11-07  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Pseudo element matchedCSSRules do not include matching selector info
+        https://bugs.webkit.org/show_bug.cgi?id=138438
+
+        Reviewed by Benjamin Poulain.
+
+        * UserInterface/Base/Test.js:
+        (WebInspector.loaded):
+        Include a global setting for shadow dom used by DOM model classes.
+        Give it a &quot;test&quot; specific name to not override non-test setting values.
+
</ins><span class="cx"> 2014-11-05  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r175628.
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceBaseTestjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Test.js (175757 => 175758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Base/Test.js        2014-11-07 20:25:17 UTC (rev 175757)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Test.js        2014-11-07 20:29:49 UTC (rev 175758)
</span><span class="lines">@@ -63,6 +63,8 @@
</span><span class="cx"> 
</span><span class="cx">     // Perform one-time tasks.
</span><span class="cx">     WebInspector.CSSCompletions.requestCSSNameCompletions();
</span><ins>+
+    this.showShadowDOMSetting = new WebInspector.Setting(&quot;test-show-shadow-dom&quot;, true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebInspector.contentLoaded = function()
</span></span></pre>
</div>
</div>

</body>
</html>