Bug 449371 Firefox/Thunderbird crashes at exit [@ gdk_display_x11_finalize], p=Brian...
[wine-gecko.git] / layout / build / nsLayoutStatics.cpp
blobf90f938174f011d7a95e81decc2938bf018ca3aa
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Mozilla platform.
16 * The Initial Developer of the Original Code is
17 * Benjamin Smedberg <benjamin@smedbergs.us>.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsLayoutStatics.h"
39 #include "nscore.h"
41 #include "nsAttrValue.h"
42 #include "nsAutoCopyListener.h"
43 #include "nsColorNames.h"
44 #include "nsComputedDOMStyle.h"
45 #include "nsContentDLF.h"
46 #include "nsContentUtils.h"
47 #include "nsCSSAnonBoxes.h"
48 #include "nsCSSFrameConstructor.h"
49 #include "nsCSSKeywords.h"
50 #include "nsCSSLoader.h"
51 #include "nsCSSProps.h"
52 #include "nsCSSPseudoClasses.h"
53 #include "nsCSSPseudoElements.h"
54 #include "nsCSSRendering.h"
55 #include "nsCSSScanner.h"
56 #include "nsICSSStyleSheet.h"
57 #include "nsDOMAttribute.h"
58 #include "nsDOMClassInfo.h"
59 #include "nsDOMScriptObjectFactory.h"
60 #include "nsEventListenerManager.h"
61 #include "nsFrame.h"
62 #include "nsGenericElement.h" // for nsDOMEventRTTearoff
63 #include "nsStyledElement.h"
64 #include "nsGlobalWindow.h"
65 #include "nsGkAtoms.h"
66 #include "nsImageFrame.h"
67 #include "nsLayoutStylesheetCache.h"
68 #include "nsNodeInfo.h"
69 #include "nsRange.h"
70 #include "nsRepeatService.h"
71 #include "nsSpaceManager.h"
72 #include "nsSprocketLayout.h"
73 #include "nsStackLayout.h"
74 #include "nsStyleSet.h"
75 #include "nsTextControlFrame.h"
76 #include "nsXBLWindowKeyHandler.h"
77 #include "txMozillaXSLTProcessor.h"
78 #include "nsDOMStorage.h"
79 #include "nsCellMap.h"
80 #include "nsTextFrameTextRunCache.h"
81 #include "nsCCUncollectableMarker.h"
82 #include "nsTextFragment.h"
83 #include "nsCSSRuleProcessor.h"
84 #include "nsXMLHttpRequest.h"
85 #include "nsIFocusEventSuppressor.h"
87 #ifdef MOZ_XUL
88 #include "nsXULPopupManager.h"
89 #include "nsXULContentUtils.h"
90 #include "nsXULElement.h"
91 #include "nsXULPrototypeCache.h"
92 #include "nsXULTooltipListener.h"
94 #ifndef MOZ_NO_INSPECTOR_APIS
95 #include "inDOMView.h"
96 #endif
97 #endif
99 #ifdef MOZ_MATHML
100 #include "nsMathMLAtoms.h"
101 #include "nsMathMLOperators.h"
102 #endif
104 #ifdef MOZ_SVG
105 PRBool NS_SVGEnabled();
106 #endif
108 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
109 #include "nsHTMLEditor.h"
110 #include "nsTextServicesDocument.h"
111 #endif
113 #ifdef MOZ_MEDIA
114 #include "nsVideoDecoder.h"
115 #endif
117 #ifdef MOZ_OGG
118 #include "nsAudioStream.h"
119 #include "nsVideoDecoder.h"
120 #endif
122 #include "nsError.h"
123 #include "nsTraceRefcnt.h"
125 #include "nsCycleCollector.h"
127 static nsrefcnt sLayoutStaticRefcnt;
129 nsresult
130 nsLayoutStatics::Initialize()
132 NS_ASSERTION(sLayoutStaticRefcnt == 0,
133 "nsLayoutStatics isn't zero!");
135 sLayoutStaticRefcnt = 1;
136 NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
137 "nsLayoutStatics", 1);
139 nsresult rv;
141 // Register all of our atoms once
142 nsCSSAnonBoxes::AddRefAtoms();
143 nsCSSPseudoClasses::AddRefAtoms();
144 nsCSSPseudoElements::AddRefAtoms();
145 nsCSSKeywords::AddRefTable();
146 nsCSSProps::AddRefTable();
147 nsColorNames::AddRefTable();
148 nsGkAtoms::AddRefAtoms();
150 nsDOMScriptObjectFactory::Startup();
151 rv = nsContentUtils::Init();
152 if (NS_FAILED(rv)) {
153 NS_ERROR("Could not initialize nsContentUtils");
154 return rv;
157 rv = nsAttrValue::Init();
158 if (NS_FAILED(rv)) {
159 NS_ERROR("Could not initialize nsAttrValue");
160 return rv;
163 rv = nsTextFragment::Init();
164 if (NS_FAILED(rv)) {
165 NS_ERROR("Could not initialize nsTextFragment");
166 return rv;
169 rv = nsCellMap::Init();
170 if (NS_FAILED(rv)) {
171 NS_ERROR("Could not initialize nsCellMap");
172 return rv;
175 rv = nsCSSRendering::Init();
176 if (NS_FAILED(rv)) {
177 NS_ERROR("Could not initialize nsCSSRendering");
178 return rv;
181 rv = nsTextFrameTextRunCache::Init();
182 if (NS_FAILED(rv)) {
183 NS_ERROR("Could not initialize textframe textrun cache");
184 return rv;
187 #ifdef MOZ_XUL
188 rv = nsXULContentUtils::Init();
189 if (NS_FAILED(rv)) {
190 NS_ERROR("Could not initialize nsXULContentUtils");
191 return rv;
194 #ifndef MOZ_NO_INSPECTOR_APIS
195 inDOMView::InitAtoms();
196 #endif
198 #endif
200 #ifdef MOZ_MATHML
201 nsMathMLOperators::AddRefTable();
202 #endif
204 #ifdef MOZ_SVG
205 if (NS_SVGEnabled())
206 nsContentDLF::RegisterSVG();
207 #endif
209 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
210 nsEditProperty::RegisterAtoms();
211 nsTextServicesDocument::RegisterAtoms();
212 #endif
214 #ifdef DEBUG
215 nsFrame::DisplayReflowStartup();
216 #endif
217 nsDOMAttribute::Initialize();
219 rv = txMozillaXSLTProcessor::Startup();
220 if (NS_FAILED(rv)) {
221 NS_ERROR("Could not initialize txMozillaXSLTProcessor");
222 return rv;
225 rv = nsDOMStorageManager::Initialize();
226 if (NS_FAILED(rv)) {
227 NS_ERROR("Could not initialize nsDOMStorageManager");
228 return rv;
231 #ifndef DEBUG_CC
232 rv = nsCCUncollectableMarker::Init();
233 if (NS_FAILED(rv)) {
234 NS_ERROR("Could not initialize nsCCUncollectableMarker");
235 return rv;
237 #endif
239 #ifdef MOZ_XUL
240 rv = nsXULPopupManager::Init();
241 if (NS_FAILED(rv)) {
242 NS_ERROR("Could not initialize nsXULPopupManager");
243 return rv;
245 #endif
247 #ifdef MOZ_MEDIA
248 rv = nsVideoDecoder::InitLogger();
249 if (NS_FAILED(rv)) {
250 NS_ERROR("Could not initialize nsVideoDecoder");
251 return rv;
254 #endif
256 #ifdef MOZ_OGG
257 rv = nsAudioStream::InitLibrary();
258 if (NS_FAILED(rv)) {
259 NS_ERROR("Could not initialize nsAudioStream");
260 return rv;
262 #endif
264 return NS_OK;
267 void
268 nsLayoutStatics::Shutdown()
270 #ifdef MOZ_XUL
271 nsXULPopupManager::Shutdown();
272 #endif
273 nsDOMStorageManager::Shutdown();
274 txMozillaXSLTProcessor::Shutdown();
275 nsDOMAttribute::Shutdown();
276 nsDOMEventRTTearoff::Shutdown();
277 nsEventListenerManager::Shutdown();
278 nsContentList::Shutdown();
279 nsComputedDOMStyle::Shutdown();
280 CSSLoaderImpl::Shutdown();
281 nsCSSRuleProcessor::FreeSystemMetrics();
282 nsTextFrameTextRunCache::Shutdown();
283 nsCSSRendering::Shutdown();
284 #ifdef DEBUG
285 nsFrame::DisplayReflowShutdown();
286 #endif
287 nsCellMap::Shutdown();
289 // Release all of our atoms
290 nsColorNames::ReleaseTable();
291 nsCSSProps::ReleaseTable();
292 nsCSSKeywords::ReleaseTable();
293 nsRepeatService::Shutdown();
294 nsStackLayout::Shutdown();
295 nsBox::Shutdown();
297 #ifdef MOZ_XUL
298 nsXULContentUtils::Finish();
299 nsXULElement::ReleaseGlobals();
300 nsXULPrototypeCache::ReleaseGlobals();
301 nsXULPrototypeElement::ReleaseGlobals();
302 nsSprocketLayout::Shutdown();
303 #endif
305 #ifdef MOZ_MATHML
306 nsMathMLOperators::ReleaseTable();
307 #endif
309 nsCSSFrameConstructor::ReleaseGlobals();
310 nsSpaceManager::Shutdown();
311 nsImageFrame::ReleaseGlobals();
313 nsCSSScanner::ReleaseGlobals();
315 NS_IF_RELEASE(nsContentDLF::gUAStyleSheet);
316 NS_IF_RELEASE(nsRuleNode::gLangService);
317 nsStyledElement::Shutdown();
319 nsTextFragment::Shutdown();
321 nsAttrValue::Shutdown();
322 nsContentUtils::Shutdown();
323 nsNodeInfo::ClearCache();
324 nsLayoutStylesheetCache::Shutdown();
325 NS_NameSpaceManagerShutdown();
326 nsStyleSet::FreeGlobals();
328 nsGlobalWindow::ShutDown();
329 nsDOMClassInfo::ShutDown();
330 nsTextControlFrame::ShutDown();
331 nsXBLWindowKeyHandler::ShutDown();
332 nsAutoCopyListener::Shutdown();
334 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
335 nsHTMLEditor::Shutdown();
336 nsTextServicesDocument::Shutdown();
337 #endif
339 NS_ShutdownFocusSuppressor();
341 #ifdef MOZ_OGG
342 nsAudioStream::ShutdownLibrary();
343 #endif
346 void
347 nsLayoutStatics::AddRef()
349 NS_ASSERTION(sLayoutStaticRefcnt,
350 "nsLayoutStatics already dropped to zero!");
352 ++sLayoutStaticRefcnt;
353 NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
354 "nsLayoutStatics", 1);
357 void
358 nsLayoutStatics::Release()
360 --sLayoutStaticRefcnt;
361 NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
362 "nsLayoutStatics");
364 if (!sLayoutStaticRefcnt)
365 Shutdown();