dom_nodeimpl.cpp

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

CPP
1,788
字号
	    m_active = false;    } else if ( m_active ) {	m_active = false;    }    if ( (oldinside != inside && m_style->hasHover()) ||	 ( oldactive != m_active && m_style->hasActive() ) )        applyChanges(true, false);    return inside;}void NodeBaseImpl::attach(){    NodeImpl *child = _first;    while(child != 0)    {        child->attach();        child = child->nextSibling();    }    NodeWParentImpl::attach();}void NodeBaseImpl::detach(){    NodeImpl *child = _first;    while(child != 0)    {        NodeImpl* prev = child;        child = child->nextSibling();        prev->detach();    }    NodeWParentImpl::detach();}void NodeBaseImpl::cloneChildNodes(NodeImpl *clone, int &exceptioncode){    NodeImpl *n;//    for(n = firstChild(); n != lastChild() && !exceptioncode; n = n->nextSibling())    for(n = firstChild(); n && !exceptioncode; n = n->nextSibling())    {        clone->appendChild(n->cloneNode(true,exceptioncode),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 += 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::setStyle(khtml::RenderStyle *style){    RenderStyle *oldStyle = m_style;    m_style = style;    if (m_style)        m_style->ref();    if (oldStyle)        oldStyle->deref();}void NodeBaseImpl::setFocus(bool received){    NodeImpl::setFocus(received);    for(NodeImpl *it=_first;it;it=it->nextSibling())        it->setFocus(received);}void NodeBaseImpl::setActive(bool down){    NodeImpl::setActive(down);    for(NodeImpl *it=_first;it;it=it->nextSibling())        it->setActive(down);}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);	if (exceptioncode)	    return;    }    if (getDocument()->hasListenerType(DocumentImpl::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) {	// dispatch the DOMNOdeInsertedInfoDocument event to all descendants	NodeImpl *p = this;	while (p->parentNode())	    p = p->parentNode();	if (p->nodeType() == Node::DOCUMENT_NODE) {	    NodeImpl *c;	    for (c = child; c; c = c->traverseNextNode(child)) {		c->dispatchEvent(new MutationEventImpl(EventImpl::DOMNODEINSERTEDINTODOCUMENT_EVENT,				 false,false,0,DOMString(),DOMString(),DOMString(),0),exceptioncode);		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}bool NodeListImpl::nodeMatches( NodeImpl */*testNode*/ ) const{  // ###    return false;}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;}TagNodeListImpl::TagNodeListImpl(NodeImpl *n, const DOMString &t )  : tagName(t){    refNode = n;    refNode->ref();    allElements = (t == "*");}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 ((allElements && testNode->nodeType() == Node::ELEMENT_NODE) ||            !strcasecmp(testNode->nodeName(),tagName));}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(){}// ----------------------------------------------------------------------------GenericRONamedNodeMapImpl::GenericRONamedNodeMapImpl() : NamedNodeMapImpl(){    // not sure why this doesn't work as a normal object    m_contents = new QList<NodeImpl>;}GenericRONamedNodeMapImpl::~GenericRONamedNodeMapImpl(){    while (m_contents->count() > 0)        m_contents->take(0)->deref();    delete m_contents;}unsigned long GenericRONamedNodeMapImpl::length(int &/*exceptioncode*/) const{    return m_contents->count();}NodeImpl *GenericRONamedNodeMapImpl::getNamedItem ( const DOMString &name, int &/*exceptioncode*/ ) const{    QListIterator<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    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    exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;    return 0;}NodeImpl *GenericRONamedNodeMapImpl::item ( unsigned long index, int &/*exceptioncode*/ ) 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);}void GenericRONamedNodeMapImpl::addNode(NodeImpl *n){    // The spec says that in the case of duplicates we only keep the first one    int exceptioncode;    if (getNamedItem(n->nodeName(),exceptioncode))        return;    n->ref();    m_contents->append(n);}// vim:ts=4:sw=4

⌨️ 快捷键说明

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