<!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>[170001] 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/170001">170001</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-06-15 23:54:08 -0700 (Sun, 15 Jun 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>CSS JIT: add support for the :lang() pseudo class
https://bugs.webkit.org/show_bug.cgi?id=133913
Reviewed by Andreas Kling.
Source/WebCore:
The selector is already very expensive to begin with, just implement it with
a function call.
It is also done after every other filter since it is so inefficient.
Tests: fast/selectors/lang-conflict.html
fast/selectors/lang-empty.html
fast/selectors/lang-specificity-xml.xhtml
fast/selectors/lang-specificity.html
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* css/SelectorCheckerTestFunctions.h:
(WebCore::matchesLangPseudoClass):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::SelectorFragment::SelectorFragment):
(WebCore::SelectorCompiler::addPseudoClassType):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsInLanguage):
* dom/Element.cpp:
(WebCore::Element::computeInheritedLanguage):
* dom/ElementData.cpp:
(WebCore::ElementData::findLanguageAttribute):
* dom/ElementData.h:
LayoutTests:
* fast/selectors/lang-conflict-expected.txt: Added.
* fast/selectors/lang-conflict.html: Added.
* fast/selectors/lang-empty-expected.txt: Added.
* fast/selectors/lang-empty.html: Added.
* fast/selectors/lang-specificity-expected.txt: Added.
* fast/selectors/lang-specificity-xml-expected.txt: Added.
* fast/selectors/lang-specificity-xml.xhtml: Added.
* fast/selectors/lang-specificity.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="#trunkSourceWebCorecssSelectorCheckercpp">trunk/Source/WebCore/css/SelectorChecker.cpp</a></li>
<li><a href="#trunkSourceWebCorecssSelectorCheckerTestFunctionsh">trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h</a></li>
<li><a href="#trunkSourceWebCorecssjitSelectorCompilercpp">trunk/Source/WebCore/cssjit/SelectorCompiler.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementDatacpp">trunk/Source/WebCore/dom/ElementData.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementDatah">trunk/Source/WebCore/dom/ElementData.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastselectorslangconflictexpectedtxt">trunk/LayoutTests/fast/selectors/lang-conflict-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangconflicthtml">trunk/LayoutTests/fast/selectors/lang-conflict.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangemptyexpectedtxt">trunk/LayoutTests/fast/selectors/lang-empty-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangemptyhtml">trunk/LayoutTests/fast/selectors/lang-empty.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangspecificityexpectedtxt">trunk/LayoutTests/fast/selectors/lang-specificity-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangspecificityxmlexpectedtxt">trunk/LayoutTests/fast/selectors/lang-specificity-xml-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangspecificityxmlxhtml">trunk/LayoutTests/fast/selectors/lang-specificity-xml.xhtml</a></li>
<li><a href="#trunkLayoutTestsfastselectorslangspecificityhtml">trunk/LayoutTests/fast/selectors/lang-specificity.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/LayoutTests/ChangeLog        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-06-15 Benjamin Poulain <benjamin@webkit.org>
+
+ CSS JIT: add support for the :lang() pseudo class
+ https://bugs.webkit.org/show_bug.cgi?id=133913
+
+ Reviewed by Andreas Kling.
+
+ * fast/selectors/lang-conflict-expected.txt: Added.
+ * fast/selectors/lang-conflict.html: Added.
+ * fast/selectors/lang-empty-expected.txt: Added.
+ * fast/selectors/lang-empty.html: Added.
+ * fast/selectors/lang-specificity-expected.txt: Added.
+ * fast/selectors/lang-specificity-xml-expected.txt: Added.
+ * fast/selectors/lang-specificity-xml.xhtml: Added.
+ * fast/selectors/lang-specificity.html: Added.
+
</ins><span class="cx"> 2014-06-14 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Masks disappear when layers become tiled
</span></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangconflictexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-conflict-expected.txt (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-conflict-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-conflict-expected.txt        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+Verify selectors with conflicting :lang().
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.querySelectorAll(":lang(fr):lang(en)").length is 0
+PASS document.querySelectorAll(":lang(en):lang(fr)").length is 0
+PASS getComputedStyle(document.getElementById("target")).color is "rgb(0, 0, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangconflicthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-conflict.html (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-conflict.html         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-conflict.html        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+<!doctype html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<style>
+* {
+ color: rgb(0, 0, 0);
+}
+:lang(fr):lang(en) {
+ color: rgb(1, 2, 3);
+}
+
+:lang(en):lang(fr) {
+ color: rgb(4, 5, 6);
+}
+</style>
+</head>
+<body>
+ <div style="display:none">
+ <a>
+ <b>
+ <c id="target"></c>
+ </b>
+ </a>
+ </div>
+</body>
+<script>
+description('Verify selectors with conflicting :lang().');
+
+shouldBe('document.querySelectorAll(":lang(fr):lang(en)").length', '0');
+shouldBe('document.querySelectorAll(":lang(en):lang(fr)").length', '0');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target")).color', 'rgb(0, 0, 0)');
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangemptyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-empty-expected.txt (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-empty-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-empty-expected.txt        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+Verify empty :lang() selectors.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.querySelectorAll(":lang()").length threw exception Error: SyntaxError: DOM Exception 12.
+PASS document.querySelectorAll(":lang() *").length threw exception Error: SyntaxError: DOM Exception 12.
+PASS getComputedStyle(document.getElementById("target1")).color is "rgb(0, 0, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangemptyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-empty.html (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-empty.html         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-empty.html        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+<!doctype html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<style>
+* {
+ color: rgb(0, 0, 0);
+}
+:lang() {
+ color: rgb(1, 2, 3);
+}
+
+:lang() * {
+ color: rgb(4, 5, 6);
+}
+</style>
+</head>
+<body>
+ <div style="display:none">
+ <a>
+ <b>
+ <c id="target1"></c>
+ </b>
+ </a>
+ </div>
+</body>
+<script>
+description('Verify empty :lang() selectors.');
+
+shouldThrow('document.querySelectorAll(":lang()").length');
+shouldThrow('document.querySelectorAll(":lang() *").length');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target1")).color', 'rgb(0, 0, 0)');
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangspecificityexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-specificity-expected.txt (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-specificity-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-specificity-expected.txt        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+Verify selector specifying multiple :lang() pseudo class.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+HTML lang only
+PASS document.querySelectorAll(":lang(fr):lang(fr-be):lang(fr) #target1").length is 1
+PASS getComputedStyle(document.getElementById("target1")).color is "rgb(1, 2, 3)"
+PASS document.querySelectorAll(":lang(fr):lang(fr-ca) #target2").length is 1
+PASS getComputedStyle(document.getElementById("target2")).color is "rgb(4, 5, 6)"
+PASS document.querySelectorAll(":lang(fr):lang(fr-ch) #target3").length is 1
+PASS getComputedStyle(document.getElementById("target3")).color is "rgb(7, 8, 9)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangspecificityxmlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-specificity-xml-expected.txt (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-specificity-xml-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-specificity-xml-expected.txt        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,30 @@
</span><ins>+Verify selector specifying multiple :lang() pseudo class.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+HTML lang only
+PASS document.querySelectorAll(":lang(fr):lang(fr-be):lang(fr) #target1").length is 1
+PASS getComputedStyle(document.getElementById("target1")).color is "rgb(1, 2, 3)"
+PASS document.querySelectorAll(":lang(fr):lang(fr-ca) #target2").length is 1
+PASS getComputedStyle(document.getElementById("target2")).color is "rgb(4, 5, 6)"
+PASS document.querySelectorAll(":lang(fr):lang(fr-ch) #target3").length is 1
+PASS getComputedStyle(document.getElementById("target3")).color is "rgb(7, 8, 9)"
+XML lang only
+PASS document.querySelectorAll(":lang(es):lang(es-ar):lang(es) #target4").length is 1
+PASS getComputedStyle(document.getElementById("target4")).color is "rgb(10, 11, 12)"
+PASS document.querySelectorAll(":lang(es):lang(es-co) #target5").length is 1
+PASS getComputedStyle(document.getElementById("target5")).color is "rgb(13, 14, 15)"
+PASS document.querySelectorAll(":lang(es):lang(es-mx) #target6").length is 1
+PASS getComputedStyle(document.getElementById("target6")).color is "rgb(16, 17, 18)"
+XML and HTML lang
+PASS document.querySelectorAll(":lang(xml):lang(xml-lang1):lang(xml) #target7").length is 1
+PASS getComputedStyle(document.getElementById("target7")).color is "rgb(19, 20, 21)"
+PASS document.querySelectorAll(":lang(xml):lang(xml-lang2) #target8").length is 1
+PASS getComputedStyle(document.getElementById("target8")).color is "rgb(22, 23, 24)"
+PASS document.querySelectorAll(":lang(xml):lang(xml-lang3) #target9").length is 1
+PASS getComputedStyle(document.getElementById("target9")).color is "rgb(25, 26, 27)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangspecificityxmlxhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-specificity-xml.xhtml (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-specificity-xml.xhtml         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-specificity-xml.xhtml        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,134 @@
</span><ins>+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<style>
+[style="display:none"] * {
+ color: rgb(0, 0, 0);
+ background-color: rgb(0, 0, 0);
+}
+:lang(fr):lang(fr-be):lang(fr) #target1 {
+ color: rgb(1, 2, 3);
+}
+:lang(fr):lang(fr-ca) #target2 {
+ color: rgb(4, 5, 6);
+}
+:lang(fr-ch):lang(fr) #target3 {
+ color: rgb(7, 8, 9);
+}
+
+:lang(es):lang(es-ar):lang(es) #target4 {
+ color: rgb(10, 11, 12);
+}
+:lang(es):lang(es-co) #target5 {
+ color: rgb(13, 14, 15);
+}
+:lang(es-mx):lang(es) #target6 {
+ color: rgb(16, 17, 18);
+}
+
+:lang(xml):lang(xml-lang1):lang(xml) #target7 {
+ color: rgb(19, 20, 21);
+}
+:lang(xml):lang(xml-lang2) #target8 {
+ color: rgb(22, 23, 24);
+}
+:lang(xml-lang3):lang(xml) #target9 {
+ color: rgb(25, 26, 27);
+}
+
+/* None of those should match. */
+:lang(html):lang(html-lang):lang(html) * {
+ background-color: rgb(1, 1, 1);
+}
+:lang(html):lang(html-lang) * {
+ background-color: rgb(1, 1, 1);
+}
+:lang(html-lang):lang(html) * {
+ background-color: rgb(1, 1, 1);
+}
+</style>
+</head>
+<body>
+ <div style="display:none">
+ <!-- HTML lang cases. -->
+ <a lang="FR-BE">
+ <b>
+ <c id="target1"></c>
+ </b>
+ </a>
+ <a lang="FR-CA">
+ <b>
+ <c id="target2"></c>
+ </b>
+ </a>
+ <a lang="FR-CH">
+ <b>
+ <c id="target3"></c>
+ </b>
+ </a>
+
+ <!-- XML lang cases. -->
+ <a xml:lang="es-ar">
+ <b>
+ <c id="target4"></c>
+ </b>
+ </a>
+ <a xml:lang="es-co">
+ <b>
+ <c id="target5"></c>
+ </b>
+ </a>
+ <a xml:lang="es-mx">
+ <b>
+ <c id="target6"></c>
+ </b>
+ </a>
+
+ <!-- XML + HTML lang cases. -->
+ <a xml:lang="xml-lang1" lang="html-lang">
+ <b>
+ <c id="target7"></c>
+ </b>
+ </a>
+ <a xml:lang="xml-lang2" lang="html-lang">
+ <b>
+ <c id="target8"></c>
+ </b>
+ </a>
+ <a xml:lang="xml-lang3" lang="html-lang">
+ <b>
+ <c id="target9"></c>
+ </b>
+ </a>
+ </div>
+</body>
+<script>
+description('Verify selector specifying multiple :lang() pseudo class.');
+
+debug("HTML lang only")
+shouldBe('document.querySelectorAll(":lang(fr):lang(fr-be):lang(fr) #target1").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target1")).color', 'rgb(1, 2, 3)');
+shouldBe('document.querySelectorAll(":lang(fr):lang(fr-ca) #target2").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target2")).color', 'rgb(4, 5, 6)');
+shouldBe('document.querySelectorAll(":lang(fr):lang(fr-ch) #target3").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target3")).color', 'rgb(7, 8, 9)');
+
+debug("XML lang only")
+shouldBe('document.querySelectorAll(":lang(es):lang(es-ar):lang(es) #target4").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target4")).color', 'rgb(10, 11, 12)');
+shouldBe('document.querySelectorAll(":lang(es):lang(es-co) #target5").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target5")).color', 'rgb(13, 14, 15)');
+shouldBe('document.querySelectorAll(":lang(es):lang(es-mx) #target6").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target6")).color', 'rgb(16, 17, 18)');
+
+debug("XML and HTML lang")
+shouldBe('document.querySelectorAll(":lang(xml):lang(xml-lang1):lang(xml) #target7").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target7")).color', 'rgb(19, 20, 21)');
+shouldBe('document.querySelectorAll(":lang(xml):lang(xml-lang2) #target8").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target8")).color', 'rgb(22, 23, 24)');
+shouldBe('document.querySelectorAll(":lang(xml):lang(xml-lang3) #target9").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target9")).color', 'rgb(25, 26, 27)');
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorslangspecificityhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/lang-specificity.html (0 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/lang-specificity.html         (rev 0)
+++ trunk/LayoutTests/fast/selectors/lang-specificity.html        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+<!doctype html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<style>
+:lang(fr):lang(fr-be):lang(fr) #target1 {
+ color: rgb(1, 2, 3);
+}
+:lang(fr):lang(fr-ca) #target2 {
+ color: rgb(4, 5, 6);
+}
+:lang(fr-ch):lang(fr) #target3 {
+ color: rgb(7, 8, 9);
+}
+</style>
+</head>
+<body>
+ <div style="display:none">
+ <a lang="FR-BE">
+ <b>
+ <c id="target1"></c>
+ </b>
+ </a>
+ <a lang="FR-CA">
+ <b>
+ <c id="target2"></c>
+ </b>
+ </a>
+ <a lang="FR-CH">
+ <b>
+ <c id="target3"></c>
+ </b>
+ </a>
+ </div>
+</body>
+<script>
+description('Verify selector specifying multiple :lang() pseudo class.');
+
+debug("HTML lang only")
+shouldBe('document.querySelectorAll(":lang(fr):lang(fr-be):lang(fr) #target1").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target1")).color', 'rgb(1, 2, 3)');
+shouldBe('document.querySelectorAll(":lang(fr):lang(fr-ca) #target2").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target2")).color', 'rgb(4, 5, 6)');
+shouldBe('document.querySelectorAll(":lang(fr):lang(fr-ch) #target3").length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById("target3")).color', 'rgb(7, 8, 9)');
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/ChangeLog        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2014-06-15 Benjamin Poulain <benjamin@webkit.org>
+
+ CSS JIT: add support for the :lang() pseudo class
+ https://bugs.webkit.org/show_bug.cgi?id=133913
+
+ Reviewed by Andreas Kling.
+
+ The selector is already very expensive to begin with, just implement it with
+ a function call.
+
+ It is also done after every other filter since it is so inefficient.
+
+ Tests: fast/selectors/lang-conflict.html
+ fast/selectors/lang-empty.html
+ fast/selectors/lang-specificity-xml.xhtml
+ fast/selectors/lang-specificity.html
+
+ * css/SelectorChecker.cpp:
+ (WebCore::SelectorChecker::checkOne):
+ * css/SelectorCheckerTestFunctions.h:
+ (WebCore::matchesLangPseudoClass):
+ * cssjit/SelectorCompiler.cpp:
+ (WebCore::SelectorCompiler::SelectorFragment::SelectorFragment):
+ (WebCore::SelectorCompiler::addPseudoClassType):
+ (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
+ (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsInLanguage):
+ * dom/Element.cpp:
+ (WebCore::Element::computeInheritedLanguage):
+ * dom/ElementData.cpp:
+ (WebCore::ElementData::findLanguageAttribute):
+ * dom/ElementData.h:
+
</ins><span class="cx"> 2014-06-15 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Add an autorelease() member function to RetainPtr
</span></span></pre></div>
<a id="trunkSourceWebCorecssSelectorCheckercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/SelectorChecker.cpp        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -740,19 +740,10 @@
</span><span class="cx"> break;
</span><span class="cx"> case CSSSelector::PseudoClassLang:
</span><span class="cx"> {
</span><del>- AtomicString value;
-#if ENABLE(VIDEO_TRACK)
- if (element->isWebVTTElement())
- value = toWebVTTElement(element)->language();
- else
-#endif
- value = element->computeInheritedLanguage();
</del><span class="cx"> const AtomicString& argument = selector->argument();
</span><del>- if (value.isEmpty() || !value.startsWith(argument, false))
- break;
- if (value.length() != argument.length() && value[argument.length()] != '-')
- break;
- return true;
</del><ins>+ if (argument.isNull())
+ return false;
+ return matchesLangPseudoClass(element, argument.impl());
</ins><span class="cx"> }
</span><span class="cx"> #if ENABLE(FULLSCREEN_API)
</span><span class="cx"> case CSSSelector::PseudoClassFullScreen:
</span></span></pre></div>
<a id="trunkSourceWebCorecssSelectorCheckerTestFunctionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -99,6 +99,30 @@
</span><span class="cx"> return element->willValidate() && element->isValidFormControlElement();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+inline bool matchesLangPseudoClass(const Element* element, AtomicStringImpl* filter)
+{
+ AtomicString value;
+#if ENABLE(VIDEO_TRACK)
+ if (element->isWebVTTElement())
+ value = toWebVTTElement(element)->language();
+ else
+#endif
+ value = element->computeInheritedLanguage();
+
+ if (value.isNull())
+ return false;
+
+ if (value.impl() == filter)
+ return true;
+
+ if (value.impl()->startsWith(filter, false)) {
+ if (value.length() == filter->length())
+ return true;
+ return value[filter->length()] == '-';
+ }
+ return false;
+}
+
</ins><span class="cx"> ALWAYS_INLINE bool matchesReadOnlyPseudoClass(const Element* element)
</span><span class="cx"> {
</span><span class="cx"> return element->matchesReadOnlyPseudoClass();
</span></span></pre></div>
<a id="trunkSourceWebCorecssjitSelectorCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -132,6 +132,7 @@
</span><span class="cx"> , widthFromIndirectAdjacent(0)
</span><span class="cx"> , tagName(nullptr)
</span><span class="cx"> , id(nullptr)
</span><ins>+ , langFilter(nullptr)
</ins><span class="cx"> , onlyMatchesLinksInQuirksMode(true)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -151,6 +152,7 @@
</span><span class="cx">
</span><span class="cx"> const QualifiedName* tagName;
</span><span class="cx"> const AtomicString* id;
</span><ins>+ const AtomicString* langFilter;
</ins><span class="cx"> Vector<const AtomicStringImpl*, 1> classNames;
</span><span class="cx"> HashSet<unsigned> pseudoClasses;
</span><span class="cx"> Vector<JSC::FunctionPtr> unoptimizedPseudoClasses;
</span><span class="lines">@@ -226,6 +228,7 @@
</span><span class="cx"> void generateElementIsActive(Assembler::JumpList& failureCases, const SelectorFragment&);
</span><span class="cx"> void generateElementIsFirstChild(Assembler::JumpList& failureCases, const SelectorFragment&);
</span><span class="cx"> void generateElementIsHovered(Assembler::JumpList& failureCases, const SelectorFragment&);
</span><ins>+ void generateElementIsInLanguage(Assembler::JumpList& failureCases, const AtomicString&);
</ins><span class="cx"> void generateElementIsLastChild(Assembler::JumpList& failureCases, const SelectorFragment&);
</span><span class="cx"> void generateElementIsOnlyChild(Assembler::JumpList& failureCases, const SelectorFragment&);
</span><span class="cx"> void generateSynchronizeStyleAttribute(Assembler::RegisterID elementDataArraySizeAndFlags);
</span><span class="lines">@@ -492,7 +495,26 @@
</span><span class="cx">
</span><span class="cx"> return functionType;
</span><span class="cx"> }
</span><ins>+ case CSSSelector::PseudoClassLang:
+ {
+ const AtomicString& argument = selector.argument();
+ if (argument.isEmpty())
+ return FunctionType::CannotMatchAnything;
</ins><span class="cx">
</span><ins>+ if (!fragment.langFilter)
+ fragment.langFilter = &argument;
+ else if (*fragment.langFilter != argument) {
+ // If there are multiple definition, we only care about the most restrictive one.
+ if (argument.startsWith(*fragment.langFilter, false))
+ fragment.langFilter = &argument;
+ else if (fragment.langFilter->startsWith(argument, false))
+ { } // The existing filter is more restrictive.
+ else
+ return FunctionType::CannotMatchAnything;
+ }
+ return FunctionType::SimpleSelectorChecker;
+ }
+
</ins><span class="cx"> default:
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="lines">@@ -1747,6 +1769,8 @@
</span><span class="cx"> generateElementMatchesNotPseudoClass(matchingPostTagNameFailureCases, fragment);
</span><span class="cx"> if (!fragment.anyFilters.isEmpty())
</span><span class="cx"> generateElementMatchesAnyPseudoClass(matchingPostTagNameFailureCases, fragment);
</span><ins>+ if (fragment.langFilter)
+ generateElementIsInLanguage(matchingPostTagNameFailureCases, *fragment.langFilter);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void SelectorCodeGenerator::generateElementDataMatching(Assembler::JumpList& failureCases, const SelectorFragment& fragment)
</span><span class="lines">@@ -2309,6 +2333,18 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void SelectorCodeGenerator::generateElementIsInLanguage(Assembler::JumpList& failureCases, const AtomicString& langFilter)
+{
+ LocalRegisterWithPreference langFilterRegister(m_registerAllocator, JSC::GPRInfo::argumentGPR1);
+ m_assembler.move(Assembler::TrustedImmPtr(langFilter.impl()), langFilterRegister);
+
+ Assembler::RegisterID elementAddress = elementAddressRegister;
+ FunctionCall functionCall(m_assembler, m_registerAllocator, m_stackAllocator, m_functionCalls);
+ functionCall.setFunctionAddress(matchesLangPseudoClass);
+ functionCall.setTwoArguments(elementAddress, langFilterRegister);
+ failureCases.append(functionCall.callAndBranchOnBooleanReturnValue(Assembler::Zero));
+}
+
</ins><span class="cx"> static void setLastChildState(Element* element)
</span><span class="cx"> {
</span><span class="cx"> if (RenderStyle* style = element->renderStyle())
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/dom/Element.cpp        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -2207,27 +2207,26 @@
</span><span class="cx">
</span><span class="cx"> AtomicString Element::computeInheritedLanguage() const
</span><span class="cx"> {
</span><del>- const Node* n = this;
- AtomicString value;
</del><ins>+ if (const ElementData* elementData = this->elementData()) {
+ if (const Attribute* attribute = elementData->findLanguageAttribute())
+ return attribute->value();
+ }
+
</ins><span class="cx"> // The language property is inherited, so we iterate over the parents to find the first language.
</span><del>- do {
- if (n->isElementNode()) {
- if (const ElementData* elementData = toElement(n)->elementData()) {
- // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7
- if (const Attribute* attribute = elementData->findAttributeByName(XMLNames::langAttr))
- value = attribute->value();
- else if (const Attribute* attribute = elementData->findAttributeByName(HTMLNames::langAttr))
- value = attribute->value();
</del><ins>+ const Node* currentNode = this;
+ while ((currentNode = currentNode->parentNode())) {
+ if (currentNode->isElementNode()) {
+ if (const ElementData* elementData = toElement(*currentNode).elementData()) {
+ if (const Attribute* attribute = elementData->findLanguageAttribute())
+ return attribute->value();
</ins><span class="cx"> }
</span><del>- } else if (n->isDocumentNode()) {
</del><ins>+ } else if (currentNode->isDocumentNode()) {
</ins><span class="cx"> // checking the MIME content-language
</span><del>- value = toDocument(n)->contentLanguage();
</del><ins>+ return toDocument(currentNode)->contentLanguage();
</ins><span class="cx"> }
</span><ins>+ }
</ins><span class="cx">
</span><del>- n = n->parentNode();
- } while (n && value.isNull());
-
- return value;
</del><ins>+ return nullAtom;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> Locale& Element::locale() const
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ElementData.cpp (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ElementData.cpp        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/dom/ElementData.cpp        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -27,7 +27,9 @@
</span><span class="cx"> #include "ElementData.h"
</span><span class="cx">
</span><span class="cx"> #include "Attr.h"
</span><ins>+#include "HTMLNames.h"
</ins><span class="cx"> #include "StyleProperties.h"
</span><ins>+#include "XMLNames.h"
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="lines">@@ -218,5 +220,24 @@
</span><span class="cx"> return nullptr;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+const Attribute* ElementData::findLanguageAttribute() const
+{
+ ASSERT(XMLNames::langAttr.localName() == HTMLNames::langAttr.localName());
+
+ const Attribute* attributes = attributeBase();
+ // Spec: xml:lang takes precedence over html:lang -- http://www.w3.org/TR/xhtml1/#C_7
+ const Attribute* languageAttribute = nullptr;
+ for (unsigned i = 0, count = length(); i < count; ++i) {
+ const QualifiedName& name = attributes[i].name();
+ if (name.localName() != HTMLNames::langAttr.localName())
+ continue;
+ if (name.namespaceURI() == XMLNames::langAttr.namespaceURI())
+ return &attributes[i];
+ if (name.namespaceURI() == HTMLNames::langAttr.namespaceURI())
+ languageAttribute = &attributes[i];
+ }
+ return languageAttribute;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+}
+
</ins></span></pre></div>
<a id="trunkSourceWebCoredomElementDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ElementData.h (170000 => 170001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ElementData.h        2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/Source/WebCore/dom/ElementData.h        2014-06-16 06:54:08 UTC (rev 170001)
</span><span class="lines">@@ -105,6 +105,7 @@
</span><span class="cx"> unsigned findAttributeIndexByName(const QualifiedName&) const;
</span><span class="cx"> unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
</span><span class="cx"> unsigned findAttributeIndexByNameForAttributeNode(const Attr*, bool shouldIgnoreAttributeCase = false) const;
</span><ins>+ const Attribute* findLanguageAttribute() const;
</ins><span class="cx">
</span><span class="cx"> bool hasID() const { return !m_idForStyleResolution.isNull(); }
</span><span class="cx"> bool hasClass() const { return !m_classNames.isEmpty(); }
</span></span></pre>
</div>
</div>
</body>
</html>