📄 dom_nodeimpl.cpp
字号:
return 0; } bool isFragment = newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE; // If newChild is a DocumentFragment with no children.... there's nothing to do. // Just return the document fragment if (isFragment && !newChild->firstChild()) return newChild; // Now actually add the child(ren) NodeImpl *nextChild; NodeImpl *child = isFragment ? newChild->firstChild() : newChild; NodeImpl *prev = refChild->previousSibling(); if ( prev == newChild || refChild == newChild ) // nothing to do return newChild; while (child) { nextChild = isFragment ? child->nextSibling() : 0; // If child is already present in the tree, first remove it NodeImpl *newParent = child->parentNode(); if(newParent) newParent->removeChild( child, exceptioncode ); if ( exceptioncode ) return 0; // Add child in the correct position if (prev) prev->setNextSibling(child); else _first = child; refChild->setPreviousSibling(child); child->setParent(this); child->setPreviousSibling(prev); child->setNextSibling(refChild); // Add child to the rendering tree // ### should we detach() it first if it's already attached? if (attached() && !child->attached()) child->attach(); // Dispatch the mutation events 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 ( oldChild == newChild ) // nothing to do return oldChild; // Make sure adding the new child is ok checkAddChild(newChild, exceptioncode); if (exceptioncode) return 0; // NOT_FOUND_ERR: Raised if oldChild is not a child of this node. if (!oldChild || oldChild->parentNode() != this) { exceptioncode = DOMException::NOT_FOUND_ERR; return 0; } bool isFragment = newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE; NodeImpl *nextChild; NodeImpl *child = isFragment ? newChild->firstChild() : newChild; // Remove the old child NodeImpl *prev = oldChild->previousSibling(); NodeImpl *next = oldChild->nextSibling(); removeChild(oldChild, exceptioncode); if (exceptioncode) return 0; // Add the new child(ren) while (child) { nextChild = isFragment ? child->nextSibling() : 0; // If child is already present in the tree, first remove it NodeImpl *newParent = child->parentNode(); if ( child == next ) next = child->nextSibling(); if ( child == prev ) prev = child->previousSibling(); if(newParent) newParent->removeChild( child, exceptioncode ); if (exceptioncode) return 0; // Add child in the correct position 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); // Add child to the rendering tree // ### should we detach() it first if it's already attached? if (attached() && !child->attached()) child->attach(); // Dispatch the mutation events 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; // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. if (isReadOnly()) { exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR; return 0; } // NOT_FOUND_ERR: Raised if oldChild is not a child of this node. if (!oldChild || oldChild->parentNode() != this) { exceptioncode = DOMException::NOT_FOUND_ERR; return 0; } dispatchChildRemovalEvents(oldChild,exceptioncode); if (exceptioncode) return 0; // Remove from rendering tree if (oldChild->attached()) oldChild->detach(); // Remove the child 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); setChanged(true); // Dispatch post-removal mutation events dispatchSubtreeModifiedEvent(); NodeImpl *p = this; while (p->parentNode()) p = p->parentNode(); if (p->nodeType() == Node::DOCUMENT_NODE) { for (NodeImpl *c = oldChild; c; c = c->traverseNextNode(oldChild)) c->removedFromDocument(); } return oldChild;}void NodeBaseImpl::removeChildren(){ bool inDoc = inDocument(); NodeImpl *n, *next; for( n = _first, _first = 0; n; n = next ) { next = n->nextSibling(); if (n->attached()) n->detach(); n->setPreviousSibling(0); n->setNextSibling(0); n->setParent(0); if ( inDoc ) for ( NodeImpl* c = n; c; c = c->traverseNextNode( n ) ) c->removedFromDocument(); if( !n->refCount() ) delete n; } _last = 0;}NodeImpl *NodeBaseImpl::appendChild ( NodeImpl *newChild, int &exceptioncode ){ exceptioncode = 0; // Make sure adding the new child is ok checkAddChild(newChild, exceptioncode); if (exceptioncode) return 0; if ( newChild == _last ) // nothing to do return newChild; bool isFragment = newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE; // If newChild is a DocumentFragment with no children.... there's nothing to do. // Just return the document fragment if (isFragment && !newChild->firstChild()) return newChild; // Now actually add the child(ren) NodeImpl *nextChild; NodeImpl *child = isFragment ? newChild->firstChild() : newChild; while (child) { nextChild = isFragment ? child->nextSibling() : 0; // If child is already present in the tree, first remove it NodeImpl *oldParent = child->parentNode(); if(oldParent) { oldParent->removeChild( child, exceptioncode ); if (exceptioncode) return 0; } // Append child to the end of the list child->setParent(this); if(_last) { child->setPreviousSibling(_last); _last->setNextSibling(child); _last = child; } else { _first = _last = child; } // Add child to the rendering tree // ### should we detach() it first if it's already attached? if (attached() && !child->attached()) child->attach(); // Dispatch the mutation events 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 = getDocument(); DocumentImpl *ownerDocNew = getDocument(); if(ownerDocThis != ownerDocNew) { kdDebug(6010)<< "not same document, newChild = " << newChild << "document = " << getDocument() << endl; exceptioncode = DOMException::WRONG_DOCUMENT_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;}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 (inDocument()) newChild->insertedIntoDocument(); childrenChanged(); if(newChild->nodeType() == Node::ELEMENT_NODE) return newChild; return this;}void NodeBaseImpl::attach(){ NodeImpl *child = _first; while(child != 0) { child->attach(); child = child->nextSibling(); } NodeImpl::attach();}void NodeBaseImpl::detach(){ NodeImpl *child = _first; while(child != 0) { NodeImpl* prev = child; child = child->nextSibling(); prev->detach(); } NodeImpl::detach();}void NodeBaseImpl::cloneChildNodes(NodeImpl *clone){ int exceptioncode = 0; NodeImpl *n; for(n = firstChild(); n && !exceptioncode; n = n->nextSibling()) { clone->appendChild(n->cloneNode(true),exceptioncode); }}// I don't like this way of implementing the method, but I didn't find any// other way. Larsbool NodeBaseImpl::getUpperLeftCorner(int &xPos, int &yPos) const{ if (!m_render) return false; RenderObject *o = m_render; xPos = yPos = 0; if ( !o->isInline() || o->isReplaced() ) { o->absolutePosition( xPos, yPos ); return true; } // find the next text/image child, to get a position while(o) { if(o->firstChild()) o = o->firstChild(); else if(o->nextSibling()) o = o->nextSibling(); else { RenderObject *next = 0; while(!next) { o = o->parent(); if(!o) return false; next = o->nextSibling(); } o = next; } if((o->isText() && !o->isBR()) || o->isReplaced()) { o->container()->absolutePosition( xPos, yPos ); if (o->isText()) { xPos += o->inlineXPos(); yPos += o->inlineYPos(); } else { xPos += o->xPos(); yPos += o->yPos(); } return true; } } return true;}bool NodeBaseImpl::getLowerRightCorner(int &xPos, int &yPos) const{ if (!m_render) return false; RenderObject *o = m_render; xPos = yPos = 0; if (!o->isInline() || o->isReplaced()) { o->absolutePosition( xPos, yPos ); xPos += o->width(); yPos += o->height(); return true; } // find the last text/image child, to get a position while(o) { if(o->lastChild()) o = o->lastChild(); else if(o->previousSibling()) o = o->previousSibling(); else { RenderObject *prev = 0; while(!prev) { o = o->parent(); if(!o) return false; prev = o->previousSibling(); } o = prev; } if((o->isText() && !o->isBR()) || o->isReplaced()) { o->container()->absolutePosition(xPos, yPos); if (o->isText()) { xPos += o->inlineXPos() + o->width(); yPos += o->inlineYPos() + o->height(); } else { xPos += o->xPos() + o->width(); yPos += o->yPos() + o->height(); } return true; } } return true;}void NodeBaseImpl::setFocus(bool received){ if (m_focused == received) return; NodeImpl::setFocus(received); // note that we need to recalc the style setChanged();}void NodeBaseImpl::setActive(bool down){ if (down == active()) return; NodeImpl::setActive(down); // note that we need to recalc the style if (m_render && m_render->style()->affectedByActiveRules()) setChanged();}unsigned long NodeBaseImpl::childNodeCount(){ unsigned long count = 0; NodeImpl *n; for (n = firstChild(); n; n = n->nextSibling()) count++; return count;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -