[webkit-changes] cvs commit: WebCore/layout-tests/fast/dom
set-innerHTML-expected.txt set-innerHTML.xhtml
Darin
darin at opensource.apple.com
Fri Aug 19 09:27:02 PDT 2005
darin 05/08/19 09:27:01
Modified: . ChangeLog
khtml/html html_elementimpl.cpp
khtml/xml xml_tokenizer.cpp xml_tokenizer.h
Added: layout-tests/fast/dom set-innerHTML-expected.txt
set-innerHTML.xhtml
Log:
Reviewed by Maciej.
Landed by Darin.
- Fixes <http://bugzilla.opendarwin.org/show_bug.cgi?id=3301>
innerHTML does not work for xhtml documents.
Test cases added:
layout-tests/fast/dom/set-innerHTML.xhtml: Added.
layout-tests/fast/dom/set-innerHTML-expected.txt: Added.
* khtml/html/html_elementimpl.cpp:
(HTMLElementImpl::createContextualFragment):
Call parseXMLDocumentFragment if we're an xml document.
* khtml/xml/xml_tokenizer.cpp:
(khtml::XMLTokenizer::pushNamespaces):
New function that takes an element.
(khtml::XMLTokenizer::XMLTokenizer):
New constructor that takes a DocumentFragmentImpl and fills it.
(khtml::parseXMLDocumentFragment):
New function that parses a document fragment.
(khtml::XMLNamespaceStack::pushNamespaces):
New function that takes an element and pushes namespaces based on its
xmlns attributes.
* khtml/xml/xml_tokenizer.h:
Add parseXMLDocumentFragment declaration.
Revision Changes Path
1.4599 +33 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.4598
retrieving revision 1.4599
diff -u -r1.4598 -r1.4599
--- ChangeLog 18 Aug 2005 08:31:15 -0000 1.4598
+++ ChangeLog 19 Aug 2005 16:26:56 -0000 1.4599
@@ -1,3 +1,36 @@
+2005-08-19 Anders Carlsson <andersca at mac.com>
+
+ Reviewed by Maciej.
+ Landed by Darin.
+
+ - Fixes <http://bugzilla.opendarwin.org/show_bug.cgi?id=3301>
+ innerHTML does not work for xhtml documents.
+
+ Test cases added:
+ layout-tests/fast/dom/set-innerHTML.xhtml: Added.
+ layout-tests/fast/dom/set-innerHTML-expected.txt: Added.
+
+ * khtml/html/html_elementimpl.cpp:
+ (HTMLElementImpl::createContextualFragment):
+ Call parseXMLDocumentFragment if we're an xml document.
+
+ * khtml/xml/xml_tokenizer.cpp:
+ (khtml::XMLTokenizer::pushNamespaces):
+ New function that takes an element.
+
+ (khtml::XMLTokenizer::XMLTokenizer):
+ New constructor that takes a DocumentFragmentImpl and fills it.
+
+ (khtml::parseXMLDocumentFragment):
+ New function that parses a document fragment.
+
+ (khtml::XMLNamespaceStack::pushNamespaces):
+ New function that takes an element and pushes namespaces based on its
+ xmlns attributes.
+
+ * khtml/xml/xml_tokenizer.h:
+ Add parseXMLDocumentFragment declaration.
+
2005-08-18 Eric Seidel <eseidel at apple.com>
No review needed, affects only SVGSupport.
1.95 +10 -3 WebCore/khtml/html/html_elementimpl.cpp
Index: html_elementimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_elementimpl.cpp,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- html_elementimpl.cpp 4 Aug 2005 22:45:54 -0000 1.94
+++ html_elementimpl.cpp 19 Aug 2005 16:27:00 -0000 1.95
@@ -277,11 +277,18 @@
hasLocalName(headTag) || hasLocalName(styleTag) || hasLocalName(titleTag))
return 0;
- if (!getDocument()->isHTMLDocument())
- return 0;
-
DocumentFragmentImpl *fragment = new DocumentFragmentImpl(docPtr());
fragment->ref();
+
+ if (!getDocument()->isHTMLDocument()) {
+ bool ret = parseXMLDocumentFragment(html, fragment, this);
+
+ if (!ret) {
+ // FIXME: We should propagate a syntax error exception out here.
+ return 0;
+ }
+ }
+ else
{
HTMLTokenizer tok(docPtr(), fragment);
tok.setForceSynchronous(true); // disable asynchronous parsing
1.37 +83 -0 WebCore/khtml/xml/xml_tokenizer.cpp
Index: xml_tokenizer.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/xml_tokenizer.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- xml_tokenizer.cpp 9 Aug 2005 17:33:38 -0000 1.36
+++ xml_tokenizer.cpp 19 Aug 2005 16:27:01 -0000 1.37
@@ -22,6 +22,7 @@
#include "xml_tokenizer.h"
#include "xml/dom_docimpl.h"
+#include "xml/dom_elementimpl.h"
#include "xml/dom_textimpl.h"
#include "xml/dom_xmlimpl.h"
#include "html/html_headimpl.h"
@@ -39,6 +40,9 @@
#include <qptrstack.h>
+using DOM::AttributeImpl;
+using DOM::NamedAttrMapImpl;
+using DOM::DocumentFragmentImpl;
using DOM::DocumentImpl;
using DOM::DocumentPtr;
using DOM::DOMString;
@@ -121,6 +125,8 @@
public:
~XMLNamespaceStack();
XMLNamespace *pushNamespaces(XMLAttributes& attributes);
+ XMLNamespace *pushNamespaces(ElementImpl& element);
+
void popNamespaces();
private:
QPtrStack<XMLNamespace> m_namespaceStack;
@@ -130,6 +136,7 @@
{
public:
XMLTokenizer(DocumentPtr *, KHTMLView * = 0);
+ XMLTokenizer(DocumentFragmentImpl *);
~XMLTokenizer();
enum ErrorType { warning, nonFatal, fatal };
@@ -156,6 +163,8 @@
void cdataBlock(const xmlChar *s, int len);
void comment(const xmlChar *s);
+ XMLNamespace *pushNamespaces(ElementImpl& element) { return m_namespaceStack.pushNamespaces(element); }
+
private:
void end();
@@ -262,6 +271,20 @@
loadStopped = false;
}
+XMLTokenizer::XMLTokenizer(DocumentFragmentImpl *fragment)
+ : m_doc(fragment->docPtr()), m_view(0),
+ m_context(0), m_currentNode(fragment),
+ m_sawError(false), m_parserStopped(false), m_errorCount(0),
+ m_lastErrorLine(0), m_scriptsIt(0), m_cachedScript(0)
+{
+ if (m_doc)
+ m_doc->ref();
+
+ //FIXME: XMLTokenizer should use this in a fashion similiar to how
+ //HTMLTokenizer uses loadStopped, in the future.
+ loadStopped = false;
+}
+
XMLTokenizer::~XMLTokenizer()
{
if (m_doc)
@@ -755,6 +778,40 @@
m_parserStopped = true;
}
+bool parseXMLDocumentFragment(const DOMString &string, DocumentFragmentImpl *fragment, ElementImpl *parent)
+{
+ XMLTokenizer tokenizer(fragment);
+
+ xmlSAXHandler sax;
+ memset(&sax, 0, sizeof(sax));
+ sax.characters = charactersHandler;
+ sax.endElement = endElementHandler;
+ sax.processingInstruction = processingInstructionHandler;
+ sax.startElement = startElementHandler;
+ sax.cdataBlock = cdataBlockHandler;
+ sax.comment = commentHandler;
+ sax.warning = warningHandler;
+
+ // Add namespaces based on the parent node
+ QPtrStack<DOM::ElementImpl> elemStack;
+ while (parent) {
+ elemStack.push(parent);
+
+ NodeImpl *n = parent->parentNode();
+ if (!n || !n->isElementNode())
+ break;
+ parent = static_cast<ElementImpl *>(n);
+ }
+ while (!elemStack.isEmpty()) {
+ tokenizer.pushNamespaces(*elemStack.pop());
+ }
+
+ int result = xmlParseBalancedChunkMemory(0, &sax, &tokenizer, 0,
+ (const xmlChar*)(const char*)(string.string().utf8()), 0);
+
+ return result == 0;
+}
+
#if 0
bool XMLHandler::attributeDecl(const QString &/*eName*/, const QString &/*aName*/, const QString &/*type*/,
@@ -809,6 +866,32 @@
ns->deref();
}
+XMLNamespace *XMLNamespaceStack::pushNamespaces(ElementImpl& element)
+{
+ XMLNamespace *ns = m_namespaceStack.current();
+ NamedAttrMapImpl *attrs = element.attributes();
+
+ if (!ns)
+ ns = new XMLNamespace;
+
+ if (!attrs)
+ return ns;
+
+ // Search for any xmlns attributes
+ for (unsigned i = 0; i < attrs->length(); i++) {
+ AttributeImpl *attr = attrs->attributeItem(i);
+
+ if (attr->localName() == "xmlns")
+ ns = new XMLNamespace(QString::null, attr->value().string(), ns);
+ else if (attr->prefix() == "xmlns")
+ ns = new XMLNamespace(attr->localName().string(), attr->value().string(), ns);
+ }
+
+ m_namespaceStack.push(ns);
+ ns->ref();
+ return ns;
+}
+
XMLNamespace *XMLNamespaceStack::pushNamespaces(XMLAttributes& attrs)
{
XMLNamespace *ns = m_namespaceStack.current();
1.18 +3 -1 WebCore/khtml/xml/xml_tokenizer.h
Index: xml_tokenizer.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/xml_tokenizer.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- xml_tokenizer.h 15 Mar 2005 21:44:32 -0000 1.17
+++ xml_tokenizer.h 19 Aug 2005 16:27:01 -0000 1.18
@@ -37,6 +37,8 @@
namespace DOM {
class DocumentPtr;
class DocumentImpl;
+ class DocumentFragmentImpl;
+ class ElementImpl;
class NodeImpl;
};
@@ -84,7 +86,7 @@
Tokenizer *newXMLTokenizer(DOM::DocumentPtr *, KHTMLView * = 0);
QMap<QString, QString> parseAttributes(const DOM::DOMString &, bool &attrsOK);
-
+bool parseXMLDocumentFragment(const DOM::DOMString &, DOM::DocumentFragmentImpl *, DOM::ElementImpl *parent = 0);
}
#endif
1.1 WebCore/layout-tests/fast/dom/set-innerHTML-expected.txt
Index: set-innerHTML-expected.txt
===================================================================
error
1.1 WebCore/layout-tests/fast/dom/set-innerHTML.xhtml
Index: set-innerHTML.xhtml
===================================================================
<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript">
<![CDATA[
function debug(str) {
li = document.createElementNS('http://www.w3.org/1999/xhtml', 'li');
li.appendChild(document.createTextNode(str));
document.getElementById('console').appendChild(li);
}
function runTests() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
e = document.getElementById('test');
e.innerHTML = '<b>Success!</b>';
if (e.firstChild.namespaceURI == 'http://www.w3.org/1999/xhtml')
debug('namespace is correct')
else
debug('namespace is incorrect');
}
]]>
</script>
<body onload="runTests();">
<p>This tests that setting innerHTML on an xhtml document works. If this test is successful, the text below should say "Success", and "namespace is correct".</p>
<p id="test"/>
<ul id="console"/>
</body>
</html>
More information about the webkit-changes
mailing list