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