• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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/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     //kDebug(6000) << this;
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         // clean up static data
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         //kDebug(6000) << "Creating KHTMLGlobal instance";
00112         // we can't use a staticdeleter here, because that would mean
00113         // that the KHTMLGlobal instance gets deleted from within a qPostRoutine, called
00114         // from the QApplication destructor. That however is too late, because
00115         // we want to destruct a KComponentData object, which involves destructing
00116         // a KConfig object, which might call KGlobal::dirs() (in sync()) which
00117         // probably is not going to work ;-)
00118         // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
00119         // safe side ;-) -> let's use a simple reference counting scheme
00120         // (Simon)
00121         new KHTMLGlobal; // does initial ref()
00122     } else {
00123         ++s_refcnt;
00124     }
00125     //kDebug(6000) << "s_refcnt=" << s_refcnt;
00126 }
00127 
00128 void KHTMLGlobal::deref()
00129 {
00130     //kDebug(6000) << "s_refcnt=" << s_refcnt - 1;
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     //kDebug(6000) << part;
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     //kDebug(6000) << part;
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     //kDebug(6000) << doc;
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     //kDebug(6000) << doc;
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     //kDebug(6000) << "s_refcnt=" << s_refcnt;
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 }

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal