<!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>[174379] 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/174379">174379</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-10-06 18:55:17 -0700 (Mon, 06 Oct 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: Highlighted selectors in Rules sidebar break with selectors that contain nested selector lists
https://bugs.webkit.org/show_bug.cgi?id=137378
Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-10-06
Reviewed by Joseph Pecoraro.
We should not update the parser's selectorRange when matching a nested selector list.
To implement this with low risk of unbalanced start+end and good error recovery,
I have wrapped the parsing of selector_list between a start/end function at the grammar
level. Whenever the parser enter a nested selector list, m_nestedSelectorLevel goes up
by one. Any time the parsing is currently in a nested selector list, we never update
the selector ranges.
* css/CSSGrammar.y.in:
* css/CSSParser.cpp:
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::markSelectorStart):
(WebCore::CSSParser::markSelectorEnd):
* css/CSSParser.h:
(WebCore::CSSParser::startNestedSelectorList):
(WebCore::CSSParser::endNestedSelectorList):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSGrammaryin">trunk/Source/WebCore/css/CSSGrammar.y.in</a></li>
<li><a href="#trunkSourceWebCorecssCSSParsercpp">trunk/Source/WebCore/css/CSSParser.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSParserh">trunk/Source/WebCore/css/CSSParser.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (174378 => 174379)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-10-07 01:16:47 UTC (rev 174378)
+++ trunk/Source/WebCore/ChangeLog        2014-10-07 01:55:17 UTC (rev 174379)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-10-06 Benjamin Poulain <bpoulain@apple.com>
+
+ Web Inspector: Highlighted selectors in Rules sidebar break with selectors that contain nested selector lists
+ https://bugs.webkit.org/show_bug.cgi?id=137378
+
+ Reviewed by Joseph Pecoraro.
+
+ We should not update the parser's selectorRange when matching a nested selector list.
+
+ To implement this with low risk of unbalanced start+end and good error recovery,
+ I have wrapped the parsing of selector_list between a start/end function at the grammar
+ level. Whenever the parser enter a nested selector list, m_nestedSelectorLevel goes up
+ by one. Any time the parsing is currently in a nested selector list, we never update
+ the selector ranges.
+
+ * css/CSSGrammar.y.in:
+ * css/CSSParser.cpp:
+ (WebCore::CSSParser::CSSParser):
+ (WebCore::CSSParser::markSelectorStart):
+ (WebCore::CSSParser::markSelectorEnd):
+ * css/CSSParser.h:
+ (WebCore::CSSParser::startNestedSelectorList):
+ (WebCore::CSSParser::endNestedSelectorList):
+
</ins><span class="cx"> 2014-10-06 Roger Fong <roger_fong@apple.com>
</span><span class="cx">
</span><span class="cx"> [Windows] Build fix for EWS bots.
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSGrammaryin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (174378 => 174379)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSGrammar.y.in        2014-10-07 01:16:47 UTC (rev 174378)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in        2014-10-07 01:55:17 UTC (rev 174379)
</span><span class="lines">@@ -309,8 +309,8 @@
</span><span class="cx"> %destructor { delete $$; } attrib class page_selector pseudo pseudo_page complex_selector complex_selector_with_trailing_whitespace compound_selector specifier specifier_list
</span><span class="cx">
</span><span class="cx"> %union { Vector<std::unique_ptr<CSSParserSelector>>* selectorList; }
</span><del>-%type <selectorList> selector_list simple_selector_list nth_selector_ending
-%destructor { delete $$; } selector_list simple_selector_list nth_selector_ending
</del><ins>+%type <selectorList> selector_list nested_selector_list simple_selector_list nth_selector_ending
+%destructor { delete $$; } selector_list nested_selector_list simple_selector_list nth_selector_ending
</ins><span class="cx">
</span><span class="cx"> %union { bool boolean; }
</span><span class="cx"> %type <boolean> declaration declaration_list decl_list priority
</span><span class="lines">@@ -1091,6 +1091,15 @@
</span><span class="cx"> }
</span><span class="cx"> ;
</span><span class="cx">
</span><ins>+before_nested_selector_list: { parser->startNestedSelectorList(); } ;
+after_nested_selector_list: { parser->endNestedSelectorList(); } ;
+
+nested_selector_list:
+ before_nested_selector_list selector_list after_nested_selector_list {
+ $$ = $2;
+ }
+ ;
+
</ins><span class="cx"> complex_selector_with_trailing_whitespace:
</span><span class="cx"> complex_selector WHITESPACE;
</span><span class="cx">
</span><span class="lines">@@ -1300,7 +1309,7 @@
</span><span class="cx"> | space ')' {
</span><span class="cx"> $$ = nullptr;
</span><span class="cx"> }
</span><del>- | space NTHCHILDSELECTORSEPARATOR space selector_list maybe_space ')' {
</del><ins>+ | space NTHCHILDSELECTORSEPARATOR space nested_selector_list maybe_space ')' {
</ins><span class="cx"> if ($4)
</span><span class="cx"> $$ = $4;
</span><span class="cx"> else
</span><span class="lines">@@ -1339,7 +1348,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #if ENABLE_CSS_SELECTORS_LEVEL4
</span><del>- | ':' MATCHESFUNCTION maybe_space selector_list maybe_space ')' {
</del><ins>+ | ':' MATCHESFUNCTION maybe_space nested_selector_list maybe_space ')' {
</ins><span class="cx"> $$ = nullptr;
</span><span class="cx"> if ($4) {
</span><span class="cx"> auto selector = std::make_unique<CSSParserSelector>();
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParser.cpp (174378 => 174379)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSParser.cpp        2014-10-07 01:16:47 UTC (rev 174378)
+++ trunk/Source/WebCore/css/CSSParser.cpp        2014-10-07 01:55:17 UTC (rev 174379)
</span><span class="lines">@@ -317,6 +317,7 @@
</span><span class="cx"> , m_ignoreErrorsInDeclaration(false)
</span><span class="cx"> , m_defaultNamespace(starAtom)
</span><span class="cx"> , m_parsedTextPrefixLength(0)
</span><ins>+ , m_nestedSelectorLevel(0)
</ins><span class="cx"> , m_propertyRange(UINT_MAX, UINT_MAX)
</span><span class="cx"> , m_ruleSourceDataResult(0)
</span><span class="cx"> , m_parsingMode(NormalMode)
</span><span class="lines">@@ -12052,7 +12053,7 @@
</span><span class="cx">
</span><span class="cx"> void CSSParser::markSelectorStart()
</span><span class="cx"> {
</span><del>- if (!isExtractingSourceData())
</del><ins>+ if (!isExtractingSourceData() || m_nestedSelectorLevel)
</ins><span class="cx"> return;
</span><span class="cx"> ASSERT(!m_selectorRange.end);
</span><span class="cx">
</span><span class="lines">@@ -12061,7 +12062,7 @@
</span><span class="cx">
</span><span class="cx"> void CSSParser::markSelectorEnd()
</span><span class="cx"> {
</span><del>- if (!isExtractingSourceData())
</del><ins>+ if (!isExtractingSourceData() || m_nestedSelectorLevel)
</ins><span class="cx"> return;
</span><span class="cx"> ASSERT(!m_selectorRange.end);
</span><span class="cx"> ASSERT(m_currentRuleDataStack->size());
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParser.h (174378 => 174379)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSParser.h        2014-10-07 01:16:47 UTC (rev 174378)
+++ trunk/Source/WebCore/css/CSSParser.h        2014-10-07 01:55:17 UTC (rev 174379)
</span><span class="lines">@@ -375,6 +375,7 @@
</span><span class="cx">
</span><span class="cx"> // tokenizer methods and data
</span><span class="cx"> size_t m_parsedTextPrefixLength;
</span><ins>+ unsigned m_nestedSelectorLevel;
</ins><span class="cx"> SourceRange m_selectorRange;
</span><span class="cx"> SourceRange m_propertyRange;
</span><span class="cx"> std::unique_ptr<RuleSourceDataList> m_currentRuleDataStack;
</span><span class="lines">@@ -384,8 +385,12 @@
</span><span class="cx"> void fixUnparsedPropertyRanges(CSSRuleSourceData*);
</span><span class="cx"> void markRuleHeaderStart(CSSRuleSourceData::Type);
</span><span class="cx"> void markRuleHeaderEnd();
</span><ins>+
+ void startNestedSelectorList() { ++m_nestedSelectorLevel; }
+ void endNestedSelectorList() { --m_nestedSelectorLevel; }
</ins><span class="cx"> void markSelectorStart();
</span><span class="cx"> void markSelectorEnd();
</span><ins>+
</ins><span class="cx"> void markRuleBodyStart();
</span><span class="cx"> void markRuleBodyEnd();
</span><span class="cx"> void markPropertyStart();
</span></span></pre>
</div>
</div>
</body>
</html>