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

📄 dom_docimpl.cpp

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    Id id = getId( NodeImpl::AttributeId, tagName.implementation(),                  false /* allocate */, isHTMLDocument(), pExceptioncode);    if ( pExceptioncode && *pExceptioncode )        return 0;    AttrImpl* attr = new AttrImpl( 0, document, id, DOMString("").implementation());    attr->setHTMLCompat( htmlMode() != XHtml );    return attr;}DocumentFragmentImpl *DocumentImpl::createDocumentFragment(  ){    return new DocumentFragmentImpl( docPtr() );}CommentImpl *DocumentImpl::createComment ( DOMStringImpl* data ){    return new CommentImpl( docPtr(), data );}CDATASectionImpl *DocumentImpl::createCDATASection ( DOMStringImpl* data ){    return new CDATASectionImpl( docPtr(), data );}ProcessingInstructionImpl *DocumentImpl::createProcessingInstruction ( const DOMString &target, DOMStringImpl* data ){    return new ProcessingInstructionImpl( docPtr(),target,data);}EntityReferenceImpl *DocumentImpl::createEntityReference ( const DOMString &name ){    return new EntityReferenceImpl(docPtr(), name.implementation());}NodeImpl *DocumentImpl::importNode(NodeImpl *importedNode, bool deep, int &exceptioncode){    NodeImpl *result = 0;    // Not mentioned in spec: throw NOT_FOUND_ERR if evt is null    if (!importedNode) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return 0;    }    if(importedNode->nodeType() == Node::ELEMENT_NODE)    {        // Why not use cloneNode?	ElementImpl *otherElem = static_cast<ElementImpl*>(importedNode);	NamedAttrMapImpl *otherMap = static_cast<ElementImpl *>(importedNode)->attributes(true);	ElementImpl *tempElementImpl;	if (!importedNode->localName().isNull())	    tempElementImpl = createElementNS(otherElem->namespaceURI(),otherElem->nodeName());	else	    tempElementImpl = createElement(otherElem->nodeName());	result = tempElementImpl;	if(otherMap) {	    for(unsigned long i = 0; i < otherMap->length(); i++)	    {		AttrImpl *otherAttr = otherMap->attrAt(i)->createAttr(otherElem,otherElem->docPtr());		if (!otherAttr->localName().isNull()) {		    // attr was created via createElementNS()		    tempElementImpl->setAttributeNS(otherAttr->namespaceURI(),						    otherAttr->name(),						    otherAttr->nodeValue(),						  exceptioncode);		}		else {		    // attr was created via createElement()		    tempElementImpl->setAttribute(otherAttr->id(),                                                  otherAttr->nodeValue(),                                                  otherAttr->name(),						  exceptioncode);		}		if(exceptioncode != 0)		    break; // ### properly cleanup here	    }	}    }    else if(importedNode->nodeType() == Node::TEXT_NODE)    {	result = createTextNode(static_cast<TextImpl*>(importedNode)->string());	deep = false;    }    else if(importedNode->nodeType() == Node::CDATA_SECTION_NODE)    {	result = createCDATASection(static_cast<CDATASectionImpl*>(importedNode)->string());	deep = false;    }    else if(importedNode->nodeType() == Node::ENTITY_REFERENCE_NODE)	result = createEntityReference(importedNode->nodeName());    else if(importedNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE)    {	result = createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue().implementation());	deep = false;    }    else if(importedNode->nodeType() == Node::COMMENT_NODE)    {	result = createComment(static_cast<CommentImpl*>(importedNode)->string());	deep = false;    }    else	exceptioncode = DOMException::NOT_SUPPORTED_ERR;    if(deep)    {	for(Node n = importedNode->firstChild(); !n.isNull(); n = n.nextSibling())	    result->appendChild(importNode(n.handle(), true, exceptioncode), exceptioncode);    }    return result;}ElementImpl *DocumentImpl::createElementNS( const DOMString &_namespaceURI, const DOMString &_qualifiedName, int* pExceptioncode ){    ElementImpl *e = 0;    int colonPos = -2;    // check NAMESPACE_ERR/INVALID_CHARACTER_ERR    if (pExceptioncode && !checkQualifiedName(_qualifiedName, _namespaceURI, &colonPos,                                              false/*nameCanBeNull*/, false/*nameCanBeEmpty*/,                                              pExceptioncode))        return 0;    DOMString prefix, localName;    splitPrefixLocalName(_qualifiedName.implementation(), prefix, localName, colonPos);    if ((isHTMLDocument() && _namespaceURI.isNull()) ||        (_namespaceURI == XHTML_NAMESPACE && localName == localName.lower())) {        e = createHTMLElement(localName);        if (e) {            int _exceptioncode = 0;            if (!prefix.isNull())                e->setPrefix(prefix, _exceptioncode);            if ( _exceptioncode ) {                 if ( pExceptioncode ) *pExceptioncode = _exceptioncode;                 delete e;                 return 0;            }            e->setHTMLCompat( _namespaceURI.isNull() && htmlMode() != XHtml );        }    }    if (!e) {        Id id = getId(NodeImpl::ElementId, _namespaceURI.implementation(), prefix.implementation(),                      localName.implementation(), false, false /*HTML already looked up*/);        e = new XMLElementImpl( document, id, prefix.implementation() );    }    return e;}AttrImpl *DocumentImpl::createAttributeNS( const DOMString &_namespaceURI,                                           const DOMString &_qualifiedName, int* pExceptioncode){    int colonPos = -2;    // check NAMESPACE_ERR/INVALID_CHARACTER_ERR    if (pExceptioncode && !checkQualifiedName(_qualifiedName, _namespaceURI, &colonPos,                                              false/*nameCanBeNull*/, false/*nameCanBeEmpty*/,                                              pExceptioncode))        return 0;    DOMString prefix, localName;    splitPrefixLocalName(_qualifiedName.implementation(), prefix, localName, colonPos);    Id id = getId(NodeImpl::AttributeId, _namespaceURI.implementation(), prefix.implementation(),                  localName.implementation(), false, true /*lookupHTML*/);    AttrImpl* attr = new AttrImpl(0, document, id, DOMString("").implementation(),                         prefix.implementation());    attr->setHTMLCompat( _namespaceURI.isNull() && htmlMode() != XHtml );    return attr;}ElementImpl *DocumentImpl::getElementById( const DOMString &elementId ) const{    QString stringKey = elementId.string();    ElementMappingCache::ItemInfo* info = m_getElementByIdCache.get(stringKey);    if (!info)         return 0;    //See if cache has an unambiguous answer.    if (info->nd)        return info->nd;    //Now we actually have to walk.    QPtrStack<NodeImpl> nodeStack;    NodeImpl *current = _first;    while(1)    {        if(!current)        {            if(nodeStack.isEmpty()) break;            current = nodeStack.pop();            current = current->nextSibling();        }        else        {            if(current->isElementNode())            {                ElementImpl *e = static_cast<ElementImpl *>(current);                if(e->getAttribute(ATTR_ID) == elementId) {                    info->nd = e;                    return e;                }            }            NodeImpl *child = current->firstChild();            if(child)            {                nodeStack.push(current);                current = child;            }            else            {                current = current->nextSibling();            }        }    }    assert(0); //If there is no item with such an ID, we should never get here    //kdDebug() << "WARNING: *DocumentImpl::getElementById not found " << elementId.string() << endl;    return 0;}void DocumentImpl::setTitle(const DOMString& _title){    if (_title == m_title && !m_title.isNull()) return;    m_title = _title;    QString titleStr = m_title.string();    for (unsigned int i = 0; i < titleStr.length(); ++i)        if (titleStr[i] < ' ')            titleStr[i] = ' ';    titleStr = titleStr.simplifyWhiteSpace();    titleStr.compose();    if ( view() && !view()->part()->parentPart() ) {	if (titleStr.isNull() || titleStr.isEmpty()) {	    // empty title... set window caption as the URL	    KURL url = m_url;	    url.setRef(QString::null);	    url.setQuery(QString::null);	    titleStr = url.prettyURL();	}	emit view()->part()->setWindowCaption( KStringHandler::csqueeze( titleStr, 128 ) );    }}DOMString DocumentImpl::nodeName() const{    return "#document";}unsigned short DocumentImpl::nodeType() const{    return Node::DOCUMENT_NODE;}ElementImpl *DocumentImpl::createHTMLElement( const DOMString &name ){    uint id = khtml::getTagID( name.string().lower().latin1(), name.string().length() );    ElementImpl *n = 0;    switch(id)    {    case ID_HTML:        n = new HTMLHtmlElementImpl(docPtr());        break;    case ID_HEAD:        n = new HTMLHeadElementImpl(docPtr());        break;    case ID_BODY:        n = new HTMLBodyElementImpl(docPtr());        break;// head elements    case ID_BASE:        n = new HTMLBaseElementImpl(docPtr());        break;    case ID_LINK:        n = new HTMLLinkElementImpl(docPtr());        break;    case ID_META:        n = new HTMLMetaElementImpl(docPtr());        break;    case ID_STYLE:        n = new HTMLStyleElementImpl(docPtr());        break;    case ID_TITLE:        n = new HTMLTitleElementImpl(docPtr());        break;// frames    case ID_FRAME:        n = new HTMLFrameElementImpl(docPtr());        break;    case ID_FRAMESET:        n = new HTMLFrameSetElementImpl(docPtr());        break;    case ID_IFRAME:        n = new HTMLIFrameElementImpl(docPtr());        break;// form elements// ### FIXME: we need a way to set form dependency after we have made the form elements    case ID_FORM:            n = new HTMLFormElementImpl(docPtr(), false);        break;    case ID_BUTTON:            n = new HTMLButtonElementImpl(docPtr());        break;    case ID_FIELDSET:            n = new HTMLFieldSetElementImpl(docPtr());        break;    case ID_INPUT:            n = new HTMLInputElementImpl(docPtr());        break;    case ID_ISINDEX:            n = new HTMLIsIndexElementImpl(docPtr());        break;    case ID_LABEL:            n = new HTMLLabelElementImpl(docPtr());        break;    case ID_LEGEND:            n = new HTMLLegendElementImpl(docPtr());        break;    case ID_OPTGROUP:            n = new HTMLOptGroupElementImpl(docPtr());        break;    case ID_OPTION:            n = new HTMLOptionElementImpl(docPtr());        break;    case ID_SELECT:            n = new HTMLSelectElementImpl(docPtr());        break;    case ID_TEXTAREA:            n = new HTMLTextAreaElementImpl(docPtr());        break;// lists    case ID_DL:        n = new HTMLDListElementImpl(docPtr());        break;    case ID_DD:        n = new HTMLGenericElementImpl(docPtr(), id);        break;    case ID_DT:        n = new HTMLGenericElementImpl(docPtr(), id);        break;    case ID_UL:        n = new HTMLUListElementImpl(docPtr());        break;    case ID_OL:        n = new HTMLOListElementImpl(docPtr());        break;    case ID_DIR:        n = new HTMLDirectoryElementImpl(docPtr());        break;    case ID_MENU:        n = new HTMLMenuElementImpl(docPtr());        break;    case ID_LI:        n = new HTMLLIElementImpl(docPtr());        break;// formatting elements (block)    case ID_DIV:    case ID_P:        n = new HTMLDivElementImpl( docPtr(), id );        break;    case ID_BLOCKQUOTE:    case ID_H1:    case ID_H2:    case ID_H3:    case ID_H4:    case ID_H5:    case ID_H6:        n = new HTMLGenericElementImpl(docPtr(), id);        break;    case ID_HR:        n = new HTMLHRElementImpl(docPtr());        break;    case ID_PRE:        n = new HTMLPreElementImpl(docPtr(), id);        break;// font stuff    case ID_BASEFONT:        n = new HTMLBaseFontElementImpl(docPtr());        break;    case ID_FONT:        n = new HTMLFontElementImpl(docPtr());        break;// ins/del    case ID_DEL:    case ID_INS:        n = new HTMLGenericElementImpl(docPtr(), id);        break;// anchor    case ID_A:        n = new HTMLAnchorElementImpl(docPtr());        break;// images    case ID_IMG:        n = new HTMLImageElementImpl(docPtr());        break;    case ID_MAP:        n = new HTMLMapElementImpl(docPtr());        /*n = map;*/        break;    case ID_AREA:        n = new HTMLAreaElementImpl(docPtr());        break;// objects, applets and scripts    case ID_APPLET:        n = new HTMLAppletElementImpl(docPtr());        break;    case ID_OBJECT:        n = new HTMLObjectElementImpl(docPtr());        break;    case ID_EMBED:        n = new HTMLEmbedElementImpl(docPtr());        break;    case ID_PARAM:        n = new HTMLParamElementImpl(docPtr());        break;

⌨️ 快捷键说明

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