Title: [113710] trunk
Revision
113710
Author
[email protected]
Date
2012-04-10 05:34:25 -0700 (Tue, 10 Apr 2012)

Log Message

getElementsByTagName unable to find SVG camelCase elements imported into HTML
https://bugs.webkit.org/show_bug.cgi?id=46800

Reviewed by Nikolas Zimmermann.

Source/WebCore:

Implement getElementsByTagName according to the algorithm in
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagname.
If the owner document of the element is html, the new class HTMLTagNodeList deals with
finding the match(es) based on this algorithm. If the owner document is non HTML, the existing
TagNodeList is used.

Implement getElementsByTagNameNS according to the algorithm in
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagnamens.
The existing TagNodeList implements this algorithm.

Cached results may have less hits after this change. Tag names that are equal when case
insensitive but different when case sensitive can't share the result due to above algorithms, i.e.
they would match differently in the non html part of the document.

Tests: fast/dom/getElementsByTagName-localName-matching.html
       fast/dom/getElementsByTagName-localName-matching2.xhtml
       svg/dom/getElementsByTagName-localName-matching.html

* dom/Node.cpp:
(WebCore::Node::getElementsByTagName): create TagNodeList depending on owner document type.
(WebCore::Node::getElementsByTagNameNS): do not lowercase localName for html.
* dom/TagNodeList.cpp:
(WebCore::HTMLTagNodeList::HTMLTagNodeList): add specialized TagNodeList for html matching rules.
(WebCore):
(WebCore::HTMLTagNodeList::nodeMatches):
* dom/TagNodeList.h:
(TagNodeList):
(HTMLTagNodeList):
(WebCore::HTMLTagNodeList::create):

LayoutTests:

Add tests for getElementsByTagName(NS) in html, xhtml, and svg documents.

* fast/dom/getElementsByTagName-localName-matching-expected.txt: Added.
* fast/dom/getElementsByTagName-localName-matching.html: Added.
* fast/dom/getElementsByTagName-localName-matching2-expected.txt: Added.
* fast/dom/getElementsByTagName-localName-matching2.xhtml: Added.
* svg/dom/getElementsByTagName-localName-matching-expected.txt: Added.
* svg/dom/getElementsByTagName-localName-matching.html: Added.
* svg/dom/script-tests/getElementsByTagName-localName-matching.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (113709 => 113710)


--- trunk/LayoutTests/ChangeLog	2012-04-10 12:29:15 UTC (rev 113709)
+++ trunk/LayoutTests/ChangeLog	2012-04-10 12:34:25 UTC (rev 113710)
@@ -1,3 +1,20 @@
+2012-04-10  Rob Buis  <[email protected]>
+
+        getElementsByTagName unable to find SVG camelCase elements imported into HTML
+        https://bugs.webkit.org/show_bug.cgi?id=46800
+
+        Reviewed by Nikolas Zimmermann.
+
+        Add tests for getElementsByTagName(NS) in html, xhtml, and svg documents.
+
+        * fast/dom/getElementsByTagName-localName-matching-expected.txt: Added.
+        * fast/dom/getElementsByTagName-localName-matching.html: Added.
+        * fast/dom/getElementsByTagName-localName-matching2-expected.txt: Added.
+        * fast/dom/getElementsByTagName-localName-matching2.xhtml: Added.
+        * svg/dom/getElementsByTagName-localName-matching-expected.txt: Added.
+        * svg/dom/getElementsByTagName-localName-matching.html: Added.
+        * svg/dom/script-tests/getElementsByTagName-localName-matching.js: Added.
+
 2012-04-09  Alexander Pavlov  <[email protected]>
 
         Web Inspector: [Device Metrics] Introduce the "Fit window" option

Added: trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching-expected.txt (0 => 113710)


--- trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching-expected.txt	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,25 @@
+PASS container.getElementsByTagName('linearGradient').length is 2
+PASS container.getElementsByTagName('lineargradient').length is 1
+PASS container.getElementsByTagName('LINEARGRADIENT').length is 1
+PASS container.getElementsByTagName('FOO').length is 2
+PASS container.getElementsByTagName('foo').length is 2
+PASS container.getElementsByTagName('Foo').length is 2
+PASS container.getElementsByTagName('img').length is 2
+PASS container.getElementsByTagName('IMG').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length is 2
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length is 0
+

Added: trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching.html (0 => 113710)


--- trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching.html	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,46 @@
+<!doctype html>
+<head>
+    <script src=""
+</head>
+<body>
+<div id="container"><FOO><foo><linearGradient/></foo></FOO><img/></div>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var container = document.getElementById('container');
+var svgdoc = new DOMParser().parseFromString(
+	'<svg xmlns="http://www.w3.org/2000/svg"><linearGradient></linearGradient><img/></svg>', 'text/xml');
+
+var elem = document.importNode(svgdoc.documentElement,true);
+container.appendChild(elem);
+
+shouldBe("container.getElementsByTagName('linearGradient').length", "2");
+shouldBe("container.getElementsByTagName('lineargradient').length", "1");
+shouldBe("container.getElementsByTagName('LINEARGRADIENT').length", "1");
+shouldBe("container.getElementsByTagName('FOO').length", "2");
+shouldBe("container.getElementsByTagName('foo').length", "2");
+shouldBe("container.getElementsByTagName('Foo').length", "2");
+shouldBe("container.getElementsByTagName('img').length", "2");
+shouldBe("container.getElementsByTagName('IMG').length", "1");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length", "2");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length", "0");
+</script>
+</body>

Added: trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching2-expected.txt (0 => 113710)


--- trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching2-expected.txt	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,25 @@
+PASS container.getElementsByTagName('linearGradient').length is 2
+PASS container.getElementsByTagName('lineargradient').length is 0
+PASS container.getElementsByTagName('LINEARGRADIENT').length is 0
+PASS container.getElementsByTagName('FOO').length is 1
+PASS container.getElementsByTagName('foo').length is 1
+PASS container.getElementsByTagName('Foo').length is 0
+PASS container.getElementsByTagName('img').length is 2
+PASS container.getElementsByTagName('IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length is 0
+

Added: trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching2.xhtml (0 => 113710)


--- trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching2.xhtml	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/getElementsByTagName-localName-matching2.xhtml	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,47 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <script src=""
+</head>
+<body>
+<div id="container"><FOO><foo><linearGradient/></foo></FOO><img/></div>
+
+<script><![CDATA[
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var container = document.getElementById('container');
+var svgdoc = new DOMParser().parseFromString(
+	'<svg xmlns="http://www.w3.org/2000/svg"><linearGradient></linearGradient><img/></svg>', 'text/xml');
+
+var elem = document.importNode(svgdoc.documentElement,true);
+container.appendChild(elem);
+
+shouldBe("container.getElementsByTagName('linearGradient').length", "2");
+shouldBe("container.getElementsByTagName('lineargradient').length", "0");
+shouldBe("container.getElementsByTagName('LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagName('FOO').length", "1");
+shouldBe("container.getElementsByTagName('foo').length", "1");
+shouldBe("container.getElementsByTagName('Foo').length", "0");
+shouldBe("container.getElementsByTagName('img').length", "2");
+shouldBe("container.getElementsByTagName('IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length", "0");
+]]></script>
+</body>
+</html>

Added: trunk/LayoutTests/svg/dom/getElementsByTagName-localName-matching-expected.txt (0 => 113710)


--- trunk/LayoutTests/svg/dom/getElementsByTagName-localName-matching-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/svg/dom/getElementsByTagName-localName-matching-expected.txt	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,33 @@
+This test checks the behaviour of getElementsByTagName in a non-HTML document
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS container.getElementsByTagName('linearGradient').length is 1
+PASS container.getElementsByTagName('lineargradient').length is 0
+PASS container.getElementsByTagName('LINEARGRADIENT').length is 0
+PASS container.getElementsByTagName('FOO').length is 1
+PASS container.getElementsByTagName('foo').length is 1
+PASS container.getElementsByTagName('Foo').length is 0
+PASS container.getElementsByTagName('img').length is 1
+PASS container.getElementsByTagName('IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/svg/dom/getElementsByTagName-localName-matching.html (0 => 113710)


--- trunk/LayoutTests/svg/dom/getElementsByTagName-localName-matching.html	                        (rev 0)
+++ trunk/LayoutTests/svg/dom/getElementsByTagName-localName-matching.html	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/svg/dom/script-tests/getElementsByTagName-localName-matching.js (0 => 113710)


--- trunk/LayoutTests/svg/dom/script-tests/getElementsByTagName-localName-matching.js	                        (rev 0)
+++ trunk/LayoutTests/svg/dom/script-tests/getElementsByTagName-localName-matching.js	2012-04-10 12:34:25 UTC (rev 113710)
@@ -0,0 +1,38 @@
+description("This test checks the behaviour of getElementsByTagName in a non-HTML document");
+
+var documentString = "<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'>" +
+                     "<linearGradient/><img/><foreignObject><body xmlns='http://www.w3.org/1999/xhtml'><foo/><FOO/></body></foreignObject>" +
+                     "</svg>";
+
+var parser = new DOMParser();
+var svgDocument = parser.parseFromString(documentString, "image/svg+xml");
+var container = svgDocument.documentElement;
+
+shouldBe("container.getElementsByTagName('linearGradient').length", "1");
+shouldBe("container.getElementsByTagName('lineargradient').length", "0");
+shouldBe("container.getElementsByTagName('LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagName('FOO').length", "1");
+shouldBe("container.getElementsByTagName('foo').length", "1");
+shouldBe("container.getElementsByTagName('Foo').length", "0");
+shouldBe("container.getElementsByTagName('img').length", "1");
+shouldBe("container.getElementsByTagName('IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length", "0");
+
+var successfullyParsed = true;

Modified: trunk/Source/WebCore/ChangeLog (113709 => 113710)


--- trunk/Source/WebCore/ChangeLog	2012-04-10 12:29:15 UTC (rev 113709)
+++ trunk/Source/WebCore/ChangeLog	2012-04-10 12:34:25 UTC (rev 113710)
@@ -1,3 +1,40 @@
+2012-04-10  Rob Buis  <[email protected]>
+
+        getElementsByTagName unable to find SVG camelCase elements imported into HTML
+        https://bugs.webkit.org/show_bug.cgi?id=46800
+
+        Reviewed by Nikolas Zimmermann.
+
+        Implement getElementsByTagName according to the algorithm in
+        http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagname.
+        If the owner document of the element is html, the new class HTMLTagNodeList deals with
+        finding the match(es) based on this algorithm. If the owner document is non HTML, the existing
+        TagNodeList is used.
+
+        Implement getElementsByTagNameNS according to the algorithm in
+        http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagnamens.
+        The existing TagNodeList implements this algorithm.
+
+        Cached results may have less hits after this change. Tag names that are equal when case
+        insensitive but different when case sensitive can't share the result due to above algorithms, i.e.
+        they would match differently in the non html part of the document.
+
+        Tests: fast/dom/getElementsByTagName-localName-matching.html
+               fast/dom/getElementsByTagName-localName-matching2.xhtml
+               svg/dom/getElementsByTagName-localName-matching.html
+
+        * dom/Node.cpp:
+        (WebCore::Node::getElementsByTagName): create TagNodeList depending on owner document type.
+        (WebCore::Node::getElementsByTagNameNS): do not lowercase localName for html.
+        * dom/TagNodeList.cpp:
+        (WebCore::HTMLTagNodeList::HTMLTagNodeList): add specialized TagNodeList for html matching rules.
+        (WebCore):
+        (WebCore::HTMLTagNodeList::nodeMatches):
+        * dom/TagNodeList.h:
+        (TagNodeList):
+        (HTMLTagNodeList):
+        (WebCore::HTMLTagNodeList::create):
+
 2012-04-09  Alexander Pavlov  <[email protected]>
 
         Web Inspector: [Device Metrics] Introduce the "Fit window" option

Modified: trunk/Source/WebCore/dom/Node.cpp (113709 => 113710)


--- trunk/Source/WebCore/dom/Node.cpp	2012-04-10 12:29:15 UTC (rev 113709)
+++ trunk/Source/WebCore/dom/Node.cpp	2012-04-10 12:34:25 UTC (rev 113710)
@@ -1606,17 +1606,17 @@
     if (localName.isNull())
         return 0;
 
-    String name = localName;
-    if (document()->isHTMLDocument())
-        name = localName.lower();
+    AtomicString localNameAtom = localName;
 
-    AtomicString localNameAtom = name;
-
     NodeListsNodeData::TagNodeListCache::AddResult result = ensureRareData()->ensureNodeLists(this)->m_tagNodeListCache.add(localNameAtom, 0);
     if (!result.isNewEntry)
         return PassRefPtr<TagNodeList>(result.iterator->second);
 
-    RefPtr<TagNodeList> list = TagNodeList::create(this, starAtom, localNameAtom);
+    RefPtr<TagNodeList> list;
+    if (document()->isHTMLDocument())
+        list = HTMLTagNodeList::create(this, starAtom, localNameAtom);
+    else
+        list = TagNodeList::create(this, starAtom, localNameAtom);
     result.iterator->second = list.get();
     return list.release();   
 }
@@ -1629,12 +1629,8 @@
     if (namespaceURI == starAtom)
         return getElementsByTagName(localName);
 
-    String name = localName;
-    if (document()->isHTMLDocument())
-        name = localName.lower();
+    AtomicString localNameAtom = localName;
 
-    AtomicString localNameAtom = name;
-
     NodeListsNodeData::TagNodeListCacheNS::AddResult result
         = ensureRareData()->ensureNodeLists(this)->m_tagNodeListCacheNS.add(QualifiedName(nullAtom, localNameAtom, namespaceURI).impl(), 0);
     if (!result.isNewEntry)

Modified: trunk/Source/WebCore/dom/TagNodeList.cpp (113709 => 113710)


--- trunk/Source/WebCore/dom/TagNodeList.cpp	2012-04-10 12:29:15 UTC (rev 113709)
+++ trunk/Source/WebCore/dom/TagNodeList.cpp	2012-04-10 12:34:25 UTC (rev 113710)
@@ -47,10 +47,29 @@
 
 bool TagNodeList::nodeMatches(Element* testNode) const
 {
+    // Implements http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagnamens
     if (m_localName != starAtom && m_localName != testNode->localName())
         return false;
 
     return m_namespaceURI == starAtom || m_namespaceURI == testNode->namespaceURI();
 }
 
+HTMLTagNodeList::HTMLTagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
+    : TagNodeList(rootNode, namespaceURI, localName)
+    , m_loweredLocalName(localName.lower())
+{
+}
+
+bool HTMLTagNodeList::nodeMatches(Element* testNode) const
+{
+    // Implements http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagname
+    if (m_localName != starAtom) {
+        const AtomicString& localName = testNode->isHTMLElement() ? m_loweredLocalName : m_localName;
+        if (localName != testNode->localName())
+            return false;
+    }
+
+    return m_namespaceURI == starAtom || m_namespaceURI == testNode->namespaceURI();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/TagNodeList.h (113709 => 113710)


--- trunk/Source/WebCore/dom/TagNodeList.h	2012-04-10 12:29:15 UTC (rev 113709)
+++ trunk/Source/WebCore/dom/TagNodeList.h	2012-04-10 12:34:25 UTC (rev 113710)
@@ -39,7 +39,7 @@
 
         virtual ~TagNodeList();
 
-    private:
+    protected:
         TagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName);
 
         virtual bool nodeMatches(Element*) const;
@@ -48,6 +48,20 @@
         AtomicString m_localName;
     };
 
+    class HTMLTagNodeList : public TagNodeList {
+    public:
+        static PassRefPtr<TagNodeList> create(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
+        {
+            return adoptRef(new HTMLTagNodeList(rootNode, namespaceURI, localName));
+        }
+
+    private:
+        HTMLTagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName);
+
+        virtual bool nodeMatches(Element*) const;
+
+        AtomicString m_loweredLocalName;
+    };
 } // namespace WebCore
 
 #endif // TagNodeList_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to