📄 dom_nodeimpl.cpp
字号:
NodeImpl::insertedIntoDocument(); for (NodeImpl *child = _first; child; child = child->nextSibling()) child->insertedIntoDocument();}void NodeBaseImpl::removedFromDocument(){ NodeImpl::removedFromDocument(); for (NodeImpl *child = _first; child; child = child->nextSibling()) child->removedFromDocument();}void NodeBaseImpl::cloneChildNodes(NodeImpl *clone){ int exceptioncode = 0; NodeImpl *n; for(n = firstChild(); n && !exceptioncode; n = n->nextSibling()) { clone->appendChild(n->cloneNode(true),exceptioncode); }}NodeListImpl* NodeBaseImpl::getElementsByTagNameNS ( DOMStringImpl* namespaceURI, DOMStringImpl* localName ){ if (!localName) return 0; NodeImpl::Id idMask = namespaceMask | localNameMask; if (localName->l && localName->s[0] == '*') idMask &= ~localNameMask; if (namespaceURI && namespaceURI->l && namespaceURI->s[0] == '*') idMask &= ~namespaceMask; Id id = 0; // 0 means "all items" if ( (idMask & localNameMask) || namespaceURI ) // not getElementsByTagName("*") { id = getDocument()->tagId( namespaceURI, localName, true); if ( !id ) // not found -> we want to return an empty list, not "all items" id = (Id)-1; // HACK. HEAD has a cleaner implementation of TagNodeListImpl it seems. } return new TagNodeListImpl( this, id, idMask );}// 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 += static_cast<RenderText *>(o)->minXPos(); 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->isReplaced()) { o->container()->absolutePosition(xPos, yPos); if (o->isText()) xPos += static_cast<RenderText *>(o)->minXPos() + o->width(); else xPos += o->xPos()+o->width(); yPos += o->yPos()+o->height(); return true; } } return true;}QRect NodeBaseImpl::getRect() const{ int xPos, yPos; if (!getUpperLeftCorner(xPos,yPos)) { xPos=0; yPos=0; } int xEnd, yEnd; if (!getLowerRightCorner(xEnd,yEnd)) { if (xPos) xEnd = xPos; if (yPos) yEnd = yPos; } else { if (xPos==0) xPos = xEnd; if (yPos==0) yPos = yEnd; } if ( xEnd <= xPos || yEnd <= yPos ) return QRect( QPoint( xPos, yPos ), QSize() ); return QRect(xPos, yPos, xEnd - xPos, yEnd - yPos);}void NodeBaseImpl::setFocus(bool received){ if (m_focused == received) return; NodeImpl::setFocus(received); if (received && isEditableBlock() && !hasChildNodes()) { KHTMLPart *part = getDocument()->part(); part->setSelection(Selection(Position(this, 0))); } // 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;}NodeImpl *NodeBaseImpl::childNode(unsigned long index){ unsigned long i; NodeImpl *n = firstChild(); for (i = 0; i < index; i++) n = n->nextSibling(); return n;}void NodeBaseImpl::dispatchChildInsertedEvents( NodeImpl *child, int &exceptioncode ){ if (getDocument()->hasListenerType(DocumentImpl::DOMNODEINSERTED_LISTENER)) { child->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEINSERTED_EVENT, true,false,this,DOMString(),DOMString(),DOMString(),0),exceptioncode,true); if (exceptioncode) return; } // dispatch the DOMNOdeInsertedInfoDocument event to all descendants bool hasInsertedListeners = getDocument()->hasListenerType(DocumentImpl::DOMNODEINSERTEDINTODOCUMENT_LISTENER); NodeImpl *p = this; while (p->parentNode()) p = p->parentNode(); if (p->nodeType() == Node::DOCUMENT_NODE) { for (NodeImpl *c = child; c; c = c->traverseNextNode(child)) { c->insertedIntoDocument(); if (hasInsertedListeners) { c->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEINSERTEDINTODOCUMENT_EVENT, false,false,0,DOMString(),DOMString(),DOMString(),0),exceptioncode,true); if (exceptioncode) return; } } }}void NodeBaseImpl::dispatchChildRemovalEvents( NodeImpl *child, int &exceptioncode ){ // Dispatch pre-removal mutation events getDocument()->notifyBeforeNodeRemoval(child); // ### use events instead if (getDocument()->hasListenerType(DocumentImpl::DOMNODEREMOVED_LISTENER)) { child->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEREMOVED_EVENT, true,false,this,DOMString(),DOMString(),DOMString(),0),exceptioncode,true); if (exceptioncode) return; } bool hasRemovalListeners = 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) { for (NodeImpl *c = child; c; c = c->traverseNextNode(child)) { if (hasRemovalListeners) { c->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEREMOVEDFROMDOCUMENT_EVENT, false,false,0,DOMString(),DOMString(),DOMString(),0),exceptioncode,true); if (exceptioncode) return; } } }}// ---------------------------------------------------------------------------NodeImpl *NodeListImpl::item( unsigned long /*index*/ ) const{ return 0;}unsigned long NodeListImpl::length() const{ return 0;}unsigned long NodeListImpl::recursiveLength(NodeImpl *start) const{ unsigned long len = 0; for(NodeImpl *n = start->firstChild(); n != 0; n = n->nextSibling()) { if ( n->nodeType() == Node::ELEMENT_NODE ) { if (nodeMatches(n)) len++; len+= recursiveLength(n); } } return len;}NodeImpl *NodeListImpl::recursiveItem ( NodeImpl *start, unsigned long &offset ) const{ for(NodeImpl *n = start->firstChild(); n != 0; n = n->nextSibling()) { if ( n->nodeType() == Node::ELEMENT_NODE ) { if (nodeMatches(n)) if (!offset--) return n; NodeImpl *depthSearch= recursiveItem(n, offset); if (depthSearch) return depthSearch; } } return 0; // no matching node in this subtree}ChildNodeListImpl::ChildNodeListImpl( NodeImpl *n ){ refNode = n; refNode->ref();}ChildNodeListImpl::~ChildNodeListImpl(){ refNode->deref();}unsigned long ChildNodeListImpl::length() const{ unsigned long len = 0; NodeImpl *n; for(n = refNode->firstChild(); n != 0; n = n->nextSibling()) len++; return len;}NodeImpl *ChildNodeListImpl::item ( unsigned long index ) const{ unsigned int pos = 0; NodeImpl *n = refNode->firstChild(); while( n != 0 && pos < index ) { n = n->nextSibling(); pos++; } return n;}bool ChildNodeListImpl::nodeMatches( NodeImpl */*testNode*/ ) const{ return true;}TagNodeListImpl::TagNodeListImpl(NodeImpl *n, NodeImpl::Id _id, NodeImpl::Id _idMask ) : refNode(n), m_id(_id & _idMask), m_idMask(_idMask){ refNode->ref();}TagNodeListImpl::~TagNodeListImpl(){ refNode->deref();}unsigned long TagNodeListImpl::length() const{ return recursiveLength( refNode );}NodeImpl *TagNodeListImpl::item ( unsigned long index ) const{ return recursiveItem( refNode, index );}bool TagNodeListImpl::nodeMatches( NodeImpl *testNode ) const{ return ( testNode->isElementNode() && (testNode->id() & m_idMask) == m_id);}NameNodeListImpl::NameNodeListImpl(NodeImpl *n, const DOMString &t ) : nodeName(t){ refNode= n; refNode->ref();}NameNodeListImpl::~NameNodeListImpl(){ refNode->deref();}unsigned long NameNodeListImpl::length() const{ return recursiveLength( refNode );}NodeImpl *NameNodeListImpl::item ( unsigned long index ) const{ return recursiveItem( refNode, index );}bool NameNodeListImpl::nodeMatches( NodeImpl *testNode ) const{ return static_cast<ElementImpl *>(testNode)->getAttribute(ATTR_NAME) == nodeName;}// ---------------------------------------------------------------------------NamedNodeMapImpl::NamedNodeMapImpl(){}NamedNodeMapImpl::~NamedNodeMapImpl(){}// ----------------------------------------------------------------------------// ### unused#if 0GenericRONamedNodeMapImpl::GenericRONamedNodeMapImpl(DocumentPtr* doc) : NamedNodeMapImpl(){ m_doc = doc->document(); m_contents = new QPtrList<NodeImpl>;}GenericRONamedNodeMapImpl::~GenericRONamedNodeMapImpl(){ while (m_contents->count() > 0) m_contents->take(0)->deref(); delete m_contents;}NodeImpl *GenericRONamedNodeMapImpl::getNamedItem ( const DOMString &name, int &/*exceptioncode*/ ) const{ QPtrListIterator<NodeImpl> it(*m_contents); for (; it.current(); ++it) if (it.current()->nodeName() == name) return it.current(); return 0;}Node GenericRONamedNodeMapImpl::setNamedItem ( const Node &/*arg*/, int &exceptioncode ){ // can't modify this list through standard DOM functions // NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR; return 0;}Node GenericRONamedNodeMapImpl::removeNamedItem ( const DOMString &/*name*/, int &exceptioncode ){ // can't modify this list through standard DOM functions // NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR; return 0;}NodeImpl *GenericRONamedNodeMapImpl::item ( unsigned long index ) const{ // ### check this when calling from javascript using -1 = 2^sizeof(int)-1 // (also for other similar methods) if (index >= m_contents->count()) return 0; return m_contents->at(index);}unsigned long GenericRONamedNodeMapImpl::length( ) const{ return m_contents->count(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -