1 /* This file is part of the KDE project
3 * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * Copyright (C) 2007 David Faure <faure@kde.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include "khtml_global.h"
23 #include "khtml_part.h"
24 #include "khtml_settings.h"
26 #include "css/cssstyleselector.h"
27 #include "css/css_mediaquery.h"
28 #include "html/html_imageimpl.h"
29 #include "rendering/render_style.h"
30 #include "rendering/break_lines.h"
31 #include "misc/loader.h"
32 #include "misc/arena.h"
33 #include "misc/paintbuffer.h"
35 #include <QtCore/QLinkedList>
37 #include <kcomponentdata.h>
38 #include <kiconloader.h>
39 #include <kaboutdata.h>
47 #include "svg/SVGNames.h"
49 KHTMLGlobal
*KHTMLGlobal::s_self
= 0;
50 unsigned long int KHTMLGlobal::s_refcnt
= 0;
51 KComponentData
*KHTMLGlobal::s_componentData
= 0;
52 KIconLoader
*KHTMLGlobal::s_iconLoader
= 0;
53 KAboutData
*KHTMLGlobal::s_about
= 0;
54 KHTMLSettings
*KHTMLGlobal::s_settings
= 0;
56 static QLinkedList
<KHTMLPart
*> *s_parts
= 0;
57 static QLinkedList
<DOM::DocumentImpl
*> *s_docs
= 0;
59 KHTMLGlobal::KHTMLGlobal()
67 khtml::NamespaceFactory::initIdTable();
68 khtml::PrefixFactory::initIdTable();
69 khtml::LocalNameFactory::initIdTable();
70 DOM::emptyLocalName
= DOM::LocalName::fromId(0);
71 DOM::emptyPrefixName
= DOM::PrefixName::fromId(0);
72 DOM::emptyNamespaceName
= DOM::NamespaceName::fromId(0);
73 WebCore::SVGNames::init();
76 KHTMLGlobal::~KHTMLGlobal()
78 //kDebug(6000) << this;
83 delete s_componentData
;
86 delete KHTMLSettings::avFamilies
;
88 assert(s_parts
->isEmpty());
92 assert(s_docs
->isEmpty());
102 KHTMLSettings::avFamilies
= 0;
104 // clean up static data
105 khtml::CSSStyleSelector::clear();
106 khtml::RenderStyle::cleanup();
107 khtml::RenderObject::cleanup();
108 khtml::PaintBuffer::cleanup();
109 khtml::MediaQueryEvaluator::cleanup();
110 khtml::Cache::clear();
111 khtml::cleanup_thaibreaks();
112 khtml::ArenaFinish();
118 void KHTMLGlobal::ref()
120 if ( !s_refcnt
&& !s_self
)
122 //kDebug(6000) << "Creating KHTMLGlobal instance";
123 // we can't use a staticdeleter here, because that would mean
124 // that the KHTMLGlobal instance gets deleted from within a qPostRoutine, called
125 // from the QApplication destructor. That however is too late, because
126 // we want to destruct a KComponentData object, which involves destructing
127 // a KConfig object, which might call KGlobal::dirs() (in sync()) which
128 // probably is not going to work ;-)
129 // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
130 // safe side ;-) -> let's use a simple reference counting scheme
132 new KHTMLGlobal
; // does initial ref()
136 //kDebug(6000) << "s_refcnt=" << s_refcnt;
139 void KHTMLGlobal::deref()
141 //kDebug(6000) << "s_refcnt=" << s_refcnt - 1;
142 if ( !--s_refcnt
&& s_self
)
149 void KHTMLGlobal::registerPart( KHTMLPart
*part
)
151 //kDebug(6000) << part;
153 s_parts
= new QLinkedList
<KHTMLPart
*>;
155 if ( !s_parts
->contains( part
) ) {
156 s_parts
->append( part
);
161 void KHTMLGlobal::deregisterPart( KHTMLPart
*part
)
163 //kDebug(6000) << part;
166 if ( s_parts
->removeAll( part
) ) {
167 if ( s_parts
->isEmpty() ) {
175 void KHTMLGlobal::registerDocumentImpl( DOM::DocumentImpl
*doc
)
177 //kDebug(6000) << doc;
179 s_docs
= new QLinkedList
<DOM::DocumentImpl
*>;
181 if ( !s_docs
->contains( doc
) ) {
182 s_docs
->append( doc
);
187 void KHTMLGlobal::deregisterDocumentImpl( DOM::DocumentImpl
*doc
)
189 //kDebug(6000) << doc;
192 if ( s_docs
->removeAll( doc
) ) {
193 if ( s_docs
->isEmpty() ) {
201 const KComponentData
&KHTMLGlobal::componentData()
205 if ( !s_componentData
)
207 s_about
= new KAboutData( "khtml", 0, ki18n( "KHTML" ), "4.0",
208 ki18n( "Embeddable HTML component" ),
209 KAboutData::License_LGPL
);
210 s_about
->addAuthor(ki18n("Lars Knoll"), KLocalizedString(), "knoll@kde.org");
211 s_about
->addAuthor(ki18n("Antti Koivisto"), KLocalizedString(), "koivisto@kde.org");
212 s_about
->addAuthor(ki18n("Waldo Bastian"), KLocalizedString(), "bastian@kde.org");
213 s_about
->addAuthor(ki18n("Dirk Mueller"), KLocalizedString(), "mueller@kde.org");
214 s_about
->addAuthor(ki18n("Peter Kelly"), KLocalizedString(), "pmk@kde.org");
215 s_about
->addAuthor(ki18n("Torben Weis"), KLocalizedString(), "weis@kde.org");
216 s_about
->addAuthor(ki18n("Martin Jones"), KLocalizedString(), "mjones@kde.org");
217 s_about
->addAuthor(ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org");
218 s_about
->addAuthor(ki18n("Tobias Anton"), KLocalizedString(), "anton@stud.fbi.fh-darmstadt.de");
220 s_componentData
= new KComponentData( s_about
);
223 return *s_componentData
;
226 KIconLoader
*KHTMLGlobal::iconLoader()
230 s_iconLoader
= new KIconLoader(componentData().componentName(), componentData().dirs());
236 KHTMLSettings
*KHTMLGlobal::defaultHTMLSettings()
240 s_settings
= new KHTMLSettings();
245 void KHTMLGlobal::finalCheck()
247 //kDebug(6000) << "s_refcnt=" << s_refcnt;
249 if (s_parts
&& !s_parts
->isEmpty()) {
250 kWarning(6000) << s_parts
->count() << "parts not deleted";
251 kWarning(6000) << "Part" << s_parts
->first() << "wasn't deleted";
253 if (s_docs
&& !s_docs
->isEmpty()) {
254 kWarning(6000) << s_docs
->count() << "docs not deleted";
255 kWarning(6000) << "Document" << s_docs
->first() << "wasn't deleted";