KHTML
khtml_global.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org> 00004 * Copyright (C) 2007 David Faure <faure@kde.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "khtml_global.h" 00023 #include "khtml_part.h" 00024 #include "khtml_settings.h" 00025 00026 #include "css/cssstyleselector.h" 00027 #include "css/css_mediaquery.h" 00028 #include "html/html_imageimpl.h" 00029 #include "rendering/render_style.h" 00030 #include "rendering/break_lines.h" 00031 #include "misc/htmlnames.h" 00032 #include "misc/loader.h" 00033 #include "misc/arena.h" 00034 #include "misc/paintbuffer.h" 00035 00036 #include <QtCore/QLinkedList> 00037 00038 #include <kcomponentdata.h> 00039 #include <kiconloader.h> 00040 #include <kaboutdata.h> 00041 #include <klocale.h> 00042 00043 #include <assert.h> 00044 00045 #include <kdebug.h> 00046 00047 // SVG 00048 #include "svg/SVGNames.h" 00049 00050 KHTMLGlobal *KHTMLGlobal::s_self = 0; 00051 unsigned long int KHTMLGlobal::s_refcnt = 0; 00052 KComponentData *KHTMLGlobal::s_componentData = 0; 00053 KIconLoader *KHTMLGlobal::s_iconLoader = 0; 00054 KAboutData *KHTMLGlobal::s_about = 0; 00055 KHTMLSettings *KHTMLGlobal::s_settings = 0; 00056 00057 static QLinkedList<KHTMLPart*> *s_parts = 0; 00058 static QLinkedList<DOM::DocumentImpl*> *s_docs = 0; 00059 00060 KHTMLGlobal::KHTMLGlobal() 00061 { 00062 assert(!s_self); 00063 s_self = this; 00064 ref(); 00065 00066 khtml::Cache::init(); 00067 00068 khtml::NamespaceFactory::initIdTable(); 00069 khtml::PrefixFactory::initIdTable(); 00070 khtml::LocalNameFactory::initIdTable(); 00071 DOM::emptyLocalName = DOM::LocalName::fromId(0); 00072 DOM::emptyPrefixName = DOM::PrefixName::fromId(0); 00073 DOM::emptyNamespaceName = DOM::NamespaceName::fromId(DOM::emptyNamespace); 00074 WebCore::SVGNames::init(); 00075 } 00076 00077 KHTMLGlobal::~KHTMLGlobal() 00078 { 00079 //kDebug(6000) << this; 00080 if ( s_self == this ) 00081 { 00082 finalCheck(); 00083 delete s_iconLoader; 00084 delete s_componentData; 00085 delete s_about; 00086 delete s_settings; 00087 delete KHTMLSettings::avFamilies; 00088 if (s_parts) { 00089 assert(s_parts->isEmpty()); 00090 delete s_parts; 00091 } 00092 if (s_docs) { 00093 assert(s_docs->isEmpty()); 00094 delete s_docs; 00095 } 00096 00097 s_iconLoader = 0; 00098 s_componentData = 0; 00099 s_about = 0; 00100 s_settings = 0; 00101 s_parts = 0; 00102 s_docs = 0; 00103 KHTMLSettings::avFamilies = 0; 00104 00105 // clean up static data 00106 khtml::CSSStyleSelector::clear(); 00107 khtml::RenderStyle::cleanup(); 00108 khtml::RenderObject::cleanup(); 00109 khtml::PaintBuffer::cleanup(); 00110 khtml::MediaQueryEvaluator::cleanup(); 00111 khtml::Cache::clear(); 00112 khtml::cleanup_thaibreaks(); 00113 khtml::ArenaFinish(); 00114 } 00115 else 00116 deref(); 00117 } 00118 00119 void KHTMLGlobal::ref() 00120 { 00121 if ( !s_refcnt && !s_self ) 00122 { 00123 //kDebug(6000) << "Creating KHTMLGlobal instance"; 00124 // we can't use a staticdeleter here, because that would mean 00125 // that the KHTMLGlobal instance gets deleted from within a qPostRoutine, called 00126 // from the QApplication destructor. That however is too late, because 00127 // we want to destruct a KComponentData object, which involves destructing 00128 // a KConfig object, which might call KGlobal::dirs() (in sync()) which 00129 // probably is not going to work ;-) 00130 // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the 00131 // safe side ;-) -> let's use a simple reference counting scheme 00132 // (Simon) 00133 new KHTMLGlobal; // does initial ref() 00134 } else { 00135 ++s_refcnt; 00136 } 00137 //kDebug(6000) << "s_refcnt=" << s_refcnt; 00138 } 00139 00140 void KHTMLGlobal::deref() 00141 { 00142 //kDebug(6000) << "s_refcnt=" << s_refcnt - 1; 00143 if ( !--s_refcnt && s_self ) 00144 { 00145 delete s_self; 00146 s_self = 0; 00147 } 00148 } 00149 00150 void KHTMLGlobal::registerPart( KHTMLPart *part ) 00151 { 00152 //kDebug(6000) << part; 00153 if ( !s_parts ) 00154 s_parts = new QLinkedList<KHTMLPart*>; 00155 00156 if ( !s_parts->contains( part ) ) { 00157 s_parts->append( part ); 00158 ref(); 00159 } 00160 } 00161 00162 void KHTMLGlobal::deregisterPart( KHTMLPart *part ) 00163 { 00164 //kDebug(6000) << part; 00165 assert( s_parts ); 00166 00167 if ( s_parts->removeAll( part ) ) { 00168 if ( s_parts->isEmpty() ) { 00169 delete s_parts; 00170 s_parts = 0; 00171 } 00172 deref(); 00173 } 00174 } 00175 00176 void KHTMLGlobal::registerDocumentImpl( DOM::DocumentImpl *doc ) 00177 { 00178 //kDebug(6000) << doc; 00179 if ( !s_docs ) 00180 s_docs = new QLinkedList<DOM::DocumentImpl*>; 00181 00182 if ( !s_docs->contains( doc ) ) { 00183 s_docs->append( doc ); 00184 ref(); 00185 } 00186 } 00187 00188 void KHTMLGlobal::deregisterDocumentImpl( DOM::DocumentImpl *doc ) 00189 { 00190 //kDebug(6000) << doc; 00191 assert( s_docs ); 00192 00193 if ( s_docs->removeAll( doc ) ) { 00194 if ( s_docs->isEmpty() ) { 00195 delete s_docs; 00196 s_docs = 0; 00197 } 00198 deref(); 00199 } 00200 } 00201 00202 const KComponentData &KHTMLGlobal::componentData() 00203 { 00204 assert( s_self ); 00205 00206 if ( !s_componentData ) 00207 { 00208 s_about = new KAboutData( "khtml", 0, ki18n( "KHTML" ), "4.0", 00209 ki18n( "Embeddable HTML component" ), 00210 KAboutData::License_LGPL ); 00211 s_about->addAuthor(ki18n("Lars Knoll"), KLocalizedString(), "knoll@kde.org"); 00212 s_about->addAuthor(ki18n("Antti Koivisto"), KLocalizedString(), "koivisto@kde.org"); 00213 s_about->addAuthor(ki18n("Waldo Bastian"), KLocalizedString(), "bastian@kde.org"); 00214 s_about->addAuthor(ki18n("Dirk Mueller"), KLocalizedString(), "mueller@kde.org"); 00215 s_about->addAuthor(ki18n("Peter Kelly"), KLocalizedString(), "pmk@kde.org"); 00216 s_about->addAuthor(ki18n("Torben Weis"), KLocalizedString(), "weis@kde.org"); 00217 s_about->addAuthor(ki18n("Martin Jones"), KLocalizedString(), "mjones@kde.org"); 00218 s_about->addAuthor(ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org"); 00219 s_about->addAuthor(ki18n("Tobias Anton"), KLocalizedString(), "anton@stud.fbi.fh-darmstadt.de"); 00220 00221 s_componentData = new KComponentData( s_about ); 00222 } 00223 00224 return *s_componentData; 00225 } 00226 00227 KIconLoader *KHTMLGlobal::iconLoader() 00228 { 00229 if ( !s_iconLoader ) 00230 { 00231 s_iconLoader = new KIconLoader(componentData().componentName(), componentData().dirs()); 00232 } 00233 00234 return s_iconLoader; 00235 } 00236 00237 KHTMLSettings *KHTMLGlobal::defaultHTMLSettings() 00238 { 00239 assert( s_self ); 00240 if ( !s_settings ) 00241 s_settings = new KHTMLSettings(); 00242 00243 return s_settings; 00244 } 00245 00246 void KHTMLGlobal::finalCheck() 00247 { 00248 #ifndef NDEBUG 00249 if (s_refcnt) { 00250 if (s_parts && !s_parts->isEmpty()) { 00251 Q_FOREACH(KHTMLPart *part, *s_parts) { 00252 kWarning(6000) << "Part" << part->url() << "was not deleted"; 00253 } 00254 } 00255 if (s_docs && !s_docs->isEmpty()) { 00256 Q_FOREACH(DOM::DocumentImpl *doc, *s_docs) { 00257 kWarning(6000) << "Document" << doc->URL() << "was not deleted"; 00258 } 00259 } 00260 } 00261 #endif 00262 }
KDE 4.6 API Reference