📄 dom_docimpl.cpp
字号:
/** * 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. * * $Id: dom_docimpl.cpp,v 1.102.2.4 2003/06/20 15:19:10 pchitescu Exp $ */#include "dom_docimpl.h"#include "dom_node.h"#include "dom_elementimpl.h"#include "dom_textimpl.h"#include "dom_exception.h"#include "dom_xmlimpl.h"#include "dom2_rangeimpl.h"#include "dom2_traversalimpl.h"#include "dom2_viewsimpl.h"#include "dom2_eventsimpl.h"#include "css/cssstyleselector.h"#include "css/css_stylesheetimpl.h"#include "misc/helper.h"#include "css/csshelper.h"#include <qstring.h>#include <qstack.h>#include <qlist.h>#include <qpaintdevicemetrics.h>#include <qfontdatabase.h>#include "misc/htmlhashes.h"#include "misc/loader.h"#include <kdebug.h>#include "htmltokenizer.h"#include "xml_tokenizer.h"#include "rendering/render_object.h"#include "rendering/render_root.h"#include "rendering/render_style.h"#include "khtmlview.h"#include "khtml_part.h"#include <kglobal.h>#include <kcharsets.h>#include <kglobalsettings.h>#include "khtml_settings.h"#include "html_baseimpl.h"#include "html_blockimpl.h"#include "html_documentimpl.h"#include "html_elementimpl.h"#include "html_formimpl.h"#include "html_headimpl.h"#include "html_imageimpl.h"#include "html_inlineimpl.h"#include "html_listimpl.h"#include "html_miscimpl.h"#include "html_tableimpl.h"#include "html_objectimpl.h"using namespace DOM;using namespace khtml;//template class QStack<DOM::NodeImpl>; // needed ?DOMImplementationImpl::DOMImplementationImpl(){}DOMImplementationImpl::~DOMImplementationImpl(){}bool DOMImplementationImpl::hasFeature ( const DOMString &feature, const DOMString &version ){ QString lower = feature.string().lower(); if ((lower == "html" || lower == "xml") && (version == "1.0" || version == "" || version.isNull())) return true; else return false;}CSSStyleSheetImpl *DOMImplementationImpl::createCSSStyleSheet(DOMStringImpl */*title*/, DOMStringImpl */*media*/){ return 0; // ###}// ------------------------------------------------------------------------// KHTMLView might be 0DocumentImpl::DocumentImpl(KHTMLView *v) : NodeBaseImpl( new DocumentPtr() ){ document->doc = this; m_styleSelector = 0; m_paintDeviceMetrics = 0; m_view = v; if ( v ) { m_docLoader = new DocLoader(v->part()); setPaintDevice( m_view ); } else m_docLoader = new DocLoader( 0 ); visuallyOrdered = false; m_loadingSheet = false; m_sheet = 0; m_elemSheet = 0; m_tokenizer = 0; m_doctype = new DocumentTypeImpl( docPtr() ); m_doctype->ref(); m_implementation = new DOMImplementationImpl(); m_implementation->ref(); pMode = Strict; m_textColor = "#000000"; m_elementNames = 0; m_elementNameAlloc = 0; m_elementNameCount = 0; m_focusNode = 0; m_defaultView = new AbstractViewImpl(this); m_defaultView->ref(); m_listenerTypes = 0; m_styleSheets = new StyleSheetListImpl; m_styleSheets->ref();}DocumentImpl::~DocumentImpl(){ document->doc = 0; delete m_sheet; delete m_styleSelector; delete m_docLoader; if (m_elemSheet ) m_elemSheet->deref(); delete m_tokenizer; m_doctype->deref(); m_implementation->deref(); delete m_paintDeviceMetrics; if (m_elementNames) { unsigned short id; for (id = 0; id < m_elementNameCount; id++) { m_elementNames[id]->deref(); } delete [] m_elementNames; } m_defaultView->deref(); m_styleSheets->deref();}const DOMString DocumentImpl::nodeName() const{ return "#document";}unsigned short DocumentImpl::nodeType() const{ return Node::DOCUMENT_NODE;}ElementImpl *DocumentImpl::documentElement() const{ NodeImpl *n = firstChild(); while (n && n->nodeType() != Node::ELEMENT_NODE) n = n->nextSibling(); return static_cast<ElementImpl*>(n);}ElementImpl *DocumentImpl::createElement( const DOMString &name ){ return new XMLElementImpl( document, name.implementation() );}ElementImpl *DocumentImpl::createElementNS ( const DOMString &_namespaceURI, const DOMString &_qualifiedName ){ ElementImpl *e = 0; // ### somehow set the namespace for html elements to http://www.w3.org/1999/xhtml ? if (_namespaceURI == "http://www.w3.org/1999/xhtml") { QString qName = _qualifiedName.string(); int colonPos = qName.find(':',0); e = createHTMLElement(colonPos ? qName.mid(colonPos+1) : qName); } if (!e) e = new XMLElementImpl( document, _qualifiedName.implementation(), _namespaceURI.implementation() ); return e;}ElementImpl *DocumentImpl::createHTMLElement( const DOMString &name ){ uint id = khtml::getTagID( name.string().lower().latin1(), name.string().length() ); ElementImpl *n = 0; switch(id) { case ID_HTML: n = new HTMLHtmlElementImpl(docPtr()); break; case ID_HEAD: n = new HTMLHeadElementImpl(docPtr()); break; case ID_BODY: n = new HTMLBodyElementImpl(docPtr()); break;// head elements case ID_BASE: n = new HTMLBaseElementImpl(docPtr()); break; case ID_LINK: n = new HTMLLinkElementImpl(docPtr()); break; case ID_META: n = new HTMLMetaElementImpl(docPtr()); break; case ID_STYLE: n = new HTMLStyleElementImpl(docPtr()); break; case ID_TITLE: n = new HTMLTitleElementImpl(docPtr()); break;// frames case ID_FRAME: n = new HTMLFrameElementImpl(docPtr()); break; case ID_FRAMESET: n = new HTMLFrameSetElementImpl(docPtr()); break; case ID_IFRAME: n = new HTMLIFrameElementImpl(docPtr()); break;// form elements// ### FIXME: we need a way to set form dependency after we have made the form elements case ID_FORM: n = new HTMLFormElementImpl(docPtr()); break; case ID_BUTTON: n = new HTMLButtonElementImpl(docPtr()); break; case ID_FIELDSET: n = new HTMLFieldSetElementImpl(docPtr()); break; case ID_INPUT: n = new HTMLInputElementImpl(docPtr()); break; case ID_ISINDEX: n = new HTMLIsIndexElementImpl(docPtr()); break; case ID_LABEL: n = new HTMLLabelElementImpl(docPtr()); break; case ID_LEGEND: n = new HTMLLegendElementImpl(docPtr()); break; case ID_OPTGROUP: n = new HTMLOptGroupElementImpl(docPtr()); break; case ID_OPTION: n = new HTMLOptionElementImpl(docPtr()); break; case ID_SELECT: n = new HTMLSelectElementImpl(docPtr()); break; case ID_TEXTAREA: n = new HTMLTextAreaElementImpl(docPtr()); break;// lists case ID_DL: n = new HTMLDListElementImpl(docPtr()); break; case ID_DD: n = new HTMLGenericElementImpl(docPtr(), id); break; case ID_DT: n = new HTMLGenericElementImpl(docPtr(), id); break; case ID_UL: n = new HTMLUListElementImpl(docPtr()); break; case ID_OL: n = new HTMLOListElementImpl(docPtr()); break; case ID_DIR: n = new HTMLDirectoryElementImpl(docPtr()); break; case ID_MENU: n = new HTMLMenuElementImpl(docPtr()); break; case ID_LI: n = new HTMLLIElementImpl(docPtr()); break;// formatting elements (block) case ID_BLOCKQUOTE: n = new HTMLBlockquoteElementImpl(docPtr()); break; case ID_DIV: n = new HTMLDivElementImpl(docPtr()); break; case ID_H1: case ID_H2: case ID_H3: case ID_H4: case ID_H5: case ID_H6: n = new HTMLHeadingElementImpl(docPtr(), id); break; case ID_HR: n = new HTMLHRElementImpl(docPtr()); break; case ID_P: n = new HTMLParagraphElementImpl(docPtr()); break; case ID_PRE: n = new HTMLPreElementImpl(docPtr()); break;// font stuff case ID_BASEFONT: n = new HTMLBaseFontElementImpl(docPtr()); break; case ID_FONT: n = new HTMLFontElementImpl(docPtr()); break;// ins/del case ID_DEL: case ID_INS: n = new HTMLModElementImpl(docPtr(), id); break;// anchor case ID_A: n = new HTMLAnchorElementImpl(docPtr()); break;// images case ID_IMG: n = new HTMLImageElementImpl(docPtr()); break; case ID_MAP: n = new HTMLMapElementImpl(docPtr()); /*n = map;*/ break; case ID_AREA: n = new HTMLAreaElementImpl(docPtr()); break;// objects, applets and scripts case ID_APPLET: n = new HTMLAppletElementImpl(docPtr()); break; case ID_OBJECT: n = new HTMLObjectElementImpl(docPtr()); break; case ID_PARAM: n = new HTMLParamElementImpl(docPtr()); break; case ID_SCRIPT: n = new HTMLScriptElementImpl(docPtr()); break;// tables case ID_TABLE: n = new HTMLTableElementImpl(docPtr()); break; case ID_CAPTION: n = new HTMLTableCaptionElementImpl(docPtr()); break; case ID_COLGROUP: case ID_COL: n = new HTMLTableColElementImpl(docPtr(), id); break; case ID_TR: n = new HTMLTableRowElementImpl(docPtr()); break; case ID_TD: case ID_TH: n = new HTMLTableCellElementImpl(docPtr(), id); break; case ID_THEAD: case ID_TBODY: case ID_TFOOT: n = new HTMLTableSectionElementImpl(docPtr(), id); break;// inline elements case ID_BR: n = new HTMLBRElementImpl(docPtr()); break; case ID_Q: n = new HTMLQuoteElementImpl(docPtr()); break;// elements with no special representation in the DOM// block: case ID_ADDRESS: case ID_CENTER: n = new HTMLGenericElementImpl(docPtr(), id); break;// inline // %fontstyle case ID_TT: case ID_U: case ID_B: case ID_I: case ID_S: case ID_STRIKE: case ID_BIG: case ID_SMALL: // %phrase case ID_EM: case ID_STRONG: case ID_DFN: case ID_CODE: case ID_SAMP: case ID_KBD: case ID_VAR: case ID_CITE: case ID_ABBR: case ID_ACRONYM: // %special case ID_SUB: case ID_SUP: case ID_SPAN: n = new HTMLGenericElementImpl(docPtr(), id); break; case ID_BDO: break;// text case ID_TEXT: kdDebug( 6020 ) << "Use document->createTextNode()" << endl; break; default: break; } return n;}// Used to maintain list of all forms in documentQString DocumentImpl::registerElement(ElementImpl *e){ m_registeredElements.append(e); QString state; if (!m_state.isEmpty()) { state = m_state.first(); m_state.remove(m_state.begin()); } return state;}// Used to maintain list of all forms in documentvoid DocumentImpl::removeElement(ElementImpl *e){ m_registeredElements.removeRef(e);}QStringList DocumentImpl::state(){ QStringList s; for( ElementImpl *e = m_registeredElements.first(); e; e = m_registeredElements.next()) { s.append(e->state()); } return s;}RangeImpl *DocumentImpl::createRange(){ return new RangeImpl( docPtr() );}NodeIteratorImpl *DocumentImpl::createNodeIterator(NodeImpl *root, unsigned long whatToShow, NodeFilter filter, bool entityReferenceExpansion, int &exceptioncode){ if (!root) { exceptioncode = DOMException::NOT_SUPPORTED_ERR; return 0; } return new NodeIteratorImpl(root,whatToShow,filter,entityReferenceExpansion);}TreeWalkerImpl *DocumentImpl::createTreeWalker(Node /*root*/, unsigned long /*whatToShow*/, NodeFilter /*filter*/, bool /*entityReferenceExpansion*/){ return new TreeWalkerImpl;}void DocumentImpl::applyChanges(bool,bool force){ // ### move the following two lines to createSelector???? delete m_styleSelector; m_styleSelector = 0; m_styleSelector = new CSSStyleSelector(this); if(!m_render) return; 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(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -