• Skip to content
  • Skip to link menu
KDE 4.3 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 // SVG
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     //kDebug(6000) << this;
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         // clean up static data
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         //kDebug(6000) << "Creating KHTMLGlobal instance";
00123         // we can't use a staticdeleter here, because that would mean
00124         // that the KHTMLGlobal instance gets deleted from within a qPostRoutine, called
00125         // from the QApplication destructor. That however is too late, because
00126         // we want to destruct a KComponentData object, which involves destructing
00127         // a KConfig object, which might call KGlobal::dirs() (in sync()) which
00128         // probably is not going to work ;-)
00129         // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
00130         // safe side ;-) -> let's use a simple reference counting scheme
00131         // (Simon)
00132         new KHTMLGlobal; // does initial ref()
00133     } else {
00134         ++s_refcnt;
00135     }
00136     //kDebug(6000) << "s_refcnt=" << s_refcnt;
00137 }
00138 
00139 void KHTMLGlobal::deref()
00140 {
00141     //kDebug(6000) << "s_refcnt=" << s_refcnt - 1;
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     //kDebug(6000) << part;
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     //kDebug(6000) << part;
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     //kDebug(6000) << doc;
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     //kDebug(6000) << doc;
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     //kDebug(6000) << "s_refcnt=" << s_refcnt;
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 }

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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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