Source/WebCore/ChangeLog

 12013-01-11 Rafael Weinstein <rafaelw@chromium.org>
 2
 3 Template element should parse in XHTML just as it does in HTML
 4 https://bugs.webkit.org/show_bug.cgi?id=106491
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#parsing-xhtml-documents.
 9
 10 This patch modifies the XML parser in two ways: (1) when nodes are created, their owner document is
 11 the owner document of the current node, rather than the containing document, and (2) when an HTMLTemplateElement
 12 is encountered, its content document fragment is pushed onto the stack, rather than the element itself, so that children
 13 are appended to the template content.
 14
 15 Tests: fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml
 16 fast/xpath/xpath-template-element.html
 17 fast/xsl/xslt-processor-template.html
 18 fast/xsl/xslt-xhtml-template.xml
 19
 20 * xml/parser/XMLDocumentParser.cpp:
 21 (WebCore::XMLDocumentParser::enterText):
 22 * xml/parser/XMLDocumentParserLibxml2.cpp:
 23 (WebCore::XMLDocumentParser::startElementNs):
 24 (WebCore::XMLDocumentParser::processingInstruction):
 25 (WebCore::XMLDocumentParser::cdataBlock):
 26 (WebCore::XMLDocumentParser::comment):
 27
1282013-01-16 Benjamin Poulain <bpoulain@apple.com>
229
330 Force a rebuild of RenderObject

Source/WebCore/xml/parser/XMLDocumentParser.cpp

@@void XMLDocumentParser::enterText()
146146 ASSERT(m_bufferedText.size() == 0);
147147#endif
148148 ASSERT(!m_leafTextNode);
149  m_leafTextNode = Text::create(document(), "");
 149 m_leafTextNode = Text::create(m_currentNode->document(), "");
150150 m_currentNode->parserAppendChild(m_leafTextNode.get());
151151}
152152

Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp

4242#include "HTMLLinkElement.h"
4343#include "HTMLNames.h"
4444#include "HTMLStyleElement.h"
 45#include "HTMLTemplateElement.h"
4546#include "ProcessingInstruction.h"
4647#include "ResourceError.h"
4748#include "ResourceHandle.h"

@@void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
788789 m_sawFirstElement = true;
789790
790791 QualifiedName qName(prefix, localName, uri);
791  RefPtr<Element> newElement = document()->createElement(qName, true);
 792 RefPtr<Element> newElement = m_currentNode->document()->createElement(qName, true);
792793 if (!newElement) {
793794 stopParsing();
794795 return;

@@void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
818819
819820 m_currentNode->parserAppendChild(newElement.get());
820821
 822#if ENABLE(TEMPLATE_ELEMENT)
 823 if (newElement->hasTagName(HTMLNames::templateTag))
 824 pushCurrentNode(toHTMLTemplateElement(newElement.get())->content());
 825 else
 826 pushCurrentNode(newElement.get());
 827#else
821828 pushCurrentNode(newElement.get());
 829#endif
 830
822831 if (m_view && !newElement->attached())
823832 newElement->attach();
824833

@@void XMLDocumentParser::processingInstruction(const xmlChar* target, const xmlCh
961970
962971 // ### handle exceptions
963972 ExceptionCode ec = 0;
964  RefPtr<ProcessingInstruction> pi = document()->createProcessingInstruction(
 973 RefPtr<ProcessingInstruction> pi = m_currentNode->document()->createProcessingInstruction(
965974 toString(target), toString(data), ec);
966975 if (ec)
967976 return;

@@void XMLDocumentParser::cdataBlock(const xmlChar* s, int len)
9951004
9961005 exitText();
9971006
998  RefPtr<CDATASection> newNode = CDATASection::create(document(), toString(s, len));
 1007 RefPtr<CDATASection> newNode = CDATASection::create(m_currentNode->document(), toString(s, len));
9991008 m_currentNode->parserAppendChild(newNode.get());
10001009 if (m_view && !newNode->attached())
10011010 newNode->attach();

@@void XMLDocumentParser::comment(const xmlChar* s)
10131022
10141023 exitText();
10151024
1016  RefPtr<Comment> newNode = Comment::create(document(), toString(s));
 1025 RefPtr<Comment> newNode = Comment::create(m_currentNode->document(), toString(s));
10171026 m_currentNode->parserAppendChild(newNode.get());
10181027 if (m_view && !newNode->attached())
10191028 newNode->attach();

LayoutTests/ChangeLog

 12013-01-11 Rafael Weinstein <rafaelw@chromium.org>
 2
 3 Template element should parse in XHTML just as it does in HTML
 4 https://bugs.webkit.org/show_bug.cgi?id=106491
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt: Added.
 9 * fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml: Added.
 10 * fast/xpath/xpath-template-element-expected.txt: Added.
 11 * fast/xpath/xpath-template-element.html: Added.
 12 * fast/xsl/resources/xhtml-template.xsl: Added.
 13 * fast/xsl/xslt-processor-template-expected.txt: Added.
 14 * fast/xsl/xslt-processor-template.html: Added.
 15 * fast/xsl/xslt-xhtml-template-expected.txt: Added.
 16 * fast/xsl/xslt-xhtml-template.xml: Added.
 17
1182013-01-16 Sheriff Bot <webkit.review.bot@gmail.com>
219
320 Unreviewed, rolling out r139853.

LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt

 1This tests that content within template is lifted to the template contents when parsed as xhtml.
 2The template content made it through the wormhole
 3<template xmlns="http://www.w3.org/1999/xhtml"><div>Template content</div></template>

LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml

 1<!DOCTYPE html
 2 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 4<html xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
 5 <body>
 6 <template><div>Template content</div></template>
 7 <span>This tests that content within template is lifted to the template contents when parsed as xhtml.</span>
 8 <div id="output">
 9 </div>
 10 <div id="serialization">
 11 </div>
 12<script>
 13if (window.testRunner) {
 14 testRunner.dumpAsText();
 15}
 16
 17var output = document.getElementById("output");
 18var template = document.querySelector("template");
 19if (template.content.childNodes.length > template.childNodes.length)
 20 output.textContent = "The template content made it through the wormhole\n";
 21
 22var serialization = document.getElementById("serialization");
 23serialization.textContent = new XMLSerializer().serializeToString(template);
 24</script>
 25 </body>
 26</html>

LayoutTests/fast/xpath/xpath-template-element-expected.txt

 1This tests that XPath expressions do not consider (traverse into) template content
 2
 3A B
 4PASS document.evaluate('count(//span)', test, null, XPathResult.NUMBER_TYPE, null).numberValue is 2
 5PASS successfullyParsed is true
 6
 7TEST COMPLETE
 8

LayoutTests/fast/xpath/xpath-template-element.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script src="../js/resources/js-test-pre.js"></script>
 5</head>
 6<body>
 7<p>This tests that XPath expressions do not consider (traverse into) template content</p>
 8
 9<div id=test>
 10 <span>A</span>
 11 <span>B</span>
 12 <template>
 13 <span>C</span>
 14 <span>D</span>
 15 </template>
 16</div>
 17
 18<div id="console"></div>
 19<script>
 20var test = document.getElementById('test');
 21var result = document.evaluate('count(//span)', test, null, XPathResult.NUMBER_TYPE, null);
 22shouldBe("document.evaluate('count(//span)', test, null, XPathResult.NUMBER_TYPE, null).numberValue", "2");
 23</script>
 24<script src="../js/resources/js-test-post.js"></script>
 25</body>
 26</html>

LayoutTests/fast/xsl/resources/xhtml-template.xsl

 1<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 2 xmlns:xhtml="http://www.w3.org/1999/xhtml"
 3 xmlns="http://www.w3.org/1999/xhtml"
 4 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 5 exclude-result-prefixes="xhtml xsl xs">
 6 <xsl:output method="xml" omit-xml-declaration="yes"/>
 7 <xsl:template match="xhtml:html">
 8 <html>
 9 <body>
 10 <template>
 11 <xsl:apply-templates select="//xhtml:body/xhtml:span" />
 12 </template>
 13 <xsl:apply-templates select="//xhtml:template//xhtml:span" />
 14 <p>This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template.
 15 If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D)
 16 and replaced the spans with divs.</p>
 17<script>
 18if (window.testRunner)
 19 testRunner.dumpAsText();
 20
 21function divChildTextNodes(parent) {
 22 var output = '';
 23
 24 for (var child = parent.firstChild; child; child = child.nextSibling) {
 25 if (child.tagName == 'div') {
 26 output += child.textContent;
 27 }
 28 }
 29
 30 return output;
 31}
 32
 33var span = document.body.appendChild(document.createElement('span'));
 34span.textContent = 'Body divs: ' + divChildTextNodes(document.body);
 35
 36span = document.body.appendChild(document.createElement('span'));
 37var template = document.querySelector('template');
 38span.textContent = ', Template content divs: ' + divChildTextNodes(template.content);
 39</script>
 40 </body>
 41 </html>
 42 </xsl:template>
 43 <xsl:template match="xhtml:span">
 44 <div><xsl:value-of select="text()" /></div>
 45 </xsl:template>
 46</xsl:stylesheet>

LayoutTests/fast/xsl/xslt-processor-template-expected.txt

 1This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template. If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D) and replaced the spans with divs.
 2
 3Body divs: CD, Template content divs: AB

LayoutTests/fast/xsl/xslt-processor-template.html

 1<html>
 2<head>
 3</head>
 4<body id="body">
 5<p>This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template.
 6If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D)
 7and replaced the spans with divs.</p>
 8<script>
 9if (window.testRunner)
 10 testRunner.dumpAsText();
 11
 12var requester = new XMLHttpRequest();
 13var processor = new XSLTProcessor();
 14var serializer = new XMLSerializer();
 15
 16function getXMLDocument(name)
 17{
 18 requester.open("GET", name, false);
 19 requester.send(null);
 20 return requester.responseXML;
 21}
 22
 23function addStringResult(text)
 24{
 25 document.writeln("<span>" + text + "</span>");
 26}
 27
 28function divChildTextNodes(parent) {
 29 var output = '';
 30
 31 for (var child = parent.firstChild; child; child = child.nextSibling) {
 32 if (child.tagName == 'div') {
 33 output += child.textContent;
 34 }
 35 }
 36
 37 return output;
 38}
 39
 40var xml = getXMLDocument("xslt-xhtml-template.xml");
 41var xsl = getXMLDocument("resources/xhtml-template.xsl");
 42
 43processor.importStylesheet(xsl);
 44
 45var ownerDocument = document.implementation.createDocument("", "test", null);
 46var frag = processor.transformToFragment(xml, ownerDocument);
 47
 48addStringResult('Body divs: ' + divChildTextNodes(frag.querySelector('body')) +
 49 ', Template content divs: ' + divChildTextNodes(frag.querySelector('template').content));
 50
 51</script>
 52</body>
 53</html>

LayoutTests/fast/xsl/xslt-xhtml-template-expected.txt

 1C
 2D
 3This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template. If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D) and replaced the spans with divs.
 4
 5Body divs: CD, Template content divs: AB

LayoutTests/fast/xsl/xslt-xhtml-template.xml

 1<?xml version="1.0" encoding="utf-8"?>
 2<?xml-stylesheet href="resources/xhtml-template.xsl" type="text/xsl"?>
 3
 4<!DOCTYPE html
 5 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 6 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 7
 8<html xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
 9 <body>
 10 <span>A</span>
 11 <span>B</span>
 12 <template>
 13 <span>C</span>
 14 <span>D</span>
 15 </template>
 16 </body>
 17</html>

LayoutTests/platform/gtk/TestExpectations

@@http/tests/xmlhttprequest/default-content-type-dashboard.html [ WontFix ]
8888fast/css/draggable-region-parser.html [ WontFix ]
8989
9090# ENABLE(TEMPLATE_ELEMENT) is disabled.
91 webkit.org/b/10357 fast/dom/HTMLTemplateElement [ Skip ]
92 webkit.org/b/10357 html5lib/run-template.html [ Skip ]
 91webkit.org/b/103547 fast/dom/HTMLTemplateElement [ Skip ]
 92webkit.org/b/103547 html5lib/run-template.html [ Skip ]
 93webkit.org/b/103547 fast/xsl/xslt-xhtml-template.xml [ Skip ]
 94webkit.org/b/103547 fast/xpath/xpath-template-element.html [ Skip ]
 95webkit.org/b/103547 fast/xsl/xslt-processor-template.html [ Skip ]
9396
9497# These test -apple- and -khtml- prefixed CSS properties, which we don't support.
9598inspector/styles/vendor-prefixes.html [ WontFix ]

LayoutTests/platform/mac/TestExpectations

@@accessibility/corresponding-control-deleted-crash.html
439439# ENABLE(TEMPLATE_ELEMENT) is disabled.
440440fast/dom/HTMLTemplateElement
441441html5lib/run-template.html
 442fast/xsl/xslt-xhtml-template.xml
 443fast/xpath/xpath-template-element.html
 444fast/xsl/xslt-processor-template.html
442445
443446# JSC does not support setIsolatedWorldSecurityOrigin (http://webkit.org/b/61540)
444447http/tests/security/isolatedWorld/cross-origin-xhr.html

LayoutTests/platform/qt/TestExpectations

@@fast/css/cursor-parsing-image-set.html
191191# ENABLE(TEMPLATE_ELEMENT) is disabled.
192192fast/dom/HTMLTemplateElement
193193html5lib/run-template.html
 194fast/xsl/xslt-xhtml-template.xml
 195fast/xpath/xpath-template-element.html
 196fast/xsl/xslt-processor-template.html
194197
195198# Fail until SUBPIXEL_LAYOUT is enabled
196199# https://bugs.webkit.org/show_bug.cgi?id=85532

LayoutTests/platform/win/TestExpectations

@@fast/dom/shadow
15331533# ENABLE(TEMPLATE_ELEMENT) is disabled.
15341534fast/dom/HTMLTemplateElement
15351535html5lib/run-template.html
 1536fast/xsl/xslt-xhtml-template.xml
 1537fast/xpath/xpath-template-element.html
 1538fast/xsl/xslt-processor-template.html
15361539
15371540# CSS Regions support not yet enabled. http://webkit.org/b/57312
15381541fast/regions

LayoutTests/platform/wincairo/TestExpectations

@@fast/dom/shadow
20622062# ENABLE(TEMPLATE_ELEMENT) is disabled.
20632063fast/dom/HTMLTemplateElement
20642064html5lib/run-template.html
 2065fast/xsl/xslt-xhtml-template.xml
 2066fast/xpath/xpath-template-element.html
 2067fast/xsl/xslt-processor-template.html
20652068
20662069# CSS Regions support not yet enabled. http://webkit.org/b/57312
20672070fast/regions