khtml_factory.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "khtml_factory.h"
00022 #include "khtml_part.h"
00023 #include "khtml_settings.h"
00024
00025 #include "css/cssstyleselector.h"
00026 #include "html/html_imageimpl.h"
00027 #include "rendering/render_style.h"
00028 #include "misc/loader.h"
00029
00030 #include <kinstance.h>
00031 #include <kaboutdata.h>
00032 #include <klocale.h>
00033
00034 #include <assert.h>
00035
00036 #include <kdebug.h>
00037
00038 template class QPtrList<KHTMLPart>;
00039
00040 extern "C"
00041 {
00042 void *init_libkhtml()
00043 {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 return new KHTMLFactory( true );
00057 }
00058 }
00059
00060 KHTMLFactory *KHTMLFactory::s_self = 0;
00061 unsigned long int KHTMLFactory::s_refcnt = 0;
00062 KInstance *KHTMLFactory::s_instance = 0;
00063 KAboutData *KHTMLFactory::s_about = 0;
00064 KHTMLSettings *KHTMLFactory::s_settings = 0;
00065 QPtrList<KHTMLPart> *KHTMLFactory::s_parts = 0;
00066 QString *KHTMLSettings::avFamilies = 0;
00067
00068 KHTMLFactory::KHTMLFactory( bool clone )
00069 {
00070 if ( clone )
00071 ref();
00072 }
00073
00074 KHTMLFactory::~KHTMLFactory()
00075 {
00076 if ( s_self == this )
00077 {
00078 assert( !s_refcnt );
00079
00080 if ( s_instance )
00081 delete s_instance;
00082 if ( s_about )
00083 delete s_about;
00084 if ( s_settings )
00085 delete s_settings;
00086 if ( KHTMLSettings::avFamilies )
00087 delete KHTMLSettings::avFamilies;
00088 if ( s_parts )
00089 {
00090 assert( s_parts->isEmpty() );
00091 delete s_parts;
00092 }
00093
00094 s_instance = 0;
00095 s_about = 0;
00096 s_settings = 0;
00097 s_parts = 0;
00098 KHTMLSettings::avFamilies = 0;
00099
00100 kdDebug( 6000 ) << "KHTMLFactory::~KHTMLFactory" << endl;
00101
00102 khtml::CSSStyleSelector::clear();
00103 khtml::RenderStyle::cleanup();
00104 khtml::Cache::clear();
00105 }
00106 else
00107 deref();
00108 }
00109
00110 KParts::Part *KHTMLFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *className, const QStringList & )
00111 {
00112 KHTMLPart::GUIProfile prof = KHTMLPart::DefaultGUI;
00113 if ( strcmp( className, "Browser/View" ) == 0 )
00114 prof = KHTMLPart::BrowserViewGUI;
00115
00116 return new KHTMLPart( parentWidget, widgetName, parent, name, prof );
00117 }
00118
00119 void KHTMLFactory::ref()
00120 {
00121 if ( !s_refcnt && !s_self )
00122 {
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 s_self = new KHTMLFactory;
00133 khtml::Cache::init();
00134 }
00135
00136 s_refcnt++;
00137 }
00138
00139 void KHTMLFactory::deref()
00140 {
00141 if ( !--s_refcnt && s_self )
00142 {
00143 delete s_self;
00144 s_self = 0;
00145 }
00146 }
00147
00148 void KHTMLFactory::registerPart( KHTMLPart *part )
00149 {
00150 if ( !s_parts )
00151 s_parts = new QPtrList<KHTMLPart>;
00152
00153 if ( !s_parts->containsRef( part ) )
00154 {
00155 s_parts->append( part );
00156 ref();
00157 }
00158 }
00159
00160 void KHTMLFactory::deregisterPart( KHTMLPart *part )
00161 {
00162 assert( s_parts );
00163
00164 if ( s_parts->removeRef( part ) )
00165 {
00166 if ( s_parts->isEmpty() )
00167 {
00168 delete s_parts;
00169 s_parts = 0;
00170 }
00171 deref();
00172 }
00173 }
00174
00175 KInstance *KHTMLFactory::instance()
00176 {
00177 assert( s_self );
00178
00179 if ( !s_instance )
00180 {
00181 s_about = new KAboutData( "khtml", I18N_NOOP( "KHTML" ), "4.0",
00182 I18N_NOOP( "Embeddable HTML component" ),
00183 KAboutData::License_LGPL );
00184 s_about->addAuthor( "Lars Knoll", 0, "knoll@kde.org" );
00185 s_about->addAuthor( "Antti Koivisto", 0, "koivisto@kde.org" );
00186 s_about->addAuthor( "Waldo Bastian", 0, "bastian@kde.org" );
00187 s_about->addAuthor( "Dirk Mueller", 0, "mueller@kde.org" );
00188 s_about->addAuthor( "Peter Kelly", 0, "ptrkelly@hotmail.com" );
00189 s_about->addAuthor( "Torben Weis", 0, "weis@kde.org" );
00190 s_about->addAuthor( "Martin Jones", 0, "mjones@kde.org" );
00191 s_about->addAuthor( "Simon Hausmann", 0, "hausmann@kde.org" );
00192 s_about->addAuthor( "Tobias Anton", 0, "anton@stud.fbi.fh-darmstadt.de" );
00193
00194 s_instance = new KInstance( s_about );
00195 }
00196
00197 return s_instance;
00198 }
00199
00200 KHTMLSettings *KHTMLFactory::defaultHTMLSettings()
00201 {
00202 assert( s_self );
00203 if ( !s_settings )
00204 s_settings = new KHTMLSettings();
00205
00206 return s_settings;
00207 }
00208
00209 using namespace KParts;
00210 #include "khtml_factory.moc"
00211
This file is part of the documentation for kdelibs Version 3.1.4.