dom_nodeimpl.cpp

来自「将konqueror浏览器移植到ARM9 2410中」· C++ 代码 · 共 1,788 行 · 第 1/4 页

CPP
1,788
字号
NodeImpl *NodeBaseImpl::lastChild() const{    return _last;}NodeImpl *NodeBaseImpl::insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode ){    exceptioncode = 0;    if (checkReadOnly()) {        exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;        return 0;    }    if (!newChild || (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE && !newChild->firstChild())) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return 0;    }    if(!refChild)        return appendChild(newChild, exceptioncode);    if (newChild == refChild) // ### HIERARCHY_REUEST_ERR ?	return 0;    if( checkSameDocument(newChild, exceptioncode) )        return 0;    if( checkNoOwner(newChild, exceptioncode) )        return 0;    if( checkIsChild(refChild, exceptioncode) )        return 0;    if(newChild->parentNode() == this)        removeChild(newChild, exceptioncode);    if( exceptioncode )        return 0;    bool isFragment = newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE;    NodeImpl *nextChild;    NodeImpl *child = isFragment ? newChild->firstChild() : newChild;    NodeImpl *prev = refChild->previousSibling();    while (child) {        nextChild = isFragment ? child->nextSibling() : 0;        if( checkNoOwner(child, exceptioncode) )            return 0;        if(!childAllowed(child)) {            exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;            return 0;        }        // if already in the tree, remove it first!        NodeImpl *newParent = child->parentNode();        if(newParent)            newParent->removeChild( child, exceptioncode );        if ( exceptioncode )            return 0;        // seems ok, lets's insert it.        if (prev)            prev->setNextSibling(child);        else            _first = child;        refChild->setPreviousSibling(child);        child->setParent(this);        child->setPreviousSibling(prev);        child->setNextSibling(refChild);        if (attached() && !child->attached() && ownerDocument() )            child->attach();        dispatchChildInsertedEvents(child,exceptioncode);        prev = child;        child = nextChild;    }    // ### set style in case it's attached    setChanged(true);    dispatchSubtreeModifiedEvent();    return newChild;}NodeImpl *NodeBaseImpl::replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ){    exceptioncode = 0;    if (checkReadOnly()) {        exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;        return 0;    }    if (!newChild || (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE && !newChild->firstChild())) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return 0;    }    if( checkSameDocument(newChild, exceptioncode) )        return 0;    if( checkIsChild(oldChild, exceptioncode) )        return 0;    if( checkNoOwner(newChild, exceptioncode) )        return 0;    bool isFragment = newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE;    NodeImpl *nextChild;    NodeImpl *child = isFragment ? newChild->firstChild() : newChild;    // make sure we will be able to insert the first node before we go removing the old one    if( checkNoOwner(isFragment ? newChild->firstChild() : newChild, exceptioncode) )        return 0;    if(!childAllowed(isFragment ? newChild->firstChild() : newChild)) {        exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;        return 0;    }    NodeImpl *prev = oldChild->previousSibling();    NodeImpl *next = oldChild->nextSibling();    oldChild->setPreviousSibling(0);    oldChild->setNextSibling(0);    oldChild->setParent(0);    if(oldChild->attached())	oldChild->detach();    while (child) {        nextChild = isFragment ? child->nextSibling() : 0;        if( checkNoOwner(child, exceptioncode ) )            return 0;        if(!childAllowed(child)) {            exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;            return 0;        }        // if already in the tree, remove it first!        NodeImpl *newParent = child->parentNode();        if(newParent)            newParent->removeChild( child, exceptioncode );        if ( exceptioncode )            return 0;        // seems ok, lets's insert it.        if (prev) prev->setNextSibling(child);        if (next) next->setPreviousSibling(child);        if(!prev) _first = child;        if(!next) _last = child;        child->setParent(this);        child->setPreviousSibling(prev);        child->setNextSibling(next);        if (attached() && !child->attached() && ownerDocument() )            child->attach();        dispatchChildInsertedEvents(child,exceptioncode);        prev = child;        child = nextChild;    }    // ### set style in case it's attached    setChanged(true);    dispatchSubtreeModifiedEvent();    return oldChild;}NodeImpl *NodeBaseImpl::removeChild ( NodeImpl *oldChild, int &exceptioncode ){    exceptioncode = 0;    if( checkReadOnly() )        return 0;    if( checkIsChild(oldChild, exceptioncode) )        return 0;    getDocument()->notifyBeforeNodeRemoval(oldChild); // ### use events instead    if (getDocument()->hasListenerType(DocumentImpl::DOMNODEREMOVED_LISTENER)) {	oldChild->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEREMOVED_EVENT,			     true,false,this,DOMString(),DOMString(),DOMString(),0),exceptioncode);	if (exceptioncode)	    return 0;    }    if (getDocument()->hasListenerType(DocumentImpl::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) {	// dispatch the DOMNOdeRemovedFromDocument event to all descendants	NodeImpl *p = this;	while (p->parentNode())	    p = p->parentNode();	if (p->nodeType() == Node::DOCUMENT_NODE) {	    NodeImpl *c;	    for (c = oldChild; c; c = c->traverseNextNode(oldChild)) {		c->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEREMOVEDFROMDOCUMENT_EVENT,				 false,false,0,DOMString(),DOMString(),DOMString(),0),exceptioncode);		if (exceptioncode)		    return 0;	    }	}    }    NodeImpl *prev, *next;    prev = oldChild->previousSibling();    next = oldChild->nextSibling();    if(next) next->setPreviousSibling(prev);    if(prev) prev->setNextSibling(next);    if(_first == oldChild) _first = next;    if(_last == oldChild) _last = prev;    oldChild->setPreviousSibling(0);    oldChild->setNextSibling(0);    oldChild->setParent(0);    if (oldChild->attached())        oldChild->detach();    setChanged(true);    dispatchSubtreeModifiedEvent();    return oldChild;}void NodeBaseImpl::removeChildren(){    NodeImpl *n, *next;    for( n = _first; n != 0; n = next )    {        next = n->nextSibling();        n->setPreviousSibling(0);        n->setNextSibling(0);        n->setParent(0);        if (n->attached())	    n->detach();        n->setRenderer( 0 );        n->setStyle( 0 );        if(n->deleteMe())            delete n;    }    _first = _last = 0;}NodeImpl *NodeBaseImpl::appendChild ( NodeImpl *newChild, int &exceptioncode ){//    kdDebug(6010) << "NodeBaseImpl::appendChild( " << newChild << " );" <<endl;    checkReadOnly();    if (!newChild || (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE && !newChild->firstChild())) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return 0;    }    if( checkSameDocument(newChild, exceptioncode) )        return 0;    if( checkNoOwner(newChild, exceptioncode) )        return 0;    if(newChild->parentNode() == this)        removeChild(newChild, exceptioncode);    if ( exceptioncode )        return 0;    bool isFragment = newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE;    NodeImpl *nextChild;    NodeImpl *child = isFragment ? newChild->firstChild() : newChild;    while (child) {        nextChild = isFragment ? child->nextSibling() : 0;        if (checkNoOwner(child, exceptioncode) )            return 0;        if(!childAllowed(child)) {            exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;            return 0;        }        // if already in the tree, remove it first!        NodeImpl *oldParent = child->parentNode();        if(oldParent)            oldParent->removeChild( child, exceptioncode );        if ( exceptioncode )            return 0;        // lets append it        child->setParent(this);        if(_last)        {            child->setPreviousSibling(_last);            _last->setNextSibling(child);            _last = child;        }        else        {            _first = _last = child;        }        if (attached() && !child->attached() && ownerDocument() )            child->attach();        dispatchChildInsertedEvents(child,exceptioncode);        child = nextChild;    }    setChanged(true);    // ### set style in case it's attached    dispatchSubtreeModifiedEvent();    return newChild;}bool NodeBaseImpl::hasChildNodes (  ) const{    return _first != 0;}// not part of the DOMvoid NodeBaseImpl::setFirstChild(NodeImpl *child){    _first = child;}void NodeBaseImpl::setLastChild(NodeImpl *child){    _last = child;}// check for same source document:bool NodeBaseImpl::checkSameDocument( NodeImpl *newChild, int &exceptioncode ){    exceptioncode = 0;    DocumentImpl *ownerDocThis = static_cast<DocumentImpl*>(nodeType() == Node::DOCUMENT_NODE ? this : ownerDocument());    DocumentImpl *ownerDocNew = static_cast<DocumentImpl*>(newChild->nodeType() == Node::DOCUMENT_NODE ? newChild : newChild->ownerDocument());    if(ownerDocThis != ownerDocNew) {        kdDebug(6010)<< "not same document, newChild = " << newChild << "document = " << ownerDocument() << endl;        exceptioncode = DOMException::WRONG_DOCUMENT_ERR;        return true;    }    return false;}// check for being (grand-..)father:bool NodeBaseImpl::checkNoOwner( NodeImpl *newChild, int &exceptioncode ){  //check if newChild is parent of this...  NodeImpl *n;  for( n = this; n != (NodeImpl *)ownerDocument() && n!= 0; n = n->parentNode() )      if(n == newChild) {          exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;          return true;      }  return false;}// check for being child:bool NodeBaseImpl::checkIsChild( NodeImpl *oldChild, int &exceptioncode ){    if(!oldChild || oldChild->parentNode() != this) {        exceptioncode = DOMException::NOT_FOUND_ERR;        return true;    }    return false;}bool NodeBaseImpl::childAllowed( NodeImpl *newChild ){    return childTypeAllowed(newChild->nodeType());}NodeImpl *NodeBaseImpl::addChild(NodeImpl *newChild){    // do not add applyChanges here! This function is only used during parsing    // short check for consistency with DTD    if(!isXMLElementNode() && !newChild->isXMLElementNode() && !childAllowed(newChild))    {        //kdDebug( 6020 ) << "AddChild failed! id=" << id() << ", child->id=" << newChild->id() << endl;        return 0;    }    // just add it...    newChild->setParent(this);    if(_last)    {        newChild->setPreviousSibling(_last);        _last->setNextSibling(newChild);        _last = newChild;    }    else    {        _first = _last = newChild;    }    if(newChild->nodeType() == Node::ELEMENT_NODE)        return newChild;    return this;}void NodeBaseImpl::applyChanges(bool top, bool force){    setChanged(false);    if (!attached())	    return;    int ow = (m_style?m_style->outlineWidth():0);    if (top)        recalcStyle();    // a style change can influence the children, so we just go    // through them and trigger an appplyChanges there too    NodeImpl *n = _first;    while(n) {        n->applyChanges(false,force || changed());        n = n->nextSibling();    }    if ( !m_render )        return;    m_render->calcMinMaxWidth();    if ( top ) {        if ( force ) {            // force a relayout of this part of the document            m_render->updateSize();            // force a repaint of this part.            // ### if updateSize() changes any size, it will already force a            // repaint, so we might do double work here...            m_render->repaint();        }        else {            // ### FIX ME            if (m_style) ow = QMAX(ow, m_style->outlineWidth());            RenderObject *cb = m_render->containingBlock();            if (cb && cb != m_render)                cb->repaintRectangle(-ow, -ow, cb->width()+2*ow, cb->height()+2*ow);            else                m_render->repaint();        }    }    setChanged(false);}bool NodeBaseImpl::prepareMouseEvent( int _x, int _y,                                     int _tx, int _ty,                                     MouseEvent *ev){    bool oldinside=mouseInside();    bool inside = NodeWParentImpl::prepareMouseEvent( _x, _y, _tx, _ty, ev );    setMouseInside(inside);    bool oldactive = active();    if ( inside ) {	if ( ev->type == MousePress )	    m_active = true;	else if ( ev->type == MouseRelease )

⌨️ 快捷键说明

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