<!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>[207854] 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/207854">207854</a></dd>
<dt>Author</dt> <dd>hyatt@apple.com</dd>
<dt>Date</dt> <dd>2016-10-25 16:21:03 -0700 (Tue, 25 Oct 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[CSS Parser] Improvements to selector parsing
https://bugs.webkit.org/show_bug.cgi?id=163964
Reviewed by Zalan Bujtas.
* css/CSSSelector.cpp:
(WebCore::CSSSelector::setAttribute):
(WebCore::CSSSelector::setNth):
* css/CSSSelector.h:
(WebCore::CSSSelector::setAttributeValueMatchingIsCaseInsensitive):
* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::StyleSheetContents):
(WebCore::StyleSheetContents::parserAppendRule):
(WebCore::StyleSheetContents::ruleAt):
(WebCore::StyleSheetContents::ruleCount):
(WebCore::StyleSheetContents::clearRules):
(WebCore::StyleSheetContents::wrapperInsertRule):
(WebCore::StyleSheetContents::wrapperDeleteRule):
* css/StyleSheetContents.h:
* css/parser/CSSParser.cpp:
(WebCore::CSSParserContext::CSSParserContext):
(WebCore::CSSParser::parseSelector):
* css/parser/CSSParserValues.h:
(WebCore::CSSParserSelector::setAttribute):
(WebCore::CSSParserSelector::setArgument):
(WebCore::CSSParserSelector::setNth):
* css/parser/CSSSelectorParser.cpp:
(WebCore::consumeLangArgumentList):
(WebCore::CSSSelectorParser::consumeCompoundSelector):
(WebCore::CSSSelectorParser::consumeAttribute):
(WebCore::isPseudoClassFunction):
(WebCore::isPseudoElementFunction):
(WebCore::CSSSelectorParser::consumePseudo):
(WebCore::CSSSelectorParser::consumeCombinator):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSSelectorcpp">trunk/Source/WebCore/css/CSSSelector.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSSelectorh">trunk/Source/WebCore/css/CSSSelector.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleSheetContentscpp">trunk/Source/WebCore/css/StyleSheetContents.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleSheetContentsh">trunk/Source/WebCore/css/StyleSheetContents.h</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSParsercpp">trunk/Source/WebCore/css/parser/CSSParser.cpp</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSParserValuescpp">trunk/Source/WebCore/css/parser/CSSParserValues.cpp</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSParserValuesh">trunk/Source/WebCore/css/parser/CSSParserValues.h</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSSelectorParsercpp">trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/ChangeLog        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-10-25 Dave Hyatt <hyatt@apple.com>
+
+ [CSS Parser] Improvements to selector parsing
+ https://bugs.webkit.org/show_bug.cgi?id=163964
+
+ Reviewed by Zalan Bujtas.
+
+ * css/CSSSelector.cpp:
+ (WebCore::CSSSelector::setAttribute):
+ (WebCore::CSSSelector::setNth):
+ * css/CSSSelector.h:
+ (WebCore::CSSSelector::setAttributeValueMatchingIsCaseInsensitive):
+ * css/StyleSheetContents.cpp:
+ (WebCore::StyleSheetContents::StyleSheetContents):
+ (WebCore::StyleSheetContents::parserAppendRule):
+ (WebCore::StyleSheetContents::ruleAt):
+ (WebCore::StyleSheetContents::ruleCount):
+ (WebCore::StyleSheetContents::clearRules):
+ (WebCore::StyleSheetContents::wrapperInsertRule):
+ (WebCore::StyleSheetContents::wrapperDeleteRule):
+ * css/StyleSheetContents.h:
+ * css/parser/CSSParser.cpp:
+ (WebCore::CSSParserContext::CSSParserContext):
+ (WebCore::CSSParser::parseSelector):
+ * css/parser/CSSParserValues.h:
+ (WebCore::CSSParserSelector::setAttribute):
+ (WebCore::CSSParserSelector::setArgument):
+ (WebCore::CSSParserSelector::setNth):
+ * css/parser/CSSSelectorParser.cpp:
+ (WebCore::consumeLangArgumentList):
+ (WebCore::CSSSelectorParser::consumeCompoundSelector):
+ (WebCore::CSSSelectorParser::consumeAttribute):
+ (WebCore::isPseudoClassFunction):
+ (WebCore::isPseudoElementFunction):
+ (WebCore::CSSSelectorParser::consumePseudo):
+ (WebCore::CSSSelectorParser::consumeCombinator):
+
</ins><span class="cx"> 2016-10-25 Beth Dakin <bdakin@apple.com>
</span><span class="cx">
</span><span class="cx"> Numbered list should be represented without ‘…’
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSSelectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSSelector.cpp (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSSelector.cpp        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/CSSSelector.cpp        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -763,6 +763,14 @@
</span><span class="cx"> m_data.m_rareData->m_attributeCanonicalLocalName = isCaseInsensitive ? value.localName().convertToASCIILowercase() : value.localName();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void CSSSelector::setAttribute(const QualifiedName& value, bool convertToLowercase, AttributeMatchType matchType)
+{
+ createRareData();
+ m_data.m_rareData->m_attribute = value;
+ m_data.m_rareData->m_attributeCanonicalLocalName = convertToLowercase ? value.localName().convertToASCIILowercase() : value.localName();
+ m_caseInsensitiveAttributeValueMatching = matchType == CaseInsensitive;
+}
+
</ins><span class="cx"> void CSSSelector::setArgument(const AtomicString& value)
</span><span class="cx"> {
</span><span class="cx"> createRareData();
</span><span class="lines">@@ -781,6 +789,16 @@
</span><span class="cx"> m_data.m_rareData->m_selectorList = WTFMove(selectorList);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void CSSSelector::setNth(int a, int b)
+{
+ createRareData();
+ m_parsedNth = true; // FIXME-NEWPARSER: Can remove this parsed boolean once old parser is gone.
+ m_data.m_rareData->m_a = a;
+ m_data.m_rareData->m_b = b;
+}
+
+// FIXME-NEWPARSER: All the code to parse nth-child stuff can be removed when
+// the new parser is enabled.
</ins><span class="cx"> bool CSSSelector::parseNth() const
</span><span class="cx"> {
</span><span class="cx"> if (!m_hasRareData)
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSSelectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSSelector.h (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSSelector.h        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/CSSSelector.h        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -244,9 +244,13 @@
</span><span class="cx"> const CSSSelectorList* selectorList() const { return m_hasRareData ? m_data.m_rareData->m_selectorList.get() : nullptr; }
</span><span class="cx">
</span><span class="cx"> void setValue(const AtomicString&);
</span><del>- void setAttribute(const QualifiedName&, bool isCaseInsensitive);
</del><ins>+
+ // FIXME-NEWPARSER: These two methods can go away once the old parser is gone.
+ void setAttribute(const QualifiedName&, bool);
+ void setAttributeValueMatchingIsCaseInsensitive(bool);
+ void setAttribute(const QualifiedName&, bool convertToLowercase, AttributeMatchType);
+ void setNth(int a, int b);
</ins><span class="cx"> void setArgument(const AtomicString&);
</span><del>- void setAttributeValueMatchingIsCaseInsensitive(bool);
</del><span class="cx"> void setLangArgumentList(std::unique_ptr<Vector<AtomicString>>);
</span><span class="cx"> void setSelectorList(std::unique_ptr<CSSSelectorList>);
</span><span class="cx">
</span><span class="lines">@@ -585,7 +589,7 @@
</span><span class="cx"> ASSERT(isAttributeSelector() && match() != CSSSelector::Set);
</span><span class="cx"> m_caseInsensitiveAttributeValueMatching = isCaseInsensitive;
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> inline bool CSSSelector::attributeValueMatchingIsCaseInsensitive() const
</span><span class="cx"> {
</span><span class="cx"> return m_caseInsensitiveAttributeValueMatching;
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleSheetContentscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleSheetContents.cpp (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleSheetContents.cpp        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/StyleSheetContents.cpp        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx"> , m_originalURL(o.m_originalURL)
</span><span class="cx"> , m_encodingFromCharsetRule(o.m_encodingFromCharsetRule)
</span><span class="cx"> , m_importRules(o.m_importRules.size())
</span><ins>+ , m_namespaceRules(o.m_namespaceRules.size())
</ins><span class="cx"> , m_childRules(o.m_childRules.size())
</span><span class="cx"> , m_namespaces(o.m_namespaces)
</span><span class="cx"> , m_defaultNamespace(o.m_defaultNamespace)
</span><span class="lines">@@ -142,6 +143,16 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ if (is<StyleRuleNamespace>(rule)) {
+ // Parser enforces that @namespace rules come before all rules other than
+ // import/charset rules
+ ASSERT(m_childRules.isEmpty());
+ StyleRuleNamespace& namespaceRule = downcast<StyleRuleNamespace>(rule.get());
+ parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri());
+ m_namespaceRules.append(downcast<StyleRuleNamespace>(rule.ptr()));
+ return;
+ }
+
</ins><span class="cx"> if (is<StyleRuleMedia>(rule))
</span><span class="cx"> reportMediaQueryWarningIfNeeded(singleOwnerDocument(), downcast<StyleRuleMedia>(rule.get()).mediaQueries());
</span><span class="cx">
</span><span class="lines">@@ -164,6 +175,12 @@
</span><span class="cx"> return m_importRules[childVectorIndex].get();
</span><span class="cx">
</span><span class="cx"> childVectorIndex -= m_importRules.size();
</span><ins>+
+ if (childVectorIndex < m_namespaceRules.size())
+ return m_namespaceRules[childVectorIndex].get();
+
+ childVectorIndex -= m_namespaceRules.size();
+
</ins><span class="cx"> return m_childRules[childVectorIndex].get();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -171,6 +188,7 @@
</span><span class="cx"> {
</span><span class="cx"> unsigned result = 0;
</span><span class="cx"> result += m_importRules.size();
</span><ins>+ result += m_namespaceRules.size();
</ins><span class="cx"> result += m_childRules.size();
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="lines">@@ -187,6 +205,7 @@
</span><span class="cx"> m_importRules[i]->clearParentStyleSheet();
</span><span class="cx"> }
</span><span class="cx"> m_importRules.clear();
</span><ins>+ m_namespaceRules.clear();
</ins><span class="cx"> m_childRules.clear();
</span><span class="cx"> clearCharsetRule();
</span><span class="cx"> }
</span><span class="lines">@@ -221,6 +240,31 @@
</span><span class="cx"> return false;
</span><span class="cx"> childVectorIndex -= m_importRules.size();
</span><span class="cx">
</span><ins>+
+ if (childVectorIndex < m_namespaceRules.size() || (childVectorIndex == m_namespaceRules.size() && rule->isNamespaceRule())) {
+ // Inserting non-namespace rules other than import rule before @namespace is
+ // not allowed.
+ if (!is<StyleRuleNamespace>(rule))
+ return false;
+ // Inserting @namespace rule when rules other than import/namespace/charset
+ // are present is not allowed.
+ if (!m_childRules.isEmpty())
+ return false;
+
+ StyleRuleNamespace& namespaceRule = downcast<StyleRuleNamespace>(rule.get());
+ m_namespaceRules.insert(index, downcast<StyleRuleNamespace>(rule.ptr()));
+
+ // For now to be compatible with IE and Firefox if a namespace rule with the same
+ // prefix is added, it overwrites previous ones.
+ // FIXME: The eventual correct behavior would be to ensure that the last value in
+ // the list wins.
+ parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri());
+ return true;
+ }
+ if (is<StyleRuleNamespace>(rule))
+ return false;
+ childVectorIndex -= m_namespaceRules.size();
+
</ins><span class="cx"> // If the number of selectors would overflow RuleData, we drop the operation.
</span><span class="cx"> if (is<StyleRule>(rule) && downcast<StyleRule>(rule.get()).selectorList().componentCount() > RuleData::maximumSelectorComponentCount)
</span><span class="cx"> return false;
</span><span class="lines">@@ -242,6 +286,14 @@
</span><span class="cx"> }
</span><span class="cx"> childVectorIndex -= m_importRules.size();
</span><span class="cx">
</span><ins>+ if (childVectorIndex < m_namespaceRules.size()) {
+ if (!m_childRules.isEmpty())
+ return;
+ m_namespaceRules.remove(childVectorIndex);
+ return;
+ }
+ childVectorIndex -= m_namespaceRules.size();
+
</ins><span class="cx"> m_childRules.remove(childVectorIndex);
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleSheetContentsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleSheetContents.h (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleSheetContents.h        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/StyleSheetContents.h        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> class SecurityOrigin;
</span><span class="cx"> class StyleRuleBase;
</span><span class="cx"> class StyleRuleImport;
</span><ins>+class StyleRuleNamespace;
</ins><span class="cx">
</span><span class="cx"> class StyleSheetContents final : public RefCounted<StyleSheetContents> {
</span><span class="cx"> public:
</span><span class="lines">@@ -104,6 +105,7 @@
</span><span class="cx"> // Rules other than @charset and @import.
</span><span class="cx"> const Vector<RefPtr<StyleRuleBase>>& childRules() const { return m_childRules; }
</span><span class="cx"> const Vector<RefPtr<StyleRuleImport>>& importRules() const { return m_importRules; }
</span><ins>+ const Vector<RefPtr<StyleRuleNamespace>>& namespaceRules() const { return m_namespaceRules; }
</ins><span class="cx">
</span><span class="cx"> void notifyLoadedSheet(const CachedCSSStyleSheet*);
</span><span class="cx">
</span><span class="lines">@@ -154,6 +156,7 @@
</span><span class="cx">
</span><span class="cx"> String m_encodingFromCharsetRule;
</span><span class="cx"> Vector<RefPtr<StyleRuleImport>> m_importRules;
</span><ins>+ Vector<RefPtr<StyleRuleNamespace>> m_namespaceRules;
</ins><span class="cx"> Vector<RefPtr<StyleRuleBase>> m_childRules;
</span><span class="cx"> typedef HashMap<AtomicString, AtomicString> PrefixNamespaceURIMap;
</span><span class="cx"> PrefixNamespaceURIMap m_namespaces;
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSParser.cpp        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -64,9 +64,11 @@
</span><span class="cx"> #include "CSSReflectValue.h"
</span><span class="cx"> #include "CSSRevertValue.h"
</span><span class="cx"> #include "CSSSelector.h"
</span><ins>+#include "CSSSelectorParser.h"
</ins><span class="cx"> #include "CSSShadowValue.h"
</span><span class="cx"> #include "CSSStyleSheet.h"
</span><span class="cx"> #include "CSSTimingFunctionValue.h"
</span><ins>+#include "CSSTokenizer.h"
</ins><span class="cx"> #include "CSSUnicodeRangeValue.h"
</span><span class="cx"> #include "CSSUnsetValue.h"
</span><span class="cx"> #include "CSSValueKeywords.h"
</span><span class="lines">@@ -1411,8 +1413,14 @@
</span><span class="cx">
</span><span class="cx"> void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
</span><span class="cx"> {
</span><ins>+ if (m_context.useNewParser && m_context.mode != UASheetMode) {
+ CSSTokenizer::Scope scope(string);
+ selectorList = CSSSelectorParser::parseSelector(scope.tokenRange(), m_context, nullptr);
+ return;
+ }
+
</ins><span class="cx"> m_selectorListForParseSelector = &selectorList;
</span><del>-
</del><ins>+
</ins><span class="cx"> setupParser("@-webkit-selector{", string, "}");
</span><span class="cx">
</span><span class="cx"> cssyyparse(this);
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSParserValuescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSParserValues.cpp (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSParserValues.cpp        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/parser/CSSParserValues.cpp        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -410,7 +410,13 @@
</span><span class="cx"> argumentList->append(languageArgument);
</span><span class="cx"> m_selector->setLangArgumentList(WTFMove(argumentList));
</span><span class="cx"> }
</span><del>-
</del><ins>+
+void CSSParserSelector::setLangArgumentList(std::unique_ptr<Vector<AtomicString>> argumentList)
+{
+ ASSERT_WITH_MESSAGE(!argumentList->isEmpty(), "No CSS Selector takes an empty argument list.");
+ m_selector->setLangArgumentList(WTFMove(argumentList));
+}
+
</ins><span class="cx"> void CSSParserSelector::setSelectorList(std::unique_ptr<CSSSelectorList> selectorList)
</span><span class="cx"> {
</span><span class="cx"> m_selector->setSelectorList(WTFMove(selectorList));
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSParserValuesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSParserValues.h (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSParserValues.h        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/parser/CSSParserValues.h        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -222,9 +222,15 @@
</span><span class="cx"> std::unique_ptr<CSSSelector> releaseSelector() { return WTFMove(m_selector); }
</span><span class="cx">
</span><span class="cx"> void setValue(const AtomicString& value) { m_selector->setValue(value); }
</span><ins>+
+ // FIXME-NEWPARSER: These two methods can go away once old parser is gone.
</ins><span class="cx"> void setAttribute(const QualifiedName& value, bool isCaseInsensitive) { m_selector->setAttribute(value, isCaseInsensitive); }
</span><ins>+ void setAttributeValueMatchingIsCaseInsensitive(bool isCaseInsensitive) { m_selector->setAttributeValueMatchingIsCaseInsensitive(isCaseInsensitive); }
+
+ void setAttribute(const QualifiedName& value, bool convertToLowercase, CSSSelector::AttributeMatchType type) { m_selector->setAttribute(value, convertToLowercase, type); }
+
</ins><span class="cx"> void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
</span><del>- void setAttributeValueMatchingIsCaseInsensitive(bool isCaseInsensitive) { m_selector->setAttributeValueMatchingIsCaseInsensitive(isCaseInsensitive); }
</del><ins>+ void setNth(int a, int b) { m_selector->setNth(a, b); }
</ins><span class="cx"> void setMatch(CSSSelector::Match value) { m_selector->setMatch(value); }
</span><span class="cx"> void setRelation(CSSSelector::RelationType value) { m_selector->setRelation(value); }
</span><span class="cx"> void setForPage() { m_selector->setForPage(); }
</span><span class="lines">@@ -235,6 +241,7 @@
</span><span class="cx">
</span><span class="cx"> void adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
</span><span class="cx"> void setLangArgumentList(const Vector<CSSParserString>& stringVector);
</span><ins>+ void setLangArgumentList(std::unique_ptr<Vector<AtomicString>>);
</ins><span class="cx"> void setSelectorList(std::unique_ptr<CSSSelectorList>);
</span><span class="cx">
</span><span class="cx"> void setPseudoClassValue(const CSSParserString& pseudoClassString);
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSSelectorParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp (207853 => 207854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp        2016-10-25 23:01:18 UTC (rev 207853)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp        2016-10-25 23:21:03 UTC (rev 207854)
</span><span class="lines">@@ -100,6 +100,28 @@
</span><span class="cx"> return list;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool consumeLangArgumentList(std::unique_ptr<Vector<AtomicString>>& argumentList, CSSParserTokenRange& range)
+{
+ const CSSParserToken& ident = range.consumeIncludingWhitespace();
+ if (ident.type() != IdentToken && ident.type() != StringToken)
+ return false;
+ StringView string = ident.value();
+ if (string.startsWith("--"))
+ return false;
+ argumentList->append(string.toAtomicString());
+ while (!range.atEnd() && range.peek().type() == CommaToken) {
+ range.consumeIncludingWhitespace();
+ const CSSParserToken& ident = range.consumeIncludingWhitespace();
+ if (ident.type() != IdentToken && ident.type() != StringToken)
+ return false;
+ StringView string = ident.value();
+ if (string.startsWith("--"))
+ return false;
+ argumentList->append(string.toAtomicString());
+ }
+ return range.atEnd();
+}
+
</ins><span class="cx"> namespace {
</span><span class="cx">
</span><span class="cx"> enum CompoundSelectorFlags {
</span><span class="lines">@@ -257,8 +279,6 @@
</span><span class="cx"> if (compoundSelector->match() == CSSSelector::PseudoElement)
</span><span class="cx"> compoundPseudoElement = compoundSelector->pseudoElementType();
</span><span class="cx"> }
</span><del>- if (m_context.isHTMLDocument)
- elementName = elementName.convertToASCIILowercase();
</del><span class="cx">
</span><span class="cx"> while (std::unique_ptr<CSSParserSelector> simpleSelector = consumeSimpleSelector(range)) {
</span><span class="cx"> // FIXME: https://bugs.webkit.org/show_bug.cgi?id=161747
</span><span class="lines">@@ -400,9 +420,6 @@
</span><span class="cx"> return nullptr;
</span><span class="cx"> block.consumeWhitespace();
</span><span class="cx">
</span><del>- if (m_context.isHTMLDocument)
- attributeName = attributeName.convertToASCIILowercase();
-
</del><span class="cx"> AtomicString namespaceURI = determineNamespace(namespacePrefix);
</span><span class="cx"> if (namespaceURI.isNull())
</span><span class="cx"> return nullptr;
</span><span class="lines">@@ -414,7 +431,7 @@
</span><span class="cx"> std::unique_ptr<CSSParserSelector> selector = std::unique_ptr<CSSParserSelector>(new CSSParserSelector());
</span><span class="cx">
</span><span class="cx"> if (block.atEnd()) {
</span><del>- selector->setAttribute(qualifiedName, CSSSelector::CaseSensitive);
</del><ins>+ selector->setAttribute(qualifiedName, m_context.isHTMLDocument, CSSSelector::CaseSensitive);
</ins><span class="cx"> selector->setMatch(CSSSelector::Set);
</span><span class="cx"> return selector;
</span><span class="cx"> }
</span><span class="lines">@@ -425,7 +442,8 @@
</span><span class="cx"> if (attributeValue.type() != IdentToken && attributeValue.type() != StringToken)
</span><span class="cx"> return nullptr;
</span><span class="cx"> selector->setValue(attributeValue.value().toAtomicString());
</span><del>- selector->setAttribute(qualifiedName, consumeAttributeFlags(block));
</del><ins>+
+ selector->setAttribute(qualifiedName, m_context.isHTMLDocument, consumeAttributeFlags(block));
</ins><span class="cx">
</span><span class="cx"> if (!block.atEnd())
</span><span class="cx"> return nullptr;
</span><span class="lines">@@ -432,6 +450,41 @@
</span><span class="cx"> return selector;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool isPseudoClassFunction(CSSSelector::PseudoClassType pseudoClassType)
+{
+ switch (pseudoClassType) {
+ case CSSSelector::PseudoClassNot:
+ case CSSSelector::PseudoClassMatches:
+ case CSSSelector::PseudoClassNthChild:
+ case CSSSelector::PseudoClassNthLastChild:
+ case CSSSelector::PseudoClassNthOfType:
+ case CSSSelector::PseudoClassNthLastOfType:
+ case CSSSelector::PseudoClassLang:
+ case CSSSelector::PseudoClassAny:
+ case CSSSelector::PseudoClassHost:
+#if ENABLE_CSS_SELECTORS_LEVEL4
+ case CSSSelector::PseudoClassDir:
+ case CSSSelector::PseudoClassRole:
+#endif
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+static bool isPseudoElementFunction(CSSSelector::PseudoElementType pseudoElementType)
+{
+ switch (pseudoElementType) {
+ case CSSSelector::PseudoElementCue:
+ case CSSSelector::PseudoElementSlotted:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
</ins><span class="cx"> std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumePseudo(CSSParserTokenRange& range)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(range.peek().type() == ColonToken);
</span><span class="lines">@@ -459,7 +512,8 @@
</span><span class="cx">
</span><span class="cx"> if (token.type() == IdentToken) {
</span><span class="cx"> range.consume();
</span><del>- if ((selector->match() == CSSSelector::PseudoElement && selector->pseudoElementType() == CSSSelector::PseudoElementUnknown) || (selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassUnknown))
</del><ins>+ if ((selector->match() == CSSSelector::PseudoElement && (selector->pseudoElementType() == CSSSelector::PseudoElementUnknown || isPseudoElementFunction(selector->pseudoElementType())))
+ || (selector->match() == CSSSelector::PseudoClass && (selector->pseudoClassType() == CSSSelector::PseudoClassUnknown || isPseudoClassFunction(selector->pseudoClassType()))))
</ins><span class="cx"> return nullptr;
</span><span class="cx"> return selector;
</span><span class="cx"> }
</span><span class="lines">@@ -469,78 +523,112 @@
</span><span class="cx"> if (token.type() != FunctionToken)
</span><span class="cx"> return nullptr;
</span><span class="cx">
</span><del>- switch (selector->pseudoClassType()) {
- case CSSSelector::PseudoClassNot: {
- std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
- block.consumeWhitespace();
- if (!innerSelector || !block.atEnd())
- return nullptr;
- Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
- selectorVector.append(WTFMove(innerSelector));
- selector->adoptSelectorVector(selectorVector);
- return selector;
- }
- case CSSSelector::PseudoClassNthChild:
- case CSSSelector::PseudoClassNthLastChild:
- case CSSSelector::PseudoClassNthOfType:
- case CSSSelector::PseudoClassNthLastOfType: {
- std::pair<int, int> ab;
- if (!consumeANPlusB(block, ab))
- return nullptr;
- block.consumeWhitespace();
- if (!block.atEnd())
- return nullptr;
- selector->setArgument(AtomicString::number(ab.first * ab.second));
- return selector;
- }
- case CSSSelector::PseudoClassLang: {
- // FIXME: CSS Selectors Level 4 allows :lang(*-foo)
- const CSSParserToken& ident = block.consumeIncludingWhitespace();
- if (ident.type() != IdentToken || !block.atEnd())
- return nullptr;
- selector->setArgument(ident.value().toAtomicString());
- return selector;
- }
- // FIXME-NEWPARSER: Support :host-context
- case CSSSelector::PseudoClassAny:
- case CSSSelector::PseudoClassHost: {
- DisallowPseudoElementsScope scope(this);
- std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
- *selectorList = consumeCompoundSelectorList(block);
- if (!selectorList->isValid() || !block.atEnd())
- return nullptr;
- selector->setSelectorList(WTFMove(selectorList));
- return selector;
- }
- default:
- break;
- }
</del><ins>+ if (selector->match() == CSSSelector::PseudoClass) {
+ switch (selector->pseudoClassType()) {
+ case CSSSelector::PseudoClassNot: {
+ DisallowPseudoElementsScope scope(this);
+ std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+ *selectorList = consumeComplexSelectorList(block);
+ if (!selectorList->componentCount() || !block.atEnd())
+ return nullptr;
+ selector->setSelectorList(WTFMove(selectorList));
+ return selector;
+ }
+ case CSSSelector::PseudoClassNthChild:
+ case CSSSelector::PseudoClassNthLastChild:
+ case CSSSelector::PseudoClassNthOfType:
+ case CSSSelector::PseudoClassNthLastOfType: {
+ std::pair<int, int> ab;
+ if (!consumeANPlusB(block, ab))
+ return nullptr;
+ block.consumeWhitespace();
+ if (!block.atEnd()) {
+ if (block.peek().type() != IdentToken)
+ return nullptr;
+ const CSSParserToken& ident = block.consume();
+ if (!equalIgnoringASCIICase(ident.value(), "of"))
+ return nullptr;
+ DisallowPseudoElementsScope scope(this);
+ block.consumeWhitespace();
+ std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+ *selectorList = consumeComplexSelectorList(block);
+ if (!selectorList->componentCount() || !block.atEnd())
+ return nullptr;
+ selector->setSelectorList(WTFMove(selectorList));
+ }
+ selector->setNth(ab.first, ab.second);
+ return selector;
+ }
+ case CSSSelector::PseudoClassLang: {
+ // FIXME: CSS Selectors Level 4 allows :lang(*-foo)
+ auto argumentList = std::make_unique<Vector<AtomicString>>();
+ if (!consumeLangArgumentList(argumentList, block))
+ return nullptr;
+ selector->setLangArgumentList(WTFMove(argumentList));
+ return selector;
+ }
+ case CSSSelector::PseudoClassMatches: {
+ std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+ *selectorList = consumeComplexSelectorList(block);
+ if (!selectorList->componentCount() || !block.atEnd())
+ return nullptr;
+ selector->setSelectorList(WTFMove(selectorList));
+ return selector;
+ }
+ // FIXME-NEWPARSER: Support :host-context
+ case CSSSelector::PseudoClassAny:
+ case CSSSelector::PseudoClassHost: {
+ DisallowPseudoElementsScope scope(this);
+ std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+ *selectorList = consumeCompoundSelectorList(block);
+ if (!selectorList->componentCount() || !block.atEnd())
+ return nullptr;
+ selector->setSelectorList(WTFMove(selectorList));
+ return selector;
+ }
+#if ENABLE_CSS_SELECTORS_LEVEL4
+ case CSSSelector::PseudoClassDir:
+ case CSSSelector::PseudoClassRole: {
+ const CSSParserToken& ident = block.consumeIncludingWhitespace();
+ if (ident.type() != IdentToken)
+ return nullptr;
+ selector->setArgument(ident.value().toAtomicString());
+ return selector;
+ }
+#endif
+ default:
+ break;
+ }
</ins><span class="cx">
</span><del>- switch (selector->pseudoElementType()) {
- case CSSSelector::PseudoElementCue: {
- DisallowPseudoElementsScope scope(this);
- std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
- *selectorList = consumeCompoundSelectorList(block);
- if (!selectorList->isValid() || !block.atEnd())
- return nullptr;
- selector->setSelectorList(WTFMove(selectorList));
- return selector;
</del><span class="cx"> }
</span><del>- case CSSSelector::PseudoElementSlotted: {
- DisallowPseudoElementsScope scope(this);
</del><ins>+
+ if (selector->match() == CSSSelector::PseudoElement) {
+ switch (selector->pseudoElementType()) {
+ case CSSSelector::PseudoElementCue: {
+ DisallowPseudoElementsScope scope(this);
+ std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+ *selectorList = consumeCompoundSelectorList(block);
+ if (!selectorList->isValid() || !block.atEnd())
+ return nullptr;
+ selector->setSelectorList(WTFMove(selectorList));
+ return selector;
+ }
+ case CSSSelector::PseudoElementSlotted: {
+ DisallowPseudoElementsScope scope(this);
</ins><span class="cx">
</span><del>- std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
- block.consumeWhitespace();
- if (!innerSelector || !block.atEnd())
- return nullptr;
- Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
- selectorVector.append(WTFMove(innerSelector));
- selector->adoptSelectorVector(selectorVector);
- return selector;
</del><ins>+ std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
+ block.consumeWhitespace();
+ if (!innerSelector || !block.atEnd())
+ return nullptr;
+ Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
+ selectorVector.append(WTFMove(innerSelector));
+ selector->adoptSelectorVector(selectorVector);
+ return selector;
+ }
+ default:
+ break;
+ }
</ins><span class="cx"> }
</span><del>- default:
- break;
- }
</del><span class="cx">
</span><span class="cx"> return nullptr;
</span><span class="cx"> }
</span><span class="lines">@@ -564,6 +652,13 @@
</span><span class="cx"> return CSSSelector::DirectAdjacent;
</span><span class="cx"> if (delimiter == '~')
</span><span class="cx"> return CSSSelector::IndirectAdjacent;
</span><ins>+#if ENABLE_CSS_SELECTORS_LEVEL4
+ // FIXME-NEWPARSER: Need to set that this was a >> so serialization is correct
+ if (delimiter == '>' && range.peek().type() == DelimiterToken && range.peek().delimiter() == '>') {
+ range.consumeIncludingWhitespace();
+ return CSSSelector::Descendant;
+ }
+#endif
</ins><span class="cx"> return CSSSelector::Child;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>