Title: [170001] trunk
Revision
170001
Author
[email protected]
Date
2014-06-15 23:54:08 -0700 (Sun, 15 Jun 2014)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (170000 => 170001)


--- trunk/LayoutTests/ChangeLog	2014-06-16 04:09:25 UTC (rev 170000)
+++ trunk/LayoutTests/ChangeLog	2014-06-16 06:54:08 UTC (rev 170001)
@@ -1,3 +1,19 @@
+2014-06-15  Benjamin Poulain  <[email protected]>
+
+        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.
+
 2014-06-14  Simon Fraser  <[email protected]>
 
         Masks disappear when layers become tiled

Added: trunk/LayoutTests/fast/selectors/lang-conflict-expected.txt (0 => 170001)


--- 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)
@@ -0,0 +1,12 @@
+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
+

Added: trunk/LayoutTests/fast/selectors/lang-conflict.html (0 => 170001)


--- 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)
@@ -0,0 +1,35 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<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=""
+</html>

Added: trunk/LayoutTests/fast/selectors/lang-empty-expected.txt (0 => 170001)


--- 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)
@@ -0,0 +1,12 @@
+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
+

Added: trunk/LayoutTests/fast/selectors/lang-empty.html (0 => 170001)


--- 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)
@@ -0,0 +1,35 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<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=""
+</html>

Added: trunk/LayoutTests/fast/selectors/lang-specificity-expected.txt (0 => 170001)


--- 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)
@@ -0,0 +1,16 @@
+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
+

Added: trunk/LayoutTests/fast/selectors/lang-specificity-xml-expected.txt (0 => 170001)


--- 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)
@@ -0,0 +1,30 @@
+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
+

Added: trunk/LayoutTests/fast/selectors/lang-specificity-xml.xhtml (0 => 170001)


--- 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)
@@ -0,0 +1,134 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script src=""
+<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=""
+</html>

Added: trunk/LayoutTests/fast/selectors/lang-specificity.html (0 => 170001)


--- 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)
@@ -0,0 +1,48 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<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=""
+</html>

Modified: trunk/Source/WebCore/ChangeLog (170000 => 170001)


--- 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)
@@ -1,3 +1,35 @@
+2014-06-15  Benjamin Poulain  <[email protected]>
+
+        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:
+
 2014-06-15  Anders Carlsson  <[email protected]>
 
         Add an autorelease() member function to RetainPtr

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (170000 => 170001)


--- 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)
@@ -740,19 +740,10 @@
             break;
         case CSSSelector::PseudoClassLang:
             {
-                AtomicString value;
-#if ENABLE(VIDEO_TRACK)
-                if (element->isWebVTTElement())
-                    value = toWebVTTElement(element)->language();
-                else
-#endif
-                    value = element->computeInheritedLanguage();
                 const AtomicString& argument = selector->argument();
-                if (value.isEmpty() || !value.startsWith(argument, false))
-                    break;
-                if (value.length() != argument.length() && value[argument.length()] != '-')
-                    break;
-                return true;
+                if (argument.isNull())
+                    return false;
+                return matchesLangPseudoClass(element, argument.impl());
             }
 #if ENABLE(FULLSCREEN_API)
         case CSSSelector::PseudoClassFullScreen:

Modified: trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h (170000 => 170001)


--- 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)
@@ -99,6 +99,30 @@
     return element->willValidate() && element->isValidFormControlElement();
 }
 
+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;
+}
+
 ALWAYS_INLINE bool matchesReadOnlyPseudoClass(const Element* element)
 {
     return element->matchesReadOnlyPseudoClass();

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (170000 => 170001)


--- 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)
@@ -132,6 +132,7 @@
         , widthFromIndirectAdjacent(0)
         , tagName(nullptr)
         , id(nullptr)
+        , langFilter(nullptr)
         , onlyMatchesLinksInQuirksMode(true)
     {
     }
@@ -151,6 +152,7 @@
 
     const QualifiedName* tagName;
     const AtomicString* id;
+    const AtomicString* langFilter;
     Vector<const AtomicStringImpl*, 1> classNames;
     HashSet<unsigned> pseudoClasses;
     Vector<JSC::FunctionPtr> unoptimizedPseudoClasses;
@@ -226,6 +228,7 @@
     void generateElementIsActive(Assembler::JumpList& failureCases, const SelectorFragment&);
     void generateElementIsFirstChild(Assembler::JumpList& failureCases, const SelectorFragment&);
     void generateElementIsHovered(Assembler::JumpList& failureCases, const SelectorFragment&);
+    void generateElementIsInLanguage(Assembler::JumpList& failureCases, const AtomicString&);
     void generateElementIsLastChild(Assembler::JumpList& failureCases, const SelectorFragment&);
     void generateElementIsOnlyChild(Assembler::JumpList& failureCases, const SelectorFragment&);
     void generateSynchronizeStyleAttribute(Assembler::RegisterID elementDataArraySizeAndFlags);
@@ -492,7 +495,26 @@
 
             return functionType;
         }
+    case CSSSelector::PseudoClassLang:
+        {
+            const AtomicString& argument = selector.argument();
+            if (argument.isEmpty())
+                return FunctionType::CannotMatchAnything;
 
+            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;
+        }
+
     default:
         break;
     }
@@ -1747,6 +1769,8 @@
         generateElementMatchesNotPseudoClass(matchingPostTagNameFailureCases, fragment);
     if (!fragment.anyFilters.isEmpty())
         generateElementMatchesAnyPseudoClass(matchingPostTagNameFailureCases, fragment);
+    if (fragment.langFilter)
+        generateElementIsInLanguage(matchingPostTagNameFailureCases, *fragment.langFilter);
 }
 
 void SelectorCodeGenerator::generateElementDataMatching(Assembler::JumpList& failureCases, const SelectorFragment& fragment)
@@ -2309,6 +2333,18 @@
     }
 }
 
+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));
+}
+
 static void setLastChildState(Element* element)
 {
     if (RenderStyle* style = element->renderStyle())

Modified: trunk/Source/WebCore/dom/Element.cpp (170000 => 170001)


--- 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)
@@ -2207,27 +2207,26 @@
 
 AtomicString Element::computeInheritedLanguage() const
 {
-    const Node* n = this;
-    AtomicString value;
+    if (const ElementData* elementData = this->elementData()) {
+        if (const Attribute* attribute = elementData->findLanguageAttribute())
+            return attribute->value();
+    }
+
     // The language property is inherited, so we iterate over the parents to find the first language.
-    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();
+    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();
             }
-        } else if (n->isDocumentNode()) {
+        } else if (currentNode->isDocumentNode()) {
             // checking the MIME content-language
-            value = toDocument(n)->contentLanguage();
+            return toDocument(currentNode)->contentLanguage();
         }
+    }
 
-        n = n->parentNode();
-    } while (n && value.isNull());
-
-    return value;
+    return nullAtom;
 }
 
 Locale& Element::locale() const

Modified: trunk/Source/WebCore/dom/ElementData.cpp (170000 => 170001)


--- 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)
@@ -27,7 +27,9 @@
 #include "ElementData.h"
 
 #include "Attr.h"
+#include "HTMLNames.h"
 #include "StyleProperties.h"
+#include "XMLNames.h"
 
 namespace WebCore {
 
@@ -218,5 +220,24 @@
     return nullptr;
 }
 
+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;
 }
 
+}
+

Modified: trunk/Source/WebCore/dom/ElementData.h (170000 => 170001)


--- 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)
@@ -105,6 +105,7 @@
     unsigned findAttributeIndexByName(const QualifiedName&) const;
     unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
     unsigned findAttributeIndexByNameForAttributeNode(const Attr*, bool shouldIgnoreAttributeCase = false) const;
+    const Attribute* findLanguageAttribute() const;
 
     bool hasID() const { return !m_idForStyleResolution.isNull(); }
     bool hasClass() const { return !m_classNames.isEmpty(); }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to