• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • khtml
 

khtml

  • khtml
khtml_factory.cpp
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "khtml_factory.h"
22 #include "khtml_part.h"
23 #include "khtml_settings.h"
24 
25 #include "css/cssstyleselector.h"
26 #include "html/html_imageimpl.h"
27 #include "rendering/render_style.h"
28 #include "rendering/break_lines.h"
29 #include "misc/loader.h"
30 #include "misc/arena.h"
31 
32 #include <kinstance.h>
33 #include <kaboutdata.h>
34 #include <klocale.h>
35 
36 #include <assert.h>
37 
38 #include <kdebug.h>
39 
40 template class TQPtrList<KHTMLPart>;
41 
42 extern "C" KDE_EXPORT void *init_libkhtml()
43 {
44  // We can't use a plain self() here, because that would
45  // return the global factory, which might already exist
46  // at the time init_libkhtml is called! As soon as someone
47  // does new KHTMLPart() in his application and loads up
48  // an html document into that part which either embeds
49  // embeds another KHTMLPart instance via <object> or
50  // as html frame, then we cannot return self(), as
51  // what we return here is what the KLibLoader deletes
52  // in the end, and we don't want the libloader to
53  // delete our global instance. Anyway, the new
54  // KHTMLFactory we create here is very cheap :)
55  // (Simon)
56  return new KHTMLFactory( true );
57 }
58 
59 KHTMLFactory *KHTMLFactory::s_self = 0;
60 unsigned long int KHTMLFactory::s_refcnt = 0;
61 KInstance *KHTMLFactory::s_instance = 0;
62 KAboutData *KHTMLFactory::s_about = 0;
63 KHTMLSettings *KHTMLFactory::s_settings = 0;
64 TQPtrList<KHTMLPart> *KHTMLFactory::s_parts = 0;
65 TQString *KHTMLSettings::avFamilies = 0;
66 
67 KHTMLFactory::KHTMLFactory( bool clone )
68 {
69  if ( clone )
70  ref();
71 }
72 
73 KHTMLFactory::~KHTMLFactory()
74 {
75  if ( s_self == this )
76  {
77  assert( !s_refcnt );
78 
79  delete s_instance;
80  delete s_about;
81  delete s_settings;
82  delete KHTMLSettings::avFamilies;
83  if ( s_parts )
84  {
85  assert( s_parts->isEmpty() );
86  delete s_parts;
87  }
88 
89  s_instance = 0;
90  s_about = 0;
91  s_settings = 0;
92  s_parts = 0;
93  KHTMLSettings::avFamilies = 0;
94 
95  // clean up static data
96  khtml::CSSStyleSelector::clear();
97  khtml::RenderStyle::cleanup();
98  khtml::Cache::clear();
99  khtml::cleanup_thaibreaks();
100  khtml::ArenaFinish();
101  }
102  else
103  deref();
104 }
105 
106 KParts::Part *KHTMLFactory::createPartObject( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const char *className, const TQStringList & )
107 {
108  KHTMLPart::GUIProfile prof = KHTMLPart::DefaultGUI;
109  if ( strcmp( className, "Browser/View" ) == 0 )
110  prof = KHTMLPart::BrowserViewGUI;
111 
112  return new KHTMLPart( parentWidget, widgetName, parent, name, prof );
113 }
114 
115 void KHTMLFactory::ref()
116 {
117  if ( !s_refcnt && !s_self )
118  {
119  // we can't use a staticdeleter here, because that would mean
120  // that the factory gets deleted from within a qPostRoutine, called
121  // from the TQApplication destructor. That however is too late, because
122  // we want to destruct a KInstance object, which involves destructing
123  // a KConfig object, which might call KGlobal::dirs() (in sync()) which
124  // probably is not going to work ;-)
125  // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
126  // safe side ;-) -> let's use a simple reference counting scheme
127  // (Simon)
128  s_self = new KHTMLFactory;
129  khtml::Cache::init();
130  }
131 
132  s_refcnt++;
133 }
134 
135 void KHTMLFactory::deref()
136 {
137  if ( !--s_refcnt && s_self )
138  {
139  delete s_self;
140  s_self = 0;
141  }
142 }
143 
144 void KHTMLFactory::registerPart( KHTMLPart *part )
145 {
146  if ( !s_parts )
147  s_parts = new TQPtrList<KHTMLPart>;
148 
149  if ( !s_parts->containsRef( part ) )
150  {
151  s_parts->append( part );
152  ref();
153  }
154 }
155 
156 void KHTMLFactory::deregisterPart( KHTMLPart *part )
157 {
158  assert( s_parts );
159 
160  if ( s_parts->removeRef( part ) )
161  {
162  if ( s_parts->isEmpty() )
163  {
164  delete s_parts;
165  s_parts = 0;
166  }
167  deref();
168  }
169 }
170 
171 KInstance *KHTMLFactory::instance()
172 {
173  assert( s_self );
174 
175  if ( !s_instance )
176  {
177  s_about = new KAboutData( "khtml", I18N_NOOP( "KHTML" ), "4.0",
178  I18N_NOOP( "Embeddable HTML component" ),
179  KAboutData::License_LGPL );
180  s_about->addAuthor( "Lars Knoll", 0, "knoll@kde.org" );
181  s_about->addAuthor( "Antti Koivisto", 0, "koivisto@kde.org" );
182  s_about->addAuthor( "Waldo Bastian", 0, "bastian@kde.org" );
183  s_about->addAuthor( "Dirk Mueller", 0, "mueller@kde.org" );
184  s_about->addAuthor( "Peter Kelly", 0, "pmk@kde.org" );
185  s_about->addAuthor( "Torben Weis", 0, "weis@kde.org" );
186  s_about->addAuthor( "Martin Jones", 0, "mjones@kde.org" );
187  s_about->addAuthor( "Simon Hausmann", 0, "hausmann@kde.org" );
188  s_about->addAuthor( "Tobias Anton", 0, "anton@stud.fbi.fh-darmstadt.de" );
189 
190  s_instance = new KInstance( s_about );
191  }
192 
193  return s_instance;
194 }
195 
196 KHTMLSettings *KHTMLFactory::defaultHTMLSettings()
197 {
198  assert( s_self );
199  if ( !s_settings )
200  s_settings = new KHTMLSettings();
201 
202  return s_settings;
203 }
204 
205 using namespace KParts;
206 #include "khtml_factory.moc"
207 
KHTMLSettings
Settings for the HTML view.
Definition: khtml_settings.h:38
KParts
KHTMLPart
This class is khtml's main class.
Definition: khtml_part.h:184
KParts::Part
klocale.h
I18N_NOOP
#define I18N_NOOP(x)
KInstance
KAboutData

khtml

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

khtml

Skip menu "khtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for khtml by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |