⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dom_doc.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/** * This file is part of the DOM implementation for KDE. * * (C) 1999 Lars Knoll (knoll@kde.org) * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */#include "dom/dom_exception.h"#include "dom/dom_xml.h"#include "dom/dom2_range.h"#include "dom/dom2_events.h"#include "dom/dom2_views.h"#include "dom/dom2_traversal.h"#include "dom/html_document.h"#include "html/html_documentimpl.h"#include "xml/dom_docimpl.h"#include "xml/dom_elementimpl.h"#include <kdebug.h>namespace DOM {DOMImplementation::DOMImplementation(){    impl = 0;}DOMImplementation::DOMImplementation(const DOMImplementation &other){    impl = other.impl;    if (impl) impl->ref();}DOMImplementation::DOMImplementation(DOMImplementationImpl *i){    impl = i;    if (impl) impl->ref();}DOMImplementation &DOMImplementation::operator = (const DOMImplementation &other){    if ( impl != other.impl ) {    if (impl) impl->deref();    impl = other.impl;    if (impl) impl->ref();    }    return *this;}DOMImplementation::~DOMImplementation(){    if (impl) impl->deref();}bool DOMImplementation::hasFeature( const DOMString &feature, const DOMString &version ){    if (!impl)        return false; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR); or { _exceptioncode = DOMException::NOT_FOUND_ERR; return false; }    return impl->hasFeature(feature,version);}DocumentType DOMImplementation::createDocumentType ( const DOMString &qualifiedName,                                                     const DOMString &publicId,                                                     const DOMString &systemId ){    if (!impl)#if KHTML_NO_EXCEPTIONS            { _exceptioncode = DOMException::NOT_FOUND_ERR; return 0; }#else	throw DOMException(DOMException::NOT_FOUND_ERR);#endif        int exceptioncode = 0;    DocumentTypeImpl *r = impl->createDocumentType(qualifiedName, publicId, systemId, exceptioncode);    if ( exceptioncode )#if KHTML_NO_EXCEPTIONS            { _exceptioncode =  exceptioncode ; return 0; }#else        throw DOMException( exceptioncode );#endif        return r;}Document DOMImplementation::createDocument ( const DOMString &namespaceURI,                                             const DOMString &qualifiedName,                                             const DocumentType &doctype ){    if (!impl)#if KHTML_NO_EXCEPTIONS            { _exceptioncode = DOMException::NOT_FOUND_ERR; return Document(); }#else	throw DOMException(DOMException::NOT_FOUND_ERR);#endif        int exceptioncode = 0;    DocumentImpl *r = impl->createDocument(namespaceURI, qualifiedName, doctype, exceptioncode );    if ( exceptioncode )#if KHTML_NO_EXCEPTIONS            { _exceptioncode =  exceptioncode ; return Document(); }#else        throw DOMException( exceptioncode );#endif        return r;}HTMLDocument DOMImplementation::createHTMLDocument( const DOMString& title ){#if KHTML_NO_EXCEPTIONS        if (!impl) { _exceptioncode = DOMException::NOT_FOUND_ERR; return HTMLDocument(); }#else    if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);#endif        HTMLDocumentImpl* r = impl->createHTMLDocument( 0 /* ### create a view otherwise it doesn't work */);    r->open();    r->write(QString::fromLatin1("<HTML><HEAD><TITLE>") + title.string() +             QString::fromLatin1("</TITLE></HEAD>"));    return r;}DOMImplementation DOMImplementation::getInterface(const DOMString &feature) const{    if (!impl)#if KHTML_NO_EXCEPTIONS            { _exceptioncode = DOMException::NOT_FOUND_ERR; return 0; }#else        throw DOMException(DOMException::NOT_FOUND_ERR);#endif        return impl->getInterface(feature);}CSSStyleSheet DOMImplementation::createCSSStyleSheet(const DOMString &title, const DOMString &media){    if (!impl)#if KHTML_NO_EXCEPTIONS            { _exceptioncode = DOMException::NOT_FOUND_ERR; return 0; }#else        throw DOMException(DOMException::NOT_FOUND_ERR);#endif        int exceptioncode = 0;    CSSStyleSheetImpl *r = impl->createCSSStyleSheet(title.implementation(), media.implementation(),                                                     exceptioncode);    if ( exceptioncode )#if KHTML_NO_EXCEPTIONS            { _exceptioncode =  exceptioncode ; return 0; }#else        throw DOMException( exceptioncode );#endif        return r;}DOMImplementationImpl *DOMImplementation::handle() const{    return impl;}bool DOMImplementation::isNull() const{    return (impl == 0);}// ----------------------------------------------------------------------------Document::Document()    : Node(){    // we always want an implementation    impl = DOMImplementationImpl::instance()->createDocument();    impl->ref();}Document::Document(bool create)    : Node(){    if(create)    {	impl = DOMImplementationImpl::instance()->createDocument();	impl->ref();    }    else	impl = 0;//    kdDebug(6090) << "Document::Document(bool)" << endl;}Document::Document(const Document &other) : Node(other){//    kdDebug(6090) << "Document::Document(Document &)" << endl;}Document::Document(DocumentImpl *i) : Node(i){//    kdDebug(6090) << "Document::Document(DocumentImpl)" << endl;}Document &Document::operator = (const Node &other){    NodeImpl* ohandle = other.handle();    if ( impl != ohandle ) {    if (!ohandle || ohandle->nodeType() != DOCUMENT_NODE) {	    if ( impl ) impl->deref();	impl = 0;	} else {    Node::operator =(other);	}    }    return *this;}Document &Document::operator = (const Document &other){    Node::operator =(other);    return *this;}Document::~Document(){//    kdDebug(6090) << "Document::~Document\n" << endl;}DocumentType Document::doctype() const{    if (impl) {      // Doctype is null for HTML documents.      if (((DocumentImpl*)impl)->isHTMLDocument())	return 0;      else	return ((DocumentImpl *)impl)->doctype();    }    return 0;}DOMImplementation Document::implementation() const{    if (impl) return ((DocumentImpl *)impl)->implementation();    return 0;}Element Document::documentElement() const{    if (impl) return ((DocumentImpl *)impl)->documentElement();    return 0;}Element Document::createElement( const DOMString &tagName ){    if (!impl) return 0;    int exceptioncode = 0;    ElementImpl *e = ((DocumentImpl *)impl)->createElement(tagName, exceptioncode);    if (exceptioncode) {#if KHTML_NO_EXCEPTIONS            _exceptioncode = exceptioncode; return 0;#else        throw DOMException(exceptioncode);#endif        }    return e;}Element Document::createElementNS( const DOMString &namespaceURI, const DOMString &qualifiedName ){    if (!impl) return 0;    int exceptioncode = 0;    ElementImpl *e = ((DocumentImpl *)impl)->createElementNS(namespaceURI, qualifiedName, exceptioncode);    if (exceptioncode) {#if KHTML_NO_EXCEPTIONS            _exceptioncode = exceptioncode; return 0;#else        throw DOMException(exceptioncode);#endif        }    return e;}DocumentFragment Document::createDocumentFragment(  ){    if (impl) return ((DocumentImpl *)impl)->createDocumentFragment();    return 0;}Text Document::createTextNode( const DOMString &data ){    if (impl) return ((DocumentImpl *)impl)->createTextNode( data );    return 0;}Comment Document::createComment( const DOMString &data ){    if (impl) return ((DocumentImpl *)impl)->createComment( data );    return 0;}CDATASection Document::createCDATASection( const DOMString &data ){    // ### DOM1 spec says raise exception if html documents - what about XHTML documents?    if (impl) return ((DocumentImpl *)impl)->createCDATASection( data );    return 0;}ProcessingInstruction Document::createProcessingInstruction( const DOMString &target, const DOMString &data ){    if (impl) return ((DocumentImpl *)impl)->createProcessingInstruction( target, data );    return 0;}Attr Document::createAttribute( const DOMString &name ){    return createAttributeNS(DOMString(), name);}Attr Document::createAttributeNS( const DOMString &namespaceURI, const DOMString &qualifiedName ){#if KHTML_NO_EXCEPTIONS        if (!impl) { _exceptioncode = DOMException::NOT_FOUND_ERR; return 0; }    if (qualifiedName.isNull()) { _exceptioncode = DOMException::NAMESPACE_ERR; return 0; }#else    if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);    if (qualifiedName.isNull()) throw DOMException(DOMException::NAMESPACE_ERR);#endif        DOMString localName(qualifiedName.copy());    DOMString prefix;    int colonpos;    if ((colonpos = qualifiedName.find(':')) >= 0) {        prefix = qualifiedName.copy();        prefix.truncate(colonpos);        localName.remove(0, colonpos+1);    }#if KHTML_NO_EXCEPTIONS        if (!DocumentImpl::isValidName(localName))  { _exceptioncode = DOMException::INVALID_CHARACTER_ERR ; return Attr(); }#else    if (!DocumentImpl::isValidName(localName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR);#endif        // ### check correctness of namespace, prefix?    NodeImpl::Id id = static_cast<DocumentImpl*>(impl)->attrId(namespaceURI.implementation(), localName.implementation(), false /* allocate */);    Attr r = static_cast<DocumentImpl*>(impl)->createAttribute(id);    int exceptioncode = 0;    if (r.handle() && prefix.implementation())        r.handle()->setPrefix(prefix.implementation(), exceptioncode);    if (exceptioncode)#if KHTML_NO_EXCEPTIONS            { _exceptioncode = exceptioncode; return 0; }#else        throw DOMException(exceptioncode);#endif        return r;}EntityReference Document::createEntityReference( const DOMString &name ){    if (impl) return ((DocumentImpl *)impl)->createEntityReference( name );    return 0;}Element Document::getElementById( const DOMString &elementId ) const{    if(impl) return ((DocumentImpl *)impl)->getElementById( elementId );    return 0;}NodeList Document::getElementsByTagName( const DOMString &tagName ){    if (!impl) return 0;    return static_cast<DocumentImpl*>(impl)->        getElementsByTagNameNS(0, tagName.implementation());}NodeList Document::getElementsByTagNameNS( const DOMString &namespaceURI, const DOMString &localName ){    if (!impl) return 0;    return static_cast<DocumentImpl*>(impl)->        getElementsByTagNameNS(namespaceURI.implementation(), localName.implementation());}Node Document::importNode( const Node & importedNode, bool deep ){    if (!impl)#if KHTML_NO_EXCEPTIONS    	{ _exceptioncode = DOMException::INVALID_STATE_ERR; return 0; }#else	throw DOMException(DOMException::INVALID_STATE_ERR);#endif        int exceptioncode = 0;    NodeImpl *r = static_cast<DocumentImpl*>(impl)->importNode(importedNode.handle(), deep, exceptioncode);    if (exceptioncode)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -