• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
khtml_global.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * Copyright (C) 2007 David Faure <faure@kde.org>
5 *
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.
10 *
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.
15 *
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.
20 */
21
22#include "khtml_global.h"
23#include "khtml_part.h"
24#include "khtml_settings.h"
25
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/htmlnames.h"
32#include "misc/loader.h"
33#include "misc/arena.h"
34#include "misc/paintbuffer.h"
35
36#include <QtCore/QLinkedList>
37
38#include <kcomponentdata.h>
39#include <kiconloader.h>
40#include <kaboutdata.h>
41#include <klocale.h>
42
43#include <assert.h>
44
45#include <kdebug.h>
46
47// SVG
48#include "svg/SVGNames.h"
49
50KHTMLGlobal *KHTMLGlobal::s_self = 0;
51unsigned long int KHTMLGlobal::s_refcnt = 0;
52KComponentData *KHTMLGlobal::s_componentData = 0;
53KIconLoader *KHTMLGlobal::s_iconLoader = 0;
54KAboutData *KHTMLGlobal::s_about = 0;
55KHTMLSettings *KHTMLGlobal::s_settings = 0;
56
57static QLinkedList<KHTMLPart*> *s_parts = 0;
58static QLinkedList<DOM::DocumentImpl*> *s_docs = 0;
59
60KHTMLGlobal::KHTMLGlobal()
61{
62 assert(!s_self);
63 s_self = this;
64 ref();
65
66 khtml::Cache::init();
67
68 khtml::NamespaceFactory::initIdTable();
69 khtml::PrefixFactory::initIdTable();
70 khtml::LocalNameFactory::initIdTable();
71 DOM::emptyLocalName = DOM::LocalName::fromId(0);
72 DOM::emptyPrefixName = DOM::PrefixName::fromId(0);
73 DOM::emptyNamespaceName = DOM::NamespaceName::fromId(DOM::emptyNamespace);
74 WebCore::SVGNames::init();
75}
76
77KHTMLGlobal::~KHTMLGlobal()
78{
79 //kDebug(6000) << this;
80 if ( s_self == this )
81 {
82 finalCheck();
83 delete s_iconLoader;
84 delete s_componentData;
85 delete s_about;
86 delete s_settings;
87 delete KHTMLSettings::avFamilies;
88 if (s_parts) {
89 assert(s_parts->isEmpty());
90 delete s_parts;
91 }
92 if (s_docs) {
93 assert(s_docs->isEmpty());
94 delete s_docs;
95 }
96
97 s_iconLoader = 0;
98 s_componentData = 0;
99 s_about = 0;
100 s_settings = 0;
101 s_parts = 0;
102 s_docs = 0;
103 KHTMLSettings::avFamilies = 0;
104
105 // clean up static data
106 khtml::CSSStyleSelector::clear();
107 khtml::RenderStyle::cleanup();
108 khtml::RenderObject::cleanup();
109 khtml::PaintBuffer::cleanup();
110 khtml::MediaQueryEvaluator::cleanup();
111 khtml::Cache::clear();
112 khtml::cleanup_thaibreaks();
113 khtml::ArenaFinish();
114 }
115 else
116 deref();
117}
118
119void KHTMLGlobal::ref()
120{
121 if ( !s_refcnt && !s_self )
122 {
123 //kDebug(6000) << "Creating KHTMLGlobal instance";
124 // we can't use a staticdeleter here, because that would mean
125 // that the KHTMLGlobal instance gets deleted from within a qPostRoutine, called
126 // from the QApplication destructor. That however is too late, because
127 // we want to destruct a KComponentData object, which involves destructing
128 // a KConfig object, which might call KGlobal::dirs() (in sync()) which
129 // probably is not going to work ;-)
130 // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
131 // safe side ;-) -> let's use a simple reference counting scheme
132 // (Simon)
133 new KHTMLGlobal; // does initial ref()
134 } else {
135 ++s_refcnt;
136 }
137 //kDebug(6000) << "s_refcnt=" << s_refcnt;
138}
139
140void KHTMLGlobal::deref()
141{
142 //kDebug(6000) << "s_refcnt=" << s_refcnt - 1;
143 if ( !--s_refcnt && s_self )
144 {
145 delete s_self;
146 s_self = 0;
147 }
148}
149
150void KHTMLGlobal::registerPart( KHTMLPart *part )
151{
152 //kDebug(6000) << part;
153 if ( !s_parts )
154 s_parts = new QLinkedList<KHTMLPart*>;
155
156 if ( !s_parts->contains( part ) ) {
157 s_parts->append( part );
158 ref();
159 }
160}
161
162void KHTMLGlobal::deregisterPart( KHTMLPart *part )
163{
164 //kDebug(6000) << part;
165 assert( s_parts );
166
167 if ( s_parts->removeAll( part ) ) {
168 if ( s_parts->isEmpty() ) {
169 delete s_parts;
170 s_parts = 0;
171 }
172 deref();
173 }
174}
175
176void KHTMLGlobal::registerDocumentImpl( DOM::DocumentImpl *doc )
177{
178 //kDebug(6000) << doc;
179 if ( !s_docs )
180 s_docs = new QLinkedList<DOM::DocumentImpl*>;
181
182 if ( !s_docs->contains( doc ) ) {
183 s_docs->append( doc );
184 ref();
185 }
186}
187
188void KHTMLGlobal::deregisterDocumentImpl( DOM::DocumentImpl *doc )
189{
190 //kDebug(6000) << doc;
191 assert( s_docs );
192
193 if ( s_docs->removeAll( doc ) ) {
194 if ( s_docs->isEmpty() ) {
195 delete s_docs;
196 s_docs = 0;
197 }
198 deref();
199 }
200}
201
202const KComponentData &KHTMLGlobal::componentData()
203{
204 assert( s_self );
205
206 if ( !s_componentData )
207 {
208 s_about = new KAboutData( "khtml", 0, ki18n( "KHTML" ), "4.0",
209 ki18n( "Embeddable HTML component" ),
210 KAboutData::License_LGPL );
211 s_about->addAuthor(ki18n("Lars Knoll"), KLocalizedString(), "knoll@kde.org");
212 s_about->addAuthor(ki18n("Antti Koivisto"), KLocalizedString(), "koivisto@kde.org");
213 s_about->addAuthor(ki18n("Waldo Bastian"), KLocalizedString(), "bastian@kde.org");
214 s_about->addAuthor(ki18n("Dirk Mueller"), KLocalizedString(), "mueller@kde.org");
215 s_about->addAuthor(ki18n("Peter Kelly"), KLocalizedString(), "pmk@kde.org");
216 s_about->addAuthor(ki18n("Torben Weis"), KLocalizedString(), "weis@kde.org");
217 s_about->addAuthor(ki18n("Martin Jones"), KLocalizedString(), "mjones@kde.org");
218 s_about->addAuthor(ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org");
219 s_about->addAuthor(ki18n("Tobias Anton"), KLocalizedString(), "anton@stud.fbi.fh-darmstadt.de");
220
221 s_componentData = new KComponentData( s_about );
222 }
223
224 return *s_componentData;
225}
226
227KIconLoader *KHTMLGlobal::iconLoader()
228{
229 if ( !s_iconLoader )
230 {
231 s_iconLoader = new KIconLoader(componentData().componentName(), componentData().dirs());
232 }
233
234 return s_iconLoader;
235}
236
237KHTMLSettings *KHTMLGlobal::defaultHTMLSettings()
238{
239 assert( s_self );
240 if ( !s_settings )
241 s_settings = new KHTMLSettings();
242
243 return s_settings;
244}
245
246void KHTMLGlobal::finalCheck()
247{
248#ifndef NDEBUG
249 if (s_refcnt) {
250 if (s_parts && !s_parts->isEmpty()) {
251 Q_FOREACH(KHTMLPart *part, *s_parts) {
252 kWarning(6000) << "Part" << part->url() << "was not deleted";
253 }
254 }
255 if (s_docs && !s_docs->isEmpty()) {
256 Q_FOREACH(DOM::DocumentImpl *doc, *s_docs) {
257 kWarning(6000) << "Document" << doc->URL() << "was not deleted";
258 }
259 }
260 }
261#endif
262}
SVGNames.h
KAboutData
KAboutData::addAuthor
KAboutData & addAuthor(const KLocalizedString &name, const KLocalizedString &task, const QByteArray &emailAddress, const QByteArray &webAddress, const QByteArray &ocsUsername)
KAboutData::License_LGPL
License_LGPL
KComponentData
KHTMLGlobal
Definition: khtml_global.h:50
KHTMLGlobal::registerDocumentImpl
static void registerDocumentImpl(DOM::DocumentImpl *doc)
Definition: khtml_global.cpp:176
KHTMLGlobal::~KHTMLGlobal
~KHTMLGlobal()
Definition: khtml_global.cpp:77
KHTMLGlobal::componentData
static const KComponentData & componentData()
Definition: khtml_global.cpp:202
KHTMLGlobal::iconLoader
static KIconLoader * iconLoader()
Definition: khtml_global.cpp:227
KHTMLGlobal::deregisterDocumentImpl
static void deregisterDocumentImpl(DOM::DocumentImpl *doc)
Definition: khtml_global.cpp:188
KHTMLGlobal::deregisterPart
static void deregisterPart(KHTMLPart *part)
Definition: khtml_global.cpp:162
KHTMLGlobal::defaultHTMLSettings
static KHTMLSettings * defaultHTMLSettings()
Definition: khtml_global.cpp:237
KHTMLGlobal::KHTMLGlobal
KHTMLGlobal()
Definition: khtml_global.cpp:60
KHTMLGlobal::registerPart
static void registerPart(KHTMLPart *part)
Definition: khtml_global.cpp:150
KHTMLGlobal::finalCheck
static void finalCheck()
Definition: khtml_global.cpp:246
KHTMLPart
This class is khtml's main class.
Definition: khtml_part.h:207
KHTMLSettings
Settings for the HTML view.
Definition: khtml_settings.h:42
KIconLoader
KLocalizedString
KParts::ReadOnlyPart::url
KUrl url
assert
#define assert(x)
Definition: editor.cpp:43
kWarning
#define kWarning
kaboutdata.h
kcomponentdata.h
kdebug.h
s_parts
static QLinkedList< KHTMLPart * > * s_parts
Definition: khtml_global.cpp:57
s_docs
static QLinkedList< DOM::DocumentImpl * > * s_docs
Definition: khtml_global.cpp:58
khtml_global.h
khtml_part.h
khtml_settings.h
kiconloader.h
klocale.h
ki18n
KLocalizedString ki18n(const char *msg)
dirs
KStandardDirs * dirs()
WebCore::SVGNames::init
void init()
Definition: SVGNames.cpp:350
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal