From kde-commits Sat Apr 05 15:23:19 2008 From: Harri Porten Date: Sat, 05 Apr 2008 15:23:19 +0000 To: kde-commits Subject: branches/KDE/4.0/kdelibs/khtml/xml Message-Id: <1207408999.841994.24574.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120740901015122 SVN commit 793896 by porten: Make createDocument() work as specified in DOM Level 2: Use the user-supplied doctype and set its Node.ownerDocument attribute to the document being created. M +11 -5 dom_docimpl.cpp M +20 -0 dom_nodeimpl.cpp M +1 -0 dom_nodeimpl.h --- branches/KDE/4.0/kdelibs/khtml/xml/dom_docimpl.cpp #793895:793896 @@ -176,11 +176,15 @@ // ### this is completely broken.. without a view it will not work (Dirk) DocumentImpl *doc = new DocumentImpl(this, 0); - // ### this should be created during parsing a - doc->setDocType(new DocumentTypeImpl(this, doc, - DOMString() /* qualifiedName */, - DOMString() /* publicId */, - DOMString() /* systemId */)); + if (dtype) { + doc->setDocType(dtype); + } else { + // ### this should be created during parsing a + doc->setDocType(new DocumentTypeImpl(this, doc, + DOMString() /* qualifiedName */, + DOMString() /* publicId */, + DOMString() /* systemId */)); + } // now get the interesting parts of the doctype // ### create new one if not there (currently always there) @@ -510,8 +514,10 @@ void DocumentImpl::setDocType(DocumentTypeImpl* dt) { + assert(m_doctype == 0 && dt != 0); m_doctype = dt; m_doctype->ref(); + m_doctype->setDocument(this); } DOMImplementationImpl *DocumentImpl::implementation() const --- branches/KDE/4.0/kdelibs/khtml/xml/dom_nodeimpl.cpp #793895:793896 @@ -1125,7 +1125,27 @@ return doc; } +void NodeImpl::setDocument(DocumentImpl* doc) +{ + if (m_document == doc) + return; +#if 1 // implemented for one special case only so far + assert(m_document == 0 && doc != 0 && + nodeType() == Node::DOCUMENT_TYPE_NODE); + m_document = doc; +#else // for general use do something like this + m_document = 0; + if (inDocument()) + removedFromDocument(); + + ScriptInterpreter::updateDOMNodeDocument(this, m_document, doc); + + m_document = doc; + insertedIntoDocument(); +#endif +} + //------------------------------------------------------------------------- NodeBaseImpl::~NodeBaseImpl() --- branches/KDE/4.0/kdelibs/khtml/xml/dom_nodeimpl.h #793895:793896 @@ -277,6 +277,7 @@ // Returns the document that this node is associated with. This is guaranteed to always be non-null, as opposed to // DOM's ownerDocument() which is null for Document nodes (and sometimes DocumentType nodes). DocumentImpl* getDocument() const { return m_document.get(); } + void setDocument(DocumentImpl* doc); void addEventListener(int id, EventListener *listener, const bool useCapture); void removeEventListener(int id, EventListener *listener, bool useCapture);