KHTML
khtml_global.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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/loader.h"
00032 #include "misc/arena.h"
00033 #include "misc/paintbuffer.h"
00034
00035 #include <QtCore/QLinkedList>
00036
00037 #include <kcomponentdata.h>
00038 #include <kiconloader.h>
00039 #include <kaboutdata.h>
00040 #include <klocale.h>
00041
00042 #include <assert.h>
00043
00044 #include <kdebug.h>
00045
00046
00047 #include "svg/SVGNames.h"
00048
00049 KHTMLGlobal *KHTMLGlobal::s_self = 0;
00050 unsigned long int KHTMLGlobal::s_refcnt = 0;
00051 KComponentData *KHTMLGlobal::s_componentData = 0;
00052 KIconLoader *KHTMLGlobal::s_iconLoader = 0;
00053 KAboutData *KHTMLGlobal::s_about = 0;
00054 KHTMLSettings *KHTMLGlobal::s_settings = 0;
00055
00056 static QLinkedList<KHTMLPart*> *s_parts = 0;
00057 static QLinkedList<DOM::DocumentImpl*> *s_docs = 0;
00058
00059 KHTMLGlobal::KHTMLGlobal()
00060 {
00061 assert(!s_self);
00062 s_self = this;
00063 ref();
00064
00065 khtml::Cache::init();
00066
00067 khtml::NamespaceFactory::initIdTable();
00068 khtml::PrefixFactory::initIdTable();
00069 khtml::LocalNameFactory::initIdTable();
00070 DOM::emptyLocalName = DOM::LocalName::fromId(0);
00071 DOM::emptyPrefixName = DOM::PrefixName::fromId(0);
00072 DOM::emptyNamespaceName = DOM::NamespaceName::fromId(0);
00073 WebCore::SVGNames::init();
00074 }
00075
00076 KHTMLGlobal::~KHTMLGlobal()
00077 {
00078
00079 if ( s_self == this )
00080 {
00081 finalCheck();
00082 delete s_iconLoader;
00083 delete s_componentData;
00084 delete s_about;
00085 delete s_settings;
00086 delete KHTMLSettings::avFamilies;
00087 if (s_parts) {
00088 assert(s_parts->isEmpty());
00089 delete s_parts;
00090 }
00091 if (s_docs) {
00092 assert(s_docs->isEmpty());
00093 delete s_docs;
00094 }
00095
00096 s_iconLoader = 0;
00097 s_componentData = 0;
00098 s_about = 0;
00099 s_settings = 0;
00100 s_parts = 0;
00101 s_docs = 0;
00102 KHTMLSettings::avFamilies = 0;
00103
00104
00105 khtml::CSSStyleSelector::clear();
00106 khtml::RenderStyle::cleanup();
00107 khtml::RenderObject::cleanup();
00108 khtml::PaintBuffer::cleanup();
00109 khtml::MediaQueryEvaluator::cleanup();
00110 khtml::Cache::clear();
00111 khtml::cleanup_thaibreaks();
00112 khtml::ArenaFinish();
00113 }
00114 else
00115 deref();
00116 }
00117
00118 void KHTMLGlobal::ref()
00119 {
00120 if ( !s_refcnt && !s_self )
00121 {
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 new KHTMLGlobal;
00133 } else {
00134 ++s_refcnt;
00135 }
00136
00137 }
00138
00139 void KHTMLGlobal::deref()
00140 {
00141
00142 if ( !--s_refcnt && s_self )
00143 {
00144 delete s_self;
00145 s_self = 0;
00146 }
00147 }
00148
00149 void KHTMLGlobal::registerPart( KHTMLPart *part )
00150 {
00151
00152 if ( !s_parts )
00153 s_parts = new QLinkedList<KHTMLPart*>;
00154
00155 if ( !s_parts->contains( part ) ) {
00156 s_parts->append( part );
00157 ref();
00158 }
00159 }
00160
00161 void KHTMLGlobal::deregisterPart( KHTMLPart *part )
00162 {
00163
00164 assert( s_parts );
00165
00166 if ( s_parts->removeAll( part ) ) {
00167 if ( s_parts->isEmpty() ) {
00168 delete s_parts;
00169 s_parts = 0;
00170 }
00171 deref();
00172 }
00173 }
00174
00175 void KHTMLGlobal::registerDocumentImpl( DOM::DocumentImpl *doc )
00176 {
00177
00178 if ( !s_docs )
00179 s_docs = new QLinkedList<DOM::DocumentImpl*>;
00180
00181 if ( !s_docs->contains( doc ) ) {
00182 s_docs->append( doc );
00183 ref();
00184 }
00185 }
00186
00187 void KHTMLGlobal::deregisterDocumentImpl( DOM::DocumentImpl *doc )
00188 {
00189
00190 assert( s_docs );
00191
00192 if ( s_docs->removeAll( doc ) ) {
00193 if ( s_docs->isEmpty() ) {
00194 delete s_docs;
00195 s_docs = 0;
00196 }
00197 deref();
00198 }
00199 }
00200
00201 const KComponentData &KHTMLGlobal::componentData()
00202 {
00203 assert( s_self );
00204
00205 if ( !s_componentData )
00206 {
00207 s_about = new KAboutData( "khtml", 0, ki18n( "KHTML" ), "4.0",
00208 ki18n( "Embeddable HTML component" ),
00209 KAboutData::License_LGPL );
00210 s_about->addAuthor(ki18n("Lars Knoll"), KLocalizedString(), "knoll@kde.org");
00211 s_about->addAuthor(ki18n("Antti Koivisto"), KLocalizedString(), "koivisto@kde.org");
00212 s_about->addAuthor(ki18n("Waldo Bastian"), KLocalizedString(), "bastian@kde.org");
00213 s_about->addAuthor(ki18n("Dirk Mueller"), KLocalizedString(), "mueller@kde.org");
00214 s_about->addAuthor(ki18n("Peter Kelly"), KLocalizedString(), "pmk@kde.org");
00215 s_about->addAuthor(ki18n("Torben Weis"), KLocalizedString(), "weis@kde.org");
00216 s_about->addAuthor(ki18n("Martin Jones"), KLocalizedString(), "mjones@kde.org");
00217 s_about->addAuthor(ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org");
00218 s_about->addAuthor(ki18n("Tobias Anton"), KLocalizedString(), "anton@stud.fbi.fh-darmstadt.de");
00219
00220 s_componentData = new KComponentData( s_about );
00221 }
00222
00223 return *s_componentData;
00224 }
00225
00226 KIconLoader *KHTMLGlobal::iconLoader()
00227 {
00228 if ( !s_iconLoader )
00229 {
00230 s_iconLoader = new KIconLoader(componentData().componentName(), componentData().dirs());
00231 }
00232
00233 return s_iconLoader;
00234 }
00235
00236 KHTMLSettings *KHTMLGlobal::defaultHTMLSettings()
00237 {
00238 assert( s_self );
00239 if ( !s_settings )
00240 s_settings = new KHTMLSettings();
00241
00242 return s_settings;
00243 }
00244
00245 void KHTMLGlobal::finalCheck()
00246 {
00247
00248 if (s_refcnt) {
00249 if (s_parts && !s_parts->isEmpty()) {
00250 kWarning(6000) << s_parts->count() << "parts not deleted";
00251 kWarning(6000) << "Part" << s_parts->first() << "wasn't deleted";
00252 }
00253 if (s_docs && !s_docs->isEmpty()) {
00254 kWarning(6000) << s_docs->count() << "docs not deleted";
00255 kWarning(6000) << "Document" << s_docs->first() << "wasn't deleted";
00256 }
00257 }
00258 assert( !s_refcnt );
00259 }