📄 html_documentimpl.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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#include "html/html_documentimpl.h"#include "html/html_imageimpl.h"#include "html/html_headimpl.h"#include "html/html_baseimpl.h"#include "html/htmltokenizer.h"#include "html/html_miscimpl.h"#include "html/html_formimpl.h"#include "khtmlview.h"#include "khtml_part.h"#include "khtmlpart_p.h"#include "khtml_settings.h"#include "misc/htmlattrs.h"#include "misc/htmlhashes.h"#include "xml/xml_tokenizer.h"#include "xml/dom2_eventsimpl.h"#include "khtml_factory.h"#include "rendering/render_object.h"#include "dom/dom_exception.h"#include <dcopclient.h>#include <kapplication.h>#include <kdebug.h>#include <kurl.h>#include <kglobal.h>#include <kcharsets.h>#include <kglobalsettings.h>#include "css/cssproperties.h"#include "css/cssstyleselector.h"#include "css/css_stylesheetimpl.h"#include <stdlib.h>#include <qptrstack.h>// Turn off inlining to avoid warning with newer gcc.#undef __inline#define __inline#include "doctypes.cpp"#undef __inlinetemplate class QPtrStack<DOM::NodeImpl>;using namespace DOM;using namespace khtml;HTMLDocumentImpl::HTMLDocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v) : DocumentImpl(_implementation, v){// kdDebug( 6090 ) << "HTMLDocumentImpl constructor this = " << this << endl; htmlElement = 0; m_doAutoFill = false;/* dynamic history stuff to be fixed later (pfeiffer) connect( KHTMLFactory::vLinks(), SIGNAL( inserted( const QString& )), SLOT( slotHistoryChanged() )); connect( KHTMLFactory::vLinks(), SIGNAL( removed( const QString& )), SLOT( slotHistoryChanged() ));*/ connect( KHTMLFactory::vLinks(), SIGNAL( cleared()), SLOT( slotHistoryChanged() ));}HTMLDocumentImpl::~HTMLDocumentImpl(){}DOMString HTMLDocumentImpl::referrer() const{ if ( view() ) return view()->part()->pageReferrer(); return DOMString();}DOMString HTMLDocumentImpl::lastModified() const{ if ( view() ) return view()->part()->lastModified(); return DOMString();}DOMString HTMLDocumentImpl::cookie() const{ long windowId = 0; KHTMLView *v = view (); if ( v && v->topLevelWidget() ) windowId = v->topLevelWidget()->winId(); QCString replyType; QByteArray params, reply; QDataStream stream(params, IO_WriteOnly); stream << URL().url() << windowId; if (!kapp->dcopClient()->call("kcookiejar", "kcookiejar", "findDOMCookies(QString,long int)", params, replyType, reply)) { kdWarning(6010) << "Can't communicate with cookiejar!" << endl; return DOMString(); } QDataStream stream2(reply, IO_ReadOnly); if(replyType != "QString") { kdError(6010) << "DCOP function findDOMCookies(...) returns " << replyType << ", expected QString" << endl; return DOMString(); } QString result; stream2 >> result; return DOMString(result);}void HTMLDocumentImpl::setCookie( const DOMString & value ){ long windowId = 0; KHTMLView *v = view (); if ( v && v->topLevelWidget() ) windowId = v->topLevelWidget()->winId(); QByteArray params; QDataStream stream(params, IO_WriteOnly); QCString fake_header("Set-Cookie: "); fake_header.append(value.string().latin1()); fake_header.append("\n"); stream << URL().url() << fake_header << windowId; if (!kapp->dcopClient()->send("kcookiejar", "kcookiejar", "addCookies(QString,QCString,long int)", params)) { // Maybe it wasn't running (e.g. we're opening local html files) KApplication::startServiceByDesktopName( "kcookiejar"); if (!kapp->dcopClient()->send("kcookiejar", "kcookiejar", "addCookies(QString,QCString,long int)", params)) kdWarning(6010) << "Can't communicate with cookiejar!" << endl; }}HTMLElementImpl *HTMLDocumentImpl::body(){ NodeImpl *de = documentElement(); if (!de) return 0; // try to prefer a FRAMESET element over BODY NodeImpl* body = 0; for (NodeImpl* i = de->firstChild(); i; i = i->nextSibling()) { if (i->id() == ID_FRAMESET) return static_cast<HTMLElementImpl*>(i); if (i->id() == ID_BODY) body = i; } return static_cast<HTMLElementImpl *>(body);}void HTMLDocumentImpl::setBody(HTMLElementImpl *_body, int& exceptioncode){ HTMLElementImpl *b = body(); if ( !_body ) { exceptioncode = DOMException::HIERARCHY_REQUEST_ERR; return; } if ( !b ) documentElement()->appendChild( _body, exceptioncode ); else documentElement()->replaceChild( _body, b, exceptioncode );}Tokenizer *HTMLDocumentImpl::createTokenizer(){ return new HTMLTokenizer(docPtr(),m_view);}// --------------------------------------------------------------------------// not part of the DOM// --------------------------------------------------------------------------bool HTMLDocumentImpl::childAllowed( NodeImpl *newChild ){ // ### support comments. etc as a child return (newChild->id() == ID_HTML || newChild->id() == ID_COMMENT);}ElementImpl *HTMLDocumentImpl::createElement( const DOMString &name, int* pExceptioncode ){ ElementImpl *e = createHTMLElement(name); if ( e ) { e->setHTMLCompat( htmlMode() != XHtml ); return e; } return DocumentImpl::createElement(name, pExceptioncode);}void HTMLDocumentImpl::slotHistoryChanged(){ if ( true || !m_render ) // disabled for now return; recalcStyle( Force ); m_render->repaint();}HTMLMapElementImpl* HTMLDocumentImpl::getMap(const DOMString& _url){ QString url = _url.string(); QString s; int pos = url.find('#'); //kdDebug(0) << "map pos of #:" << pos << endl; s = QString(_url.unicode() + pos + 1, _url.length() - pos - 1); QMapConstIterator<QString,HTMLMapElementImpl*> it = mapMap.find(s); if (it != mapMap.end()) return *it; else return 0;}void HTMLDocumentImpl::close(){ bool doload = !parsing() && m_tokenizer; DocumentImpl::close(); if (doload) { if (title().isEmpty()) // ensure setTitle is called at least once setTitle( DOMString() ); // auto fill: walk the tree and try to fill in login credentials if (view() && m_doAutoFill) { for (NodeImpl* n = this; n; n = n->traverseNextNode()) if (n->id() == ID_FORM) static_cast<HTMLFormElementImpl*>(n)->doAutoFill(); m_doAutoFill = false; } // According to dom the load event must not bubble // but other browsers execute in a frameset document // the first(IE)/last(Moz/Konq) registered onload on a <frame> and the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -