dom_nodeimpl.cpp
来自「将konqueror浏览器移植到ARM9 2410中」· C++ 代码 · 共 1,788 行 · 第 1/4 页
CPP
1,788 行
/** * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */#include "dom_nodeimpl.h"#include "dom_node.h"#include "dom_exception.h"#include "htmlattrs.h"#include "dom_elementimpl.h"#include "dom_docimpl.h"#include "dom2_eventsimpl.h"#include <kdebug.h>#include "rendering/render_object.h"#include "rendering/render_text.h"#include <qrect.h>#include <qevent.h>#include <qnamespace.h>using namespace DOM;using namespace khtml;NodeImpl::NodeImpl(DocumentPtr *doc) : document(doc), m_render(0), m_complexText( false ), m_hasEvents( false ), m_hasId( false ), m_hasClass( false ), m_hasStyle( false ), m_pressed( false ), m_mouseInside( false ), m_attached( false ), m_changed( false ), m_specified( false ), m_focused( false ), m_active( false ), m_regdListeners( 0 ){ document->ref();}NodeImpl::~NodeImpl(){ if (document->document()) document->document()->changedNodes.remove(this); if (m_regdListeners) delete m_regdListeners; document->deref();}DOMString NodeImpl::nodeValue() const{ return DOMString();}void NodeImpl::setNodeValue( const DOMString &, int &exceptioncode ){ exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;}const DOMString NodeImpl::nodeName() const{ return DOMString();}unsigned short NodeImpl::nodeType() const{ return 0;}NodeImpl *NodeImpl::parentNode() const{ return 0;}NodeListImpl *NodeImpl::childNodes(){ return new ChildNodeListImpl(this);}NodeImpl *NodeImpl::firstChild() const{ return 0;}NodeImpl *NodeImpl::lastChild() const{ return 0;}NodeImpl *NodeImpl::previousSibling() const{ return 0;}NodeImpl *NodeImpl::nextSibling() const{ return 0;}NamedNodeMapImpl *NodeImpl::attributes(){ return 0;}void NodeImpl::setPreviousSibling(NodeImpl *){}void NodeImpl::setNextSibling(NodeImpl *){}NodeImpl *NodeImpl::insertBefore( NodeImpl *, NodeImpl *, int &exceptioncode ){ exceptioncode = DOMException::HIERARCHY_REQUEST_ERR; return 0;}NodeImpl *NodeImpl::replaceChild( NodeImpl *, NodeImpl *, int &exceptioncode ){ exceptioncode = DOMException::HIERARCHY_REQUEST_ERR; return 0;}NodeImpl *NodeImpl::removeChild( NodeImpl *, int &exceptioncode ){ exceptioncode = DOMException::NOT_FOUND_ERR; return 0;}NodeImpl *NodeImpl::appendChild( NodeImpl *, int &exceptioncode ){ exceptioncode = DOMException::HIERARCHY_REQUEST_ERR; return 0;}bool NodeImpl::hasChildNodes( ) const{ return false;}// helper functions not being part of the DOMvoid NodeImpl::setParent(NodeImpl *){}void NodeImpl::setFirstChild(NodeImpl *){}void NodeImpl::setLastChild(NodeImpl *){}NodeImpl *NodeImpl::addChild(NodeImpl *){ return 0;}QString NodeImpl::toHTML() const{ NodeImpl* fc = firstChild(); if ( fc ) return fc->recursive_toHTML(true); return "";}QString NodeImpl::recursive_toHTML(bool start) const{ QString me = ""; // Copy who I am into the htmlText string if ( nodeType() == Node::TEXT_NODE ) me = nodeValue().string(); else { // If I am an element, not a text NodeImpl* temp = previousSibling(); if(temp) { if( !start && (temp->nodeType() != Node::TEXT_NODE && nodeType() != Node::TEXT_NODE ) ) me = QString(" ") + QChar('<') + nodeName().string(); else me = QChar('<') + nodeName().string(); } else me = QChar('<') + nodeName().string(); // print attributes if( nodeType() == Node::ELEMENT_NODE ) { ElementImpl *el = const_cast<ElementImpl*>(static_cast<const ElementImpl *>(this)); AttrImpl *attr; int exceptioncode; if(el->namedAttrMap) { NamedNodeMapImpl *attrs = el->namedAttrMap; unsigned long lmap = attrs->length(exceptioncode); for( unsigned int j=0; j<lmap; j++ ) { attr = static_cast<AttrImpl*>(attrs->item(j,exceptioncode)); me += " " + attr->name().string() + "=\"" + attr->value().string() + "\""; } } } // print ending bracket of start tag if( firstChild() == 0 ) // if element has no endtag me += " />\n"; else // if element has endtag { NodeImpl* temp = nextSibling(); if(temp) { if( (temp->nodeType() != Node::TEXT_NODE) ) me += ">\n"; else me += ">"; } else me += ">"; } } NodeImpl* n; if( (n = firstChild()) ) { // print firstChild me += n->recursive_toHTML( ); // Print my ending tag if ( nodeType() != Node::TEXT_NODE ) me += "</" + nodeName().string() + ">\n"; } // print next sibling if( (n = nextSibling()) ) me += n->recursive_toHTML( ); return me;}void NodeImpl::applyChanges(bool, bool){ setChanged(false);}void NodeImpl::getCursor(int offset, int &_x, int &_y, int &height){ if(m_render) m_render->cursorPos(offset, _x, _y, height); else _x = _y = height = -1;}QRect NodeImpl::getRect() const{ int _x, _y; if(m_render && m_render->absolutePosition(_x, _y)) return QRect( _x, _y, m_render->width(), m_render->height() ); return QRect();}void NodeImpl::setChanged(bool b){ if (!attached()) // changed compared to what? return; if (b && !changed() && ownerDocument()) ownerDocument()->changedNodes.append(this); else if (!b && changed() && ownerDocument()) ownerDocument()->changedNodes.remove(this); m_changed = b;}DOMString NodeImpl::namespaceURI() const{ return DOMString();}void NodeImpl::printTree(int indent){ QString ind; QString s; ind.fill(' ', indent); // ### find out why this isn't working if(isElementNode()) { s = ind + "<" + nodeName().string(); ElementImpl *el = const_cast<ElementImpl*>(static_cast<const ElementImpl *>(this)); AttrImpl *attr; int exceptioncode; NamedNodeMapImpl *attrs = el->attributes(); unsigned long lmap = attrs->length(exceptioncode); for( unsigned int j=0; j<lmap; j++ ) { attr = static_cast<AttrImpl*>(attrs->item(j,exceptioncode)); s += " " + attr->name().string() + "=\"" + attr->value().string() + "\""; } if(!firstChild()) s += " />"; else s += ">"; } else s = ind + "'" + nodeValue().string() + "'"; kdDebug() << s << endl; NodeImpl *child = firstChild(); while( child ) { child->printTree(indent+2); child = child->nextSibling(); } if(isElementNode() && firstChild()) kdDebug() << ind << "</" << nodeName().string() << ">" << endl;}unsigned long NodeImpl::nodeIndex() const{ return 0;}void NodeImpl::addEventListener(int id, EventListener *listener, const bool useCapture){ switch (id) { case EventImpl::DOMSUBTREEMODIFIED_EVENT: getDocument()->addListenerType(DocumentImpl::DOMSUBTREEMODIFIED_LISTENER); break; case EventImpl::DOMNODEINSERTED_EVENT: getDocument()->addListenerType(DocumentImpl::DOMNODEINSERTED_LISTENER); break; case EventImpl::DOMNODEREMOVED_EVENT: getDocument()->addListenerType(DocumentImpl::DOMNODEREMOVED_LISTENER); break; case EventImpl::DOMNODEREMOVEDFROMDOCUMENT_EVENT: getDocument()->addListenerType(DocumentImpl::DOMNODEREMOVEDFROMDOCUMENT_LISTENER); break; case EventImpl::DOMNODEINSERTEDINTODOCUMENT_EVENT: getDocument()->addListenerType(DocumentImpl::DOMNODEINSERTEDINTODOCUMENT_LISTENER); break; case EventImpl::DOMATTRMODIFIED_EVENT: getDocument()->addListenerType(DocumentImpl::DOMATTRMODIFIED_LISTENER); break; case EventImpl::DOMCHARACTERDATAMODIFIED_EVENT: getDocument()->addListenerType(DocumentImpl::DOMCHARACTERDATAMODIFIED_LISTENER); break; default: break; } RegisteredEventListener *rl = new RegisteredEventListener(static_cast<EventImpl::EventId>(id),listener,useCapture); if (!m_regdListeners) { m_regdListeners = new QList<RegisteredEventListener>; m_regdListeners->setAutoDelete(true); } // remove existing ones of the same type - ### is this correct (or do we ignore the new one?) removeEventListener(id,listener,useCapture); m_regdListeners->append(rl); listener->ref();}void NodeImpl::addEventListener(const DOMString &type, EventListener *listener, const bool useCapture, int &/*exceptioncode*/){ addEventListener(EventImpl::typeToId(type),listener,useCapture);}void NodeImpl::removeEventListener(int id, EventListener *listener, bool useCapture){ if (!m_regdListeners) // nothing to remove return; RegisteredEventListener rl(static_cast<EventImpl::EventId>(id),listener,useCapture); QListIterator<RegisteredEventListener> it(*m_regdListeners); for (; it.current(); ++it) if (*(it.current()) == rl) { m_regdListeners->removeRef(it.current()); listener->deref(); return; }}void NodeImpl::removeEventListener(const DOMString &type, EventListener *listener, bool useCapture,int &/*exceptioncode*/){ removeEventListener(EventImpl::typeToId(type),listener,useCapture);}void NodeImpl::removeHTMLEventListener(int id){ if (!m_regdListeners) // nothing to remove return; QListIterator<RegisteredEventListener> it(*m_regdListeners); for (; it.current(); ++it) if (it.current()->id == id && it.current()->listener->eventListenerType() == "_khtml_HTMLEventListener") { m_regdListeners->removeRef(it.current()); return; }}void NodeImpl::setHTMLEventListener(int id, EventListener *listener){ removeHTMLEventListener(id); if (listener) addEventListener(id,listener,false);}EventListener *NodeImpl::getHTMLEventListener(int id){ if (!m_regdListeners) // nothing to remove return 0; QListIterator<RegisteredEventListener> it(*m_regdListeners); for (; it.current(); ++it) if (it.current()->id == id &&
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?